-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1104 from Concordium/block-hashing-pv-height
Include finalization committee and block height in block hash
- Loading branch information
Showing
29 changed files
with
3,686 additions
and
2,141 deletions.
There are no files selected for viewing
Submodule concordium-base
updated
7 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 152 additions & 54 deletions
206
concordium-consensus/src/Concordium/KonsensusV1/Consensus/Blocks.hs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ import qualified Data.Sequence as Seq | |
|
||
import qualified Concordium.Genesis.Data.BaseV1 as Base | ||
import Concordium.Types | ||
import qualified Concordium.Types.Conditionally as Cond | ||
import Concordium.Types.Execution | ||
import Concordium.Types.HashableTo | ||
import Concordium.Types.Option | ||
|
@@ -183,6 +184,8 @@ data SkovData (pv :: ProtocolVersion) = SkovData | |
_roundExistingQCs :: !(Map.Map Round QuorumCertificateCheckedWitness), | ||
-- | Genesis metadata | ||
_genesisMetadata :: !GenesisMetadata, | ||
-- | Block height information of the (current) genesis block. | ||
_genesisBlockHeight :: !GenesisBlockHeightInfo, | ||
-- | Pointer to the last finalized block. | ||
_lastFinalized :: !(BlockPointer pv), | ||
-- | A finalization entry that finalizes the last finalized block, unless that is the | ||
|
@@ -277,10 +280,14 @@ purgeRoundExistingQCs rnd = roundExistingQCs %=! snd . Map.split (rnd - 1) | |
-- * The caller must make sure, that the supplied 'TransactionTable' does NOT contain any @Committed@ transactions | ||
-- and all transactions have their commit point set to 0. | ||
mkInitialSkovData :: | ||
forall pv. | ||
(IsProtocolVersion pv) => | ||
-- | The 'RuntimeParameters' | ||
RuntimeParameters -> | ||
-- | Genesis metadata. State hash should match the hash of the state. | ||
GenesisMetadata -> | ||
-- | Block height information for the genesis block. | ||
GenesisBlockHeightInfo -> | ||
-- | Genesis state | ||
PBS.HashedPersistentBlockState pv -> | ||
-- | The base timeout | ||
|
@@ -293,7 +300,7 @@ mkInitialSkovData :: | |
TT.PendingTransactionTable -> | ||
-- | The initial 'SkovData' | ||
SkovData pv | ||
mkInitialSkovData rp genMeta genState _currentTimeout _skovEpochBakers transactionTable' pendingTransactionTable' = | ||
mkInitialSkovData rp genMeta genesisBlockHeightInfo genState _currentTimeout _skovEpochBakers transactionTable' pendingTransactionTable' = | ||
let genesisBlock = GenesisBlock genMeta | ||
genesisTime = timestampToUTCTime $ Base.genesisTime (gmParameters genMeta) | ||
genesisBlockMetadata = | ||
|
@@ -302,7 +309,13 @@ mkInitialSkovData rp genMeta genState _currentTimeout _skovEpochBakers transacti | |
bmReceiveTime = genesisTime, | ||
bmArriveTime = genesisTime, | ||
bmEnergyCost = 0, | ||
bmTransactionsSize = 0 | ||
bmTransactionsSize = 0, | ||
bmBlockStateHash = | ||
Cond.conditionally | ||
( sBlockStateHashInMetadata | ||
(sBlockHashVersionFor (protocolVersion @pv)) | ||
) | ||
(getHash genState) | ||
} | ||
genesisBlockPointer = | ||
BlockPointer | ||
|
@@ -325,6 +338,7 @@ mkInitialSkovData rp genMeta genState _currentTimeout _skovEpochBakers transacti | |
_roundExistingBlocks = Map.empty | ||
_roundExistingQCs = Map.empty | ||
_genesisMetadata = genMeta | ||
_genesisBlockHeight = genesisBlockHeightInfo | ||
_lastFinalized = genesisBlockPointer | ||
_latestFinalizationEntry = Absent | ||
_statistics = Stats.initialConsensusStatistics | ||
|
@@ -375,7 +389,7 @@ mkBlockPointer [email protected]{..} = do | |
where | ||
mkHashedPersistentBlockState = do | ||
hpbsPointers <- newIORef $! BlobStore.blobRefToBufferedRef stbStatePointer | ||
let hpbsHash = blockStateHash sb | ||
let hpbsHash = LowLevel.stbBlockStateHash sb | ||
return $! PBS.HashedPersistentBlockState{..} | ||
|
||
-- | Get the 'BlockStatus' of a block based on the provided 'BlockHash'. | ||
|
@@ -461,9 +475,10 @@ getFirstFinalizedBlockOfEpoch epochOrBlock sd | |
-- The hash of the block state MUST match the block state hash of the block; this is not checked. | ||
-- [Note: this does not affect the '_branches' of the 'SkovData'.] | ||
makeLiveBlock :: | ||
(MonadState (SkovData pv) m) => | ||
forall m pv. | ||
(MonadState (SkovData pv) m, IsProtocolVersion pv) => | ||
-- | Pending block to make live | ||
PendingBlock -> | ||
PendingBlock pv -> | ||
-- | Block state associated with the block | ||
PBS.HashedPersistentBlockState pv -> | ||
BlockHeight -> | ||
|
@@ -480,7 +495,11 @@ makeLiveBlock pb st height arriveTime energyCost = do | |
bmArriveTime = arriveTime, | ||
bmHeight = height, | ||
bmEnergyCost = energyCost, | ||
bmTransactionsSize = fromIntegral $ sum (biSize <$> blockTransactions pb) | ||
bmTransactionsSize = fromIntegral $ sum (biSize <$> blockTransactions pb), | ||
bmBlockStateHash = | ||
Cond.conditionally | ||
(sBlockStateHashInMetadata (sBlockHashVersionFor (protocolVersion @pv))) | ||
(getHash st) | ||
}, | ||
bpBlock = NormalBlock (pbBlock pb), | ||
bpState = st | ||
|
Oops, something went wrong.