Skip to content

Commit

Permalink
Allow compiling without libm + Fix state corruption during sync when …
Browse files Browse the repository at this point in the history
…doing CTRL+c (#94)

Co-authored-by: Charpa <[email protected]>
  • Loading branch information
cchudant and jbcaron authored May 2, 2024
1 parent e9cfe3c commit 6635a1e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
44 changes: 11 additions & 33 deletions crates/client/sync/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ pub async fn sync<C>(
// 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
Expand Down Expand Up @@ -230,25 +228,21 @@ pub async fn sync<C>(
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
Expand All @@ -257,22 +251,6 @@ pub async fn sync<C>(
}
}
} => {},
// 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 :)");
Expand Down
4 changes: 3 additions & 1 deletion crates/client/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<sc_consensus_manual_seal::rpc::EngineCommand<sp_core::H256>>;

Expand Down
3 changes: 2 additions & 1 deletion crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6635a1e

Please sign in to comment.