Fix bug in epoch trans. finalization

This commit is contained in:
Paul Hauner 2019-06-19 03:40:30 +10:00
parent 55818e285a
commit 5a98502ad6
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 4 additions and 4 deletions

View File

@ -122,17 +122,17 @@ pub fn process_justification_and_finalization<T: EthSpec>(
state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?; state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?;
} }
// The 2nd/3rd most recent epochs are both justified, the 2nd using the 3rd as source. // The 2nd/3rd most recent epochs are both justified, the 2nd using the 3rd as source.
if (bitfield >> 1) % 4 == 0b11 && state.previous_justified_epoch == current_epoch - 2 { if (bitfield >> 1) % 4 == 0b11 && old_previous_justified_epoch == current_epoch - 2 {
state.finalized_epoch = old_previous_justified_epoch; state.finalized_epoch = old_previous_justified_epoch;
state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?; state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?;
} }
// The 1st/2nd/3rd most recent epochs are all justified, the 1st using the 2nd as source. // The 1st/2nd/3rd most recent epochs are all justified, the 1st using the 2nd as source.
if bitfield % 8 == 0b111 && state.current_justified_epoch == current_epoch - 2 { if bitfield % 8 == 0b111 && old_current_justified_epoch == current_epoch - 2 {
state.finalized_epoch = old_current_justified_epoch; state.finalized_epoch = old_current_justified_epoch;
state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?; state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?;
} }
// The 1st/2nd most recent epochs are both justified, the 1st using the 2nd as source. // The 1st/2nd most recent epochs are both justified, the 1st using the 2nd as source.
if bitfield % 4 == 0b11 && state.current_justified_epoch == current_epoch - 1 { if bitfield % 4 == 0b11 && old_current_justified_epoch == current_epoch - 1 {
state.finalized_epoch = old_current_justified_epoch; state.finalized_epoch = old_current_justified_epoch;
state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?; state.finalized_root = *state.get_block_root_at_epoch(state.finalized_epoch)?;
} }

View File

@ -125,7 +125,7 @@ impl ValidatorStatus {
/// The total effective balances for different sets of validators during the previous and current /// The total effective balances for different sets of validators during the previous and current
/// epochs. /// epochs.
#[derive(Default, Clone)] #[derive(Default, Clone, Debug)]
pub struct TotalBalances { pub struct TotalBalances {
/// The total effective balance of all active validators during the _current_ epoch. /// The total effective balance of all active validators during the _current_ epoch.
pub current_epoch: u64, pub current_epoch: u64,