Skip to content

Commit

Permalink
use genesis_hash as first checkpoint when checkpoints are missing for…
Browse files Browse the repository at this point in the history
… configured testnets too
  • Loading branch information
arya2 committed Apr 22, 2024
1 parent 6633622 commit 622293f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions zebra-consensus/src/checkpoint/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ impl ParameterCheckpoint for Network {
}

fn checkpoint_list(&self) -> CheckpointList {
let checkpoints_for_network = match self {
Network::Mainnet => MAINNET_CHECKPOINTS,
Network::Testnet(params) if !params.is_regtest() => TESTNET_CHECKPOINTS,
// Returns only the genesis checkpoint for Regtest
Network::Testnet(_params) => {
// It's okay to skip checking the hard-coded genesis checkpoint is the genesis checkpoint
return CheckpointList::from_list([(block::Height(0), self.genesis_hash())])
.expect("hard-coded checkpoint list parses and validates");
}
let (checkpoints_for_network, should_fallback_to_genesis_hash_as_checkpoint) = match self {
Network::Mainnet => (MAINNET_CHECKPOINTS, false),
Network::Testnet(params) if params.is_default_testnet() => (TESTNET_CHECKPOINTS, false),
Network::Testnet(_params) => (TESTNET_CHECKPOINTS, true),
};

// Check that the list starts with the correct genesis block and parses checkpoint list.
Expand All @@ -87,6 +82,10 @@ impl ParameterCheckpoint for Network {
Ok((block::Height(0), hash)) if hash == self.genesis_hash() => checkpoints_for_network
.parse()
.expect("hard-coded checkpoint list parses and validates"),
_ if should_fallback_to_genesis_hash_as_checkpoint => {
CheckpointList::from_list([(block::Height(0), self.genesis_hash())])
.expect("hard-coded checkpoint list parses and validates")
}
Ok((block::Height(0), _)) => {
panic!("the genesis checkpoint does not match the Mainnet or Testnet genesis hash")
}
Expand Down

0 comments on commit 622293f

Please sign in to comment.