Add network to CheckpointVerifier

This refactor allows us to re-use some block checks in the checkpoint
verifier.
This commit is contained in:
teor 2021-03-11 12:07:37 +10:00
parent 8e0fac5336
commit 252affdf84
3 changed files with 24 additions and 13 deletions

View File

@ -153,7 +153,7 @@ where
tracing::info!(?tip, ?max_checkpoint_height, "initializing chain verifier");
let block = BlockVerifier::new(network, state_service.clone());
let checkpoint = CheckpointVerifier::from_checkpoint_list(list, tip, state_service);
let checkpoint = CheckpointVerifier::from_checkpoint_list(list, network, tip, state_service);
Buffer::new(
BoxService::new(ChainVerifier {

View File

@ -108,6 +108,9 @@ where
/// The checkpoint list for this verifier.
checkpoint_list: CheckpointList,
/// The network rules used by this verifier.
network: Network,
/// The hash of the initial tip, if any.
initial_tip_hash: Option<block::Hash>,
@ -164,11 +167,11 @@ where
?initial_tip,
"initialising CheckpointVerifier"
);
Self::from_checkpoint_list(checkpoint_list, initial_tip, state_service)
Self::from_checkpoint_list(checkpoint_list, network, initial_tip, state_service)
}
/// Return a checkpoint verification service using `list`, `initial_tip`,
/// and `state_service`.
/// Return a checkpoint verification service using `list`, `network`,
/// `initial_tip`, and `state_service`.
///
/// Assumes that the provided genesis checkpoint is correct.
///
@ -181,18 +184,20 @@ where
#[allow(dead_code)]
pub(crate) fn from_list(
list: impl IntoIterator<Item = (block::Height, block::Hash)>,
network: Network,
initial_tip: Option<(block::Height, block::Hash)>,
state_service: S,
) -> Result<Self, VerifyCheckpointError> {
Ok(Self::from_checkpoint_list(
CheckpointList::from_list(list).map_err(VerifyCheckpointError::CheckpointList)?,
network,
initial_tip,
state_service,
))
}
/// Return a checkpoint verification service using `checkpoint_list`,
/// `initial_tip`, and `state_service`.
/// `network`, `initial_tip`, and `state_service`.
///
/// Assumes that the provided genesis checkpoint is correct.
///
@ -200,6 +205,7 @@ where
/// hard-coded checkpoint lists. See that function for more details.
pub(crate) fn from_checkpoint_list(
checkpoint_list: CheckpointList,
network: Network,
initial_tip: Option<(block::Height, block::Hash)>,
state_service: S,
) -> Self {
@ -220,6 +226,7 @@ where
};
CheckpointVerifier {
checkpoint_list,
network,
initial_tip_hash,
state_service,
queued: BTreeMap::new(),

View File

@ -49,7 +49,7 @@ async fn single_item_checkpoint_list() -> Result<(), Report> {
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -133,7 +133,7 @@ async fn multi_item_checkpoint_list() -> Result<(), Report> {
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, None, state_service)
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -280,9 +280,13 @@ async fn continuous_blockchain(
let state_service = ServiceBuilder::new()
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, initial_tip, state_service.clone())
.map_err(|e| eyre!(e))?;
let mut checkpoint_verifier = CheckpointVerifier::from_list(
checkpoint_list,
network,
initial_tip,
state_service.clone(),
)
.map_err(|e| eyre!(e))?;
// Setup checks
if restart_height.is_some() {
@ -457,7 +461,7 @@ async fn block_higher_than_max_checkpoint_fail() -> Result<(), Report> {
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -536,7 +540,7 @@ async fn wrong_checkpoint_hash_fail() -> Result<(), Report> {
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -720,7 +724,7 @@ async fn checkpoint_drop_cancel() -> Result<(), Report> {
.buffer(1)
.service(zebra_state::init(zebra_state::Config::ephemeral(), Mainnet));
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, None, state_service)
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(