Skip to content

Commit

Permalink
Merge of #5257
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 11, 2022
2 parents 036a982 + a0a65b6 commit cdd40b6
Show file tree
Hide file tree
Showing 35 changed files with 1,230 additions and 639 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions zebra-consensus/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,7 @@ where
let transaction = Buffer::new(BoxService::new(transaction), VERIFIER_BUFFER_BOUND);

// block verification

let list = CheckpointList::new(network);

let max_checkpoint_height = if config.checkpoint_sync {
list.max_height()
} else {
list.min_height_in_range(network.mandatory_checkpoint_height()..)
.expect("hardcoded checkpoint list extends past canopy activation")
};
let (list, max_checkpoint_height) = init_checkpoint_list(config, network);

let tip = match state_service
.ready()
Expand Down Expand Up @@ -275,3 +267,20 @@ where
max_checkpoint_height,
)
}

/// Parses the checkpoint list for `network` and `config`.
/// Returns the checkpoint list and maximum checkpoint height.
pub fn init_checkpoint_list(config: Config, network: Network) -> (CheckpointList, Height) {
// TODO: Zebra parses the checkpoint list twice at startup.
// Instead, cache the checkpoint list for each `network`.
let list = CheckpointList::new(network);

let max_checkpoint_height = if config.checkpoint_sync {
list.max_height()
} else {
list.min_height_in_range(network.mandatory_checkpoint_height()..)
.expect("hardcoded checkpoint list extends past canopy activation")
};

(list, max_checkpoint_height)
}
1 change: 1 addition & 0 deletions zebra-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dirs = "4.0.0"
displaydoc = "0.2.3"
futures = "0.3.24"
hex = "0.4.3"
indexmap = "1.9.1"
itertools = "0.10.5"
lazy_static = "1.4.0"
metrics = "0.20.1"
Expand Down
4 changes: 4 additions & 0 deletions zebra-state/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct CommitBlockError(#[from] ValidateContextError);
#[non_exhaustive]
#[allow(missing_docs)]
pub enum ValidateContextError {
#[error("block parent not found in any chain")]
#[non_exhaustive]
NotReadyToBeCommitted,

#[error("block height {candidate_height:?} is lower than the current finalized height {finalized_tip_height:?}")]
#[non_exhaustive]
OrphanedBlock {
Expand Down
Loading

0 comments on commit cdd40b6

Please sign in to comment.