fix(tree): disable cached trie updates for chains with >1 block (#7753)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Roman Krasiuk
2024-04-21 11:20:55 +02:00
committed by GitHub
parent d81cf8aa5c
commit 223dde200f
3 changed files with 9 additions and 25 deletions

View File

@ -26,7 +26,8 @@ pub struct Chain {
/// This state also contains the individual changes that lead to the current state.
state: BundleStateWithReceipts,
/// State trie updates after block is added to the chain.
/// NOTE: Currently, trie updates are present only if the block extends canonical chain.
/// NOTE: Currently, trie updates are present only for
/// single-block chains that extend the canonical chain.
trie_updates: Option<TrieUpdates>,
}
@ -210,15 +211,10 @@ impl Chain {
/// Append a single block with state to the chain.
/// This method assumes that blocks attachment to the chain has already been validated.
pub fn append_block(
&mut self,
block: SealedBlockWithSenders,
state: BundleStateWithReceipts,
trie_updates: Option<TrieUpdates>,
) {
pub fn append_block(&mut self, block: SealedBlockWithSenders, state: BundleStateWithReceipts) {
self.blocks.insert(block.number, block);
self.state.extend(state);
self.append_trie_updates(trie_updates);
self.trie_updates.take(); // reset
}
/// Merge two chains by appending the given chain into the current one.
@ -238,23 +234,11 @@ impl Chain {
// Insert blocks from other chain
self.blocks.extend(other.blocks);
self.state.extend(other.state);
self.append_trie_updates(other.trie_updates);
self.trie_updates.take(); // reset
Ok(())
}
/// Append trie updates.
/// If existing or incoming trie updates are not set, reset as neither is valid anymore.
fn append_trie_updates(&mut self, other_trie_updates: Option<TrieUpdates>) {
if let Some((trie_updates, other)) = self.trie_updates.as_mut().zip(other_trie_updates) {
// Extend trie updates.
trie_updates.extend(other);
} else {
// Reset trie updates as they are no longer valid.
self.trie_updates.take();
}
}
/// Split this chain at the given block.
///
/// The given block will be the last block in the first returned chain.