Skip to content

Commit

Permalink
Make computeBlockResultHash take epoch instead of using skov context
Browse files Browse the repository at this point in the history
  • Loading branch information
limemloh committed Jan 5, 2024
1 parent 5a7fff5 commit ee7518a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,8 @@ processBlock parent VerifiedBlock{vbBlock = pendingBlock, ..}
-- which is computed from transaction outcomes, the block state hash
-- and more.
let relativeBlockHeight = 1 + blockHeight parent
computedResultHash <- computeBlockResultHash newState relativeBlockHeight
let pendingBlockEpoch = blockEpoch pendingBlock
computedResultHash <- computeBlockResultHash newState relativeBlockHeight pendingBlockEpoch
if computedResultHash /= pendingBlockResultHash
then do
-- Incorrect block result hash
Expand All @@ -808,7 +809,7 @@ processBlock parent VerifiedBlock{vbBlock = pendingBlock, ..}
<> ") does not match computed value ("
<> show computedResultHash
<> ")."
flag $ BlockInvalidStateHash sBlock (bpBlock parent)
flag $ BlockInvalidResultHash sBlock (bpBlock parent)
rejectBlock
else continue newState energyUsed
getParentBakersAndFinalizers continue
Expand Down Expand Up @@ -1227,7 +1228,8 @@ bakeBlock BakeBlockInputs{..} = do
return $ DerivableBlockHashesV0{..}
SBlockHashVersion1 -> do
let relativeBlockHeight = 1 + blockHeight bbiParent
dbhv1BlockResultHash <- computeBlockResultHash newState relativeBlockHeight
currentEpoch <- use (roundStatus . rsCurrentEpoch)
dbhv1BlockResultHash <- computeBlockResultHash newState relativeBlockHeight currentEpoch
return $ DerivableBlockHashesV1{..}
let bakedBlock =
BakedBlock
Expand Down Expand Up @@ -1279,15 +1281,26 @@ computeBlockResultHash ::
HashedPersistentBlockState (MPV m) ->
-- | The relative block height for the block.
BlockHeight ->
-- | The epoch of the block.
Epoch ->
m BlockResultHash
computeBlockResultHash newState relativeBlockHeight = do
computeBlockResultHash newState relativeBlockHeight currentEpoch = do
theBlockStateHash <- getStateHash newState
transactionOutcomesHash <- getTransactionOutcomesHash newState
currentFinalizationCommitteeHash <- use $ to bakersForCurrentEpoch . bfFinalizerHash
currentFinalizationCommitteeHash <- do
-- Attempt to get the current finalization committee from SkovData otherwise compute it from the
-- information in the block state.
currentSkovBakersAndFinalizers <- gets (getBakersForEpoch currentEpoch)
case currentSkovBakersAndFinalizers of
Just bakersAndFinalizers -> return $ bakersAndFinalizers ^. bfFinalizerHash
Nothing -> do
currentFullBakers <- getCurrentEpochBakers newState
currentFinalizationParameters <- getCurrentEpochFinalizationCommitteeParameters newState
let nextFinalizationCommittee = computeFinalizationCommittee currentFullBakers currentFinalizationParameters
return $ computeFinalizationCommitteeHash nextFinalizationCommittee
nextFinalizationCommitteeHash <- do
-- Attempt to get the finalization committee from SkovData otherwise compute it from the
-- Attempt to get the next finalization committee from SkovData otherwise compute it from the
-- information in the block state.
currentEpoch <- use (roundStatus . rsCurrentEpoch)
nextSkovBakersAndFinalizers <- gets (getBakersForEpoch (currentEpoch + 1))
case nextSkovBakersAndFinalizers of
Just bakersAndFinalizers -> return $ bakersAndFinalizers ^. bfFinalizerHash
Expand Down
3 changes: 3 additions & 0 deletions concordium-consensus/src/Concordium/KonsensusV1/Flag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ data FlaggableOffense (pv :: ProtocolVersion)
| -- | Execution of the block resulted in an unexpected state.
-- Witnessed by the block received and the parent block.
BlockInvalidStateHash !(SignedBlock pv) !(Block pv)
| -- | Execution of the block resulted in an unexpected result.
-- Witnessed by the block received and the parent block.
BlockInvalidResultHash !(SignedBlock pv) !(Block pv)
| -- | An invalid block was signed by the 'QuorumMessage'.
-- Witnessed by the 'QuorumMessage' received.
SignedInvalidBlock !QuorumMessage
Expand Down

0 comments on commit ee7518a

Please sign in to comment.