From 6635a1e174734d82a8bdcd723827b03ff5bffd01 Mon Sep 17 00:00:00 2001 From: cchudant Date: Thu, 2 May 2024 08:19:19 -0700 Subject: [PATCH] Allow compiling without libm + Fix state corruption during sync when doing CTRL+c (#94) Co-authored-by: Charpa <102919164+jbcaron@users.noreply.github.com> --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- crates/client/sync/src/l2.rs | 44 +++++++++-------------------------- crates/client/sync/src/lib.rs | 4 +++- crates/node/Cargo.toml | 3 ++- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fc113a5c..06cce661f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ git # Deoxys Changelog ## Next release +- fix: class and store updates and block desync after ctrl+c +- fix: compile without libm - fix: genesis state_update - refactor: optimize get_class_at - fix: crash build genesis on restart diff --git a/Cargo.toml b/Cargo.toml index 81c444bad..295429a33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -236,7 +236,7 @@ mc-db = { path = "crates/client/db" } mc-genesis-data-provider = { path = "crates/client/genesis-data-provider" } mc-mapping-sync = { path = "crates/client/mapping-sync" } mc-rpc = { path = "crates/client/rpc" } -mc-sync = { path = "crates/client/sync" } +mc-sync = { path = "crates/client/sync", default-features = false } # Deoxys runtime deoxys-runtime = { path = "crates/runtime" } diff --git a/crates/client/sync/src/l2.rs b/crates/client/sync/src/l2.rs index e6dd8a088..6ea8497ac 100644 --- a/crates/client/sync/src/l2.rs +++ b/crates/client/sync/src/l2.rs @@ -150,8 +150,6 @@ pub async fn sync( // Have 10 fetches in parallel at once, using futures Buffered let fetch_stream = stream::iter(fetch_stream).buffered(10); let (fetch_stream_sender, mut fetch_stream_receiver) = mpsc::channel(10); - let (state_update_sender, mut state_update_receiver) = mpsc::channel(10); - let (class_update_sender, mut class_update_receiver) = mpsc::channel(10); tokio::select!( // update highest block hash and number, update pending block and state update @@ -230,25 +228,21 @@ pub async fn sync( block_sender.send(block_conv).await.expect("block reciever channel is closed"); }, async { - // Now send state_update, which moves it. This will be received - // by QueryBlockConsensusDataProvider in deoxys/crates/node/src/service.rs - state_update_sender - .send((block_n, state_update)) - .await - .expect("state updater is not running"); + if store_state_update(block_n, state_update).await.is_err() { + log::info!("❗ Failed to store state update for block {block_n}"); + }; + }, + async { + if store_class_update(block_n, ClassUpdateWrapper(class_update)).await.is_err() { + log::info!("❗ Failed to store class update for block {block_n}"); + }; }, async { - // do the same to class update - class_update_sender - .send((block_n, ClassUpdateWrapper(class_update))) - .await - .expect("class updater is not running"); + let start = std::time::Instant::now(); + create_block(&mut command_sink, &mut last_block_hash).await.expect("creating block"); + log::debug!("end create_block: {:?}", std::time::Instant::now() - start); } ); - - let start = std::time::Instant::now(); - create_block(&mut command_sink, &mut last_block_hash).await.expect("creating block"); - log::debug!("end create_block: {:?}", std::time::Instant::now() - start); block_n += 1; // compact DB every 1k blocks @@ -257,22 +251,6 @@ pub async fn sync( } } } => {}, - // store state updates - _ = async { - while let Some((block_number, state_update)) = pin!(state_update_receiver.recv()).await { - if store_state_update(block_number, state_update).await.is_err() { - log::info!("❗ Failed to store state update for block {block_number}"); - }; - } - } => {}, - // store class udpate - _ = async { - while let Some((block_number, class_update)) = pin!(class_update_receiver.recv()).await { - if store_class_update(block_number, class_update).await.is_err() { - log::info!("❗ Failed to store class update for block {block_number}"); - }; - } - } => {} ); log::debug!("L2 sync finished :)"); diff --git a/crates/client/sync/src/lib.rs b/crates/client/sync/src/lib.rs index 1c58f551e..15cb1f888 100644 --- a/crates/client/sync/src/lib.rs +++ b/crates/client/sync/src/lib.rs @@ -15,7 +15,9 @@ pub mod utils; pub use l2::SenderConfig; pub use mp_types::block::{DBlockT, DHashT}; -pub use utils::{convert, m, utility}; +#[cfg(feature = "m")] +pub use utils::m; +pub use utils::{convert, utility}; type CommandSink = futures::channel::mpsc::Sender>; diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 4bba67e42..47e82de59 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -100,7 +100,8 @@ url = { workspace = true } substrate-build-script-utils = { workspace = true } [features] -default = [] +default = ["sound"] +sound = ["mc-sync/m"] # Dependencies that are only required if runtime benchmarking should be build. runtime-benchmarks = [ "frame-benchmarking-cli/runtime-benchmarks",