Skip to content

Commit

Permalink
Merge #3569
Browse files Browse the repository at this point in the history
3569: Change announcement type on completion of syncing a historical block r=Fraser999 a=Fraser999

This PR includes the following changes (in three separate commits):
* renames hot block to meta block
* `BlockSynchronizer` uses a `MetaBlockAnnouncement` rather than a `BlockSynchronizerAnnouncement::CompletedBlock` when completing sync for a historical block.  This now causes the event stream server to emit execution results for historical blocks
* various renames and tweaks to meta block types

I verified via nctl that execution results are emitted for historical blocks by a joining node.

Closes #3556.


Co-authored-by: Fraser Hutchison <fraser@casperlabs.io>
  • Loading branch information
casperlabs-bors-ng[bot] and Fraser999 committed Jan 13, 2023
2 parents c0e6e86 + 8eeb2f8 commit c34c5d3
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 392 deletions.
86 changes: 43 additions & 43 deletions node/src/components/block_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ use crate::{
components::{network::blocklist::BlocklistJustification, Component},
effect::{
announcements::{
BlockAccumulatorAnnouncement, FatalAnnouncement, HotBlockAnnouncement,
BlockAccumulatorAnnouncement, FatalAnnouncement, MetaBlockAnnouncement,
PeerBehaviorAnnouncement,
},
requests::{BlockAccumulatorRequest, BlockCompleteConfirmationRequest, StorageRequest},
EffectBuilder, EffectExt, Effects,
},
fatal,
types::{
BlockHash, BlockSignatures, FinalitySignature, HotBlock, HotBlockState, NodeId,
BlockHash, BlockSignatures, FinalitySignature, MetaBlock, MetaBlockState, NodeId,
ValidatorMatrix,
},
NodeRng,
Expand Down Expand Up @@ -309,7 +309,7 @@ impl BlockAccumulator {
fn register_block<REv>(
&mut self,
effect_builder: EffectBuilder<REv>,
hot_block: HotBlock,
meta_block: MetaBlock,
sender: Option<NodeId>,
) -> Effects<Event>
where
Expand All @@ -319,10 +319,10 @@ impl BlockAccumulator {
+ From<FatalAnnouncement>
+ Send,
{
let block_hash = hot_block.block.hash();
let block_hash = meta_block.block.hash();
debug!(%block_hash, "registering block");
let era_id = hot_block.block.header().era_id();
let block_height = hot_block.block.header().height();
let era_id = meta_block.block.header().era_id();
let block_height = meta_block.block.header().height();
if self
.local_tip
.as_ref()
Expand All @@ -338,7 +338,7 @@ impl BlockAccumulator {
Some(acceptor) => acceptor,
};

match acceptor.register_block(hot_block, sender) {
match acceptor.register_block(meta_block, sender) {
Ok(_) => match self.validator_matrix.validator_weights(era_id) {
Some(evw) => {
let (should_store, faulty_senders) = acceptor.should_store_block(&evw);
Expand Down Expand Up @@ -394,8 +394,8 @@ impl BlockAccumulator {
error!(%error, "unexpected detection of bogus validator, this is a bug");
Effects::new()
}
Error::HotBlockMerge(error) => {
error!(%error, "failed to merge hot blocks, this is a bug");
Error::MetaBlockMerge(error) => {
error!(%error, "failed to merge meta blocks, this is a bug");
Effects::new()
}
},
Expand Down Expand Up @@ -492,8 +492,8 @@ impl BlockAccumulator {
error!(%error, "unexpected detection of bogus validator, this is a bug");
Effects::new()
}
Error::HotBlockMerge(error) => {
error!(%error, "failed to merge hot blocks, this is a bug");
Error::MetaBlockMerge(error) => {
error!(%error, "failed to merge meta blocks, this is a bug");
Effects::new()
}
}
Expand All @@ -504,18 +504,18 @@ impl BlockAccumulator {
fn register_stored<REv>(
&self,
effect_builder: EffectBuilder<REv>,
maybe_hot_block: Option<HotBlock>,
maybe_meta_block: Option<MetaBlock>,
maybe_block_signatures: Option<BlockSignatures>,
) -> Effects<Event>
where
REv: From<BlockAccumulatorAnnouncement>
+ From<BlockCompleteConfirmationRequest>
+ From<HotBlockAnnouncement>
+ From<MetaBlockAnnouncement>
+ Send,
{
let mut effects = Effects::new();
if let Some(hot_block) = maybe_hot_block {
effects.extend(effect_builder.announce_hot_block(hot_block).ignore());
if let Some(meta_block) = maybe_meta_block {
effects.extend(effect_builder.announce_meta_block(meta_block).ignore());
};
if let Some(block_signatures) = maybe_block_signatures {
for finality_signature in block_signatures.finality_signatures() {
Expand Down Expand Up @@ -642,11 +642,11 @@ impl BlockAccumulator {
.set(self.block_children.len().try_into().unwrap_or(i64::MIN));
}

fn update_block_children(&mut self, hot_block: &HotBlock) {
if let Some(parent_hash) = hot_block.block.parent() {
fn update_block_children(&mut self, meta_block: &MetaBlock) {
if let Some(parent_hash) = meta_block.block.parent() {
if self
.block_children
.insert(*parent_hash, *hot_block.block.hash())
.insert(*parent_hash, *meta_block.block.hash())
.is_none()
{
self.metrics.known_child_blocks.inc();
Expand All @@ -669,50 +669,50 @@ impl BlockAccumulator {
{
let mut effects = match should_store {
ShouldStore::SufficientlySignedBlock {
hot_block,
meta_block,
block_signatures,
} => {
let block_hash = hot_block.block.hash();
let block_hash = meta_block.block.hash();
debug!(%block_hash, "storing block and finality signatures");
self.update_block_children(&hot_block);
self.update_block_children(&meta_block);
// The block wasn't executed yet, so we just put it to storage. An `ExecutedBlock`
// event will then re-trigger this flow and eventually mark it complete.
let cloned_signatures = block_signatures.clone();
effect_builder
.put_block_to_storage(Arc::clone(&hot_block.block))
.put_block_to_storage(Arc::clone(&meta_block.block))
.then(move |_| effect_builder.put_signatures_to_storage(cloned_signatures))
.event(move |_| Event::Stored {
maybe_hot_block: Some(hot_block),
maybe_meta_block: Some(meta_block),
maybe_block_signatures: Some(block_signatures),
})
}
ShouldStore::CompletedBlock {
hot_block,
meta_block,
block_signatures,
} => {
let block_hash = hot_block.block.hash();
let block_hash = meta_block.block.hash();
debug!(%block_hash, "storing finality signatures and marking block complete");
self.update_block_children(&hot_block);
self.update_block_children(&meta_block);
// The block was already executed, which means it is stored and we have the global
// state for it. As on this code path we also know it is sufficiently signed,
// we mark it as complete.
let block_height = hot_block.block.height();
let block_height = meta_block.block.height();
effect_builder
.put_signatures_to_storage(block_signatures.clone())
.then(move |_| effect_builder.mark_block_completed(block_height))
.event(move |_| Event::Stored {
maybe_hot_block: Some(hot_block),
maybe_meta_block: Some(meta_block),
maybe_block_signatures: Some(block_signatures),
})
}
ShouldStore::MarkComplete(hot_block) => {
let block_hash = hot_block.block.hash();
ShouldStore::MarkComplete(meta_block) => {
let block_hash = meta_block.block.hash();
debug!(%block_hash, "marking block complete");
let block_height = hot_block.block.height();
let block_height = meta_block.block.height();
effect_builder
.mark_block_completed(block_height)
.event(move |_| Event::Stored {
maybe_hot_block: Some(hot_block),
maybe_meta_block: Some(meta_block),
maybe_block_signatures: None,
})
}
Expand All @@ -724,7 +724,7 @@ impl BlockAccumulator {
effect_builder
.put_finality_signature_to_storage(signature)
.event(move |_| Event::Stored {
maybe_hot_block: None,
maybe_meta_block: None,
maybe_block_signatures: Some(block_signatures),
})
}
Expand All @@ -750,7 +750,7 @@ pub(crate) trait ReactorEvent:
+ From<PeerBehaviorAnnouncement>
+ From<BlockAccumulatorAnnouncement>
+ From<BlockCompleteConfirmationRequest>
+ From<HotBlockAnnouncement>
+ From<MetaBlockAnnouncement>
+ From<FatalAnnouncement>
+ Send
+ 'static
Expand All @@ -762,7 +762,7 @@ impl<REv> ReactorEvent for REv where
+ From<PeerBehaviorAnnouncement>
+ From<BlockAccumulatorAnnouncement>
+ From<BlockCompleteConfirmationRequest>
+ From<HotBlockAnnouncement>
+ From<MetaBlockAnnouncement>
+ From<FatalAnnouncement>
+ Send
+ 'static
Expand Down Expand Up @@ -793,8 +793,8 @@ impl<REv: ReactorEvent> Component<REv> for BlockAccumulator {
Effects::new()
}
Event::ReceivedBlock { block, sender } => {
let hot_block = HotBlock::new(Arc::new(*block), vec![], HotBlockState::new());
self.register_block(effect_builder, hot_block, Some(sender))
let meta_block = MetaBlock::new(Arc::new(*block), vec![], MetaBlockState::new());
self.register_block(effect_builder, meta_block, Some(sender))
}
Event::CreatedFinalitySignature { finality_signature } => {
self.register_finality_signature(effect_builder, *finality_signature, None)
Expand All @@ -805,16 +805,16 @@ impl<REv: ReactorEvent> Component<REv> for BlockAccumulator {
} => {
self.register_finality_signature(effect_builder, *finality_signature, Some(sender))
}
Event::ExecutedBlock { hot_block } => {
let height = hot_block.block.header().height();
let era_id = hot_block.block.header().era_id();
Event::ExecutedBlock { meta_block } => {
let height = meta_block.block.header().height();
let era_id = meta_block.block.header().era_id();
self.register_local_tip(height, era_id);
self.register_block(effect_builder, hot_block, None)
self.register_block(effect_builder, meta_block, None)
}
Event::Stored {
maybe_hot_block,
maybe_meta_block,
maybe_block_signatures,
} => self.register_stored(effect_builder, maybe_hot_block, maybe_block_signatures),
} => self.register_stored(effect_builder, maybe_meta_block, maybe_block_signatures),
}
}

Expand Down
Loading

0 comments on commit c34c5d3

Please sign in to comment.