Ensure that `BridgeTree` state is checkpointed when constructing from a frontier.

This commit is contained in:
Kris Nuttycombe 2023-03-27 09:54:21 -06:00
parent 978da59c67
commit 02341ece26
1 changed files with 5 additions and 3 deletions

View File

@ -536,8 +536,8 @@ impl<H, C, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
impl<H: Hashable + Ord + Clone, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C, DEPTH> { impl<H: Hashable + Ord + Clone, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
/// Construct a new BridgeTree that will start recording changes from the state of /// Construct a new BridgeTree that will start recording changes from the state of
/// the specified frontier. /// the specified frontier.
pub fn from_frontier(max_checkpoints: usize, frontier: NonEmptyFrontier<H>) -> Self { pub fn from_frontier(max_checkpoints: usize, frontier: NonEmptyFrontier<H>, checkpoint_id: C) -> Self {
Self { let mut bridge = Self {
prior_bridges: vec![], prior_bridges: vec![],
current_bridge: Some(MerkleBridge::from_parts( current_bridge: Some(MerkleBridge::from_parts(
None, None,
@ -548,7 +548,9 @@ impl<H: Hashable + Ord + Clone, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C
saved: BTreeMap::new(), saved: BTreeMap::new(),
checkpoints: VecDeque::new(), checkpoints: VecDeque::new(),
max_checkpoints, max_checkpoints,
} };
bridge.checkpoint(checkpoint_id);
bridge
} }
/// Construct a new BridgeTree from its constituent parts, checking for internal /// Construct a new BridgeTree from its constituent parts, checking for internal