Skip to content

Commit

Permalink
Update zebra-state/src/service.rs
Browse files Browse the repository at this point in the history
Co-authored-by: teor <[email protected]>
  • Loading branch information
arya2 and teor2345 authored Jan 10, 2023
1 parent f774822 commit d75e17a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions zebra-state/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,11 +1718,14 @@ impl Service<ReadRequest> for ReadStateService {
tracing::info!("attempting to validate and commit block proposal onto a cloned non-finalized state");
let mut latest_non_finalized_state = state.latest_non_finalized_state();

// Check that the previous block hash is the best chain tip if there are blocks in the
// non-finalized state. The previous block of a valid proposal must be on the best chain tip.
if let Some(true) = latest_non_finalized_state.best_tip().map(|(_, tip_hash)| tip_hash != prepared.hash) {
return Err("previous block hash is not the best chain tip".into())
}
// The previous block of a valid proposal must be on the best chain tip.
let Some((_best_tip_height, best_tip_hash) = read::best_tip(&latest_non_finalized_state, &state.db) {
if prepared.block.header.previous_block_hash != best_tip_hash {
return Err("proposal is not based on the current best chain tip: previous block hash must be the best chain tip".into());
}
} else {
return Err("state is empty: wait for Zebra to sync before submitting a proposal".into());
}

// This clone of the non-finalized state is dropped when this closure returns.
// The non-finalized state that's used in the rest of the state (including finalizing
Expand Down

0 comments on commit d75e17a

Please sign in to comment.