Skip to content

Commit

Permalink
adds parallel contextual validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 16, 2022
1 parent 3472407 commit a6eb045
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions zebra-state/src/service.rs
Original file line number Diff line number Diff line change
@@ -800,6 +800,8 @@ impl ReadStateService {

/// Check the contextual validity of a block in the best chain
#[cfg(feature = "getblocktemplate-rpcs")]
#[allow(clippy::unwrap_in_result)]
#[tracing::instrument(level = "debug", skip_all)]
fn check_best_chain_contextual_validity(
&self,
block: PreparedBlock,
@@ -821,19 +823,35 @@ impl ReadStateService {
check::anchors::fetch_sprout_final_treestates(&self.db, best_chain, &block);

let contextual = best_chain.new_contextually_valid_block(block, &self.db)?;
let mut block_commitment_result = None;
let mut sprout_anchor_result = None;

rayon::in_place_scope_fifo(|scope| {
// Clone function arguments for different threads
let block = Arc::clone(&contextual.block);

scope.spawn_fifo(|_scope| {
block_commitment_result =
Some(check::anchors::sprout_anchors_refer_to_treestates(
sprout_final_treestates,
block,
contextual.height,
contextual.transaction_hashes,
));
});

check::anchors::sprout_anchors_refer_to_treestates(
sprout_final_treestates,
Arc::clone(&contextual.block),
contextual.height,
contextual.transaction_hashes,
)?;
scope.spawn_fifo(|_scope| {
sprout_anchor_result =
Some(check::block_commitment_is_valid_for_chain_history(
contextual.block,
self.network,
&best_chain.history_tree,
));
});
});

check::block_commitment_is_valid_for_chain_history(
contextual.block,
self.network,
&best_chain.history_tree,
)?;
block_commitment_result.expect("scope has finished")?;
sprout_anchor_result.expect("scope has finished")?;
} else {
let next_valid_height = self
.db

0 comments on commit a6eb045

Please sign in to comment.