diff --git a/concordium-consensus/src/Concordium/GlobalState/BlockState.hs b/concordium-consensus/src/Concordium/GlobalState/BlockState.hs index d00beac7b1..2408a96eae 100644 --- a/concordium-consensus/src/Concordium/GlobalState/BlockState.hs +++ b/concordium-consensus/src/Concordium/GlobalState/BlockState.hs @@ -1511,7 +1511,7 @@ class (BlockStateQuery m) => BlockStateOperations m where bsoIsProtocolUpdateEffective :: UpdatableBlockState m -> m Bool -- | Update the count of missed rounds for a given validator - bsoUpdateMissedBlocks :: (PVSupportsDelegation (MPV m)) => UpdatableBlockState m -> (BakerId, Int8) -> m (UpdatableBlockState m) + bsoUpdateMissedBlocks :: (PVSupportsDelegation (MPV m)) => UpdatableBlockState m -> (BakerId, Int16) -> m (UpdatableBlockState m) -- | Clear the missed round count for a given validator bsoClearMissedBlocks :: (PVSupportsDelegation (MPV m)) => UpdatableBlockState m -> BakerId -> m (UpdatableBlockState m) diff --git a/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs b/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs index 28928047f7..ffce2e1af0 100644 --- a/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs +++ b/concordium-consensus/src/Concordium/GlobalState/Persistent/BlockState.hs @@ -3465,7 +3465,7 @@ doGetProtocolUpdateStatus = protocolUpdateStatus . bspUpdates <=< loadPBS doIsProtocolUpdateEffective :: (SupportsPersistentState pv m) => PersistentBlockState pv -> m Bool doIsProtocolUpdateEffective = isProtocolUpdateEffective . bspUpdates <=< loadPBS -doUpdateMissedBlocks :: (PVSupportsDelegation pv, SupportsPersistentState pv m) => PersistentBlockState pv -> (BakerId, Int8) -> m (PersistentBlockState pv) +doUpdateMissedBlocks :: (PVSupportsDelegation pv, SupportsPersistentState pv m) => PersistentBlockState pv -> (BakerId, Int16) -> m (PersistentBlockState pv) doUpdateMissedBlocks pbs (bId, newMissedRounds) = do bsp <- loadPBS pbs bsp' <- diff --git a/concordium-consensus/src/Concordium/GlobalState/PoolRewards.hs b/concordium-consensus/src/Concordium/GlobalState/PoolRewards.hs index 85a59f3c1e..e3d577c47d 100644 --- a/concordium-consensus/src/Concordium/GlobalState/PoolRewards.hs +++ b/concordium-consensus/src/Concordium/GlobalState/PoolRewards.hs @@ -24,7 +24,7 @@ data BakerPoolRewardDetails = BakerPoolRewardDetails -- | Whether the pool contributed to a finalization proof in the reward period finalizationAwake :: !Bool, -- | The number of missed rounds in the reward period - missedRounds :: !Int8 + missedRounds :: !Int16 } deriving (Eq, Show) @@ -34,7 +34,7 @@ instance Serialize BakerPoolRewardDetails where put transactionFeesAccrued putBool finalizationAwake - get = BakerPoolRewardDetails <$> getWord64be <*> get <*> getBool <*> getInt8 + get = BakerPoolRewardDetails <$> getWord64be <*> get <*> getBool <*> getInt16be instance HashableTo Hash.Hash BakerPoolRewardDetails where getHash = Hash.hash . encode diff --git a/concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs b/concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs index 6880b4479f..c97fda77a5 100644 --- a/concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs +++ b/concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs @@ -19,6 +19,7 @@ import Data.Function import Data.Int import Data.Ord import Data.Time +import Data.List (group) import qualified Data.Vector as Vector import Lens.Micro.Platform @@ -1385,19 +1386,19 @@ computeMissedRounds :: Option TimeoutCertificate -> BlockPointer (MPV m) -> Round -> - m [(BakerId, Int8)] -computeMissedRounds tc parent rnd = do + m [(BakerId, Int16)] +computeMissedRounds tc _parent _rnd | isAbsent tc = return [] +computeMissedRounds _tc parent rnd = do let parentBlockState = bpState parent validators <- getCurrentEpochBakers parentBlockState seedState <- getSeedState parentBlockState - let missedRounds - | isPresent tc = - let beginRound = blockRound parent - endRound = rnd - 1 - leNonce = seedState ^. currentLeadershipElectionNonce - in [ (winner ^. bakerIdentity, fromIntegral r) - | r <- [beginRound .. endRound], - let winner = getLeaderFullBakers validators leNonce r - ] - | otherwise = [] + let missedRoundsValidators = + let beginRound = blockRound parent + endRound = rnd - 1 + leNonce = seedState ^. currentLeadershipElectionNonce + in [ winner ^. bakerIdentity + | r <- [beginRound .. endRound], + let winner = getLeaderFullBakers validators leNonce r + ] + let missedRounds = [(head g, fromIntegral $ length g) | g <- group missedRoundsValidators] return missedRounds diff --git a/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs b/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs index 72359e67e7..9b088a31dd 100644 --- a/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs +++ b/concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs @@ -60,6 +60,8 @@ data PaydayParameters = PaydayParameters data ParticipatingBakers = ParticipatingBakers { -- | The 'BakerId' of the block baker. pbBlockBaker :: BakerId, + -- | The 'BakerId's of the signatories to the block QC. + -- No particular ordering is assumed. pbQCSignatories :: [BakerId] } @@ -82,7 +84,7 @@ data BlockExecutionData (pv :: ProtocolVersion) = BlockExecutionData -- | Number of rounds a validator has missed (e.g. the validator was -- elected leader but a timeout certificate exist for the round) since the parent -- block. - bedMissedRounds :: [(BakerId, Int8)] + bedMissedRounds :: [(BakerId, Int16)] } -- | Details of the transactions in a block that are used for computing rewards that accrue to the @@ -308,8 +310,6 @@ executeBlockPrologue BlockExecutionData{..} = do theState5 <- doUpdateSeedStateForBlock bedTimestamp bedBlockNonce theState4 -- update the missed rounds count for each active baker theState6 <- if isJust mPaydayParms - -- TODO (drsk) For now, we just clear the missed rounds on each new payday. - -- on each new payday: update score, clear score if validator was active then foldM bsoClearMissedBlocks theState5 activeBakers else foldM bsoUpdateMissedBlocks theState5 bedMissedRounds return