refactor the state_sync to handle the long fork (#1902)
* split horizon into two explicit values for cut through and txhashset request * let node which has 2-7 days of history be able to handle forks larger than 2 days * add test simulate_long_fork * add pause/resume feature on p2p for tests * refactor the state_sync * ignore the test case simulate_long_fork for normal Travis-CI * refactor function check_txhashset_needed to be shared with body_sync * fix: state TxHashsetDone should allow header sync
This commit is contained in:
@@ -92,6 +92,14 @@ pub const MAX_SECONDARY_SCALING: u64 = 8 << 11;
|
||||
/// easier to reason about.
|
||||
pub const CUT_THROUGH_HORIZON: u32 = WEEK_HEIGHT as u32;
|
||||
|
||||
/// Default number of blocks in the past to determine the height where we request
|
||||
/// a txhashset (and full blocks from). Needs to be long enough to not overlap with
|
||||
/// a long reorg.
|
||||
/// Rational behind the value is the longest bitcoin fork was about 30 blocks, so 5h.
|
||||
/// We add an order of magnitude to be safe and round to 2x24h of blocks to make it
|
||||
/// easier to reason about.
|
||||
pub const STATE_SYNC_THRESHOLD: u32 = 2 * DAY_HEIGHT as u32;
|
||||
|
||||
/// Weight of an input when counted against the max block weight capacity
|
||||
pub const BLOCK_INPUT_WEIGHT: usize = 1;
|
||||
|
||||
|
||||
+15
-2
@@ -20,7 +20,7 @@ use consensus::HeaderInfo;
|
||||
use consensus::{
|
||||
graph_weight, BASE_EDGE_BITS, BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON,
|
||||
DAY_HEIGHT, DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, PROOFSIZE, SECOND_POW_EDGE_BITS,
|
||||
UNIT_DIFFICULTY
|
||||
STATE_SYNC_THRESHOLD, UNIT_DIFFICULTY,
|
||||
};
|
||||
use pow::{self, CuckatooContext, EdgeType, PoWContext};
|
||||
/// An enum collecting sets of parameters used throughout the
|
||||
@@ -51,7 +51,10 @@ pub const AUTOMATED_TESTING_COINBASE_MATURITY: u64 = 3;
|
||||
pub const USER_TESTING_COINBASE_MATURITY: u64 = 3;
|
||||
|
||||
/// Testing cut through horizon in blocks
|
||||
pub const TESTING_CUT_THROUGH_HORIZON: u32 = 20;
|
||||
pub const TESTING_CUT_THROUGH_HORIZON: u32 = 70;
|
||||
|
||||
/// Testing state sync threshold in blocks
|
||||
pub const TESTING_STATE_SYNC_THRESHOLD: u32 = 20;
|
||||
|
||||
/// Testing initial graph weight
|
||||
pub const TESTING_INITIAL_GRAPH_WEIGHT: u32 = 1;
|
||||
@@ -237,6 +240,16 @@ pub fn cut_through_horizon() -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Threshold at which we can request a txhashset (and full blocks from)
|
||||
pub fn state_sync_threshold() -> u32 {
|
||||
let param_ref = CHAIN_TYPE.read();
|
||||
match *param_ref {
|
||||
ChainTypes::AutomatedTesting => TESTING_STATE_SYNC_THRESHOLD,
|
||||
ChainTypes::UserTesting => TESTING_STATE_SYNC_THRESHOLD,
|
||||
_ => STATE_SYNC_THRESHOLD,
|
||||
}
|
||||
}
|
||||
|
||||
/// Are we in automated testing mode?
|
||||
pub fn is_automated_testing_mode() -> bool {
|
||||
let param_ref = CHAIN_TYPE.read();
|
||||
|
||||
Reference in New Issue
Block a user