Use blockid as tip (#549)
This commit is contained in:
parent
361b41cf27
commit
37cf900617
|
@ -18,7 +18,7 @@ pub struct Carnot<O: Overlay> {
|
||||||
highest_voted_view: View,
|
highest_voted_view: View,
|
||||||
local_high_qc: StandardQc,
|
local_high_qc: StandardQc,
|
||||||
safe_blocks: HashMap<BlockId, Block>,
|
safe_blocks: HashMap<BlockId, Block>,
|
||||||
tip: Block,
|
tip: BlockId,
|
||||||
last_view_timeout_qc: Option<TimeoutQc>,
|
last_view_timeout_qc: Option<TimeoutQc>,
|
||||||
overlay: O,
|
overlay: O,
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ impl<O: Overlay> Carnot<O> {
|
||||||
last_view_timeout_qc: None,
|
last_view_timeout_qc: None,
|
||||||
overlay,
|
overlay,
|
||||||
safe_blocks: [(genesis_block.id, genesis_block.clone())].into(),
|
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
|
/// Return the most recent safe block
|
||||||
pub fn tip(&self) -> Block {
|
pub fn tip(&self) -> Block {
|
||||||
self.tip.clone()
|
self.safe_blocks[&self.tip].clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upon reception of a block
|
/// Upon reception of a block
|
||||||
|
@ -97,8 +97,8 @@ impl<O: Overlay> Carnot<O> {
|
||||||
let mut new_state = self.clone();
|
let mut new_state = self.clone();
|
||||||
if new_state.block_is_safe(block.clone()) {
|
if new_state.block_is_safe(block.clone()) {
|
||||||
new_state.safe_blocks.insert(block.id, block.clone());
|
new_state.safe_blocks.insert(block.id, block.clone());
|
||||||
if block.view > new_state.tip.view {
|
if block.view > new_state.tip().view {
|
||||||
new_state.tip = block.clone();
|
new_state.tip = block.id;
|
||||||
}
|
}
|
||||||
new_state.update_high_qc(block.parent_qc);
|
new_state.update_high_qc(block.parent_qc);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue