diff --git a/consensus-engine/src/lib.rs b/consensus-engine/src/lib.rs index 4440d37d..6a654351 100644 --- a/consensus-engine/src/lib.rs +++ b/consensus-engine/src/lib.rs @@ -18,7 +18,7 @@ pub struct Carnot { highest_voted_view: View, local_high_qc: StandardQc, safe_blocks: HashMap, - tip: Block, + tip: BlockId, last_view_timeout_qc: Option, overlay: O, } @@ -33,7 +33,7 @@ impl Carnot { 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 Carnot { /// 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 Carnot { 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 {