From dfcbc99d2bad99220fba2f80781805900ba5cb1b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:39:58 +0800 Subject: [PATCH 01/26] Add `shared_builder` module for `ckb-shared` --- shared/src/lib.rs | 1 + shared/src/shared_builder.rs | 0 2 files changed, 1 insertion(+) create mode 100644 shared/src/shared_builder.rs diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 91d80fecd0..6465217a0f 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -2,6 +2,7 @@ // num_cpus is used in proc_macro pub mod shared; +mod shared_builder; pub use ckb_snapshot::{Snapshot, SnapshotMgr}; pub use shared::Shared; diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs new file mode 100644 index 0000000000..e69de29bb2 From ed6ea173bb758ddb1479b2a2d984aa743d534fa8 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:42:01 +0800 Subject: [PATCH 02/26] Move `SharedPacakge` from `ckb-launcher` to `ckb-shared` --- Cargo.lock | 1 + shared/Cargo.toml | 1 + shared/src/shared_builder.rs | 31 +++++++++++++++++++++++++++++ util/launcher/src/shared_builder.rs | 27 ------------------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cce0b90646..5c854a555d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1347,6 +1347,7 @@ dependencies = [ "arc-swap", "ckb-async-runtime", "ckb-chain-spec", + "ckb-channel", "ckb-constant", "ckb-db", "ckb-db-schema", diff --git a/shared/Cargo.toml b/shared/Cargo.toml index cabcc598e6..bb94f9831d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -26,6 +26,7 @@ ckb-async-runtime = { path = "../util/runtime", version = "= 0.113.0-pre" } ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.113.0-pre" } ckb-constant = { path = "../util/constant", version = "= 0.113.0-pre" } ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre" } +ckb-channel = { path = "../util/channel", version = "= 0.113.0-pre" } [dev-dependencies] ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre", features = ["enable_faketime"] } diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index e69de29bb2..706f10a8bc 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -0,0 +1,31 @@ +use ckb_channel::Receiver; +use ckb_proposal_table::ProposalTable; +use ckb_tx_pool::service::TxVerificationResult; +use ckb_tx_pool::TxPoolServiceBuilder; + +/// SharedBuilder build returning the shared/package halves +/// The package structs used for init other component +pub struct SharedPackage { + table: Option, + tx_pool_builder: Option, + relay_tx_receiver: Option>, +} + +impl SharedPackage { + /// Takes the proposal_table out of the package, leaving a None in its place. + pub fn take_proposal_table(&mut self) -> ProposalTable { + self.table.take().expect("take proposal_table") + } + + /// Takes the tx_pool_builder out of the package, leaving a None in its place. + pub fn take_tx_pool_builder(&mut self) -> TxPoolServiceBuilder { + self.tx_pool_builder.take().expect("take tx_pool_builder") + } + + /// Takes the relay_tx_receiver out of the package, leaving a None in its place. + pub fn take_relay_tx_receiver(&mut self) -> Receiver { + self.relay_tx_receiver + .take() + .expect("take relay_tx_receiver") + } +} diff --git a/util/launcher/src/shared_builder.rs b/util/launcher/src/shared_builder.rs index e6cb904c76..3655a05ea4 100644 --- a/util/launcher/src/shared_builder.rs +++ b/util/launcher/src/shared_builder.rs @@ -372,33 +372,6 @@ impl SharedBuilder { } } -/// SharedBuilder build returning the shared/package halves -/// The package structs used for init other component -pub struct SharedPackage { - table: Option, - tx_pool_builder: Option, - relay_tx_receiver: Option>, -} - -impl SharedPackage { - /// Takes the proposal_table out of the package, leaving a None in its place. - pub fn take_proposal_table(&mut self) -> ProposalTable { - self.table.take().expect("take proposal_table") - } - - /// Takes the tx_pool_builder out of the package, leaving a None in its place. - pub fn take_tx_pool_builder(&mut self) -> TxPoolServiceBuilder { - self.tx_pool_builder.take().expect("take tx_pool_builder") - } - - /// Takes the relay_tx_receiver out of the package, leaving a None in its place. - pub fn take_relay_tx_receiver(&mut self) -> Receiver { - self.relay_tx_receiver - .take() - .expect("take relay_tx_receiver") - } -} - fn start_notify_service(notify_config: NotifyConfig, handle: Handle) -> NotifyController { NotifyService::new(notify_config, handle).start() } From d88c7216aaf099d3a75f0b381c2e78da9ea23099 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:43:05 +0800 Subject: [PATCH 03/26] Move `SharedBuilder` from `ckb-launcher` to `ckb-shared` --- shared/src/shared_builder.rs | 271 ++++++++++++++++++++++++++++ util/launcher/src/shared_builder.rs | 271 ---------------------------- 2 files changed, 271 insertions(+), 271 deletions(-) diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 706f10a8bc..36f5778781 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -3,6 +3,277 @@ use ckb_proposal_table::ProposalTable; use ckb_tx_pool::service::TxVerificationResult; use ckb_tx_pool::TxPoolServiceBuilder; +/// Shared builder for construct new shared. +pub struct SharedBuilder { + db: RocksDB, + ancient_path: Option, + consensus: Option, + tx_pool_config: Option, + store_config: Option, + block_assembler_config: Option, + notify_config: Option, + async_handle: Handle, +} + +impl SharedBuilder { + /// Generates the base SharedBuilder with ancient path and async_handle + pub fn new( + bin_name: &str, + root_dir: &Path, + db_config: &DBConfig, + ancient: Option, + async_handle: Handle, + ) -> Result { + let db = open_or_create_db(bin_name, root_dir, db_config)?; + + Ok(SharedBuilder { + db, + ancient_path: ancient, + consensus: None, + tx_pool_config: None, + notify_config: None, + store_config: None, + block_assembler_config: None, + async_handle, + }) + } + + /// Generates the SharedBuilder with temp db + /// NOTICE: this is only used in testing + pub fn with_temp_db() -> Self { + use once_cell::{sync, unsync}; + use std::{ + borrow::Borrow, + sync::atomic::{AtomicUsize, Ordering}, + }; + + // once #[thread_local] is stable + // #[thread_local] + // static RUNTIME_HANDLE: unsync::OnceCell<... + thread_local! { + // NOTICE:we can't put the runtime directly into thread_local here, + // on windows the runtime in thread_local will get stuck when dropping + static RUNTIME_HANDLE: unsync::OnceCell = unsync::OnceCell::new(); + } + + static DB_COUNT: AtomicUsize = AtomicUsize::new(0); + static TMP_DIR: sync::OnceCell = sync::OnceCell::new(); + + let db = { + let db_id = DB_COUNT.fetch_add(1, Ordering::SeqCst); + let db_base_dir = TMP_DIR + .borrow() + .get_or_try_init(TempDir::new) + .unwrap() + .path() + .to_path_buf(); + let db_dir = db_base_dir.join(format!("db_{db_id}")); + RocksDB::open_in(db_dir, COLUMNS) + }; + + RUNTIME_HANDLE.with(|runtime| SharedBuilder { + db, + ancient_path: None, + consensus: None, + tx_pool_config: None, + notify_config: None, + store_config: None, + block_assembler_config: None, + async_handle: runtime.borrow().get_or_init(new_background_runtime).clone(), + }) + } +} + +impl SharedBuilder { + /// TODO(doc): @quake + pub fn consensus(mut self, value: Consensus) -> Self { + self.consensus = Some(value); + self + } + + /// TODO(doc): @quake + pub fn tx_pool_config(mut self, config: TxPoolConfig) -> Self { + self.tx_pool_config = Some(config); + self + } + + /// TODO(doc): @quake + pub fn notify_config(mut self, config: NotifyConfig) -> Self { + self.notify_config = Some(config); + self + } + + /// TODO(doc): @quake + pub fn store_config(mut self, config: StoreConfig) -> Self { + self.store_config = Some(config); + self + } + + /// TODO(doc): @quake + pub fn block_assembler_config(mut self, config: Option) -> Self { + self.block_assembler_config = config; + self + } + + /// specifies the async_handle for the shared + pub fn async_handle(mut self, async_handle: Handle) -> Self { + self.async_handle = async_handle; + self + } + + fn init_proposal_table( + store: &ChainDB, + consensus: &Consensus, + ) -> (ProposalTable, ProposalView) { + let proposal_window = consensus.tx_proposal_window(); + let tip_number = store.get_tip_header().expect("store inited").number(); + let mut proposal_ids = ProposalTable::new(proposal_window); + let proposal_start = tip_number.saturating_sub(proposal_window.farthest()); + for bn in proposal_start..=tip_number { + if let Some(hash) = store.get_block_hash(bn) { + let mut ids_set = HashSet::new(); + if let Some(ids) = store.get_block_proposal_txs_ids(&hash) { + ids_set.extend(ids) + } + + if let Some(us) = store.get_block_uncles(&hash) { + for u in us.data().into_iter() { + ids_set.extend(u.proposals().into_iter()); + } + } + proposal_ids.insert(bn, ids_set); + } + } + let dummy_proposals = ProposalView::default(); + let (_, proposals) = proposal_ids.finalize(&dummy_proposals, tip_number); + (proposal_ids, proposals) + } + + fn init_store(store: &ChainDB, consensus: &Consensus) -> Result<(HeaderView, EpochExt), Error> { + match store + .get_tip_header() + .and_then(|header| store.get_current_epoch_ext().map(|epoch| (header, epoch))) + { + Some((tip_header, epoch)) => { + if let Some(genesis_hash) = store.get_block_hash(0) { + let expect_genesis_hash = consensus.genesis_hash(); + if genesis_hash == expect_genesis_hash { + Ok((tip_header, epoch)) + } else { + Err(SpecError::GenesisMismatch { + expected: expect_genesis_hash, + actual: genesis_hash, + } + .into()) + } + } else { + Err(InternalErrorKind::Database + .other("genesis does not exist in database") + .into()) + } + } + None => store.init(consensus).map(|_| { + ( + consensus.genesis_block().header(), + consensus.genesis_epoch_ext().to_owned(), + ) + }), + } + } + + fn init_snapshot( + store: &ChainDB, + consensus: Arc, + ) -> Result<(Snapshot, ProposalTable), Error> { + let (tip_header, epoch) = Self::init_store(store, &consensus)?; + let total_difficulty = store + .get_block_ext(&tip_header.hash()) + .ok_or_else(|| InternalErrorKind::Database.other("failed to get tip's block_ext"))? + .total_difficulty; + let (proposal_table, proposal_view) = Self::init_proposal_table(store, &consensus); + + let snapshot = Snapshot::new( + tip_header, + total_difficulty, + epoch, + store.get_snapshot(), + proposal_view, + consensus, + ); + + Ok((snapshot, proposal_table)) + } + + /// TODO(doc): @quake + pub fn build(self) -> Result<(Shared, SharedPackage), ExitCode> { + let SharedBuilder { + db, + ancient_path, + consensus, + tx_pool_config, + store_config, + block_assembler_config, + notify_config, + async_handle, + } = self; + + let tx_pool_config = tx_pool_config.unwrap_or_default(); + let notify_config = notify_config.unwrap_or_default(); + let store_config = store_config.unwrap_or_default(); + let consensus = Arc::new(consensus.unwrap_or_default()); + + let notify_controller = start_notify_service(notify_config, async_handle.clone()); + + let store = build_store(db, store_config, ancient_path).map_err(|e| { + eprintln!("build_store {e}"); + ExitCode::Failure + })?; + + let txs_verify_cache = Arc::new(TokioRwLock::new(init_cache())); + + let (snapshot, table) = + Self::init_snapshot(&store, Arc::clone(&consensus)).map_err(|e| { + eprintln!("init_snapshot {e}"); + ExitCode::Failure + })?; + let snapshot = Arc::new(snapshot); + let snapshot_mgr = Arc::new(SnapshotMgr::new(Arc::clone(&snapshot))); + + let (sender, receiver) = ckb_channel::unbounded(); + + let (mut tx_pool_builder, tx_pool_controller) = TxPoolServiceBuilder::new( + tx_pool_config, + Arc::clone(&snapshot), + block_assembler_config, + Arc::clone(&txs_verify_cache), + &async_handle, + sender, + ); + + register_tx_pool_callback(&mut tx_pool_builder, notify_controller.clone()); + + let ibd_finished = Arc::new(AtomicBool::new(false)); + let shared = Shared::new( + store, + tx_pool_controller, + notify_controller, + txs_verify_cache, + consensus, + snapshot_mgr, + async_handle, + ibd_finished, + ); + + let pack = SharedPackage { + table: Some(table), + tx_pool_builder: Some(tx_pool_builder), + relay_tx_receiver: Some(receiver), + }; + + Ok((shared, pack)) + } +} + /// SharedBuilder build returning the shared/package halves /// The package structs used for init other component pub struct SharedPackage { diff --git a/util/launcher/src/shared_builder.rs b/util/launcher/src/shared_builder.rs index 3655a05ea4..c8c0c106a2 100644 --- a/util/launcher/src/shared_builder.rs +++ b/util/launcher/src/shared_builder.rs @@ -36,18 +36,6 @@ use std::sync::atomic::AtomicBool; use std::sync::Arc; use tempfile::TempDir; -/// Shared builder for construct new shared. -pub struct SharedBuilder { - db: RocksDB, - ancient_path: Option, - consensus: Option, - tx_pool_config: Option, - store_config: Option, - block_assembler_config: Option, - notify_config: Option, - async_handle: Handle, -} - pub fn open_or_create_db( bin_name: &str, root_dir: &Path, @@ -113,265 +101,6 @@ pub fn open_or_create_db( } } -impl SharedBuilder { - /// Generates the base SharedBuilder with ancient path and async_handle - pub fn new( - bin_name: &str, - root_dir: &Path, - db_config: &DBConfig, - ancient: Option, - async_handle: Handle, - ) -> Result { - let db = open_or_create_db(bin_name, root_dir, db_config)?; - - Ok(SharedBuilder { - db, - ancient_path: ancient, - consensus: None, - tx_pool_config: None, - notify_config: None, - store_config: None, - block_assembler_config: None, - async_handle, - }) - } - - /// Generates the SharedBuilder with temp db - /// NOTICE: this is only used in testing - pub fn with_temp_db() -> Self { - use once_cell::{sync, unsync}; - use std::{ - borrow::Borrow, - sync::atomic::{AtomicUsize, Ordering}, - }; - - // once #[thread_local] is stable - // #[thread_local] - // static RUNTIME_HANDLE: unsync::OnceCell<... - thread_local! { - // NOTICE:we can't put the runtime directly into thread_local here, - // on windows the runtime in thread_local will get stuck when dropping - static RUNTIME_HANDLE: unsync::OnceCell = unsync::OnceCell::new(); - } - - static DB_COUNT: AtomicUsize = AtomicUsize::new(0); - static TMP_DIR: sync::OnceCell = sync::OnceCell::new(); - - let db = { - let db_id = DB_COUNT.fetch_add(1, Ordering::SeqCst); - let db_base_dir = TMP_DIR - .borrow() - .get_or_try_init(TempDir::new) - .unwrap() - .path() - .to_path_buf(); - let db_dir = db_base_dir.join(format!("db_{db_id}")); - RocksDB::open_in(db_dir, COLUMNS) - }; - - RUNTIME_HANDLE.with(|runtime| SharedBuilder { - db, - ancient_path: None, - consensus: None, - tx_pool_config: None, - notify_config: None, - store_config: None, - block_assembler_config: None, - async_handle: runtime.borrow().get_or_init(new_background_runtime).clone(), - }) - } -} - -impl SharedBuilder { - /// TODO(doc): @quake - pub fn consensus(mut self, value: Consensus) -> Self { - self.consensus = Some(value); - self - } - - /// TODO(doc): @quake - pub fn tx_pool_config(mut self, config: TxPoolConfig) -> Self { - self.tx_pool_config = Some(config); - self - } - - /// TODO(doc): @quake - pub fn notify_config(mut self, config: NotifyConfig) -> Self { - self.notify_config = Some(config); - self - } - - /// TODO(doc): @quake - pub fn store_config(mut self, config: StoreConfig) -> Self { - self.store_config = Some(config); - self - } - - /// TODO(doc): @quake - pub fn block_assembler_config(mut self, config: Option) -> Self { - self.block_assembler_config = config; - self - } - - /// specifies the async_handle for the shared - pub fn async_handle(mut self, async_handle: Handle) -> Self { - self.async_handle = async_handle; - self - } - - fn init_proposal_table( - store: &ChainDB, - consensus: &Consensus, - ) -> (ProposalTable, ProposalView) { - let proposal_window = consensus.tx_proposal_window(); - let tip_number = store.get_tip_header().expect("store inited").number(); - let mut proposal_ids = ProposalTable::new(proposal_window); - let proposal_start = tip_number.saturating_sub(proposal_window.farthest()); - for bn in proposal_start..=tip_number { - if let Some(hash) = store.get_block_hash(bn) { - let mut ids_set = HashSet::new(); - if let Some(ids) = store.get_block_proposal_txs_ids(&hash) { - ids_set.extend(ids) - } - - if let Some(us) = store.get_block_uncles(&hash) { - for u in us.data().into_iter() { - ids_set.extend(u.proposals().into_iter()); - } - } - proposal_ids.insert(bn, ids_set); - } - } - let dummy_proposals = ProposalView::default(); - let (_, proposals) = proposal_ids.finalize(&dummy_proposals, tip_number); - (proposal_ids, proposals) - } - - fn init_store(store: &ChainDB, consensus: &Consensus) -> Result<(HeaderView, EpochExt), Error> { - match store - .get_tip_header() - .and_then(|header| store.get_current_epoch_ext().map(|epoch| (header, epoch))) - { - Some((tip_header, epoch)) => { - if let Some(genesis_hash) = store.get_block_hash(0) { - let expect_genesis_hash = consensus.genesis_hash(); - if genesis_hash == expect_genesis_hash { - Ok((tip_header, epoch)) - } else { - Err(SpecError::GenesisMismatch { - expected: expect_genesis_hash, - actual: genesis_hash, - } - .into()) - } - } else { - Err(InternalErrorKind::Database - .other("genesis does not exist in database") - .into()) - } - } - None => store.init(consensus).map(|_| { - ( - consensus.genesis_block().header(), - consensus.genesis_epoch_ext().to_owned(), - ) - }), - } - } - - fn init_snapshot( - store: &ChainDB, - consensus: Arc, - ) -> Result<(Snapshot, ProposalTable), Error> { - let (tip_header, epoch) = Self::init_store(store, &consensus)?; - let total_difficulty = store - .get_block_ext(&tip_header.hash()) - .ok_or_else(|| InternalErrorKind::Database.other("failed to get tip's block_ext"))? - .total_difficulty; - let (proposal_table, proposal_view) = Self::init_proposal_table(store, &consensus); - - let snapshot = Snapshot::new( - tip_header, - total_difficulty, - epoch, - store.get_snapshot(), - proposal_view, - consensus, - ); - - Ok((snapshot, proposal_table)) - } - - /// TODO(doc): @quake - pub fn build(self) -> Result<(Shared, SharedPackage), ExitCode> { - let SharedBuilder { - db, - ancient_path, - consensus, - tx_pool_config, - store_config, - block_assembler_config, - notify_config, - async_handle, - } = self; - - let tx_pool_config = tx_pool_config.unwrap_or_default(); - let notify_config = notify_config.unwrap_or_default(); - let store_config = store_config.unwrap_or_default(); - let consensus = Arc::new(consensus.unwrap_or_default()); - - let notify_controller = start_notify_service(notify_config, async_handle.clone()); - - let store = build_store(db, store_config, ancient_path).map_err(|e| { - eprintln!("build_store {e}"); - ExitCode::Failure - })?; - - let txs_verify_cache = Arc::new(TokioRwLock::new(init_cache())); - - let (snapshot, table) = - Self::init_snapshot(&store, Arc::clone(&consensus)).map_err(|e| { - eprintln!("init_snapshot {e}"); - ExitCode::Failure - })?; - let snapshot = Arc::new(snapshot); - let snapshot_mgr = Arc::new(SnapshotMgr::new(Arc::clone(&snapshot))); - - let (sender, receiver) = ckb_channel::unbounded(); - - let (mut tx_pool_builder, tx_pool_controller) = TxPoolServiceBuilder::new( - tx_pool_config, - Arc::clone(&snapshot), - block_assembler_config, - Arc::clone(&txs_verify_cache), - &async_handle, - sender, - ); - - register_tx_pool_callback(&mut tx_pool_builder, notify_controller.clone()); - - let ibd_finished = Arc::new(AtomicBool::new(false)); - let shared = Shared::new( - store, - tx_pool_controller, - notify_controller, - txs_verify_cache, - consensus, - snapshot_mgr, - async_handle, - ibd_finished, - ); - - let pack = SharedPackage { - table: Some(table), - tx_pool_builder: Some(tx_pool_builder), - relay_tx_receiver: Some(receiver), - }; - - Ok((shared, pack)) - } -} - fn start_notify_service(notify_config: NotifyConfig, handle: Handle) -> NotifyController { NotifyService::new(notify_config, handle).start() } From 6b885a7e7a62fb11a4044cf8dbb6eaa4d859be9d Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:52:56 +0800 Subject: [PATCH 04/26] Move `SharedBuilder`'s helper functions to `ckb-shared` Signed-off-by: Eval EXEC --- shared/src/shared_builder.rs | 182 +++++++++++++++++++++++++++- util/launcher/src/shared_builder.rs | 150 ----------------------- 2 files changed, 181 insertions(+), 151 deletions(-) diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 36f5778781..32f9c88ea7 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -1,7 +1,37 @@ use ckb_channel::Receiver; use ckb_proposal_table::ProposalTable; use ckb_tx_pool::service::TxVerificationResult; -use ckb_tx_pool::TxPoolServiceBuilder; +use ckb_tx_pool::{TokioRwLock, TxEntry, TxPool, TxPoolServiceBuilder}; +use std::cmp::Ordering; + +use ckb_chain_spec::consensus::Consensus; +use ckb_chain_spec::SpecError; + +use crate::Shared; +use ckb_proposal_table::ProposalView; +use ckb_snapshot::{Snapshot, SnapshotMgr}; + +use ckb_app_config::{ + BlockAssemblerConfig, DBConfig, ExitCode, NotifyConfig, StoreConfig, TxPoolConfig, +}; +use ckb_async_runtime::{new_background_runtime, Handle}; +use ckb_db::RocksDB; +use ckb_db_schema::COLUMNS; +use ckb_error::{Error, InternalErrorKind}; +use ckb_logger::{error, info}; +use ckb_migrate::migrate::Migrate; +use ckb_notify::{NotifyController, NotifyService}; +use ckb_store::{ChainDB, ChainStore, Freezer}; +use ckb_types::core::service::PoolTransactionEntry; +use ckb_types::core::tx_pool::Reject; +use ckb_types::core::EpochExt; +use ckb_types::core::HeaderView; +use ckb_verification::cache::init_cache; +use std::collections::HashSet; +use std::path::{Path, PathBuf}; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; +use tempfile::TempDir; /// Shared builder for construct new shared. pub struct SharedBuilder { @@ -15,6 +45,71 @@ pub struct SharedBuilder { async_handle: Handle, } +pub fn open_or_create_db( + bin_name: &str, + root_dir: &Path, + config: &DBConfig, +) -> Result { + let migrate = Migrate::new(&config.path); + + let read_only_db = migrate.open_read_only_db().map_err(|e| { + eprintln!("migrate error {e}"); + ExitCode::Failure + })?; + + if let Some(db) = read_only_db { + match migrate.check(&db) { + Ordering::Greater => { + eprintln!( + "The database is created by a higher version CKB executable binary, \n\ + so that the current CKB executable binary couldn't open this database.\n\ + Please download the latest CKB executable binary." + ); + Err(ExitCode::Failure) + } + Ordering::Equal => Ok(RocksDB::open(config, COLUMNS)), + Ordering::Less => { + if migrate.require_expensive(&db) { + eprintln!( + "For optimal performance, CKB wants to migrate the data into new format.\n\ + You can use the old version CKB if you don't want to do the migration.\n\ + We strongly recommended you to use the latest stable version of CKB, \ + since the old versions may have unfixed vulnerabilities.\n\ + Run `\"{}\" migrate -C \"{}\"` and confirm by typing \"YES\" to migrate the data.\n\ + We strongly recommend that you backup the data directory before migration.", + bin_name, + root_dir.display() + ); + Err(ExitCode::Failure) + } else { + info!("process fast migrations ..."); + + let bulk_load_db_db = migrate.open_bulk_load_db().map_err(|e| { + eprintln!("migrate error {e}"); + ExitCode::Failure + })?; + + if let Some(db) = bulk_load_db_db { + migrate.migrate(db).map_err(|err| { + eprintln!("Run error: {err:?}"); + ExitCode::Failure + })?; + } + + Ok(RocksDB::open(config, COLUMNS)) + } + } + } + } else { + let db = RocksDB::open(config, COLUMNS); + migrate.init_db_version(&db).map_err(|e| { + eprintln!("migrate init_db_version error {e}"); + ExitCode::Failure + })?; + Ok(db) + } +} + impl SharedBuilder { /// Generates the base SharedBuilder with ancient path and async_handle pub fn new( @@ -274,6 +369,91 @@ impl SharedBuilder { } } +fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify: NotifyController) { + let notify_pending = notify.clone(); + + let tx_relay_sender = tx_pool_builder.tx_relay_sender(); + let create_notify_entry = |entry: &TxEntry| PoolTransactionEntry { + transaction: entry.rtx.transaction.clone(), + cycles: entry.cycles, + size: entry.size, + fee: entry.fee, + timestamp: entry.timestamp, + }; + tx_pool_builder.register_pending(Box::new(move |tx_pool: &mut TxPool, entry: &TxEntry| { + // update statics + tx_pool.update_statics_for_add_tx(entry.size, entry.cycles); + + // notify + let notify_tx_entry = create_notify_entry(entry); + notify_pending.notify_new_transaction(notify_tx_entry); + })); + + let notify_proposed = notify.clone(); + tx_pool_builder.register_proposed(Box::new( + move |tx_pool: &mut TxPool, entry: &TxEntry, new: bool| { + // update statics + if new { + tx_pool.update_statics_for_add_tx(entry.size, entry.cycles); + } + + // notify + let notify_tx_entry = create_notify_entry(entry); + notify_proposed.notify_proposed_transaction(notify_tx_entry); + }, + )); + + tx_pool_builder.register_committed(Box::new(move |tx_pool: &mut TxPool, entry: &TxEntry| { + tx_pool.update_statics_for_remove_tx(entry.size, entry.cycles); + })); + + let notify_reject = notify; + tx_pool_builder.register_reject(Box::new( + move |tx_pool: &mut TxPool, entry: &TxEntry, reject: Reject| { + // update statics + tx_pool.update_statics_for_remove_tx(entry.size, entry.cycles); + + let tx_hash = entry.transaction().hash(); + // record recent reject + if matches!(reject, Reject::Resolve(..) | Reject::RBFRejected(..)) { + if let Some(ref mut recent_reject) = tx_pool.recent_reject { + if let Err(e) = recent_reject.put(&tx_hash, reject.clone()) { + error!("record recent_reject failed {} {} {}", tx_hash, reject, e); + } + } + } + + if reject.is_allowed_relay() { + if let Err(e) = tx_relay_sender.send(TxVerificationResult::Reject { tx_hash }) { + error!("tx-pool tx_relay_sender internal error {}", e); + } + } + + // notify + let notify_tx_entry = create_notify_entry(entry); + notify_reject.notify_reject_transaction(notify_tx_entry, reject); + }, + )); +} + +fn start_notify_service(notify_config: NotifyConfig, handle: Handle) -> NotifyController { + NotifyService::new(notify_config, handle).start() +} + +fn build_store( + db: RocksDB, + store_config: StoreConfig, + ancient_path: Option, +) -> Result { + let store = if store_config.freezer_enable && ancient_path.is_some() { + let freezer = Freezer::open(ancient_path.expect("exist checked"))?; + ChainDB::new_with_freezer(db, freezer, store_config) + } else { + ChainDB::new(db, store_config) + }; + Ok(store) +} + /// SharedBuilder build returning the shared/package halves /// The package structs used for init other component pub struct SharedPackage { diff --git a/util/launcher/src/shared_builder.rs b/util/launcher/src/shared_builder.rs index c8c0c106a2..3055a08409 100644 --- a/util/launcher/src/shared_builder.rs +++ b/util/launcher/src/shared_builder.rs @@ -35,153 +35,3 @@ use std::path::{Path, PathBuf}; use std::sync::atomic::AtomicBool; use std::sync::Arc; use tempfile::TempDir; - -pub fn open_or_create_db( - bin_name: &str, - root_dir: &Path, - config: &DBConfig, -) -> Result { - let migrate = Migrate::new(&config.path); - - let read_only_db = migrate.open_read_only_db().map_err(|e| { - eprintln!("migrate error {e}"); - ExitCode::Failure - })?; - - if let Some(db) = read_only_db { - match migrate.check(&db) { - Ordering::Greater => { - eprintln!( - "The database is created by a higher version CKB executable binary, \n\ - so that the current CKB executable binary couldn't open this database.\n\ - Please download the latest CKB executable binary." - ); - Err(ExitCode::Failure) - } - Ordering::Equal => Ok(RocksDB::open(config, COLUMNS)), - Ordering::Less => { - if migrate.require_expensive(&db) { - eprintln!( - "For optimal performance, CKB wants to migrate the data into new format.\n\ - You can use the old version CKB if you don't want to do the migration.\n\ - We strongly recommended you to use the latest stable version of CKB, \ - since the old versions may have unfixed vulnerabilities.\n\ - Run `\"{}\" migrate -C \"{}\"` and confirm by typing \"YES\" to migrate the data.\n\ - We strongly recommend that you backup the data directory before migration.", - bin_name, - root_dir.display() - ); - Err(ExitCode::Failure) - } else { - info!("process fast migrations ..."); - - let bulk_load_db_db = migrate.open_bulk_load_db().map_err(|e| { - eprintln!("migrate error {e}"); - ExitCode::Failure - })?; - - if let Some(db) = bulk_load_db_db { - migrate.migrate(db).map_err(|err| { - eprintln!("Run error: {err:?}"); - ExitCode::Failure - })?; - } - - Ok(RocksDB::open(config, COLUMNS)) - } - } - } - } else { - let db = RocksDB::open(config, COLUMNS); - migrate.init_db_version(&db).map_err(|e| { - eprintln!("migrate init_db_version error {e}"); - ExitCode::Failure - })?; - Ok(db) - } -} - -fn start_notify_service(notify_config: NotifyConfig, handle: Handle) -> NotifyController { - NotifyService::new(notify_config, handle).start() -} - -fn build_store( - db: RocksDB, - store_config: StoreConfig, - ancient_path: Option, -) -> Result { - let store = if store_config.freezer_enable && ancient_path.is_some() { - let freezer = Freezer::open(ancient_path.expect("exist checked"))?; - ChainDB::new_with_freezer(db, freezer, store_config) - } else { - ChainDB::new(db, store_config) - }; - Ok(store) -} - -fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify: NotifyController) { - let notify_pending = notify.clone(); - - let tx_relay_sender = tx_pool_builder.tx_relay_sender(); - let create_notify_entry = |entry: &TxEntry| PoolTransactionEntry { - transaction: entry.rtx.transaction.clone(), - cycles: entry.cycles, - size: entry.size, - fee: entry.fee, - timestamp: entry.timestamp, - }; - tx_pool_builder.register_pending(Box::new(move |tx_pool: &mut TxPool, entry: &TxEntry| { - // update statics - tx_pool.update_statics_for_add_tx(entry.size, entry.cycles); - - // notify - let notify_tx_entry = create_notify_entry(entry); - notify_pending.notify_new_transaction(notify_tx_entry); - })); - - let notify_proposed = notify.clone(); - tx_pool_builder.register_proposed(Box::new( - move |tx_pool: &mut TxPool, entry: &TxEntry, new: bool| { - // update statics - if new { - tx_pool.update_statics_for_add_tx(entry.size, entry.cycles); - } - - // notify - let notify_tx_entry = create_notify_entry(entry); - notify_proposed.notify_proposed_transaction(notify_tx_entry); - }, - )); - - tx_pool_builder.register_committed(Box::new(move |tx_pool: &mut TxPool, entry: &TxEntry| { - tx_pool.update_statics_for_remove_tx(entry.size, entry.cycles); - })); - - let notify_reject = notify; - tx_pool_builder.register_reject(Box::new( - move |tx_pool: &mut TxPool, entry: &TxEntry, reject: Reject| { - // update statics - tx_pool.update_statics_for_remove_tx(entry.size, entry.cycles); - - let tx_hash = entry.transaction().hash(); - // record recent reject - if matches!(reject, Reject::Resolve(..) | Reject::RBFRejected(..)) { - if let Some(ref mut recent_reject) = tx_pool.recent_reject { - if let Err(e) = recent_reject.put(&tx_hash, reject.clone()) { - error!("record recent_reject failed {} {} {}", tx_hash, reject, e); - } - } - } - - if reject.is_allowed_relay() { - if let Err(e) = tx_relay_sender.send(TxVerificationResult::Reject { tx_hash }) { - error!("tx-pool tx_relay_sender internal error {}", e); - } - } - - // notify - let notify_tx_entry = create_notify_entry(entry); - notify_reject.notify_reject_transaction(notify_tx_entry, reject); - }, - )); -} From f65deec05dee22ef962aa8c46c0f2116433f08de Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:53:39 +0800 Subject: [PATCH 05/26] Add dependencies for `ckb-shared` --- shared/Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared/Cargo.toml b/shared/Cargo.toml index bb94f9831d..58f1336db0 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -27,6 +27,11 @@ ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.113.0-pre" } ckb-constant = { path = "../util/constant", version = "= 0.113.0-pre" } ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre" } ckb-channel = { path = "../util/channel", version = "= 0.113.0-pre" } +ckb-app-config = {path = "../util/app-config", version = "= 0.113.0-pre"} +ckb-migrate = { path = "../util/migrate", version = "= 0.113.0-pre" } +once_cell = "1.8.0" +tempfile.workspace = true + [dev-dependencies] ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre", features = ["enable_faketime"] } From ecab91b2e9a4439e7b3100e25cad76307fcdd2fa Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:54:25 +0800 Subject: [PATCH 06/26] Remove `shared_builder` from `ckb-launcher` --- util/launcher/src/lib.rs | 2 -- util/launcher/src/shared_builder.rs | 37 ----------------------------- 2 files changed, 39 deletions(-) delete mode 100644 util/launcher/src/shared_builder.rs diff --git a/util/launcher/src/lib.rs b/util/launcher/src/lib.rs index bc4d1bf517..d6c09849ca 100644 --- a/util/launcher/src/lib.rs +++ b/util/launcher/src/lib.rs @@ -2,8 +2,6 @@ //! //! ckb launcher is helps to launch ckb node. -mod shared_builder; - use ckb_app_config::{ BlockAssemblerConfig, ExitCode, RpcConfig, RpcModule, RunArgs, SupportProtocol, }; diff --git a/util/launcher/src/shared_builder.rs b/util/launcher/src/shared_builder.rs deleted file mode 100644 index 3055a08409..0000000000 --- a/util/launcher/src/shared_builder.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! Shared factory -//! -//! which can be used in order to configure the properties of a new shared. - -use ckb_app_config::ExitCode; -use ckb_app_config::{BlockAssemblerConfig, DBConfig, NotifyConfig, StoreConfig, TxPoolConfig}; -use ckb_async_runtime::{new_background_runtime, Handle}; -use ckb_chain_spec::consensus::Consensus; -use ckb_chain_spec::SpecError; -use ckb_channel::Receiver; -use ckb_db::RocksDB; -use ckb_db_schema::COLUMNS; -use ckb_error::{Error, InternalErrorKind}; -use ckb_freezer::Freezer; -use ckb_logger::{error, info}; -use ckb_migrate::migrate::Migrate; -use ckb_notify::{NotifyController, NotifyService, PoolTransactionEntry}; -use ckb_proposal_table::ProposalTable; -use ckb_proposal_table::ProposalView; -use ckb_shared::Shared; -use ckb_snapshot::{Snapshot, SnapshotMgr}; - -use ckb_store::ChainDB; -use ckb_store::ChainStore; -use ckb_tx_pool::{ - error::Reject, service::TxVerificationResult, TokioRwLock, TxEntry, TxPool, - TxPoolServiceBuilder, -}; -use ckb_types::core::EpochExt; -use ckb_types::core::HeaderView; -use ckb_verification::cache::init_cache; -use std::cmp::Ordering; -use std::collections::HashSet; -use std::path::{Path, PathBuf}; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; -use tempfile::TempDir; From 0d69b2593a7bfc594e84672bff6fc1f73fe60221 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:55:07 +0800 Subject: [PATCH 07/26] Make `ckb-shared::shared_builder` public --- shared/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 6465217a0f..e6709238e5 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -2,7 +2,7 @@ // num_cpus is used in proc_macro pub mod shared; -mod shared_builder; +pub mod shared_builder; pub use ckb_snapshot::{Snapshot, SnapshotMgr}; pub use shared::Shared; From b8775184e70bd07672ef8ba6e66ec34c6ad451d1 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 18:55:32 +0800 Subject: [PATCH 08/26] Let `ckb-launcher` import `ckb-shared` --- util/launcher/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/launcher/src/lib.rs b/util/launcher/src/lib.rs index d6c09849ca..b0e4af2de5 100644 --- a/util/launcher/src/lib.rs +++ b/util/launcher/src/lib.rs @@ -31,7 +31,7 @@ use ckb_verification::GenesisVerifier; use ckb_verification_traits::Verifier; use std::sync::Arc; -pub use crate::shared_builder::{SharedBuilder, SharedPackage}; +pub use ckb_shared::shared_builder::{SharedBuilder, SharedPackage}; const SECP256K1_BLAKE160_SIGHASH_ALL_ARG_LEN: usize = 20; From ab2891a82529f199f4c029b423b45a533f449483 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:01:40 +0800 Subject: [PATCH 09/26] Update `Cargo.lock` by `make prod` --- Cargo.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5c854a555d..2b428946f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1345,6 +1345,7 @@ name = "ckb-shared" version = "0.113.0-pre" dependencies = [ "arc-swap", + "ckb-app-config", "ckb-async-runtime", "ckb-chain-spec", "ckb-channel", @@ -1353,6 +1354,7 @@ dependencies = [ "ckb-db-schema", "ckb-error", "ckb-logger", + "ckb-migrate", "ckb-notify", "ckb-proposal-table", "ckb-snapshot", @@ -1362,6 +1364,8 @@ dependencies = [ "ckb-tx-pool", "ckb-types", "ckb-verification", + "once_cell", + "tempfile", ] [[package]] From 64a646ab75ca70d3d5fd6c1c04ec4fd139154a9b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:28:29 +0800 Subject: [PATCH 10/26] Prevent `ckb-launcher` re-export `ckb-shared::shared_builder` --- util/launcher/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/launcher/src/lib.rs b/util/launcher/src/lib.rs index b0e4af2de5..3c14a139df 100644 --- a/util/launcher/src/lib.rs +++ b/util/launcher/src/lib.rs @@ -23,6 +23,7 @@ use ckb_resource::Resource; use ckb_rpc::{RpcServer, ServiceBuilder}; use ckb_shared::Shared; +use ckb_shared::shared_builder::{SharedBuilder, SharedPackage}; use ckb_store::{ChainDB, ChainStore}; use ckb_sync::{BlockFilter, NetTimeProtocol, Relayer, SyncShared, Synchronizer}; use ckb_tx_pool::service::TxVerificationResult; @@ -31,8 +32,6 @@ use ckb_verification::GenesisVerifier; use ckb_verification_traits::Verifier; use std::sync::Arc; -pub use ckb_shared::shared_builder::{SharedBuilder, SharedPackage}; - const SECP256K1_BLAKE160_SIGHASH_ALL_ARG_LEN: usize = 20; /// Ckb launcher is helps to launch ckb node. From cdbb1b3ebb7603935c8be16cc3b8df0f23814f94 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:30:38 +0800 Subject: [PATCH 11/26] Re-export `SharedPackage` and `SharedBuilder` for `ckb-shared` --- shared/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/src/lib.rs b/shared/src/lib.rs index e6709238e5..63bfa56a35 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -6,3 +6,4 @@ pub mod shared_builder; pub use ckb_snapshot::{Snapshot, SnapshotMgr}; pub use shared::Shared; +pub use shared_builder::{SharedBuilder, SharedPackage}; From a2a143c043304ebc8a305ee3ef4412079bd51438 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:52:15 +0800 Subject: [PATCH 12/26] Fix `ckb_shared::SharedBuilder` usage in verification-contextual --- verification/contextual/Cargo.toml | 1 - verification/contextual/src/tests/contextual_block_verifier.rs | 2 +- verification/contextual/src/tests/uncle_verifier.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/verification/contextual/Cargo.toml b/verification/contextual/Cargo.toml index 26953c8657..09f5316fa2 100644 --- a/verification/contextual/Cargo.toml +++ b/verification/contextual/Cargo.toml @@ -29,7 +29,6 @@ ckb-merkle-mountain-range = "0.5.2" [dev-dependencies] ckb-chain = { path = "../../chain", version = "= 0.113.0-pre" } ckb-shared = { path = "../../shared", version = "= 0.113.0-pre" } -ckb-launcher = { path = "../../util/launcher", version = "= 0.113.0-pre" } ckb-test-chain-utils = { path = "../../util/test-chain-utils", version = "= 0.113.0-pre" } ckb-systemtime = { path = "../../util/systemtime", version = "= 0.113.0-pre", features = ["enable_faketime"]} rand = "0.7" diff --git a/verification/contextual/src/tests/contextual_block_verifier.rs b/verification/contextual/src/tests/contextual_block_verifier.rs index 06e4ed79f6..cd599d1439 100644 --- a/verification/contextual/src/tests/contextual_block_verifier.rs +++ b/verification/contextual/src/tests/contextual_block_verifier.rs @@ -3,7 +3,7 @@ use crate::contextual_block_verifier::{RewardVerifier, VerifyContext}; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_error::assert_error_eq; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::Shared; use ckb_store::{ChainDB, ChainStore}; use ckb_test_chain_utils::always_success_cell; diff --git a/verification/contextual/src/tests/uncle_verifier.rs b/verification/contextual/src/tests/uncle_verifier.rs index 1e89a86117..39d5707364 100644 --- a/verification/contextual/src/tests/uncle_verifier.rs +++ b/verification/contextual/src/tests/uncle_verifier.rs @@ -5,7 +5,7 @@ use crate::uncles_verifier::UnclesVerifier; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::Consensus; use ckb_error::assert_error_eq; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::Shared; use ckb_store::{ChainDB, ChainStore}; use ckb_types::{ From 5c0504e4f6c34dee4110eb3315b960617f7077d2 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:52:35 +0800 Subject: [PATCH 13/26] Fix `ckb_shared::SharedBuilder` usage in light-client-protocol-server --- util/light-client-protocol-server/Cargo.toml | 1 - util/light-client-protocol-server/src/tests/utils/chain.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/util/light-client-protocol-server/Cargo.toml b/util/light-client-protocol-server/Cargo.toml index c55c9727ee..979c634f12 100644 --- a/util/light-client-protocol-server/Cargo.toml +++ b/util/light-client-protocol-server/Cargo.toml @@ -21,7 +21,6 @@ ckb-systemtime = {path = "../systemtime", version = "= 0.113.0-pre"} ckb-chain = { path = "../../chain", version = "= 0.113.0-pre" } ckb-chain-spec = { path = "../../spec", version = "= 0.113.0-pre" } ckb-tx-pool = { path = "../../tx-pool", version = "= 0.113.0-pre" } -ckb-launcher = { path = "../launcher", version = "= 0.113.0-pre" } ckb-app-config = { path = "../app-config", version = "= 0.113.0-pre" } ckb-jsonrpc-types = { path = "../jsonrpc-types", version = "= 0.113.0-pre" } ckb-dao-utils = { path = "../dao/utils", version = "= 0.113.0-pre" } diff --git a/util/light-client-protocol-server/src/tests/utils/chain.rs b/util/light-client-protocol-server/src/tests/utils/chain.rs index fcfd483a86..ffa6e49dfd 100644 --- a/util/light-client-protocol-server/src/tests/utils/chain.rs +++ b/util/light-client-protocol-server/src/tests/utils/chain.rs @@ -8,7 +8,7 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{build_genesis_epoch_ext, ConsensusBuilder}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::Shared; use ckb_systemtime::unix_time_as_millis; From 8b4612e5294dc7e6d1e7cf273fd9eed22b09ef3b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:52:44 +0800 Subject: [PATCH 14/26] Fix `ckb_shared::SharedBuilder` usage in ckb-sync --- sync/Cargo.toml | 1 - sync/src/relayer/tests/helper.rs | 2 +- sync/src/tests/sync_shared.rs | 2 +- sync/src/tests/synchronizer/basic_sync.rs | 2 +- sync/src/tests/synchronizer/functions.rs | 2 +- sync/src/tests/util.rs | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 79c1d1e5c7..9b81f0a99b 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -48,7 +48,6 @@ ckb-dao = { path = "../util/dao", version = "= 0.113.0-pre" } ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.113.0-pre" } ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.113.0-pre" } ckb-chain = { path = "../chain", version = "= 0.113.0-pre", features = ["mock"] } -ckb-launcher = { path = "../util/launcher", version = "= 0.113.0-pre" } faux = "^0.1" once_cell = "1.8.0" ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre" , features = ["enable_faketime"]} diff --git a/sync/src/relayer/tests/helper.rs b/sync/src/relayer/tests/helper.rs index eb6b3c0a08..ad3b9fe3bf 100644 --- a/sync/src/relayer/tests/helper.rs +++ b/sync/src/relayer/tests/helper.rs @@ -2,7 +2,7 @@ use crate::{Relayer, SyncShared}; use ckb_app_config::NetworkConfig; use ckb_chain::chain::ChainService; use ckb_chain_spec::consensus::{build_genesis_epoch_ext, ConsensusBuilder}; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{ async_trait, bytes::Bytes as P2pBytes, Behaviour, CKBProtocolContext, Error, Flags, NetworkController, NetworkService, NetworkState, Peer, PeerIndex, ProtocolId, SupportProtocols, diff --git a/sync/src/tests/sync_shared.rs b/sync/src/tests/sync_shared.rs index 0543d4bf69..9955ef84b7 100644 --- a/sync/src/tests/sync_shared.rs +++ b/sync/src/tests/sync_shared.rs @@ -2,7 +2,7 @@ use crate::block_status::BlockStatus; use crate::tests::util::{build_chain, inherit_block}; use crate::SyncShared; use ckb_chain::chain::ChainService; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_store::{self, ChainStore}; use ckb_test_chain_utils::always_success_cellbase; use ckb_types::core::{BlockBuilder, BlockView, Capacity}; diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index 01796ee363..e0b632f5de 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -9,7 +9,7 @@ use ckb_chain_spec::consensus::ConsensusBuilder; use ckb_channel::bounded; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::SupportProtocols; use ckb_reward_calculator::RewardCalculator; use ckb_shared::Shared; diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 2064589ab6..7b93a14204 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -3,7 +3,7 @@ use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_constant::sync::{CHAIN_SYNC_TIMEOUT, EVICTION_HEADERS_RESPONSE_TIME, MAX_TIP_AGE}; use ckb_dao::DaoCalculator; use ckb_error::InternalErrorKind; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{ async_trait, bytes::Bytes, Behaviour, CKBProtocolContext, Peer, PeerId, PeerIndex, ProtocolId, SessionType, TargetSession, diff --git a/sync/src/tests/util.rs b/sync/src/tests/util.rs index 092981eaaf..6c07458291 100644 --- a/sync/src/tests/util.rs +++ b/sync/src/tests/util.rs @@ -1,7 +1,7 @@ use crate::SyncShared; use ckb_chain::chain::{ChainController, ChainService}; use ckb_dao::DaoCalculator; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_reward_calculator::RewardCalculator; use ckb_shared::{Shared, Snapshot}; use ckb_store::ChainStore; From 3bb3242607d2cd70d7707983378defb4c37e25ca Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:52:50 +0800 Subject: [PATCH 15/26] Fix `ckb_shared::SharedBuilder` usage in ckb-rpc --- rpc/Cargo.toml | 2 +- rpc/src/tests/examples.rs | 2 +- rpc/src/tests/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index b7fe1adbc6..d8bebd1b3b 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -49,7 +49,7 @@ tokio = "1" [dev-dependencies] reqwest = { version = "=0.11.20", features = ["blocking", "json"] } serde = { version = "1.0", features = ["derive"] } -ckb-launcher = { path = "../util/launcher", version = "= 0.113.0-pre" } +ckb-shared = { path = "../shared", version = " = 0.113.0-pre" } ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.113.0-pre" } tempfile.workspace = true pretty_assertions = "1.3.0" diff --git a/rpc/src/tests/examples.rs b/rpc/src/tests/examples.rs index ef03381e54..4be46c567d 100644 --- a/rpc/src/tests/examples.rs +++ b/rpc/src/tests/examples.rs @@ -9,10 +9,10 @@ use ckb_chain::chain::ChainService; use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_chain_spec::versionbits::{ActiveMode, Deployment, DeploymentPos}; use ckb_dao_utils::genesis_dao_data; -use ckb_launcher::SharedBuilder; use ckb_network::{Flags, NetworkService, NetworkState}; use ckb_network_alert::alert_relayer::AlertRelayer; use ckb_notify::NotifyService; +use ckb_shared::SharedBuilder; use ckb_sync::SyncShared; use ckb_test_chain_utils::always_success_cell; use ckb_types::{ diff --git a/rpc/src/tests/mod.rs b/rpc/src/tests/mod.rs index 78ead1f75b..461e5cfc77 100644 --- a/rpc/src/tests/mod.rs +++ b/rpc/src/tests/mod.rs @@ -4,7 +4,7 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::Consensus; use ckb_dao::DaoCalculator; use ckb_jsonrpc_types::ScriptHashType; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkService, NetworkState}; use ckb_reward_calculator::RewardCalculator; use ckb_shared::{Shared, Snapshot}; From 3001cd6b02455f94d21bda53b23aef58d02b7317 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:53:02 +0800 Subject: [PATCH 16/26] Fix `ckb_shared::SharedBuilder` usage in ckb-chain --- chain/Cargo.toml | 1 - chain/src/tests/block_assembler.rs | 2 +- chain/src/tests/find_fork.rs | 2 +- chain/src/tests/truncate.rs | 2 +- chain/src/tests/uncle.rs | 2 +- chain/src/tests/util.rs | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 976925c719..6e7326e322 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -36,7 +36,6 @@ ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.113 ckb-tx-pool = { path = "../tx-pool", version = "= 0.113.0-pre", features = ["internal"] } ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.113.0-pre" } ckb-network = { path = "../network", version = "= 0.113.0-pre" } -ckb-launcher = { path = "../util/launcher", version = "= 0.113.0-pre" } lazy_static = "1.4" tempfile.workspace = true ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre" ,features = ["enable_faketime"]} diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index c8d9bcbe4c..ff7205e057 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -4,7 +4,7 @@ use ckb_app_config::BlockAssemblerConfig; use ckb_chain_spec::consensus::Consensus; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::Shared; use ckb_shared::Snapshot; use ckb_store::ChainStore; diff --git a/chain/src/tests/find_fork.rs b/chain/src/tests/find_fork.rs index 3e1d4bb6ac..78cdc665fa 100644 --- a/chain/src/tests/find_fork.rs +++ b/chain/src/tests/find_fork.rs @@ -1,7 +1,7 @@ use crate::chain::{ChainService, ForkChanges}; use crate::tests::util::{MockChain, MockStore}; use ckb_chain_spec::consensus::{Consensus, ProposalWindow}; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_systemtime::unix_time_as_millis; use ckb_types::{ diff --git a/chain/src/tests/truncate.rs b/chain/src/tests/truncate.rs index c149756e8a..3ad0865e28 100644 --- a/chain/src/tests/truncate.rs +++ b/chain/src/tests/truncate.rs @@ -1,7 +1,7 @@ use crate::chain::ChainService; use crate::tests::util::{MockChain, MockStore}; use ckb_chain_spec::consensus::Consensus; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_verification_traits::Switch; use std::sync::Arc; diff --git a/chain/src/tests/uncle.rs b/chain/src/tests/uncle.rs index c42f0e4d92..3f59352471 100644 --- a/chain/src/tests/uncle.rs +++ b/chain/src/tests/uncle.rs @@ -1,7 +1,7 @@ use crate::chain::ChainService; use crate::tests::util::{MockChain, MockStore}; use ckb_chain_spec::consensus::Consensus; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_verification_traits::Switch; use std::sync::Arc; diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index 7ade19bc53..ac1bdd710b 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -5,7 +5,7 @@ use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::shared::Shared; use ckb_store::ChainStore; From eb78eabcc0474329828821024d48f7de2a1da0ba Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:53:21 +0800 Subject: [PATCH 17/26] Fix `ckb_shared::SharedBuilder` usage in ckb-benches --- benches/Cargo.toml | 1 - benches/benches/benchmarks/overall.rs | 2 +- benches/benches/benchmarks/resolve.rs | 2 +- benches/benches/benchmarks/util.rs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index b09e42db2e..91b5925e09 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -32,7 +32,6 @@ ckb-verification-traits = { path = "../verification/traits", version = "= 0.113. ckb-app-config = { path = "../util/app-config", version = "= 0.113.0-pre" } ckb-resource = { path = "../resource", version = "= 0.113.0-pre" } ckb-network = { path = "../network", version = "= 0.113.0-pre" } -ckb-launcher = { path = "../util/launcher", version = "= 0.113.0-pre" } tempfile.workspace = true [[bench]] diff --git a/benches/benches/benchmarks/overall.rs b/benches/benches/benchmarks/overall.rs index 15a76de599..2a42a1b0d3 100644 --- a/benches/benches/benchmarks/overall.rs +++ b/benches/benches/benchmarks/overall.rs @@ -5,7 +5,7 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::JsonBytes; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::Shared; use ckb_store::ChainStore; diff --git a/benches/benches/benchmarks/resolve.rs b/benches/benches/benchmarks/resolve.rs index 2d3545126e..83c4897335 100644 --- a/benches/benches/benchmarks/resolve.rs +++ b/benches/benches/benchmarks/resolve.rs @@ -3,7 +3,7 @@ use ckb_app_config::{BlockAssemblerConfig, TxPoolConfig}; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::{ChainSpec, IssuedCell}; use ckb_jsonrpc_types::JsonBytes; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_resource::Resource; use ckb_shared::{Shared, Snapshot}; use ckb_types::{ diff --git a/benches/benches/benchmarks/util.rs b/benches/benches/benchmarks/util.rs index 52ac98b071..5ede86be56 100644 --- a/benches/benches/benchmarks/util.rs +++ b/benches/benches/benchmarks/util.rs @@ -3,7 +3,7 @@ use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow}; use ckb_crypto::secp::Privkey; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::{Shared, Snapshot}; use ckb_store::ChainStore; use ckb_system_scripts::BUNDLED_CELL; From 8f4f597e0db9b0e1c966cabb1d0a40c574d4d5e3 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:53:30 +0800 Subject: [PATCH 18/26] Fix `ckb_shared::SharedBuilder` usage in ckb-bin --- ckb-bin/src/subcommand/export.rs | 2 +- ckb-bin/src/subcommand/import.rs | 2 +- ckb-bin/src/subcommand/replay.rs | 2 +- ckb-bin/src/subcommand/stats.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ckb-bin/src/subcommand/export.rs b/ckb-bin/src/subcommand/export.rs index 4ec13245be..04459d3f67 100644 --- a/ckb-bin/src/subcommand/export.rs +++ b/ckb-bin/src/subcommand/export.rs @@ -1,7 +1,7 @@ use ckb_app_config::{ExitCode, ExportArgs}; use ckb_async_runtime::Handle; use ckb_instrument::Export; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; pub fn export(args: ExportArgs, async_handle: Handle) -> Result<(), ExitCode> { let builder = SharedBuilder::new( diff --git a/ckb-bin/src/subcommand/import.rs b/ckb-bin/src/subcommand/import.rs index 574da91d49..8c03cfd7f9 100644 --- a/ckb-bin/src/subcommand/import.rs +++ b/ckb-bin/src/subcommand/import.rs @@ -2,7 +2,7 @@ use ckb_app_config::{ExitCode, ImportArgs}; use ckb_async_runtime::Handle; use ckb_chain::chain::ChainService; use ckb_instrument::Import; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; pub fn import(args: ImportArgs, async_handle: Handle) -> Result<(), ExitCode> { let builder = SharedBuilder::new( diff --git a/ckb-bin/src/subcommand/replay.rs b/ckb-bin/src/subcommand/replay.rs index 592924dd73..0b3f0ce140 100644 --- a/ckb-bin/src/subcommand/replay.rs +++ b/ckb-bin/src/subcommand/replay.rs @@ -3,7 +3,7 @@ use ckb_async_runtime::Handle; use ckb_chain::chain::ChainService; use ckb_chain_iter::ChainIterator; use ckb_instrument::{ProgressBar, ProgressStyle}; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::Shared; use ckb_store::ChainStore; use ckb_verification_traits::Switch; diff --git a/ckb-bin/src/subcommand/stats.rs b/ckb-bin/src/subcommand/stats.rs index 50583f742a..52b9ccc5d8 100644 --- a/ckb-bin/src/subcommand/stats.rs +++ b/ckb-bin/src/subcommand/stats.rs @@ -1,6 +1,6 @@ use ckb_app_config::{ExitCode, StatsArgs}; use ckb_async_runtime::Handle; -use ckb_launcher::SharedBuilder; +use ckb_shared::SharedBuilder; use ckb_shared::Shared; use ckb_store::ChainStore; use ckb_types::{ From 13c49d2671d029859b6d91af247a319ca2cb9a90 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 17 Nov 2023 19:53:42 +0800 Subject: [PATCH 19/26] Update `Cargo.lock` by `make prod` --- Cargo.lock | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b428946f8..8c38cb4271 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -526,7 +526,6 @@ dependencies = [ "ckb-dao-utils", "ckb-hash", "ckb-jsonrpc-types", - "ckb-launcher", "ckb-network", "ckb-resource", "ckb-shared", @@ -611,7 +610,6 @@ dependencies = [ "ckb-dao-utils", "ckb-error", "ckb-jsonrpc-types", - "ckb-launcher", "ckb-logger", "ckb-merkle-mountain-range", "ckb-metrics", @@ -925,7 +923,6 @@ dependencies = [ "ckb-chain-spec", "ckb-dao-utils", "ckb-jsonrpc-types", - "ckb-launcher", "ckb-logger", "ckb-merkle-mountain-range", "ckb-network", @@ -1272,7 +1269,6 @@ dependencies = [ "ckb-error", "ckb-indexer", "ckb-jsonrpc-types", - "ckb-launcher", "ckb-logger", "ckb-logger-service", "ckb-memory-tracker", @@ -1436,7 +1432,6 @@ dependencies = [ "ckb-dao", "ckb-dao-utils", "ckb-error", - "ckb-launcher", "ckb-logger", "ckb-metrics", "ckb-network", @@ -1612,7 +1607,6 @@ dependencies = [ "ckb-dao", "ckb-dao-utils", "ckb-error", - "ckb-launcher", "ckb-logger", "ckb-merkle-mountain-range", "ckb-reward-calculator", From ce24fc09fa069959a9c2318ad6a514408e48f341 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sat, 18 Nov 2023 23:48:04 +0800 Subject: [PATCH 20/26] Execute `cargo fmt` --- benches/benches/benchmarks/overall.rs | 2 +- benches/benches/benchmarks/resolve.rs | 2 +- chain/src/tests/block_assembler.rs | 2 +- chain/src/tests/util.rs | 2 +- ckb-bin/src/subcommand/replay.rs | 2 +- ckb-bin/src/subcommand/stats.rs | 2 +- rpc/src/tests/mod.rs | 2 +- sync/src/relayer/tests/helper.rs | 2 +- sync/src/tests/synchronizer/basic_sync.rs | 2 +- sync/src/tests/synchronizer/functions.rs | 2 +- sync/src/tests/util.rs | 2 +- util/light-client-protocol-server/src/tests/utils/chain.rs | 2 +- verification/contextual/src/tests/contextual_block_verifier.rs | 2 +- verification/contextual/src/tests/uncle_verifier.rs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/benches/benches/benchmarks/overall.rs b/benches/benches/benchmarks/overall.rs index 2a42a1b0d3..70324e8dbd 100644 --- a/benches/benches/benchmarks/overall.rs +++ b/benches/benches/benchmarks/overall.rs @@ -5,9 +5,9 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::JsonBytes; -use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_types::{ bytes::Bytes, diff --git a/benches/benches/benchmarks/resolve.rs b/benches/benches/benchmarks/resolve.rs index 83c4897335..f057b99d0c 100644 --- a/benches/benches/benchmarks/resolve.rs +++ b/benches/benches/benchmarks/resolve.rs @@ -3,8 +3,8 @@ use ckb_app_config::{BlockAssemblerConfig, TxPoolConfig}; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::{ChainSpec, IssuedCell}; use ckb_jsonrpc_types::JsonBytes; -use ckb_shared::SharedBuilder; use ckb_resource::Resource; +use ckb_shared::SharedBuilder; use ckb_shared::{Shared, Snapshot}; use ckb_types::{ bytes::Bytes, diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index ff7205e057..76bfc984fe 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -4,8 +4,8 @@ use ckb_app_config::BlockAssemblerConfig; use ckb_chain_spec::consensus::Consensus; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_shared::SharedBuilder; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_shared::Snapshot; use ckb_store::ChainStore; use ckb_tx_pool::{block_assembler::CandidateUncles, PlugTarget, TxEntry}; diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index ac1bdd710b..b7fcb5e1e3 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -5,9 +5,9 @@ use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; pub use ckb_test_chain_utils::MockStore; use ckb_test_chain_utils::{ diff --git a/ckb-bin/src/subcommand/replay.rs b/ckb-bin/src/subcommand/replay.rs index 0b3f0ce140..7ae7958d5f 100644 --- a/ckb-bin/src/subcommand/replay.rs +++ b/ckb-bin/src/subcommand/replay.rs @@ -3,8 +3,8 @@ use ckb_async_runtime::Handle; use ckb_chain::chain::ChainService; use ckb_chain_iter::ChainIterator; use ckb_instrument::{ProgressBar, ProgressStyle}; -use ckb_shared::SharedBuilder; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_verification_traits::Switch; use std::sync::Arc; diff --git a/ckb-bin/src/subcommand/stats.rs b/ckb-bin/src/subcommand/stats.rs index 52b9ccc5d8..94342758a5 100644 --- a/ckb-bin/src/subcommand/stats.rs +++ b/ckb-bin/src/subcommand/stats.rs @@ -1,7 +1,7 @@ use ckb_app_config::{ExitCode, StatsArgs}; use ckb_async_runtime::Handle; -use ckb_shared::SharedBuilder; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_types::{ core::{BlockNumber, ScriptHashType}, diff --git a/rpc/src/tests/mod.rs b/rpc/src/tests/mod.rs index 461e5cfc77..b56f513c75 100644 --- a/rpc/src/tests/mod.rs +++ b/rpc/src/tests/mod.rs @@ -4,9 +4,9 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::Consensus; use ckb_dao::DaoCalculator; use ckb_jsonrpc_types::ScriptHashType; -use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkService, NetworkState}; use ckb_reward_calculator::RewardCalculator; +use ckb_shared::SharedBuilder; use ckb_shared::{Shared, Snapshot}; use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cell, always_success_cellbase}; diff --git a/sync/src/relayer/tests/helper.rs b/sync/src/relayer/tests/helper.rs index ad3b9fe3bf..643373a8e5 100644 --- a/sync/src/relayer/tests/helper.rs +++ b/sync/src/relayer/tests/helper.rs @@ -2,13 +2,13 @@ use crate::{Relayer, SyncShared}; use ckb_app_config::NetworkConfig; use ckb_chain::chain::ChainService; use ckb_chain_spec::consensus::{build_genesis_epoch_ext, ConsensusBuilder}; -use ckb_shared::SharedBuilder; use ckb_network::{ async_trait, bytes::Bytes as P2pBytes, Behaviour, CKBProtocolContext, Error, Flags, NetworkController, NetworkService, NetworkState, Peer, PeerIndex, ProtocolId, SupportProtocols, TargetSession, }; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_systemtime::{self, unix_time_as_millis}; use ckb_test_chain_utils::always_success_cell; diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index e0b632f5de..b5bc2e1562 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -9,10 +9,10 @@ use ckb_chain_spec::consensus::ConsensusBuilder; use ckb_channel::bounded; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; -use ckb_shared::SharedBuilder; use ckb_network::SupportProtocols; use ckb_reward_calculator::RewardCalculator; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::ChainStore; use ckb_systemtime::{self, unix_time_as_millis}; use ckb_test_chain_utils::always_success_cell; diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 7b93a14204..a66399e9b7 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -3,12 +3,12 @@ use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_constant::sync::{CHAIN_SYNC_TIMEOUT, EVICTION_HEADERS_RESPONSE_TIME, MAX_TIP_AGE}; use ckb_dao::DaoCalculator; use ckb_error::InternalErrorKind; -use ckb_shared::SharedBuilder; use ckb_network::{ async_trait, bytes::Bytes, Behaviour, CKBProtocolContext, Peer, PeerId, PeerIndex, ProtocolId, SessionType, TargetSession, }; use ckb_reward_calculator::RewardCalculator; +use ckb_shared::SharedBuilder; use ckb_shared::{Shared, Snapshot}; use ckb_store::ChainStore; use ckb_systemtime::unix_time_as_millis; diff --git a/sync/src/tests/util.rs b/sync/src/tests/util.rs index 6c07458291..dfb1d488e8 100644 --- a/sync/src/tests/util.rs +++ b/sync/src/tests/util.rs @@ -1,8 +1,8 @@ use crate::SyncShared; use ckb_chain::chain::{ChainController, ChainService}; use ckb_dao::DaoCalculator; -use ckb_shared::SharedBuilder; use ckb_reward_calculator::RewardCalculator; +use ckb_shared::SharedBuilder; use ckb_shared::{Shared, Snapshot}; use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cellbase, always_success_consensus}; diff --git a/util/light-client-protocol-server/src/tests/utils/chain.rs b/util/light-client-protocol-server/src/tests/utils/chain.rs index ffa6e49dfd..d8e2a6ee8b 100644 --- a/util/light-client-protocol-server/src/tests/utils/chain.rs +++ b/util/light-client-protocol-server/src/tests/utils/chain.rs @@ -8,9 +8,9 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{build_genesis_epoch_ext, ConsensusBuilder}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_shared::SharedBuilder; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_systemtime::unix_time_as_millis; use ckb_test_chain_utils::always_success_cell; use ckb_tx_pool::TxPoolController; diff --git a/verification/contextual/src/tests/contextual_block_verifier.rs b/verification/contextual/src/tests/contextual_block_verifier.rs index cd599d1439..83741c755c 100644 --- a/verification/contextual/src/tests/contextual_block_verifier.rs +++ b/verification/contextual/src/tests/contextual_block_verifier.rs @@ -3,8 +3,8 @@ use crate::contextual_block_verifier::{RewardVerifier, VerifyContext}; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_error::assert_error_eq; -use ckb_shared::SharedBuilder; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::{ChainDB, ChainStore}; use ckb_test_chain_utils::always_success_cell; use ckb_types::{ diff --git a/verification/contextual/src/tests/uncle_verifier.rs b/verification/contextual/src/tests/uncle_verifier.rs index 39d5707364..0d471f52ec 100644 --- a/verification/contextual/src/tests/uncle_verifier.rs +++ b/verification/contextual/src/tests/uncle_verifier.rs @@ -5,8 +5,8 @@ use crate::uncles_verifier::UnclesVerifier; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::Consensus; use ckb_error::assert_error_eq; -use ckb_shared::SharedBuilder; use ckb_shared::Shared; +use ckb_shared::SharedBuilder; use ckb_store::{ChainDB, ChainStore}; use ckb_types::{ core::{ From 10f85d348b1fb7a0a92707d70f31be244b345a62 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 19 Nov 2023 00:10:28 +0800 Subject: [PATCH 21/26] Add doc for shared_builder Signed-off-by: Eval EXEC --- shared/src/shared_builder.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 32f9c88ea7..e8bb9f9773 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -1,3 +1,4 @@ +//! shared_builder provide SharedBuilder and SharedPacakge use ckb_channel::Receiver; use ckb_proposal_table::ProposalTable; use ckb_tx_pool::service::TxVerificationResult; @@ -45,6 +46,7 @@ pub struct SharedBuilder { async_handle: Handle, } +/// Open or create a rocksdb pub fn open_or_create_db( bin_name: &str, root_dir: &Path, From 0179847064e601d03c6e8c3675231322af732d00 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 19 Nov 2023 00:15:35 +0800 Subject: [PATCH 22/26] Re-format rpc/Cargo.toml --- rpc/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index d8bebd1b3b..eaf36a7eed 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -49,7 +49,7 @@ tokio = "1" [dev-dependencies] reqwest = { version = "=0.11.20", features = ["blocking", "json"] } serde = { version = "1.0", features = ["derive"] } -ckb-shared = { path = "../shared", version = " = 0.113.0-pre" } +ckb-shared = { path = "../shared", version = "= 0.113.0-pre" } ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.113.0-pre" } tempfile.workspace = true pretty_assertions = "1.3.0" From 0ba97b43ad36f6d0dd67293128ab00e60af32ada Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 19 Nov 2023 00:35:38 +0800 Subject: [PATCH 23/26] `ckb-launcher` use `ckb-shared` portable and march-native feature --- Cargo.lock | 10 ---------- shared/Cargo.toml | 4 ++-- util/launcher/Cargo.toml | 14 ++------------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c38cb4271..d517d8d08d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -872,32 +872,22 @@ dependencies = [ "ckb-block-filter", "ckb-build-info", "ckb-chain", - "ckb-chain-spec", "ckb-channel", - "ckb-db", - "ckb-db-schema", - "ckb-error", - "ckb-freezer", "ckb-jsonrpc-types", "ckb-light-client-protocol-server", "ckb-logger", - "ckb-migrate", "ckb-network", "ckb-network-alert", - "ckb-notify", "ckb-proposal-table", "ckb-resource", "ckb-rpc", "ckb-shared", - "ckb-snapshot", "ckb-store", "ckb-sync", "ckb-tx-pool", "ckb-types", "ckb-verification", "ckb-verification-traits", - "once_cell", - "tempfile", ] [[package]] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 58f1336db0..ac19a4b885 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -37,5 +37,5 @@ tempfile.workspace = true ckb-systemtime = { path = "../util/systemtime", version = "= 0.113.0-pre", features = ["enable_faketime"] } [features] -portable = ["ckb-db/portable", "ckb-store/portable", "ckb-tx-pool/portable"] -march-native = ["ckb-db/march-native", "ckb-store/march-native", "ckb-tx-pool/march-native"] +portable = ["ckb-db/portable", "ckb-store/portable", "ckb-tx-pool/portable", "ckb-migrate/portable"] +march-native = ["ckb-db/march-native", "ckb-store/march-native", "ckb-tx-pool/march-native", "ckb-migrate/march-native"] diff --git a/util/launcher/Cargo.toml b/util/launcher/Cargo.toml index 055c3609d8..2c4d2b7dba 100644 --- a/util/launcher/Cargo.toml +++ b/util/launcher/Cargo.toml @@ -13,11 +13,8 @@ repository = "https://github.com/nervosnetwork/ckb" [dependencies] ckb-types = { path = "../types", version = "= 0.113.0-pre" } ckb-store = { path = "../../store", version = "= 0.113.0-pre" } -ckb-db = { path = "../../db", version = "= 0.113.0-pre" } ckb-app-config = { path = "../app-config", version = "= 0.113.0-pre" } ckb-logger = { path = "../logger", version = "= 0.113.0-pre" } -ckb-db-schema = { path = "../../db-schema", version = "= 0.113.0-pre" } -ckb-error = { path = "../../error", version = "= 0.113.0-pre" } ckb-build-info = { path = "../build-info", version = "= 0.113.0-pre" } ckb-jsonrpc-types = { path = "../jsonrpc-types", version = "= 0.113.0-pre" } ckb-chain = { path = "../../chain", version = "= 0.113.0-pre" } @@ -32,18 +29,11 @@ ckb-verification-traits = { path = "../../verification/traits", version = "= 0.1 ckb-async-runtime = { path = "../runtime", version = "= 0.113.0-pre" } ckb-proposal-table = { path = "../proposal-table", version = "= 0.113.0-pre" } ckb-channel = { path = "../channel", version = "= 0.113.0-pre" } -ckb-chain-spec = { path = "../../spec", version = "= 0.113.0-pre" } -ckb-freezer = { path = "../../freezer", version = "= 0.113.0-pre" } -ckb-notify = { path = "../../notify", version = "= 0.113.0-pre" } -ckb-snapshot = { path = "../snapshot", version = "= 0.113.0-pre" } ckb-tx-pool = { path = "../../tx-pool", version = "= 0.113.0-pre" } ckb-light-client-protocol-server = { path = "../light-client-protocol-server", version = "= 0.113.0-pre" } ckb-block-filter = { path = "../../block-filter", version = "= 0.113.0-pre" } -ckb-migrate = { path = "../migrate", version = "= 0.113.0-pre" } -once_cell = "1.8.0" -tempfile.workspace = true [features] with_sentry = [ "ckb-sync/with_sentry", "ckb-network/with_sentry", "ckb-app-config/with_sentry" ] -portable = ["ckb-db/portable", "ckb-migrate/portable"] -march-native = ["ckb-db/march-native", "ckb-migrate/march-native"] +portable = ["ckb-shared/portable"] +march-native = ["ckb-shared/march-native"] From 5d8e8a1ff420c420f6139c57d20cde39eb3c5c8b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sun, 19 Nov 2023 00:49:39 +0800 Subject: [PATCH 24/26] Sort ckb's workspace members --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7711140c3..5a20572a33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ members = [ "error", "util/multisig", "util/gen-types", + "util/migrate/migration-template", "util/types", "util/jsonrpc-types", "freezer", @@ -76,6 +77,7 @@ members = [ "util/dao", "util/reward-calculator", "util/snapshot", + "util/migrate", "verification/traits", "verification", "verification/contextual", @@ -86,8 +88,6 @@ members = [ "sync", "util/instrument", "rpc", - "util/migrate/migration-template", - "util/migrate", "util/light-client-protocol-server", "util/launcher", "ckb-bin" From 1c0619362da72c1e2b3b4834c57b42362aa1f059 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 20 Nov 2023 16:03:31 +0800 Subject: [PATCH 25/26] Merge `ckb_shared`'s import statements Co-authored-by: Quake Wang --- benches/benches/benchmarks/resolve.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/benches/benches/benchmarks/resolve.rs b/benches/benches/benchmarks/resolve.rs index f057b99d0c..ebc278351b 100644 --- a/benches/benches/benchmarks/resolve.rs +++ b/benches/benches/benchmarks/resolve.rs @@ -4,8 +4,7 @@ use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::{ChainSpec, IssuedCell}; use ckb_jsonrpc_types::JsonBytes; use ckb_resource::Resource; -use ckb_shared::SharedBuilder; -use ckb_shared::{Shared, Snapshot}; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_types::{ bytes::Bytes, core::{ From 480f1b1b4e85ff41b624d2ff6d597cf45eed2445 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 20 Nov 2023 16:10:34 +0800 Subject: [PATCH 26/26] Merge `ckb_shared` related import statements into one line --- benches/benches/benchmarks/overall.rs | 3 +-- benches/benches/benchmarks/util.rs | 3 +-- chain/src/tests/block_assembler.rs | 4 +--- chain/src/tests/util.rs | 3 +-- ckb-bin/src/subcommand/replay.rs | 3 +-- ckb-bin/src/subcommand/stats.rs | 3 +-- rpc/src/tests/mod.rs | 3 +-- sync/src/relayer/tests/helper.rs | 3 +-- sync/src/tests/synchronizer/basic_sync.rs | 3 +-- sync/src/tests/synchronizer/functions.rs | 3 +-- sync/src/tests/util.rs | 3 +-- util/light-client-protocol-server/src/tests/utils/chain.rs | 3 +-- .../contextual/src/tests/contextual_block_verifier.rs | 3 +-- verification/contextual/src/tests/uncle_verifier.rs | 3 +-- 14 files changed, 14 insertions(+), 29 deletions(-) diff --git a/benches/benches/benchmarks/overall.rs b/benches/benches/benchmarks/overall.rs index 70324e8dbd..74bf84b953 100644 --- a/benches/benches/benchmarks/overall.rs +++ b/benches/benches/benchmarks/overall.rs @@ -6,8 +6,7 @@ use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::JsonBytes; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; use ckb_types::{ bytes::Bytes, diff --git a/benches/benches/benchmarks/util.rs b/benches/benches/benchmarks/util.rs index 5ede86be56..8c21dddc3b 100644 --- a/benches/benches/benchmarks/util.rs +++ b/benches/benches/benchmarks/util.rs @@ -3,8 +3,7 @@ use ckb_chain_spec::consensus::{ConsensusBuilder, ProposalWindow}; use ckb_crypto::secp::Privkey; use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; -use ckb_shared::SharedBuilder; -use ckb_shared::{Shared, Snapshot}; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_store::ChainStore; use ckb_system_scripts::BUNDLED_CELL; use ckb_test_chain_utils::always_success_cell; diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index 76bfc984fe..6f5c5e2193 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -4,9 +4,7 @@ use ckb_app_config::BlockAssemblerConfig; use ckb_chain_spec::consensus::Consensus; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; -use ckb_shared::Snapshot; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_store::ChainStore; use ckb_tx_pool::{block_assembler::CandidateUncles, PlugTarget, TxEntry}; use ckb_types::{ diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index b7fcb5e1e3..d3f1e7da65 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -6,8 +6,7 @@ use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; -use ckb_shared::shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; pub use ckb_test_chain_utils::MockStore; use ckb_test_chain_utils::{ diff --git a/ckb-bin/src/subcommand/replay.rs b/ckb-bin/src/subcommand/replay.rs index 7ae7958d5f..ea84479cf0 100644 --- a/ckb-bin/src/subcommand/replay.rs +++ b/ckb-bin/src/subcommand/replay.rs @@ -3,8 +3,7 @@ use ckb_async_runtime::Handle; use ckb_chain::chain::ChainService; use ckb_chain_iter::ChainIterator; use ckb_instrument::{ProgressBar, ProgressStyle}; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; use ckb_verification_traits::Switch; use std::sync::Arc; diff --git a/ckb-bin/src/subcommand/stats.rs b/ckb-bin/src/subcommand/stats.rs index 94342758a5..e0edc73fc1 100644 --- a/ckb-bin/src/subcommand/stats.rs +++ b/ckb-bin/src/subcommand/stats.rs @@ -1,7 +1,6 @@ use ckb_app_config::{ExitCode, StatsArgs}; use ckb_async_runtime::Handle; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; use ckb_types::{ core::{BlockNumber, ScriptHashType}, diff --git a/rpc/src/tests/mod.rs b/rpc/src/tests/mod.rs index b56f513c75..8551cd706a 100644 --- a/rpc/src/tests/mod.rs +++ b/rpc/src/tests/mod.rs @@ -6,8 +6,7 @@ use ckb_dao::DaoCalculator; use ckb_jsonrpc_types::ScriptHashType; use ckb_network::{Flags, NetworkService, NetworkState}; use ckb_reward_calculator::RewardCalculator; -use ckb_shared::SharedBuilder; -use ckb_shared::{Shared, Snapshot}; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cell, always_success_cellbase}; use ckb_types::{ diff --git a/sync/src/relayer/tests/helper.rs b/sync/src/relayer/tests/helper.rs index 643373a8e5..0531c302a6 100644 --- a/sync/src/relayer/tests/helper.rs +++ b/sync/src/relayer/tests/helper.rs @@ -7,8 +7,7 @@ use ckb_network::{ NetworkController, NetworkService, NetworkState, Peer, PeerIndex, ProtocolId, SupportProtocols, TargetSession, }; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; use ckb_systemtime::{self, unix_time_as_millis}; use ckb_test_chain_utils::always_success_cell; diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index b5bc2e1562..9c5c1977b6 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -11,8 +11,7 @@ use ckb_dao::DaoCalculator; use ckb_dao_utils::genesis_dao_data; use ckb_network::SupportProtocols; use ckb_reward_calculator::RewardCalculator; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::ChainStore; use ckb_systemtime::{self, unix_time_as_millis}; use ckb_test_chain_utils::always_success_cell; diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index a66399e9b7..8b71178d0c 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -8,8 +8,7 @@ use ckb_network::{ SessionType, TargetSession, }; use ckb_reward_calculator::RewardCalculator; -use ckb_shared::SharedBuilder; -use ckb_shared::{Shared, Snapshot}; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_store::ChainStore; use ckb_systemtime::unix_time_as_millis; use ckb_types::{ diff --git a/sync/src/tests/util.rs b/sync/src/tests/util.rs index dfb1d488e8..0ccf5ba2e8 100644 --- a/sync/src/tests/util.rs +++ b/sync/src/tests/util.rs @@ -2,8 +2,7 @@ use crate::SyncShared; use ckb_chain::chain::{ChainController, ChainService}; use ckb_dao::DaoCalculator; use ckb_reward_calculator::RewardCalculator; -use ckb_shared::SharedBuilder; -use ckb_shared::{Shared, Snapshot}; +use ckb_shared::{Shared, SharedBuilder, Snapshot}; use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cellbase, always_success_consensus}; use ckb_types::prelude::*; diff --git a/util/light-client-protocol-server/src/tests/utils/chain.rs b/util/light-client-protocol-server/src/tests/utils/chain.rs index d8e2a6ee8b..177d4c9bee 100644 --- a/util/light-client-protocol-server/src/tests/utils/chain.rs +++ b/util/light-client-protocol-server/src/tests/utils/chain.rs @@ -9,8 +9,7 @@ use ckb_chain_spec::consensus::{build_genesis_epoch_ext, ConsensusBuilder}; use ckb_dao_utils::genesis_dao_data; use ckb_jsonrpc_types::ScriptHashType; use ckb_network::{Flags, NetworkController, NetworkService, NetworkState}; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_systemtime::unix_time_as_millis; use ckb_test_chain_utils::always_success_cell; use ckb_tx_pool::TxPoolController; diff --git a/verification/contextual/src/tests/contextual_block_verifier.rs b/verification/contextual/src/tests/contextual_block_verifier.rs index 83741c755c..a53b1146ba 100644 --- a/verification/contextual/src/tests/contextual_block_verifier.rs +++ b/verification/contextual/src/tests/contextual_block_verifier.rs @@ -3,8 +3,7 @@ use crate::contextual_block_verifier::{RewardVerifier, VerifyContext}; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::{Consensus, ConsensusBuilder}; use ckb_error::assert_error_eq; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::{ChainDB, ChainStore}; use ckb_test_chain_utils::always_success_cell; use ckb_types::{ diff --git a/verification/contextual/src/tests/uncle_verifier.rs b/verification/contextual/src/tests/uncle_verifier.rs index 0d471f52ec..af12732084 100644 --- a/verification/contextual/src/tests/uncle_verifier.rs +++ b/verification/contextual/src/tests/uncle_verifier.rs @@ -5,8 +5,7 @@ use crate::uncles_verifier::UnclesVerifier; use ckb_chain::chain::{ChainController, ChainService}; use ckb_chain_spec::consensus::Consensus; use ckb_error::assert_error_eq; -use ckb_shared::Shared; -use ckb_shared::SharedBuilder; +use ckb_shared::{Shared, SharedBuilder}; use ckb_store::{ChainDB, ChainStore}; use ckb_types::{ core::{