-
Notifications
You must be signed in to change notification settings - Fork 33
[Peras 1] Introduce basic types to support Peras #1673
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
Merged
Merged
Conversation
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
d3cd2fc to
8df7902
Compare
738daaf to
f3fbd4f
Compare
f3fbd4f to
01e1c69
Compare
dnadales
reviewed
Sep 19, 2025
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Show resolved
Hide resolved
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Show resolved
Hide resolved
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Show resolved
Hide resolved
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Show resolved
Hide resolved
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Outdated
Show resolved
Hide resolved
fraser-iohk
reviewed
Sep 23, 2025
ouroboros-consensus/test/consensus-test/Test/Consensus/Peras/WeightSnapshot.hs
Show resolved
Hide resolved
dnadales
approved these changes
Sep 24, 2025
fraser-iohk
approved these changes
Sep 25, 2025
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: Nicolas "Niols" Jeannerod <[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]> Co-authored-by: Nicolas "Niols" Jeannerod <[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]> Co-authored-by: Nicolas "Niols" Jeannerod <[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]> Co-authored-by: Nicolas "Niols" Jeannerod <[email protected]>
2fdba58 to
3db7a62
Compare
github-merge-queue bot
pushed a commit
that referenced
this pull request
Oct 10, 2025
This pull request introduces the `PerasCertDB` datatype, used to hold
and access all `PerasCert`s known by a node that could affect chain
selection.
In the mid/near-term future, this will be enriched to persist
certificates across restarts, and probably also to store historical
certificates.
---
### **Peras types**
- Added modules `Ouroboros.Consensus.Storage.PerasCertDB{,.API,.Impl}`,
notably defining the types`PerasCertDB`, `PerasCertSnapshot` (read-only
snapshot of certs contained in the DB), and `AddPerasCertResult`;
alongside their respectives methods
---
### **Tests**
- Added modules
`Test.Ouroboros.Storage.PerasCertDB{,.StateMachine,.Model}` for q-s-m
testing of the `PerasCertDB` datatype. The corresponding tests have been
included in the test suite defined by `Test.Ouroboros.Storage`
---
### **Regression**
As the [previous
PR](#1673), all
the components introduced by this PR are not used at the moment by the
rest of the code, so no regression is expected.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Oct 21, 2025
…ed chain selection (#1678) # Description This PR introduces: - **Weighted chain comparisons**: We compare chains based on their *weight* instead of their length. Non-trivial weight is given by Peras certificates as introduced in #1673. - **Weighted chain selection**: Select the *weightiest* chain instead of the *longest* chain. - **Weighted immutability criterion**: Define the immutable tip in terms of *weight* instead of length. ### Commits The commits are intended to be reviewed individually: - *ChainDB: expose PerasCertDB functionality* The ChainDB maintains a PerasCertDB internally, and exposes most of its functionality through its public API. This is analogous to how the LedgerDB is managed by the ChainDB. - *`SecurityParam`: mention weighted nature* Purely a documentation update to mention the richer dynamics under Peras, plus a small helper function. - *O.C.Peras.Weight: add `takeVolatileSuffix`* In Praos, the volatile suffix of a chain is defined to be the `k` most recent blocks. Analogously, in Peras, the volatile suffix of a chain is defined to be the longest suffix with weight at most `k`. This commits adds an appropriate function (via a binary search), as well as documentation and tests. - *ChainDB: define `getCurrentChain` in terms of weight* This makes use of the previous commit in the ChainDB. Note that #1619 guarantees that the LedgerDB automatically uses the same notion of immutability. Note that this means that the immutable tip will be less than `k` blocks behind the tip when Peras is working well, ie every Peras round is giving rise to a certificate. Concretely, for plausible parameters, ie a round length of $U = 90$ slots and a Peras boost of $B = 15$, the length of the volatile suffix decreases from $k=2160$ to $$\frac{k}{1+\frac{B}{U\cdot f}} \approx 499$$ on average. - *ChainDB.StateMachine: check immutable tip monotonicity* To make sure that the more refined immutability criterion doesn't introduce any surprises, we add a postcondition to the ChainDB q-s-m test that the immutable tip never recedes. - *GSM: allow `candidateOverSelection` to be stateful* and *ChainSel: make `rollbackExceedsSuffix` weight-aware* Preparatory refactorings for when the chain comparison will become weighted and hence additionally depend on the `PerasWeightSnapshot`. - *Peras.SelectView: initialize, expose `WeightedSelectView`* This introduces the notion of a *weighted* `SelectView`, making use of #1591 https://github.com/IntersectMBO/ouroboros-consensus/blob/90131b282b4e002e9ddc0d7196043c50b255a1d4/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Peras/SelectView.hs#L35-L48 This will used in place of the "normal" `SelectView`. Eventually, we could also remove the normal `SelectView` and replace it with `WeightedSelectView`. However, to keep this already big PR more focused, we propose to do this in the future. - *Introduce weighted chain comparisons* The core change in this commit is in the `O.C.Util.AnchoredFragment` to the `preferAnchoredCandidate` and `compareAnchoredFragments` functions. These now - have a slightly strengthened precondition, namely that they intersect (as we otherwise can't meaningfully compare their weight), that we ensure is satisfied anywhere, and - take `PerasWeightSnapshot` as an additional argument. We keep the old implementation in case the `PerasWeightSnapshot` is empty; which is semantically unnecessary, but is a trivial way to make sure that no performance regression is introduced. The rest of the diff of this commit is simply due to adapting the respective call sites in a rather straightforward fashion. - *Integrate weighted BlockFetch decision logic* This commit plugs the weighted chain comparison logic into the BlockFetch decision logic. This relies on a (merged, but not yet released, hence the s-r-p) Network change, see IntersectMBO/ouroboros-network#5161 for a detailed description. - *ChainDB: implement chain selection for Peras certificates* We allow new Peras certificates to be added to the ChainDB (and therefore to the managed PerasCertDB). If the certificate is boosting a block that is not on the current selection, we perform chain selection for it, potentially switching to a fork containing it if it now is weightier than our selection. - *MockChainSel: switch to weighted chain selection* This logic is for example used in tests. - *ChainDB q-s-m: test weighted chain selection* We enrich the model ChainDB implementation with weighted chain selection, and add a new command with a simple generator for adding certificates. We also enrich labelling with the `TagSwitchedToShorterChain` tag that shows that we sometimes *do* switch to a shorter chain; which would be a bug without Peras. A follow-up PR (#1670) will further improve the generators of this test. --- ### **Regression** As of today, there is no way to generate certificates, so `PerasCertDB` is always empty, and the change to the chain selection algorithm is therefore invisible: in the absence of certificates, the Peras weight of a chain is equal to its length. Therefore, this PR does not introduce any semantic changes. Furthermore, from a performance standpoint, care is taken to ensure that if there are no certificates, we use the unweighted Praos logic, meaning that there is no change in performance when Peras is disabled.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces some base datatypes and functionality required for Peras, along with supporting tests, benchmarks, and documentation.
Specifically, it adds:
PerasWeightandPerasCert, which associate a weight with a block.PerasWeightSnapshot, a type for capturing the known weight state of blocksPeras types and weight computation
Ouroboros.Consensus.Block.SupportsPeras, defining types and logic for Peras weights and certificates.Ouroboros.Consensus.Block.Ouroboros.Consensus.Peras.Weight, introducingPerasWeightSnapshotand weight computation functions for chains and fragments.Documentation
glossary.md.Tests and benchmarks
PerasCertDB-bench, including a weight computation microbenchmark (bench/PerasCertDB-bench/Main.hs).Test.Consensus.Peras.WeightSnapshotwith property-based tests for weight computation on chains and fragments.Regression
The new code added with this PR is not actually used, so it shouldn't introduce regressions.