Skip to content

Commit

Permalink
move to Int16 for missed rounds, fix computeMissedRounds
Browse files Browse the repository at this point in the history
  • Loading branch information
drsk committed Oct 22, 2024
1 parent 3f3e0b5 commit b7a0f7e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
25 changes: 13 additions & 12 deletions concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions concordium-consensus/src/Concordium/KonsensusV1/Scheduler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b7a0f7e

Please sign in to comment.