Fix three consensus bugs!

This commit is contained in:
Michael Sproul
2023-10-11 11:18:22 +11:00
parent ca1abfeb2d
commit d4f87ef1a1
4 changed files with 23 additions and 7 deletions

View File

@@ -351,6 +351,7 @@ where
#[test_random(default)]
pub validators: VList<GenericValidator, T::ValidatorRegistryLimit>,
#[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")]
#[compare_fields(as_iter)]
#[test_random(default)]
pub balances: VList<u64, T::ValidatorRegistryLimit>,

View File

@@ -93,10 +93,16 @@ impl EpochTotalBalances {
pub fn on_effective_balance_change(
&mut self,
is_slashed: bool,
current_epoch_participation_flags: ParticipationFlags,
old_effective_balance: u64,
new_effective_balance: u64,
) -> Result<(), BeaconStateError> {
// If the validator is slashed then we should not update the effective balance, because this
// validator's effective balance has already been removed from the totals.
if is_slashed {
return Ok(());
}
for flag_index in 0..NUM_FLAG_INDICES {
if current_epoch_participation_flags.has_flag(flag_index)? {
let total = self
@@ -188,12 +194,14 @@ impl ProgressiveBalancesCache {
/// its share of the target attesting balance in the cache.
pub fn on_effective_balance_change(
&mut self,
is_slashed: bool,
current_epoch_participation: ParticipationFlags,
old_effective_balance: u64,
new_effective_balance: u64,
) -> Result<(), BeaconStateError> {
let cache = self.get_inner_mut()?;
cache.current_epoch_cache.on_effective_balance_change(
is_slashed,
current_epoch_participation,
old_effective_balance,
new_effective_balance,