-
Notifications
You must be signed in to change notification settings - Fork 38
[Peras 9] Peras voting rules prep: parameters, arrival times, and CertDB updates #1784
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
base: main
Are you sure you want to change the base?
Conversation
14229b9 to
85e4b39
Compare
tbagrel1
left a comment
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.
LGTM!
I think we may change the title of the PR though (and maybe part of its description) to better reflect that most changes are related to adding timestamps on certs and propagate the necessary stuff to make it work.
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Peras/Params.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Peras/Params.hs
Outdated
Show resolved
Hide resolved
nbacquey
left a comment
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.
Besides my comments, it seems ok to undraft
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Peras/Params.hs
Show resolved
Hide resolved
ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/PerasCertDB/API.hs
Outdated
Show resolved
Hide resolved
...consensus/test/consensus-test/Test/Consensus/MiniProtocol/ObjectDiffusion/PerasCert/Smoke.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/PerasCertDB/StateMachine.hs
Outdated
Show resolved
Hide resolved
97685c7 to
64748d9
Compare
013f36d to
590a1e6
Compare
590a1e6 to
95a3906
Compare
| let | ||
| runOutboundPeer outbound outboundChannel tracer = | ||
| runPeer | ||
| ((\x -> "Outbound (Client): " ++ show x) `contramap` tracer) | ||
| codecObjectDiffusionId | ||
| outboundChannel | ||
| (objectDiffusionOutboundPeer outbound) | ||
| >> pure () | ||
| runInboundPeer inbound inboundChannel tracer = | ||
| runPipelinedPeer | ||
| ((\x -> "Inbound (Server): " ++ show x) `contramap` tracer) | ||
| codecObjectDiffusionId | ||
| inboundChannel | ||
| (objectDiffusionInboundPeerPipelined inbound) | ||
| >> pure () | ||
| mkPoolInterfaces :: | ||
| forall m. | ||
| IOLike m => | ||
| m | ||
| ( ObjectPoolReader PerasRoundNo (PerasCert TestBlock) PerasCertTicketNo m | ||
| , ObjectPoolWriter PerasRoundNo (PerasCert TestBlock) m | ||
| , m [PerasCert TestBlock] | ||
| ) | ||
| mkPoolInterfaces = do | ||
| outboundPool <- newCertDB perasTestParams certs | ||
| inboundPool <- newCertDB perasTestParams [] | ||
| forAll arbitrary $ \systemTimeSeed -> | ||
| let | ||
| runOutboundPeer outbound outboundChannel tracer = | ||
| runPeer | ||
| ((\x -> "Outbound (Client): " ++ show x) `contramap` tracer) | ||
| codecObjectDiffusionId | ||
| outboundChannel | ||
| (objectDiffusionOutboundPeer outbound) | ||
| >> pure () | ||
| runInboundPeer inbound inboundChannel tracer = | ||
| runPipelinedPeer | ||
| ((\x -> "Inbound (Server): " ++ show x) `contramap` tracer) | ||
| codecObjectDiffusionId | ||
| inboundChannel | ||
| (objectDiffusionInboundPeerPipelined inbound) | ||
| >> pure () | ||
| mkPoolInterfaces :: | ||
| forall m. | ||
| IOLike m => | ||
| m | ||
| ( ObjectPoolReader PerasRoundNo (PerasCert TestBlock) PerasCertTicketNo m | ||
| , ObjectPoolWriter PerasRoundNo (PerasCert TestBlock) m | ||
| , m [PerasCert TestBlock] | ||
| ) | ||
| mkPoolInterfaces = do | ||
| systemTime <- mockSystemTime systemTimeSeed | ||
| outboundPool <- newCertDB perasTestParams systemTime certs | ||
| inboundPool <- newCertDB perasTestParams systemTime [] | ||
|
|
||
| let outboundPoolReader = makePerasCertPoolReaderFromCertDB outboundPool | ||
| inboundPoolWriter = makePerasCertPoolWriterFromCertDB inboundPool | ||
| getAllInboundPoolContent = atomically $ do | ||
| snap <- PerasCertDB.getCertSnapshot inboundPool | ||
| let rawContent = | ||
| Map.toAscList $ | ||
| PerasCertDB.getCertsAfter snap (PerasCertDB.zeroPerasCertTicketNo) | ||
| pure $ vpcCert . snd <$> rawContent | ||
| let outboundPoolReader = makePerasCertPoolReaderFromCertDB outboundPool | ||
| inboundPoolWriter = makePerasCertPoolWriterFromCertDB systemTime inboundPool | ||
| getAllInboundPoolContent = atomically $ do | ||
| snap <- PerasCertDB.getCertSnapshot inboundPool | ||
| let rawContent = | ||
| Map.toAscList $ | ||
| PerasCertDB.getCertsAfter snap (PerasCertDB.zeroPerasCertTicketNo) | ||
| pure $ vpcCert . forgetArrivalTime . snd <$> rawContent | ||
|
|
||
| return (outboundPoolReader, inboundPoolWriter, getAllInboundPoolContent) | ||
| in | ||
| prop_smoke_object_diffusion | ||
| protocolConstants | ||
| certs | ||
| runOutboundPeer | ||
| runInboundPeer | ||
| mkPoolInterfaces | ||
| return (outboundPoolReader, inboundPoolWriter, getAllInboundPoolContent) | ||
| in | ||
| prop_smoke_object_diffusion | ||
| protocolConstants | ||
| certs | ||
| runOutboundPeer | ||
| runInboundPeer | ||
| mkPoolInterfaces |
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.
FTR: actual changes here are minimal (masked by new indentation needed by forAll):
- Parameterize the property with the seed used to derive a mocked up
SystemTimeviaforAll, and - Instantiate a mocked up
SystemTimeand pass it around to the places needing it.
95a3906 to
c0e0683
Compare
This commits introduces the module: Ouroboros.Consensus.Peras.Params To consolidate all the protocol parameters related to Peras in one place. Until we defined concrete BlockSupportsPeras for the different block types + HFC, all blocks satisfy: type PerasCfg blk = PerasParams Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
This commit adds a small helper to compute over Peras round numbers. Will be needed later on to implement the Peras voting rules. Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
This commit simplifies the interface of the HasPerasCertX typeclasses, removing the StandardHash superclass constraint, and splitting them into several smaller typeclasses. Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
This commit defines a generic WithArrivalTime combinator to wrap a value with its arrival time (as a Relative time). This is needed by Peras in several places, e.g., to evaluate the voting rules. Notably, we store a raw Relative time instead of a (arguably more apt) SlotNo or PerasRoundNo to defer as much as possible having to deal with the case where making this translation (timestamp -> slot/round) is not possible due to the HFC time translation horizon. Instead, the client will need to perform this translation in a context where such a failure cannot occur or can be more easily dealt with. Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
This commit wraps the existing ValidatedPerasCerts stored in the PerasCertDB with their corresponding arrival time. In addition, it adapts tests to use either a randomly generated arrival time, or (when appropriate) one generated by a monotonically increasing SystemTime. Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
This commit adds a method to the PerasCertDB API to retrieve the latest certificate seen. This is certificate needed to implement the Peras voting and must be kept around even after garbage collection. Because of this, we extend the internal state of the PerasCertDB to store this special certificate on the side, and (potentially) update it after new certificates are added to the database. Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
Co-authored-by: Agustin Mista <[email protected]> Co-authored-by: Alexander Esgen <[email protected]> Co-authored-by: Georgy Lukyanov <[email protected]> Co-authored-by: Thomas BAGREL <[email protected]> Co-authored-by: Nicolas BACQUEY <[email protected]>
c0e0683 to
2957426
Compare
This PR introduces some general changes and QoL improvements in anticipation to the introduction of the Peras voting rules. These are separated into hopefully digestible atomic commits:
Ouroboros.Consensus.Peras.Paramsmodule to keep track of Peras protocol parameters in a single place,onPerasRoundNo,HasPerasCertXfield projection typeclasses,WithArrivalTimecombinator to wrap values with aRelativeTime,getLatestCertSeenmethod to retrieve it.Please refer to the corresponding commit messages for more information.