Skip to content

Commit 07be4c5

Browse files
committed
fix(staking): use block's epoch instead of current epoch when validating blocks
1 parent 5b90ff5 commit 07be4c5

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

data_structures/src/staking/stakes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ where
444444
let stake_entry = self.by_key.get_mut(key);
445445
if let Some(stake_entry) = stake_entry {
446446
let penalty_epochs = Epoch::from((1 + winner_rank - index) as u32);
447-
log::debug!("Disabling mining power of {} during +{} epochs", key, penalty_epochs);
447+
log::info!(
448+
"Resetting and disabling mining power of {} (ranked as #{}) during +{} epochs",
449+
key, index + 1, penalty_epochs
450+
);
448451
stake_entry
449452
.value
450453
.write()

node/src/actors/chain_manager/mining.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl ChainManager {
110110
let checkpoint_zero_timestamp = chain_info.consensus_constants.checkpoint_zero_timestamp;
111111
let halving_period = chain_info.consensus_constants.halving_period;
112112

113+
let previous_block_epoch = chain_info.highest_block_checkpoint.checkpoint;
113114
let mut beacon = chain_info.highest_block_checkpoint;
114115
let mut vrf_input = chain_info.highest_vrf_output;
115116
let protocol_version = get_protocol_version(self.current_epoch);
@@ -251,6 +252,7 @@ impl ChainManager {
251252
.and_then(move |block, act, _ctx| {
252253
act.future_process_validations(
253254
block.clone(),
255+
previous_block_epoch,
254256
current_epoch,
255257
vrf_input,
256258
beacon,

node/src/actors/chain_manager/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,7 @@ impl ChainManager {
23252325
pub fn future_process_validations(
23262326
&mut self,
23272327
block: Block,
2328+
previous_block_epoch: Epoch,
23282329
current_epoch: Epoch,
23292330
vrf_input: CheckpointVRF,
23302331
chain_beacon: CheckpointBeacon,
@@ -2340,7 +2341,7 @@ impl ChainManager {
23402341
let protocol_version = ProtocolVersion::from_epoch(block.block_header.beacon.checkpoint);
23412342
let replication_factor = self
23422343
.consensus_constants_wit2
2343-
.get_replication_factor(current_epoch, chain_beacon.checkpoint);
2344+
.get_replication_factor(block.block_header.beacon.checkpoint, previous_block_epoch);
23442345
let res = validate_block(
23452346
&block,
23462347
current_epoch,
@@ -3127,7 +3128,7 @@ pub fn process_validations(
31273128
stakes: &StakesTracker,
31283129
protocol_version: ProtocolVersion,
31293130
) -> Result<Diff, failure::Error> {
3130-
let replication_factor = consensus_constants_wit2.get_replication_factor(current_epoch, chain_beacon.checkpoint);
3131+
let replication_factor = consensus_constants_wit2.get_replication_factor(block.block_header.beacon.checkpoint, chain_beacon.checkpoint);
31313132
if !resynchronizing {
31323133
let mut signatures_to_verify = vec![];
31333134
validate_block(

0 commit comments

Comments
 (0)