-
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.
Include finalization committee and block height in block state hash
- Loading branch information
Showing
16 changed files
with
476 additions
and
156 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
242 changes: 190 additions & 52 deletions
242
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 |
---|---|---|
|
@@ -41,6 +41,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 | ||
|
@@ -184,6 +185,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 | ||
|
@@ -278,10 +281,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 | ||
|
@@ -294,7 +301,7 @@ mkInitialSkovData :: | |
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 = | ||
|
@@ -303,7 +310,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 | ||
|
@@ -326,6 +339,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 | ||
|
@@ -376,7 +390,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'. | ||
|
@@ -462,16 +476,17 @@ 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. | ||
(MonadState (SkovData (MPV m)) m, IsProtocolVersion (MPV m)) => | ||
-- | Pending block to make live | ||
PendingBlock -> | ||
PendingBlock (MPV m) -> | ||
-- | Block state associated with the block | ||
PBS.HashedPersistentBlockState pv -> | ||
PBS.HashedPersistentBlockState (MPV m) -> | ||
BlockHeight -> | ||
UTCTime -> | ||
-- | Energy used in executing the block | ||
Energy -> | ||
m (BlockPointer pv) | ||
m (BlockPointer (MPV m)) | ||
makeLiveBlock pb st height arriveTime energyCost = do | ||
let bp = | ||
BlockPointer | ||
|
@@ -481,7 +496,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 @(MPV m)))) | ||
(getHash st) | ||
}, | ||
bpBlock = NormalBlock (pbBlock pb), | ||
bpState = st | ||
|
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
Oops, something went wrong.