diff --git a/rpc/src/module/net.rs b/rpc/src/module/net.rs index de75699e68..855cefae7a 100644 --- a/rpc/src/module/net.rs +++ b/rpc/src/module/net.rs @@ -739,7 +739,7 @@ impl NetRpc for NetRpcImpl { let unverified_tip = shared.get_unverified_tip(); let sync_state = SyncState { ibd: chain.is_initial_block_download(), - assume_valid_target_reached: shared.assume_valid_target().is_none(), + assume_valid_target_reached: shared.assume_valid_targets().is_none(), assume_valid_target: shared .assume_valid_target_specified() .as_ref() diff --git a/shared/src/shared.rs b/shared/src/shared.rs index 2939230a5f..8b523bfc83 100644 --- a/shared/src/shared.rs +++ b/shared/src/shared.rs @@ -62,7 +62,7 @@ pub struct Shared { pub(crate) async_handle: Handle, pub(crate) ibd_finished: Arc, - pub(crate) assume_valid_target: Arc>>, + pub(crate) assume_valid_targets: Arc>>>, pub(crate) assume_valid_target_specified: Arc>, pub header_map: Arc, @@ -83,7 +83,7 @@ impl Shared { async_handle: Handle, ibd_finished: Arc, - assume_valid_target: Arc>>, + assume_valid_targets: Arc>>>, assume_valid_target_specified: Arc>, header_map: Arc, block_status_map: Arc>, @@ -106,7 +106,7 @@ impl Shared { snapshot_mgr, async_handle, ibd_finished, - assume_valid_target, + assume_valid_targets, assume_valid_target_specified, header_map, block_status_map, @@ -467,8 +467,8 @@ impl Shared { ); } - pub fn assume_valid_target(&self) -> MutexGuard> { - self.assume_valid_target.lock() + pub fn assume_valid_targets(&self) -> MutexGuard>> { + self.assume_valid_targets.lock() } pub fn assume_valid_target_specified(&self) -> Arc> { diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 47f0a85e4e..72b0ce3343 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -25,6 +25,7 @@ use ckb_tx_pool::{ }; use ckb_types::core::hardfork::HardForks; use ckb_types::prelude::Pack; +use ckb_types::H256; use ckb_types::{ core::service::PoolTransactionEntry, core::tx_pool::Reject, core::EpochExt, core::HeaderView, }; @@ -352,10 +353,12 @@ impl SharedBuilder { sync_config: &SyncConfig, snapshot: &Snapshot, ) -> bool { - if let Some(ref target) = sync_config.assume_valid_target { - if snapshot.block_exists(&target.pack()) { - info!("assume valid target is already in db, CKB will do full verification from now on"); - return true; + if let Some(ref target) = sync_config.assume_valid_targets { + if let Some(last_target) = target.last() { + if snapshot.block_exists(&last_target.pack()) { + info!("assume valid target is already in db, CKB will do full verification from now on"); + return true; + } } } false @@ -442,14 +445,19 @@ impl SharedBuilder { let block_status_map = Arc::new(DashMap::new()); - let assume_valid_target = Arc::new(Mutex::new({ + let assume_valid_targets = Arc::new(Mutex::new({ if Self::check_assume_valid_target_already_exists(&sync_config, &snapshot) { None } else { - sync_config.assume_valid_target.clone() + sync_config.assume_valid_targets.clone() } })); - let assume_valid_target_specified = Arc::new(sync_config.assume_valid_target); + + let assume_valid_target_specified: Arc> = Arc::new( + sync_config + .assume_valid_targets + .and_then(|targets| targets.last().cloned()), + ); let shared = Shared::new( store, @@ -460,7 +468,7 @@ impl SharedBuilder { snapshot_mgr, async_handle, ibd_finished, - assume_valid_target, + assume_valid_targets, assume_valid_target_specified, header_map, block_status_map, diff --git a/util/app-config/src/configs/network.rs b/util/app-config/src/configs/network.rs index 34eac57790..b29de05146 100644 --- a/util/app-config/src/configs/network.rs +++ b/util/app-config/src/configs/network.rs @@ -106,7 +106,7 @@ pub struct SyncConfig { pub header_map: HeaderMapConfig, /// Block hash of assume valid target #[serde(skip, default)] - pub assume_valid_target: Option, + pub assume_valid_targets: Option>, /// Proof of minimum work during synchronization #[serde(skip, default)] pub min_chain_work: U256,