Skip to content

Commit

Permalink
perf(state_commitment): ⚡ Finished improving l2 verification performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Trantorian committed Feb 27, 2024
1 parent 3c384f0 commit 9ceb337
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/client/deoxys/src/commitments/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ async fn contract_trie_root<B: BlockT>(
csd: Arc<CommitmentStateDiff>,
bonsai_dbs: Arc<BonsaiDbs<B>>,
) -> anyhow::Result<Felt252Wrapper> {
// Risk of starving the thread pool (execution over 1s in some cases), must be run in a
// blocking-safe thread. Main bottleneck is still calling `commit` on the Bonsai db.
let mut task_set = spawn_blocking(move || {
let mut task_set = JoinSet::new();

Expand All @@ -185,6 +187,8 @@ async fn contract_trie_root<B: BlockT>(
})
.await?;

// The order in which contract trie roots are waited for is not important since each call to
// `update_contract_trie` in `contract_trie_root` mutates the Deoxys db.
let mut contract_trie_root = Felt252Wrapper::ZERO;
while let Some(res) = task_set.join_next().await {
contract_trie_root = match res? {
Expand Down
1 change: 1 addition & 0 deletions crates/client/deoxys/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ pub async fn verify_l2<B: BlockT>(

let csd = build_commitment_state_diff(state_update_wrapper.clone());

// Main l2 sync bottleneck HERE!
let state_root =
update_state_root(csd, bonsai_dbs).await.map_err(|e| format!("Failed to update state root: {e}"))?;

Expand Down

0 comments on commit 9ceb337

Please sign in to comment.