Skip to content

Commit

Permalink
feat: reset trie updates on make_canonical (#8370)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez authored May 27, 2024
1 parent 4dd2ad9 commit 89e55c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,23 @@ where
"Canonicalization finished"
);

// clear trie updates for other childs
self.block_indices()
.fork_to_child()
.get(&old_tip.hash)
.cloned()
.unwrap_or_default()
.into_iter()
.for_each(|child| {
if let Some(chain_id) = self.block_indices().get_blocks_chain_id(&child) {
if let Some(chain) = self.state.chains.get_mut(&chain_id) {
chain.clear_trie_updates();
}
}
});

durations_recorder.record_relative(MakeCanonicalAction::ClearTrieUpdatesForOtherChilds);

// Send notification about new canonical chain and return outcome of canonicalization.
let outcome = CanonicalOutcome::Committed { head: chain_notification.tip().header.clone() };
let _ = self.canon_state_notification_sender.send(chain_notification);
Expand Down
5 changes: 5 additions & 0 deletions crates/blockchain-tree/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub(crate) enum MakeCanonicalAction {
RevertCanonicalChainFromDatabase,
/// Inserting an old canonical chain.
InsertOldCanonicalChain,
/// Clearing trie updates of other childs chains after fork choice update.
ClearTrieUpdatesForOtherChilds,
}

impl MakeCanonicalAction {
Expand All @@ -104,6 +106,9 @@ impl MakeCanonicalAction {
"revert canonical chain from database"
}
MakeCanonicalAction::InsertOldCanonicalChain => "insert old canonical chain",
MakeCanonicalAction::ClearTrieUpdatesForOtherChilds => {
"clear trie updates of other childs chains after fork choice update"
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/storage/provider/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ impl Chain {
self.trie_updates.as_ref()
}

/// Remove cached trie updates for this chain.
pub fn clear_trie_updates(&mut self) {
self.trie_updates.take();
}

/// Get post state of this chain
pub fn state(&self) -> &BundleStateWithReceipts {
&self.state
Expand Down

0 comments on commit 89e55c4

Please sign in to comment.