ckb_constant/sync.rs
1use std::time::Duration;
2
3/// The default init download block interval is 24 hours
4/// If the time of the local highest block is within this range, exit the ibd state
5pub const MAX_TIP_AGE: u64 = 24 * 60 * 60 * 1000;
6
7/// Default max get header response length, if it is greater than this value, the message will be ignored
8pub const MAX_HEADERS_LEN: usize = 2_000;
9
10/// The default number of download blocks that can be requested at one time
11/* About Download Scheduler */
12
13/// ckb2021 edition new limit
14pub const INIT_BLOCKS_IN_TRANSIT_PER_PEER: usize = 32;
15/// Maximum number of download blocks that can be requested at one time
16pub const MAX_BLOCKS_IN_TRANSIT_PER_PEER: usize = 128;
17/// The point at which the scheduler adjusts the number of tasks, by default one adjustment per 512 blocks.
18pub const CHECK_POINT_WINDOW: u64 = (MAX_BLOCKS_IN_TRANSIT_PER_PEER * 4) as u64;
19
20/// Inspect the headers downloading every 2 minutes
21pub const HEADERS_DOWNLOAD_INSPECT_WINDOW: u64 = 2 * 60 * 1000;
22/// Global Average Speed
23// Expect 300 KiB/second
24// = 1600 headers/second (300*1024/192)
25// = 96000 headers/minute (1600*60)
26// = 11.11 days-in-blockchain/minute-in-reality (96000*10/60/60/24)
27// => Sync 1 year headers in blockchain will be in 32.85 minutes (365/11.11) in reality
28pub const HEADERS_DOWNLOAD_HEADERS_PER_SECOND: u64 = 1600;
29/// Acceptable Lowest Instantaneous Speed: 75.0 KiB/second (300/4)
30pub const HEADERS_DOWNLOAD_TOLERABLE_BIAS_FOR_SINGLE_SAMPLE: u64 = 4;
31/// Pow interval
32pub const POW_INTERVAL: u64 = 10;
33
34/// Protect at least this many outbound peers from disconnection due to slow
35/// behind headers chain.
36pub const MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT: usize = 4;
37/// Chain sync timeout
38pub const CHAIN_SYNC_TIMEOUT: u64 = 12 * 60 * 1000; // 12 minutes
39/// Suspend sync time
40pub const SUSPEND_SYNC_TIME: u64 = 5 * 60 * 1000; // 5 minutes
41/// Eviction response time
42pub const EVICTION_HEADERS_RESPONSE_TIME: u64 = 120 * 1000; // 2 minutes
43
44/// The maximum number of entries in a locator
45pub const MAX_LOCATOR_SIZE: usize = 101;
46
47/// Block download timeout
48pub const BLOCK_DOWNLOAD_TIMEOUT: u64 = 30 * 1000; // 30s
49
50/// Block download window size
51// Size of the "block download window": how far ahead of our current height do we fetch?
52// Larger windows tolerate larger download speed differences between peers, but increase the
53// potential degree of disordering of blocks.
54pub const BLOCK_DOWNLOAD_WINDOW: u64 = 1024 * 8; // 1024 * default_outbound_peers
55
56/// Interval between repeated inquiry transactions
57pub const RETRY_ASK_TX_TIMEOUT_INCREASE: Duration = Duration::from_secs(30);
58
59/// Default ban time for message
60// ban time
61// 5 minutes
62pub const BAD_MESSAGE_BAN_TIME: Duration = Duration::from_secs(5 * 60);
63/// Default ban time for sync useless
64// 10 minutes, peer have no common ancestor block
65pub const SYNC_USELESS_BAN_TIME: Duration = Duration::from_secs(10 * 60);
66
67/// The maximum number transaction hashes inside a `RelayTransactionHashes` message
68pub const MAX_RELAY_TXS_NUM_PER_BATCH: usize = 32767;
69/// The soft limit to the number of unknown transactions
70pub const MAX_UNKNOWN_TX_HASHES_SIZE: usize = 50000;
71/// The soft limit to the number of unknown transactions per peer
72pub const MAX_UNKNOWN_TX_HASHES_SIZE_PER_PEER: usize = MAX_RELAY_TXS_NUM_PER_BATCH;