[CTC 1] Generalize point schedule tests to parametric blk#1879
Merged
jasagredo merged 3 commits intoIntersectMBO:mainfrom Feb 26, 2026
Merged
[CTC 1] Generalize point schedule tests to parametric blk#1879jasagredo merged 3 commits intoIntersectMBO:mainfrom
blk#1879jasagredo merged 3 commits intoIntersectMBO:mainfrom
Conversation
isovector
reviewed
Feb 13, 2026
...boros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Tests/Rollback.hs
Outdated
Show resolved
Hide resolved
isovector
reviewed
Feb 13, 2026
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Trace.hs
Outdated
Show resolved
Hide resolved
e0b6a93 to
35d7201
Compare
blk
3ea081f to
45f3760
Compare
6a7cf58 to
d0a1689
Compare
0254b6f to
0cebfdd
Compare
jasagredo
reviewed
Feb 24, 2026
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/BlockTree/Tests.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/Genesis/Setup/GenChains.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PointSchedule.hs
Show resolved
Hide resolved
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Config.hs
Outdated
Show resolved
Hide resolved
ouroboros-consensus-diffusion/changelog.d/20260210_112021_isovector_testblocks.md
Outdated
Show resolved
Hide resolved
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Trace.hs
Show resolved
Hide resolved
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/BlockTree.hs
Outdated
Show resolved
Hide resolved
0608737 to
2b105db
Compare
jasagredo
approved these changes
Feb 25, 2026
536769e to
c5bb566
Compare
An important in-progress task is to make more test code block-polymorphic; right now it is largely hardcoded to use test blocks but this will not work for running conformance tests against live implementations of the protocol. We do not know the exact motivation behind making these tests monomorphic; regardless it seems the only thing the tests require is the ability to compute where a block is on the block tree. Here we add a helper function to make generalize this by constructing a map from each block hash in the tree to the `AnchoredFragment` from it to the anchor. That fragment is a prefix of the trunk if and only if the block is on the trunk. The deforested block tree is used to check for block membership, and to prevent its unnecessary regeneration many thousands of times per test, it is implemented by adding a `DeforestedBlockTree` field to `BlockTree` to cache it and a smart constructor that populates it correctly at definition time and makes it possible to deconstruct a block tree into its trunk and branches without giving access to the cached deforestation. GHC's pattern match checker [assumes that any case expression involving a pattern synonym is incomplete](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html#complete-pragmas); with either `-Wincomplete-patterns` or `-Wall`, GHC will report usage of such patterns an incomplete pattern match like this: ``` Pattern match(es) are non-exhaustive In an equation for ‘mkProperty’: Patterns of type ‘GenesisTestFull blk’, ‘StateView blk’ not matched: (GenesisTest _ _ _ _ (Test.Consensus.BlockTree.RawBlockTree _ _ _) _ _ _ _ _ _ _) _ ``` For this reason we add a `COMPLETE` pragma to let GHC know that `BlockTree` is in fact a complete set of patterns for deconstructing a block tree.
Here we generalize all uses of unnecessarily-specified `TestBlock`s to instead be parametric `blk`s. For this we introduce two new type classes. The `IssueTestBlock` class abstracts the operations needed to produce blocks during chain generation. The `HasPointScheduleTestParams` class abstracts the parameters needed to run the point schedule tests. We invoke `getProtocolInfoArgs` at the beginning of a test, and use it to construct a `ProtocolInfo`, which in turn provides both a `TopLevelConfig` and an `ExtLedgerState`. The requirement of `IO` comes from needing to eventually parse cardano config files. A key point of entry for this change is found on `PeerSimulator.Run.nodeLifecycle`, where the `ProtocolInfo` is delivered, enabling the generalization of the simulation to arbitrary blocks. We provide instances for `TestBlock`. Co-authored-by: Nathan Bloomfield <nathan.bloomfield@tweag.io> Co-authored-by: Xavier Góngora <xavier.gongora@tweag.io>
Some genesis tests still depend on 'TestBlock' specific logic. Specifically, the `TestHash` (the `HeaderHash TestBlock` type family instance) stores a number list representation of the path on the `BlockTree` leading to the corresponding block (i.e. its prefix `AnchoredFragment`); this is used to implement certain properties. Here, such properties are refactored to parametric blocks by using direct hash comparison (in some cases on the `BlockTree` trunk). tweag/ouroboros-consensus-testing@3e83852 holds a test showcasing a property of a previous refactor: namely that the order of _fork numbers_ in a `TestHash` are not relevant for the properties that depended on it. This alternative refactor (on tweag/ouroboros-consensus-testing@dab5349) intended to preserve existing code structure, which was confusing, and as such was changed in the end in search for clarity.
auto-merge was automatically disabled
February 26, 2026 15:27
Head branch was pushed to by a user without write access
c5bb566 to
afe45d7
Compare
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
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.
Node-vs-Environment tests (a.k.a. point schedule tests, represented by
GenesisTest) are currently hardcoded to useTestBlock. As part of the approved Conformance Testing of Consensus (CTC) proposal, we are tasked with exposing these tests to the wider ecosystem and therefore must support real Cardano blocks.This PR generalizes the relevant types to make the tests block-agnostic. To accomplish this:
deforestBlockTreeis introduced to generalize property test computations that previously depended on theTestHashimplementation. This function constructs a map enabling prefix lookups byHeaderHash, where a prefix is theAnchoredFragmentfrom genesis to the block corresponding to the given hash at its tip.HasPointScheduleTestParams, is introduced to construct theProtocolInfoand other pieces of state required for a test run.IssueTestBlock, defining the interface for producing blocks in tests, is introduced.Care has been taken to document the previously implicit
TestHash-related logic (based on the use of ad hoc fork numbers) and to include comprehensive property tests for the deforestation code underouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/BlockTree/Tests.hs.