From fd62060386f7eabc6feed64598ab7afead37cbe8 Mon Sep 17 00:00:00 2001 From: drcpu Date: Thu, 31 Oct 2024 12:14:46 +0000 Subject: [PATCH] chore(constants): create TWO_WEEKS constants in defaults.rs to use everywhere instead of inlining the value This constant can be used everywhere except in the data_structures package where including it introduces a cyclic dependency conflict. --- config/src/defaults.rs | 3 +++ data_structures/src/chain/tapi.rs | 4 +++- node/src/actors/chain_manager/mod.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config/src/defaults.rs b/config/src/defaults.rs index 2f955cf87..82af377ec 100644 --- a/config/src/defaults.rs +++ b/config/src/defaults.rs @@ -511,6 +511,9 @@ pub const PSEUDO_CONSENSUS_CONSTANTS_POS_UNSTAKING_DELAY_SECONDS: u64 = 1_209_60 /// Minimum amount of nanoWits which need to be staked before wit/2 activation pub const PSEUDO_CONSENSUS_CONSTANTS_POS_MIN_TOTAL_STAKE_NANOWITS: u64 = 300_000_000_000_000_000; +/// The number of epochs elapsed during a period of two weeks with a block time of 45 seconds +pub const PSEUDO_CONSENSUS_CONSTANTS_TWO_WEEKS: u32 = 26_880; + /// Struct that will implement all the development defaults pub struct Development; diff --git a/data_structures/src/chain/tapi.rs b/data_structures/src/chain/tapi.rs index 07f03ed34..b8c04e94d 100644 --- a/data_structures/src/chain/tapi.rs +++ b/data_structures/src/chain/tapi.rs @@ -5,6 +5,8 @@ use crate::{ use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; +const TWO_WEEKS: u32 = 26880; + /// Committee for superblock indices 750-1344 const FIRST_EMERGENCY_COMMITTEE: [&str; 7] = [ "wit1asdpcspwysf0hg5kgwvgsp2h6g65y5kg9gj5dz", @@ -196,7 +198,7 @@ impl TapiEngine { // Hardcoded information about WIPs in vote processing let wip_0028 = BitVotesCounter { votes: 0, - period: 26880, + period: TWO_WEEKS, wip: "WIP0028".to_string(), // Start signaling on December 14 at 9am UTC init: 2922240, diff --git a/node/src/actors/chain_manager/mod.rs b/node/src/actors/chain_manager/mod.rs index c5e6805c8..18f79e267 100644 --- a/node/src/actors/chain_manager/mod.rs +++ b/node/src/actors/chain_manager/mod.rs @@ -52,6 +52,7 @@ use witnet_config::{ config::Tapi, defaults::{ PSEUDO_CONSENSUS_CONSTANTS_POS_MIN_TOTAL_STAKE_NANOWITS, + PSEUDO_CONSENSUS_CONSTANTS_TWO_WEEKS, PSEUDO_CONSENSUS_CONSTANTS_WIP0022_REWARD_COLLATERAL_RATIO, PSEUDO_CONSENSUS_CONSTANTS_WIP0027_COLLATERAL_AGE, }, @@ -123,6 +124,7 @@ mod handlers; pub mod mining; const POS_MIN_TOTAL_STAKE_NANOWITS: u64 = PSEUDO_CONSENSUS_CONSTANTS_POS_MIN_TOTAL_STAKE_NANOWITS; +const TWO_WEEKS: u32 = PSEUDO_CONSENSUS_CONSTANTS_TWO_WEEKS; /// Maximum blocks number to be sent during synchronization process pub const MAX_BLOCKS_SYNC: usize = 500; @@ -1036,11 +1038,13 @@ impl ChainManager { if stakes.total_staked() >= Wit::from(POS_MIN_TOTAL_STAKE_NANOWITS) { register_protocol_version( ProtocolVersion::V2_0, - block_epoch + 26880, + block_epoch + TWO_WEEKS, 20, ); if let Some(epoch_constants) = &mut self.epoch_constants { - match epoch_constants.set_values_for_wit2(20, block_epoch + 26880) { + match epoch_constants + .set_values_for_wit2(20, block_epoch + TWO_WEEKS) + { Ok(_) => (), Err(_) => panic!("Could not set wit/2 checkpoint variables"), };