Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf/mapping #112

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- perf: improved perfs with parallelized iteration over tx hashes cache
- fix: graceful shutdown of rocksdb on ctrl+c
- fix: better error handling around l1 and l2 sync
- perf: compile with target_cpu=skylake by default
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mp-types = { workspace = true }
num-traits = { workspace = true }
pallet-starknet-runtime-api = { workspace = true }
prometheus-endpoint = { workspace = true }
rayon = { workspace = true }
sc-client-api = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
Expand Down
32 changes: 18 additions & 14 deletions crates/client/mapping-sync/src/sync_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use mp_types::block::{DBlockT, DHashT, DHeaderT};
use num_traits::FromPrimitive;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use prometheus_endpoint::prometheus::core::Number;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use sc_client_api::backend::{Backend, StorageProvider};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Backend as _, HeaderBackend};
Expand Down Expand Up @@ -38,8 +39,10 @@ where
let opt_storage_starknet_block = get_block_by_block_hash(client, substrate_block_hash);
match opt_storage_starknet_block {
Ok(storage_starknet_block) => {
let digest_starknet_block_hash = digest_starknet_block.header().hash::<H>();
let storage_starknet_block_hash = storage_starknet_block.header().hash::<H>();
let (digest_starknet_block_hash, storage_starknet_block_hash) = rayon::join(
|| digest_starknet_block.header().hash::<H>(),
|| storage_starknet_block.header().hash::<H>(),
);
// Ensure the two blocks sources (chain storage and block digest) agree on the block content
if digest_starknet_block_hash != storage_starknet_block_hash {
Err(anyhow::anyhow!(
Expand All @@ -48,24 +51,25 @@ where
))
} else {
let chain_id = client.runtime_api().chain_id(substrate_block_hash)?;
let tx_hashes = digest_starknet_block
.transactions()
.par_iter()
.map(|tx| {
Felt252Wrapper::from(tx.compute_hash::<H>(
chain_id,
false,
Some(digest_starknet_block.header().block_number),
))
.into()
})
.collect();

// Success, we write the Starknet to Substate hashes mapping to db
let mapping_commitment = mc_db::MappingCommitment {
block_number: digest_starknet_block.header().block_number,
block_hash: substrate_block_hash,
starknet_block_hash: digest_starknet_block_hash.into(),
starknet_transaction_hashes: digest_starknet_block
.transactions()
.iter()
.map(|tx| {
Felt252Wrapper::from(tx.compute_hash::<H>(
chain_id,
false,
Some(digest_starknet_block.header().block_number),
))
.into()
})
.collect(),
starknet_transaction_hashes: tx_hashes,
};

if let Some(block_metrics) = block_metrics {
Expand Down
Empty file added crates/tui/substrate/ok.flag
Empty file.
Loading