Use blockid as tip (#549)

This commit is contained in:
Daniel Sanchez 2024-01-02 16:11:53 +01:00 committed by GitHub
parent 361b41cf27
commit 37cf900617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -18,7 +18,7 @@ pub struct Carnot<O: Overlay> {
highest_voted_view: View,
local_high_qc: StandardQc,
safe_blocks: HashMap<BlockId, Block>,
tip: Block,
tip: BlockId,
last_view_timeout_qc: Option<TimeoutQc>,
overlay: O,
}
@ -33,7 +33,7 @@ impl<O: Overlay> Carnot<O> {
last_view_timeout_qc: None,
overlay,
safe_blocks: [(genesis_block.id, genesis_block.clone())].into(),
tip: genesis_block,
tip: genesis_block.id,
}
}
@ -51,7 +51,7 @@ impl<O: Overlay> Carnot<O> {
/// Return the most recent safe block
pub fn tip(&self) -> Block {
self.tip.clone()
self.safe_blocks[&self.tip].clone()
}
/// Upon reception of a block
@ -97,8 +97,8 @@ impl<O: Overlay> Carnot<O> {
let mut new_state = self.clone();
if new_state.block_is_safe(block.clone()) {
new_state.safe_blocks.insert(block.id, block.clone());
if block.view > new_state.tip.view {
new_state.tip = block.clone();
if block.view > new_state.tip().view {
new_state.tip = block.id;
}
new_state.update_high_qc(block.parent_qc);
} else {