-
Notifications
You must be signed in to change notification settings - Fork 33
[WIP] Enrich block bodies to contain Peras certificates #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
agustinmista
wants to merge
71
commits into
peras-staging
Choose a base branch
from
peras/enrich-shelley-blocks-with-certs
base: peras-staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
2f9b26d
Scaffolding for Peras certs and PerasCertDB
amesgen d41124b
[WIP] set structure for model-based testing for PerasCertDB
tbagrel1 ba2b453
Fix missing instances
tbagrel1 616776a
Pairing
amesgen 0b8746e
Minor polishing
amesgen d7afcad
PerasCertDB: implement garbage collection
amesgen f32763a
Re-add how-to guide for micro-benchmarks
geo2a 54e41bc
ouroboros-consensus: add Peras chain weight benchmark
geo2a 5cd4c37
ChainDB: expose PerasCertDB functionality
amesgen 1d24821
ChainDB: invoke PerasCertDB GC
amesgen 391f420
Move `PerasWeightSnapshot` to separate module
amesgen 2797c54
PerasCertDB.getWeightSnapshot: add `Fingerprint`
amesgen 43d0232
PerasCertDB.addCert: return whether we added the cert
amesgen 644cb18
Peras: minor tweaks
amesgen 52d7741
Make `PerasWeightSnapshot` opaque
amesgen 8886d71
Nomenclature: "weight boost" instead of "boosted weight"
amesgen 91a5cc9
Glossary: add Peras weight-related terms
amesgen 337558e
PerasWeightSnapshot: minimize API
amesgen a5456d9
PerasRoundNo/PerasWeight: terse output
amesgen facb6b7
O.C.Peras.Weight: add haddocks
amesgen bdb6189
`SecurityParam`: mention weighted nature
amesgen d8cbdeb
`PerasRoundNo`/`PerasWeight`: add `Condense` instances
amesgen 2323685
O.C.Peras.Weight: add `totalWeightForFragment`/`takeVolatileSuffix`
amesgen cb0877b
Add test for `PerasWeightSnapshot`
amesgen fe3c154
ChainDB.StateMachine: check immutable tip monotonicity
amesgen e6aa0ae
ChainDB: define `getCurrentChain` in terms of weight
amesgen d9a542f
GSM: allow `candidateOverSelection` to be stateful
amesgen c5759cd
Add `WeightedSelectView`
amesgen 37f9ae9
ChainSel: make `rollbackExceedsSuffix` weight-aware
amesgen 0912d45
Introduce weighted chain comparisons
amesgen 7cd188c
Integrate weighted BlockFetch decision logic
amesgen 4037e12
ChainDB: implement chain selection for certificates
amesgen 8192a51
MockChainSel: switch to weighted chain selection
amesgen 5b61869
ChainDB q-s-m: test weighted chain selection
amesgen 6739048
Fix cabal-docspec
amesgen 82d9ba2
Modify PerasCertDB (and to some extent, ChainDB) to allow snapshot of…
amesgen acdf1e9
Replace hardcoded miniprotocol parameters by default ones in unstable…
tbagrel1 c6a470c
Introduce the (generic) ObjectDiffusion protocol, ObjectPool, and the…
tbagrel1 12b73ad
Introduce the PerasCertDiffusion protocol (instance of ObjectDiffusio…
tbagrel1 bf9d848
Wire-in the PerasCertDiffusion protocol in NodeToNode
tbagrel1 64548be
Change signature of `opwHasObject` to use `STM m` instead of `m`
tbagrel1 6c4d5c4
Add module docstring to ObjectPool API
tbagrel1 2501277
Add codec for PerasCert and PerasCertDiffusion
tbagrel1 1f1bdeb
Integrate `NodeToNodeV_16`
amesgen 43bdef4
Peras: add a few `ShowProxy` instances
amesgen d0799c8
Adapt to removal of `initAgency`
amesgen 5d82e49
Adapt to changed agency of `MsgDone`
amesgen 935525d
`O.C.Network.NodeToNode`: plumbing for Peras cert diffusion
amesgen a930796
Adapt tests
amesgen 233f1b2
Add basic API for certificate validation
amesgen 36d8f01
Adapt the HFC time translation layer for Peras
geo2a 591445e
Peras.SelectView: use fragment length instead of tip `BlockNo`
amesgen e99d251
Avoid exposing Peras boostPerCert in tests
agustinmista 283fcfd
Refactor ChainDB q-s-m test to carry gap blocks between commands
agustinmista 495247e
Tweak generation frequencies in ChainDB q-s-m tests
agustinmista 17b9132
Generate security parameter for ChainDB q-s-m test on the fly
agustinmista 5fad777
Propagate feature flags down to NodeKernelArgs
agustinmista 69d709d
Bump ouroboros-network to match peras-staging/pr-5202
agustinmista 3170661
Break Idling into its own module
agustinmista df386c5
Introduce O.C.MiniProtocol.ObjectDiffusion.Inbound.State
agustinmista 46451bb
Introduce PerasCertDiffusion type synonyms
agustinmista 587c566
Generalize chainSyncState to peerState in the GSM
agustinmista 78f7e5c
Store NodeToNodeVersion in GSM peer state components
agustinmista 7ca058f
Introduce O.C.Node.GSM.PeerState
agustinmista 4e3115c
Enhance GSM view with PerasCertDiffusion information
agustinmista a14fed3
Define WithArrivalTime combinator
agustinmista e0288d4
Tweak and extend Peras cert field projection typeclasses
agustinmista a909419
Wrap validated Peras certificates with arrival time
agustinmista 1a40463
Avoid using ledger Block in ShelleyBlock
agustinmista 5dc9e03
Add Peras cert to ShelleyBlock and adapt CBOR encoder/decoder
agustinmista c0822d7
Adapt golden tests to include Peras certs on compatible eras
agustinmista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Consensus benchmarks | ||
|
|
||
| We are in the process of adding component level microbenchmarks for Consensus. | ||
|
|
||
| We check for regressions in performance on CI. | ||
|
|
||
| ## Mempool Benchmark | ||
|
|
||
| We started with microbenchmarks for adding transactions to the mempool. The | ||
| mempool benchmarks can be run using the following command. | ||
|
|
||
| ```sh | ||
| cabal new-run ouroboros-consensus:mempool-bench | ||
| ``` | ||
|
|
||
| ## ChainSync Client Benchmark | ||
|
|
||
| To aid the refactoring of the ChainSync client, we added a benchmark for it in [PR#823](https://github.com/IntersectMBO/ouroboros-consensus/pull/823). The benchmark could be invoked as follows: | ||
|
|
||
| ```sh | ||
| cabal new-run ouroboros-consensus:ChainSync-client-bench -- 10 10 | ||
| ``` | ||
|
|
||
| ## PerasCertDB Benchmark | ||
|
|
||
| We have a microbenchmark for the boosted chain fragment weight calculation, which could be run as follows: | ||
|
|
||
| ```sh | ||
| cabal run ouroboros-consensus:PerasCertDB-bench -- +RTS -T -A32m -RTS | ||
| ``` | ||
|
|
||
| We request GHC runtime system statistics with `-T` to get a memory usage estimate, and also request a large nursery with `-A32m` to minimise garbage collection. See `tasty-bench` [documentation](https://github.com/Bodigrim/tasty-bench?tab=readme-ov-file#troubleshooting) for more tips. |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+1.75 KB
...s-consensus-cardano/golden/cardano/CardanoNodeToNodeVersion2/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+856 Bytes
...-consensus-cardano/golden/cardano/CardanoNodeToNodeVersion2/Header_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion2/CardanoNodeToClientVersion12/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion2/CardanoNodeToClientVersion13/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion2/CardanoNodeToClientVersion14/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion2/CardanoNodeToClientVersion15/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion3/CardanoNodeToClientVersion16/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion3/CardanoNodeToClientVersion17/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.75 KB
...no/golden/cardano/QueryVersion3/CardanoNodeToClientVersion18/Block_Dijkstra_WithPerasCert
Binary file not shown.
Binary file added
BIN
+1.74 KB
ouroboros-consensus-cardano/golden/cardano/disk/Block_Dijkstra_WithPerasCert
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| {-# LANGUAGE GADTs #-} | ||
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
| {-# LANGUAGE MultiParamTypeClasses #-} | ||
| {-# LANGUAGE OverloadedStrings #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
| {-# LANGUAGE StandaloneDeriving #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
|
|
@@ -26,7 +27,10 @@ module Ouroboros.Consensus.Shelley.Ledger.Block | |
|
|
||
| -- * Shelley Compatibility | ||
| , ShelleyCompatible | ||
| , fromShelleyBlock | ||
| , toShelleyBlock | ||
| , mkShelleyBlock | ||
| , mkShelleyBlockWithPerasCert | ||
| , mkShelleyHeader | ||
|
|
||
| -- * Serialisation | ||
|
|
@@ -46,22 +50,31 @@ import Cardano.Ledger.Binary | |
| ( Annotator (..) | ||
| , DecCBOR (..) | ||
| , EncCBOR (..) | ||
| , EncCBORGroup (..) | ||
| , FullByteString (..) | ||
| , cborError | ||
| , decodeListLen | ||
| , encodeListLen | ||
| , fromPlainDecoder | ||
| , serialize | ||
| ) | ||
| import qualified Cardano.Ledger.Binary.Plain as Plain | ||
| import Cardano.Ledger.Core as SL | ||
| ( eraDecoder | ||
| ( EraBlockBody (..) | ||
| , eraDecoder | ||
| , eraProtVerLow | ||
| , toEraCBOR | ||
| ) | ||
| import qualified Cardano.Ledger.Core as SL (TranslationContext, hashBlockBody) | ||
| import qualified Cardano.Ledger.Core as SL (TranslationContext) | ||
| import Cardano.Ledger.Hashes (HASH) | ||
| import qualified Cardano.Ledger.Shelley.API as SL | ||
| import Cardano.Protocol.Crypto (Crypto) | ||
| import qualified Cardano.Protocol.TPraos.BHeader as SL | ||
| import Codec.Serialise (Serialise (..)) | ||
| import Control.Arrow (Arrow (..)) | ||
| import qualified Data.ByteString.Lazy as Lazy | ||
| import Data.Coerce (coerce) | ||
| import Data.Maybe.Strict (StrictMaybe (..)) | ||
| import Data.Typeable (Typeable) | ||
| import GHC.Generics (Generic) | ||
| import NoThunks.Class (NoThunks (..)) | ||
|
|
@@ -145,7 +158,9 @@ instance ShelleyCompatible proto era => ConvertRawHash (ShelleyBlock proto era) | |
| -- | ||
| -- This block is parametrised over both the (ledger) era and the protocol. | ||
| data ShelleyBlock proto era = ShelleyBlock | ||
| { shelleyBlockRaw :: !(SL.Block (ShelleyProtocolHeader proto) era) | ||
| { shelleyBlockHeader :: !(ShelleyProtocolHeader proto) | ||
| , shelleyBlockBody :: !(SL.BlockBody era) | ||
| , shelleyBlockPerasCert :: !(StrictMaybe (PerasCert (ShelleyBlock proto era))) | ||
| , shelleyBlockHeaderHash :: !ShelleyHash | ||
| } | ||
|
|
||
|
|
@@ -158,14 +173,46 @@ instance | |
|
|
||
| type instance HeaderHash (ShelleyBlock proto era) = ShelleyHash | ||
|
|
||
| -- | Reconstruct a Shelley ledger block from a 'ShelleyBlock'. | ||
| -- | ||
| -- TODO: we should be able to avoid this conversion in most cases | ||
| fromShelleyBlock :: ShelleyBlock proto era -> SL.Block (ShelleyProtocolHeader proto) era | ||
| fromShelleyBlock blk = SL.Block (shelleyBlockHeader blk) (shelleyBlockBody blk) | ||
|
|
||
| -- | Construct a 'ShelleyBlock' from a Shelley ledger block. | ||
| -- | ||
| -- TODO: we should be able to avoid this conversion in most cases | ||
| toShelleyBlock :: | ||
| ShelleyCompatible proto era => SL.Block (ShelleyProtocolHeader proto) era -> ShelleyBlock proto era | ||
| toShelleyBlock (SL.Block hdr body) = mkShelleyBlock hdr body | ||
|
|
||
| mkShelleyBlock :: | ||
| ShelleyCompatible proto era => | ||
| SL.Block (ShelleyProtocolHeader proto) era -> | ||
| ShelleyProtocolHeader proto -> | ||
| SL.BlockBody era -> | ||
| ShelleyBlock proto era | ||
| mkShelleyBlock raw = | ||
| mkShelleyBlock = mkShelleyBlockGeneric SNothing | ||
|
|
||
| mkShelleyBlockWithPerasCert :: | ||
| ShelleyCompatible proto era => | ||
| PerasCert (ShelleyBlock proto era) -> | ||
| ShelleyProtocolHeader proto -> | ||
| SL.BlockBody era -> | ||
| ShelleyBlock proto era | ||
| mkShelleyBlockWithPerasCert = mkShelleyBlockGeneric . SJust | ||
|
|
||
| mkShelleyBlockGeneric :: | ||
| ShelleyCompatible proto era => | ||
| StrictMaybe (PerasCert (ShelleyBlock proto era)) -> | ||
| ShelleyProtocolHeader proto -> | ||
| BlockBody era -> | ||
| ShelleyBlock proto era | ||
| mkShelleyBlockGeneric cert header body = | ||
| ShelleyBlock | ||
| { shelleyBlockRaw = raw | ||
| , shelleyBlockHeaderHash = pHeaderHash $ SL.bheader raw | ||
| { shelleyBlockHeader = header | ||
| , shelleyBlockBody = body | ||
| , shelleyBlockPerasCert = cert | ||
| , shelleyBlockHeaderHash = pHeaderHash header | ||
| } | ||
|
|
||
| class | ||
|
|
@@ -198,10 +245,10 @@ instance | |
| ShowProxy (Header (ShelleyBlock proto era)) | ||
|
|
||
| instance ShelleyCompatible proto era => GetHeader (ShelleyBlock proto era) where | ||
| getHeader (ShelleyBlock rawBlk hdrHash) = | ||
| getHeader block = | ||
| ShelleyHeader | ||
| { shelleyHeaderRaw = SL.bheader rawBlk | ||
| , shelleyHeaderHash = hdrHash | ||
| { shelleyHeaderRaw = shelleyBlockHeader block | ||
| , shelleyHeaderHash = shelleyBlockHeaderHash block | ||
| } | ||
|
|
||
| blockMatchesHeader hdr blk = | ||
|
|
@@ -210,7 +257,7 @@ instance ShelleyCompatible proto era => GetHeader (ShelleyBlock proto era) where | |
| SL.hashBlockBody blockBody == pHeaderBodyHash shelleyHdr | ||
| where | ||
| ShelleyHeader{shelleyHeaderRaw = shelleyHdr} = hdr | ||
| ShelleyBlock{shelleyBlockRaw = SL.Block _ blockBody} = blk | ||
| ShelleyBlock{shelleyBlockBody = blockBody} = blk | ||
|
|
||
| headerIsEBB = const Nothing | ||
|
|
||
|
|
@@ -288,10 +335,35 @@ instance HasNestedContent f (ShelleyBlock proto era) | |
|
|
||
| instance ShelleyCompatible proto era => EncCBOR (ShelleyBlock proto era) where | ||
| -- Don't encode the header hash, we recompute it during deserialisation | ||
| encCBOR = encCBOR . shelleyBlockRaw | ||
| encCBOR block = do | ||
| let header = shelleyBlockHeader block | ||
| let body = shelleyBlockBody block | ||
| let bodyLen = listLen body | ||
| case shelleyBlockPerasCert block of | ||
| SNothing -> | ||
| encodeListLen (1 + bodyLen) | ||
| <> encCBOR header | ||
| <> encCBORGroup body | ||
| SJust cert -> | ||
| encodeListLen (1 + bodyLen + 1) | ||
| <> encCBOR header | ||
| <> encCBORGroup body | ||
| <> encCBOR (encode cert) | ||
|
|
||
| instance ShelleyCompatible proto era => DecCBOR (Annotator (ShelleyBlock proto era)) where | ||
| decCBOR = fmap mkShelleyBlock <$> decCBOR | ||
| decCBOR = do | ||
| len <- decodeListLen | ||
| header <- decCBOR | ||
| body <- decCBOR | ||
| cert <- decMaybeCertOrFail len | ||
| pure $ mkShelleyBlockGeneric <$> cert <*> header <*> body | ||
| where | ||
| bodyLen = fromIntegral (numSegComponents @era) | ||
|
|
||
| decMaybeCertOrFail len | ||
| | len == 1 + bodyLen = pure <$> pure SNothing | ||
| | len == 1 + bodyLen + 1 = pure <$> (SJust <$> fromPlainDecoder decode) | ||
| | otherwise = cborError $ Plain.DecoderErrorCustom "ShelleyBlock" "invalid number of elements" | ||
agustinmista marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| instance ShelleyCompatible proto era => EncCBOR (Header (ShelleyBlock proto era)) where | ||
| -- Don't encode the header hash, we recompute it during deserialisation | ||
|
|
@@ -342,7 +414,7 @@ decodeShelleyHeader = eraDecoder @era $ (. Full) . runAnnotator <$> decCBOR | |
| -------------------------------------------------------------------------------} | ||
|
|
||
| instance ShelleyCompatible proto era => Condense (ShelleyBlock proto era) where | ||
| condense = show . shelleyBlockRaw | ||
| condense = show . ((shelleyBlockHeader &&& shelleyBlockBody) &&& shelleyBlockPerasCert) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to tweak this instance. |
||
|
|
||
| instance ShelleyCompatible proto era => Condense (Header (ShelleyBlock proto era)) where | ||
| condense = show . shelleyHeaderRaw | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also just store an
SL.Block, but encode it differently. But either way, this conversion should be super cheap