Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions node/src/components/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,39 @@ impl Display for Event {
deploys,
} => write!(
f,
"fetch deploys for finalized block {} has {} deploys",
state.finalized_block.proto_block().hash(),
"fetch deploys for finalized block with height {} has {} deploys",
state.finalized_block.height(),
deploys.len()
),
Event::DeployExecutionResult {
state,
result: Ok(_),
} => write!(
f,
"deploys execution result for finalized block {} with pre-state hash {}: success",
state.finalized_block.proto_block().hash(),
"deploys execution result for finalized block with height {} with pre-state hash {}: success",
state.finalized_block.height(),
state.pre_state_hash
),
Event::DeployExecutionResult {
state,
result: Err(_),
} => write!(
f,
"deploys execution result for finalized block {} with pre-state hash {}: root not found",
state.finalized_block.proto_block().hash(),
"deploys execution result for finalized block with height {} with pre-state hash {}: root not found",
state.finalized_block.height(),
state.pre_state_hash
),
Event::CommitExecutionEffects { state, commit_result: Ok(CommitResult::Success { state_root, ..})} => write!(
f,
"commit execution effects for finalized block {} with pre-state hash {}: success with post-state hash {}",
state.finalized_block.proto_block().hash(),
"commit execution effects for finalized block with height {} with pre-state hash {}: success with post-state hash {}",
state.finalized_block.height(),
state.pre_state_hash,
state_root,
),
Event::CommitExecutionEffects { state, commit_result } => write!(
f,
"commit execution effects for finalized block {} with pre-state hash {}: failed {:?}",
state.finalized_block.proto_block().hash(),
"commit execution effects for finalized block with height {} with pre-state hash {}: failed {:?}",
state.finalized_block.height(),
state.pre_state_hash,
commit_result,
),
Expand Down Expand Up @@ -148,7 +148,7 @@ type BlockHeight = u64;
/// The Block executor component.
#[derive(Debug, Default)]
pub(crate) struct BlockExecutor {
genesis_post_state_hash: Option<Digest>,
genesis_post_state_hash: Digest,
/// A mapping from proto block to executed block's ID and post-state hash, to allow
/// identification of a parent block's details once a finalized block has been executed.
///
Expand All @@ -160,7 +160,7 @@ pub(crate) struct BlockExecutor {
impl BlockExecutor {
pub(crate) fn new(genesis_post_state_hash: Digest) -> Self {
BlockExecutor {
genesis_post_state_hash: Some(genesis_post_state_hash),
genesis_post_state_hash,
parent_map: HashMap::new(),
}
}
Expand Down Expand Up @@ -291,8 +291,8 @@ impl BlockExecutor {
}

fn pre_state_hash(&mut self, finalized_block: &FinalizedBlock) -> Digest {
if finalized_block.is_genesis_child() && self.genesis_post_state_hash.is_some() {
self.genesis_post_state_hash.take().unwrap()
if finalized_block.is_genesis_child() {
self.genesis_post_state_hash
} else {
// Try to get the parent's post-state-hash from the `parent_map`.
// We're subtracting 1 from the height as we want to get _parent's_ post-state hash.
Expand Down
1 change: 0 additions & 1 deletion node/src/components/consensus/consensus_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub(crate) enum ConsensusProtocolResult<I, C: ConsensusValueT, VID> {
/// TODO: Add more details that are necessary for block creation.
CreateNewBlock {
block_context: BlockContext,
opt_parent: Option<C>,
},
/// A block was finalized. The timestamp is from when the block was proposed.
FinalizedBlock {
Expand Down
33 changes: 8 additions & 25 deletions node/src/components/consensus/era_supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ pub(crate) struct Era<I, R: Rng + CryptoRng + ?Sized> {
consensus: Box<dyn ConsensusProtocol<I, ProtoBlock, PublicKey, R>>,
/// The height of this era's first block.
start_height: u64,
/// The previous era's switch block. `None` for era 0.
prev_switch_block: Option<ProtoBlock>,
}

pub(crate) struct EraSupervisor<I, R: Rng + CryptoRng + ?Sized> {
Expand Down Expand Up @@ -119,7 +117,6 @@ where
validator_stakes,
highway_config.genesis_era_start_timestamp,
0,
None,
rng,
);
let effects = era_supervisor
Expand Down Expand Up @@ -152,7 +149,6 @@ where
validator_stakes: Vec<(PublicKey, Motes)>,
start_time: Timestamp,
start_height: u64,
prev_switch_block: Option<ProtoBlock>,
rng: &mut R,
) -> Vec<ConsensusProtocolResult<I, ProtoBlock, PublicKey>> {
if self.active_eras.contains_key(&era_id) {
Expand Down Expand Up @@ -207,7 +203,6 @@ where
let era = Era {
consensus: Box::new(highway),
start_height,
prev_switch_block,
};
let _ = self.active_eras.insert(era_id, era);

Expand Down Expand Up @@ -393,25 +388,14 @@ where
.set_timeout(timediff.into())
.event(move |_| Event::Timer { era_id, timestamp })
}
ConsensusProtocolResult::CreateNewBlock {
block_context,
opt_parent,
} => {
let opt_parent = opt_parent.or_else(|| {
self.era_supervisor
.active_eras
.get(&era_id)?
.prev_switch_block
.clone()
});
self.effect_builder
.request_proto_block(block_context, opt_parent, self.rng.gen())
.event(move |(proto_block, block_context)| Event::NewProtoBlock {
era_id,
proto_block,
block_context,
})
}
ConsensusProtocolResult::CreateNewBlock { block_context } => self
.effect_builder
.request_proto_block(block_context, self.rng.gen())
.event(move |(proto_block, block_context)| Event::NewProtoBlock {
era_id,
proto_block,
block_context,
}),
ConsensusProtocolResult::FinalizedBlock {
value: proto_block,
new_equivocators,
Expand Down Expand Up @@ -458,7 +442,6 @@ where
validator_stakes,
fb.timestamp(),
fb.height() + 1,
Some(fb.proto_block().clone()),
self.rng,
);
let new_era_id = era_id.successor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) enum Effect<C: Context> {
ScheduleTimer(Timestamp),
/// `propose` needs to be called with a value for a new block with the specified block context
/// and parent value.
RequestNewBlock(BlockContext, Option<C::ConsensusValue>),
RequestNewBlock(BlockContext),
}

/// A validator that actively participates in consensus by creating new vertices.
Expand Down Expand Up @@ -172,10 +172,9 @@ impl<C: Context> ActiveValidator<C> {
}
let opt_parent = opt_parent_hash.map(|bh| state.block(bh));
let height = opt_parent.map_or(0, |block| block.height);
let opt_value = opt_parent.map(|block| block.value.clone());
self.next_proposal = Some((timestamp, panorama));
let bctx = BlockContext::new(timestamp, height);
Some(Effect::RequestNewBlock(bctx, opt_value))
Some(Effect::RequestNewBlock(bctx))
}

/// Proposes a new block with the given consensus value.
Expand Down Expand Up @@ -407,7 +406,7 @@ mod tests {

// Alice wants to propose a block, and also make her witness vote at 426.
let bctx = match &*alice_av.handle_timer(416.into(), &state, &mut rng) {
[Eff::ScheduleTimer(timestamp), Eff::RequestNewBlock(bctx, None)]
[Eff::ScheduleTimer(timestamp), Eff::RequestNewBlock(bctx)]
if *timestamp == 426.into() =>
{
bctx.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ impl From<Effect<TestContext>> for HighwayMessage {
// validators so for them it's just `Vertex` that needs to be validated.
Effect::NewVertex(ValidVertex(v)) => HighwayMessage::NewVertex(v),
Effect::ScheduleTimer(t) => HighwayMessage::Timer(t),
Effect::RequestNewBlock(block_context, _opt_parent) => {
HighwayMessage::RequestBlock(block_context)
}
Effect::RequestNewBlock(block_context) => HighwayMessage::RequestBlock(block_context),
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions node/src/components/consensus/protocols/highway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ impl<I: NodeIdT, C: Context> HighwayProtocol<I, C> {
AvEffect::ScheduleTimer(timestamp) => {
vec![ConsensusProtocolResult::ScheduleTimer(timestamp)]
}
AvEffect::RequestNewBlock(block_context, opt_parent) => {
vec![ConsensusProtocolResult::CreateNewBlock {
block_context,
opt_parent,
}]
AvEffect::RequestNewBlock(block_context) => {
vec![ConsensusProtocolResult::CreateNewBlock { block_context }]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions node/src/components/deploy_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl DeployBuffer {
self.collected_deploys
.retain(|deploy_hash, _| !deploys.contains_key(deploy_hash));
self.finalized.insert(block, deploys);
} else {
} else if !block.is_empty() {
// TODO: Events are not guaranteed to be handled in order, so this could happen!
error!("finalized block that hasn't been processed!");
}
Expand Down Expand Up @@ -255,7 +255,7 @@ where
}
Event::Buffer { hash, header } => self.add_deploy(hash, *header),
Event::ProposedProtoBlock(block) => {
let (hash, _, deploys, _) = block.destructure();
let (hash, deploys, _) = block.destructure();
self.added_block(hash, deploys)
}
Event::FinalizedProtoBlock(block) => self.finalized_block(*block.hash()),
Expand Down
12 changes: 1 addition & 11 deletions node/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ impl<REv> EffectBuilder<REv> {
pub(crate) async fn request_proto_block(
self,
block_context: BlockContext,
maybe_parent: Option<ProtoBlock>,
random_bit: bool,
) -> (ProtoBlock, BlockContext)
where
Expand All @@ -648,16 +647,7 @@ impl<REv> EffectBuilder<REv> {
.await
.into_iter()
.collect();
// The only circumstance where `maybe_parent` is `None` is for the very first proto block,
// i.e. the one immediately after the genesis block. In this case, just use
// `Digest::default`, and the block executor (which knows the post-state hash of the genesis
// block) will apply the executed block's parent hash correctly.
let parent_hash = maybe_parent
.as_ref()
.map(ProtoBlock::hash)
.copied()
.unwrap_or_default();
let proto_block = ProtoBlock::new(parent_hash, deploys, random_bit);
let proto_block = ProtoBlock::new(deploys, random_bit);
(proto_block, block_context)
}

Expand Down
Loading