Skip to content

Commit

Permalink
chore(constants): create TWO_WEEKS constants in defaults.rs to use ev…
Browse files Browse the repository at this point in the history
…erywhere 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.
  • Loading branch information
drcpu-github committed Oct 31, 2024
1 parent ae9c966 commit fd62060
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion data_structures/src/chain/tapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
};
Expand Down

0 comments on commit fd62060

Please sign in to comment.