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 e91c9a6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 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 @@ -16,6 +16,7 @@ use crate::storage::storage_trait::Storage;

use std::collections::HashMap;
use std::sync::Arc;
use tokio::join;
use tokio::task::JoinSet;

pub struct FilledForest {
Expand Down Expand Up @@ -55,12 +56,6 @@ impl FilledForest {
address_to_class_hash: &HashMap<ContractAddress, ClassHash>,
address_to_nonce: &HashMap<ContractAddress, Nonce>,
) -> ForestResult<Self> {
let classes_trie = 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();
Expand Down Expand Up @@ -96,16 +91,19 @@ impl FilledForest {
filled_storage_tries.insert(address, filled_storage_trie);
}

let contracts_trie = ContractsTrie::create::<TH>(
let classes_trie_task = ClassesTrie::create::<TH>(
Arc::new(updated_forest.classes_trie),
Arc::new(classes_updates),
);
let contracts_trie_task = ContractsTrie::create::<TH>(
Arc::new(updated_forest.contracts_trie),
Arc::new(contracts_trie_modifications),
)
.await?;

);
let (classes_trie, contracts_trie) = join!(classes_trie_task, contracts_trie_task);
Ok(Self {
storage_tries: filled_storage_tries,
contracts_trie,
classes_trie,
contracts_trie: contracts_trie?,
classes_trie: classes_trie?,
})
}

Expand Down

0 comments on commit e91c9a6

Please sign in to comment.