diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 0f059d1dfb4..1627c483f69 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -60,8 +60,10 @@ pub(crate) const GENESIS_EPOCH_LENGTH: u64 = 1_000; // o_ideal = 1/40 = 2.5% pub(crate) const DEFAULT_ORPHAN_RATE_TARGET: (u32, u32) = (1, 40); -const MAX_BLOCK_INTERVAL: u64 = 48; // 48s -const MIN_BLOCK_INTERVAL: u64 = 8; // 8s +/// max block interval, 48 seconds +pub const MAX_BLOCK_INTERVAL: u64 = 48; +/// min block interval, 8 seconds +pub const MIN_BLOCK_INTERVAL: u64 = 8; /// cycles of a typical two-in-two-out tx. pub const TWO_IN_TWO_OUT_CYCLES: Cycle = 3_500_000; diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index 04170214883..3171878242a 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -4,7 +4,7 @@ use crate::utils::is_internal_db_error; use crate::{Status, StatusCode, FAST_INDEX, LOW_INDEX, NORMAL_INDEX, TIME_TRACE_SIZE}; use ckb_app_config::SyncConfig; use ckb_chain::chain::ChainController; -use ckb_chain_spec::consensus::Consensus; +use ckb_chain_spec::consensus::{Consensus, MAX_BLOCK_INTERVAL, MIN_BLOCK_INTERVAL}; use ckb_channel::Receiver; use ckb_constant::sync::{ BLOCK_DOWNLOAD_TIMEOUT, HEADERS_DOWNLOAD_HEADERS_PER_SECOND, HEADERS_DOWNLOAD_INSPECT_WINDOW, @@ -103,8 +103,8 @@ impl ChainSyncState { fn tip_synced(&mut self) { let now = unix_time_as_millis(); - // use avg block interval: (MAX_BLOCK_INTERVAL + MIN_BLOCK_INTERVAL) / 2 = 28 - self.headers_sync_state = HeadersSyncState::TipSynced(now + 28000); + let avg_interval = (MAX_BLOCK_INTERVAL + MIN_BLOCK_INTERVAL) / 2; + self.headers_sync_state = HeadersSyncState::TipSynced(now + avg_interval * 1000); } fn started(&self) -> bool { diff --git a/tx-pool/src/component/orphan.rs b/tx-pool/src/component/orphan.rs index c8dc3accc0e..ae045beab9c 100644 --- a/tx-pool/src/component/orphan.rs +++ b/tx-pool/src/component/orphan.rs @@ -1,3 +1,4 @@ +use ckb_chain_spec::consensus::MAX_BLOCK_INTERVAL; use ckb_logger::{debug, trace}; use ckb_network::PeerIndex; use ckb_types::packed::Byte32; @@ -9,7 +10,7 @@ use ckb_util::shrink_to_fit; use std::collections::HashMap; const SHRINK_THRESHOLD: usize = 100; -pub(crate) const ORPHAN_TX_EXPIRE_TIME: u64 = 2 * 48; // double block interval +pub(crate) const ORPHAN_TX_EXPIRE_TIME: u64 = 2 * MAX_BLOCK_INTERVAL; // double block interval pub(crate) const DEFAULT_MAX_ORPHAN_TRANSACTIONS: usize = 100; #[derive(Debug, Clone)]