Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use mempool::Mempool;
use payload::PayloadOrTask;
use rustc_hash::FxHashMap;
use std::collections::hash_map::Entry;
use std::collections::{BTreeMap, HashMap};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::sync::{
Arc, Mutex, RwLock,
atomic::{AtomicBool, AtomicUsize, Ordering},
Expand Down Expand Up @@ -727,6 +727,7 @@ impl Blockchain {

let mut blockhash_opcode_references = HashMap::new();
let mut codes = Vec::new();
let mut seen_code_hashes = BTreeSet::new();

for (i, block) in blocks.iter().enumerate() {
let parent_hash = block.header.parent_hash;
Expand Down Expand Up @@ -844,6 +845,11 @@ impl Blockchain {
})?
.iter()
{
// Deduplicate bytecodes by their code hash to avoid redundant allocations
if !seen_code_hashes.insert(*code_hash) {
continue;
}

let code = self
.storage
.get_account_code(*code_hash)
Expand Down Expand Up @@ -876,8 +882,7 @@ impl Blockchain {
ChainError::WitnessGeneration("Failed to lock storage trie witness".to_string())
})?;
let witness = std::mem::take(&mut *witness);
let witness = witness.into_values().collect::<Vec<_>>();
used_trie_nodes.extend_from_slice(&witness);
used_trie_nodes.extend(witness.into_values());
touched_account_storage_slots.entry(address).or_default();
}

Expand Down Expand Up @@ -905,9 +910,7 @@ impl Blockchain {
current_trie_witness = new_state_trie_witness;
}

used_trie_nodes.extend_from_slice(&Vec::from_iter(
accumulated_state_trie_witness.into_values(),
));
used_trie_nodes.extend(accumulated_state_trie_witness.into_values());

// If the witness is empty at least try to store the root
if used_trie_nodes.is_empty()
Expand Down