Skip to content

Commit

Permalink
Adds comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed May 17, 2024
1 parent 2703ec0 commit db817f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions zebra-chain/src/parameters/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ impl Default for ParametersBuilder {
.parse()
.expect("hard-coded hash parses"),
slow_start_interval: SLOW_START_INTERVAL,
// Testnet PoWLimit is defined as `2^251 - 1` on page 73 of the protocol specification:
// <https://zips.z.cash/protocol/protocol.pdf>
//
// `zcashd` converts the PoWLimit into a compact representation before
// using it to perform difficulty filter checks.
//
// The Zcash specification converts to compact for the default difficulty
// filter, but not for testnet minimum difficulty blocks. (ZIP 205 and
// ZIP 208 don't specify this conversion either.) See #1277 for details.
target_difficulty_limit: ExpandedDifficulty::from((U256::one() << 251) - 1)
.to_compact()
.to_expanded()
Expand Down Expand Up @@ -359,6 +368,7 @@ impl Parameters {
network_name: "Regtest".to_string(),
..Self::build()
.with_genesis_hash(REGTEST_GENESIS_HASH)
// This value is chosen to match zcashd, see: <https://github.com/zcash/zcash/blob/master/src/chainparams.cpp#L654>
.with_target_difficulty_limit(U256::from_big_endian(&[0x0f; 32]))
.with_disable_pow(true)
.with_slow_start_interval(Height::MIN)
Expand Down
5 changes: 3 additions & 2 deletions zebra-chain/src/work/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,10 @@ impl ParameterDifficulty for Network {
/// See [`ParameterDifficulty::target_difficulty_limit`]
fn target_difficulty_limit(&self) -> ExpandedDifficulty {
let limit: U256 = match self {
/* 2^243 - 1 */
// Mainnet PoWLimit is defined as `2^243 - 1` on page 73 of the protocol specification:
// <https://zips.z.cash/protocol/protocol.pdf>
Network::Mainnet => (U256::one() << 243) - 1,
/* 2^251 - 1 for the default testnet */
// 2^251 - 1 for the default testnet, see `testnet::ParametersBuilder::default`()
Network::Testnet(params) => return params.target_difficulty_limit(),
};

Expand Down

0 comments on commit db817f5

Please sign in to comment.