Skip to content

Commit

Permalink
refactor the block interval
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Oct 24, 2023
1 parent e9baaaf commit 67a8dd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ 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
pub const MAX_BLOCK_INTERVAL: u64 = 48; // 48s
pub const MIN_BLOCK_INTERVAL: u64 = 8; // 8s

/// cycles of a typical two-in-two-out tx.
pub const TWO_IN_TWO_OUT_CYCLES: Cycle = 3_500_000;
Expand Down
6 changes: 3 additions & 3 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tx-pool/src/component/orphan.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)]
Expand Down

0 comments on commit 67a8dd2

Please sign in to comment.