Skip to content

Commit

Permalink
refactor: commit classes trie concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Jul 18, 2024
1 parent 1d383c5 commit e103dbe
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions crates/committer/src/patricia_merkle_tree/filled_tree/forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ impl FilledForest {
address_to_class_hash: &HashMap<ContractAddress, ClassHash>,
address_to_nonce: &HashMap<ContractAddress, Nonce>,
) -> ForestResult<Self> {
let classes_trie = ClassesTrie::create::<TH>(
let classes_trie_task = tokio::spawn(ClassesTrie::create::<TH>(
Arc::new(updated_forest.classes_trie),
Arc::new(classes_updates),
)
.await?;

));
let mut contracts_trie_modifications = HashMap::new();
let mut filled_storage_tries = HashMap::new();
let mut tasks = JoinSet::new();
let mut contracts_state_tasks = JoinSet::new();

for (address, inner_updates) in storage_updates {
let updated_storage_trie = updated_forest
Expand All @@ -74,7 +72,7 @@ impl FilledForest {
let original_contract_state = original_contracts_trie_leaves
.get(&NodeIndex::from_contract_address(&address))
.ok_or(ForestError::MissingContractCurrentState(address))?;
tasks.spawn(Self::new_contract_state::<TH>(
contracts_state_tasks.spawn(Self::new_contract_state::<TH>(
address,
*(address_to_nonce
.get(&address)
Expand All @@ -87,7 +85,7 @@ impl FilledForest {
));
}

while let Some(result) = tasks.join_next().await {
while let Some(result) = contracts_state_tasks.join_next().await {
let (address, new_contract_state, filled_storage_trie) = result??;
contracts_trie_modifications.insert(
NodeIndex::from_contract_address(&address),
Expand All @@ -96,16 +94,15 @@ impl FilledForest {
filled_storage_tries.insert(address, filled_storage_trie);
}

let contracts_trie = ContractsTrie::create::<TH>(
let contracts_trie_task = tokio::spawn(ContractsTrie::create::<TH>(
Arc::new(updated_forest.contracts_trie),
Arc::new(contracts_trie_modifications),
)
.await?;
));

Ok(Self {
storage_tries: filled_storage_tries,
contracts_trie,
classes_trie,
contracts_trie: contracts_trie_task.await??,
classes_trie: classes_trie_task.await??,
})
}

Expand Down

0 comments on commit e103dbe

Please sign in to comment.