forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle max_inbound_peers and max_outbound_peers properly (paritytech#27)
* Use API from rust-bitcoin instead of calling bitcoinconsensus directly * Nits * Introduce chain_params module * Check whether utxo is spent in current block * Introduce const MEDIAN_TIME_SPAN in chain_params * Use chain_params.csv_height * Handle max_outbound_peers properly * Handle max_inbound_peers properly * Add script_flag_exceptions * Fix tests
- Loading branch information
1 parent
bdf8582
commit f56e068
Showing
12 changed files
with
276 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use bitcoin::consensus::Params; | ||
use bitcoin::{BlockHash, Network}; | ||
use std::collections::HashMap; | ||
|
||
pub const MEDIAN_TIME_SPAN: usize = 11; | ||
|
||
/// Extended [`Params`]. | ||
#[derive(Debug, Clone)] | ||
pub struct ChainParams { | ||
/// Chain params defined in rust-bitcoin. | ||
pub params: Params, | ||
/// Block height at which CSV becomes active. | ||
pub csv_height: u32, | ||
/// Block height at which Segwit becomes active. | ||
pub segwit_height: u32, | ||
pub script_flag_exceptions: HashMap<BlockHash, u32>, | ||
} | ||
|
||
impl ChainParams { | ||
/// Constructs a new instance of [`ChainParams`]. | ||
// https://github.com/bitcoin/bitcoin/blob/6f9db1ebcab4064065ccd787161bf2b87e03cc1f/src/kernel/chainparams.cpp#L71 | ||
pub fn new(network: Network) -> Self { | ||
let params = Params::new(network); | ||
match network { | ||
Network::Bitcoin => Self { | ||
params, | ||
csv_height: 419328, // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5 | ||
segwit_height: 481824, // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893 | ||
script_flag_exceptions: [ | ||
// BIP16 exception | ||
( | ||
"00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22", | ||
bitcoinconsensus::VERIFY_NONE, | ||
), | ||
// Taproot exception | ||
( | ||
"0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad", | ||
bitcoinconsensus::VERIFY_P2SH | bitcoinconsensus::VERIFY_WITNESS, | ||
), | ||
] | ||
.into_iter() | ||
.map(|(block_hash, flag)| { | ||
(block_hash.parse().expect("Hash must be valid; qed"), flag) | ||
}) | ||
.collect(), | ||
}, | ||
Network::Testnet => Self { | ||
params, | ||
csv_height: 770112, // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb | ||
segwit_height: 834624, // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca | ||
script_flag_exceptions: HashMap::from_iter([ | ||
// BIP16 exception | ||
( | ||
"00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105" | ||
.parse() | ||
.expect("Hash must be valid; qed"), | ||
bitcoinconsensus::VERIFY_NONE, | ||
), | ||
]), | ||
}, | ||
Network::Signet => Self { | ||
params, | ||
csv_height: 1, | ||
segwit_height: 1, | ||
script_flag_exceptions: Default::default(), | ||
}, | ||
Network::Regtest => Self { | ||
params, | ||
csv_height: 1, // Always active unless overridden | ||
segwit_height: 0, // Always active unless overridden | ||
script_flag_exceptions: Default::default(), | ||
}, | ||
_ => unreachable!("Unknown Bitcoin Network"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod block_executor; | ||
mod block_import; | ||
mod chain_params; | ||
mod import_queue; | ||
mod verification; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.