Skip to content

Commit

Permalink
Merge #674
Browse files Browse the repository at this point in the history
674: NDRS-693: Fix incorrect next_finalized on Block Proposer initialization r=fizyk20 a=fizyk20

https://casperlabs.atlassian.net/browse/NDRS-693

Co-authored-by: Bartłomiej Kamiński <[email protected]>
  • Loading branch information
bors[bot] and fizyk20 authored Dec 17, 2020
2 parents 434664a + 9f0191c commit ec8cdd6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
17 changes: 14 additions & 3 deletions node/src/components/block_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl BlockProposer {
pub(crate) fn new<REv>(
registry: Registry,
effect_builder: EffectBuilder<REv>,
next_finalized_block: BlockHeight,
) -> Result<(Self, Effects<Event>), prometheus::Error>
where
REv: From<Event> + From<StorageRequest> + From<StateStoreRequest> + Send + 'static,
Expand All @@ -106,7 +107,11 @@ impl BlockProposer {

(chainspec, sets)
}
.event(|(chainspec, sets)| Event::Loaded { chainspec, sets });
.event(move |(chainspec, sets)| Event::Loaded {
chainspec,
sets,
next_finalized_block,
});

let block_proposer = BlockProposer {
state: BlockProposerState::Initializing {
Expand Down Expand Up @@ -140,10 +145,16 @@ where
match (&mut self.state, event) {
(
BlockProposerState::Initializing { ref mut pending },
Event::Loaded { chainspec, sets },
Event::Loaded {
chainspec,
sets,
next_finalized_block,
},
) => {
let mut new_ready_state = BlockProposerReady {
sets: sets.unwrap_or_default(),
sets: sets
.unwrap_or_default()
.with_next_finalized(next_finalized_block),
deploy_config: chainspec.genesis.deploy_config,
state_key: deploy_sets::create_storage_key(&chainspec),
request_queue: Default::default(),
Expand Down
9 changes: 9 additions & 0 deletions node/src/components/block_proposer/deploy_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ impl Default for BlockProposerDeploySets {
}
}

impl BlockProposerDeploySets {
pub(super) fn with_next_finalized(self, next_finalized: BlockHeight) -> Self {
BlockProposerDeploySets {
next_finalized,
..self
}
}
}

impl Display for BlockProposerDeploySets {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
Expand Down
22 changes: 18 additions & 4 deletions node/src/components/block_proposer/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub enum Event {
chainspec: Arc<Chainspec>,
/// Loaded previously stored block proposer sets.
sets: Option<BlockProposerDeploySets>,
/// The height of the next expected finalized block.
next_finalized_block: BlockHeight,
},
/// A new deploy should be buffered.
BufferDeploy {
Expand All @@ -109,11 +111,23 @@ impl Display for Event {
match self {
Event::Request(req) => write!(f, "block-proposer request: {}", req),
Event::Loaded {
sets: Some(sets), ..
} => write!(f, "loaded block-proposer deploy sets: {}", sets),
Event::Loaded { sets: None, .. } => write!(
sets: Some(sets),
next_finalized_block,
..
} => write!(
f,
"loaded block-proposer deploy sets, none found in storage"
"loaded block-proposer deploy sets: {}; expected next finalized block: {}",
sets, next_finalized_block
),
Event::Loaded {
sets: None,
next_finalized_block,
..
} => write!(
f,
"loaded block-proposer deploy sets, none found in storage; \
expected next finalized block: {}",
next_finalized_block
),
Event::BufferDeploy { hash, .. } => write!(f, "block-proposer add {}", hash),
Event::Prune => write!(f, "block-proposer prune"),
Expand Down
10 changes: 8 additions & 2 deletions node/src/reactor/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,14 @@ impl reactor::Reactor for Reactor {
gossiper::get_deploy_from_storage::<Deploy, Event>,
registry,
)?;
let (block_proposer, block_proposer_effects) =
BlockProposer::new(registry.clone(), effect_builder)?;
let (block_proposer, block_proposer_effects) = BlockProposer::new(
registry.clone(),
effect_builder,
latest_block
.as_ref()
.map(|block| block.height() + 1)
.unwrap_or(0),
)?;
let mut effects = reactor::wrap_effects(Event::BlockProposer, block_proposer_effects);
// Post state hash is expected to be present.
let genesis_state_root_hash = chainspec_loader
Expand Down

0 comments on commit ec8cdd6

Please sign in to comment.