Skip to content

Commit

Permalink
Merge #676
Browse files Browse the repository at this point in the history
676: NO-TICKET: Skip GetDeploysResult for already-known empty blocks. r=afck a=afck



Co-authored-by: Andreas Fackler <[email protected]>
  • Loading branch information
bors[bot] and afck authored Dec 18, 2020
2 parents 3234e91 + 5974b84 commit 2233b8c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
38 changes: 18 additions & 20 deletions node/src/components/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ impl BlockExecutor {
.iter()
.map(|hash| **hash)
.collect::<SmallVec<_>>();
if deploy_hashes.is_empty() {
let result_event = move |_| Event::GetDeploysResult {
finalized_block,
deploys: VecDeque::new(),
};
return effect_builder.immediately().event(result_event);
}

let era_id = finalized_block.era_id();
let height = finalized_block.height();

Expand Down Expand Up @@ -431,31 +439,21 @@ impl<REv: ReactorEventT> Component<REv> for BlockExecutor {
match event {
Event::Request(BlockExecutorRequest::ExecuteBlock(finalized_block)) => {
debug!(?finalized_block, "execute block");
if finalized_block.proto_block().deploys().is_empty() {
return effect_builder
.immediately()
.event(move |_| Event::GetDeploysResult {
finalized_block,
deploys: VecDeque::new(),
});
}
effect_builder
.get_block_at_height_local(finalized_block.height())
.event(move |maybe_block| {
Event::BlockAlreadyExists(maybe_block.map(Box::new), finalized_block)
maybe_block.map(Box::new).map_or_else(
|| Event::BlockIsNew(finalized_block),
Event::BlockAlreadyExists,
)
})
}
Event::BlockAlreadyExists(maybe_block, finalized_block) => {
if let Some(block) = maybe_block {
effect_builder
.handle_linear_chain_block(block.take_header())
.ignore()
} else {
// If we haven't executed the block before in the past (for example during
// joining), do it now.
self.get_deploys(effect_builder, finalized_block)
}
}
Event::BlockAlreadyExists(block) => effect_builder
.handle_linear_chain_block(block.take_header())
.ignore(),
// If we haven't executed the block before in the past (for example during
// joining), do it now.
Event::BlockIsNew(finalized_block) => self.get_deploys(effect_builder, finalized_block),
Event::GetDeploysResult {
finalized_block,
deploys,
Expand Down
16 changes: 7 additions & 9 deletions node/src/components/block_executor/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use crate::{
/// Block executor component event.
#[derive(Debug, From)]
pub enum Event {
/// Indicates whether block has already been finalized and executed in the past.
BlockAlreadyExists(Option<Box<Block>>, FinalizedBlock),
/// Indicates that block has already been finalized and executed in the past.
BlockAlreadyExists(Box<Block>),
/// Indicates that a block is not known yet, and needs to be executed.
BlockIsNew(FinalizedBlock),
/// A request made of the Block executor component.
#[from]
Request(BlockExecutorRequest),
Expand Down Expand Up @@ -150,14 +152,10 @@ impl Display for Event {
state.state_root_hash,
result
),
Event::BlockAlreadyExists(maybe_block, fb) => {
write!(
f,
"Block at height: {} was executed before: {}",
fb.height(),
maybe_block.is_some()
)
Event::BlockAlreadyExists(block) => {
write!(f, "Block at height {} was executed before", block.height())
}
Event::BlockIsNew(fb) => write!(f, "Block at height {} is new", fb.height(),),
}
}
}
Expand Down

0 comments on commit 2233b8c

Please sign in to comment.