diff --git a/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs b/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs index 4a358266d3..0bec96c015 100644 --- a/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs +++ b/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs @@ -3479,7 +3479,7 @@ doUpdateMissedRounds pbs rds = do modifyBakerPoolRewardDetailsInPoolRewards bsp0 bId - (\bprd -> bprd{missedRounds = fmap (+ newMissedRounds) $ missedRounds bprd}) + (\bprd -> bprd{missedRounds = (+ newMissedRounds) <$> missedRounds bprd}) ) bsp rds @@ -3681,11 +3681,9 @@ doNotifyBlockBaked pbs bid = do let incBPR bpr = bpr { blockCount = blockCount bpr + 1, - missedRounds = conditionally hasValidatorSuspension 0 + missedRounds = 0 <$ missedRounds bpr } in storePBS pbs =<< modifyBakerPoolRewardDetailsInPoolRewards bsp bid incBPR - where - hasValidatorSuspension = sSupportsValidatorSuspension (accountVersion @(AccountVersionFor pv)) doUpdateAccruedTransactionFeesBaker :: forall pv m. (PVSupportsDelegation pv, SupportsPersistentState pv m) => PersistentBlockState pv -> BakerId -> AmountDelta -> m (PersistentBlockState pv) doUpdateAccruedTransactionFeesBaker pbs bid delta = do @@ -3719,8 +3717,14 @@ doMarkFinalizationAwakeBakers pbs bids = do error "Invariant violation: unable to find baker in baker pool reward details tree" Just ((), newBPRs) -> return newBPRs - setAwake bpr = return ((), bpr{finalizationAwake = True, missedRounds = conditionally hasValidatorSuspension 0}) - hasValidatorSuspension = sSupportsValidatorSuspension (accountVersion @(AccountVersionFor pv)) + setAwake bpr = + return + ( (), + bpr + { finalizationAwake = True, + missedRounds = 0 <$ missedRounds bpr + } + ) doUpdateAccruedTransactionFeesPassive :: forall pv m. (PVSupportsDelegation pv, SupportsPersistentState pv m) => PersistentBlockState pv -> AmountDelta -> m (PersistentBlockState pv) doUpdateAccruedTransactionFeesPassive pbs delta = do diff --git a/concordium-consensus/src/Concordium/GlobalState/Persistent/PoolRewards.hs b/concordium-consensus/src/Concordium/GlobalState/Persistent/PoolRewards.hs index 63c0f39bb8..44ea690bf4 100644 --- a/concordium-consensus/src/Concordium/GlobalState/Persistent/PoolRewards.hs +++ b/concordium-consensus/src/Concordium/GlobalState/Persistent/PoolRewards.hs @@ -29,7 +29,6 @@ import Data.Word import Concordium.Crypto.SHA256 as Hash import Concordium.Types -import Concordium.Types.Conditionally import Concordium.Types.HashableTo import Concordium.Utils.BinarySearch import Concordium.Utils.Serialization.Put (MonadPut (..)) @@ -133,7 +132,6 @@ migratePoolRewardsP1 curBakers nextBakers blockCounts npEpoch npMintRate = do nextPaydayMintRate = npMintRate return PoolRewards{..} where - hasValidatorSuspension = sSupportsValidatorSuspension (accountVersion @av) makeCD bkrs = makeHashed $ CapitalDistribution @@ -148,7 +146,7 @@ migratePoolRewardsP1 curBakers nextBakers blockCounts npEpoch npMintRate = do { blockCount = Map.findWithDefault 0 bid blockCounts, transactionFeesAccrued = 0, finalizationAwake = False, - missedRounds = conditionally hasValidatorSuspension 0 + missedRounds = 0 <$ missedRounds bprd } (!newRef, _) <- refFlush =<< refMake bprd return newRef diff --git a/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs b/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs index 588c69f7ae..29ce190f35 100644 --- a/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs +++ b/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs @@ -383,6 +383,14 @@ processBlockRewards :: UpdatableBlockState m -> m (UpdatableBlockState m) processBlockRewards ParticipatingBakers{..} TransactionRewardParameters{..} missedRounds theState0 = do + -- Note: The order of the following operations is important. + -- + -- The finalization awake bakers are the ones that signed the QC (possibly + -- a timeout) for the parent block. If it was a timeout, missed rounds are counted + -- between this last timeout round and the round of the block that is baked next. So if + -- a validator signed the QC for the parent block, but missed a round in the interim, + -- then its missed round counter would be 1. Though if it also baked the new block, it + -- would be reset to 0. theState1 <- bsoMarkFinalizationAwakeBakers theState0 pbQCSignatories theState2 <- bsoUpdateMissedRounds theState1 missedRounds theState3 <- bsoNotifyBlockBaked theState2 pbBlockBaker