fix(cardano): align proptest epochs with strict assertions - #1050
Open
scarmuega wants to merge 3 commits into
Open
fix(cardano): align proptest epochs with strict assertions#1050scarmuega wants to merge 3 commits into
scarmuega wants to merge 3 commits into
Conversation
The `strict` feature (enabled by `--all-features`) turns on epoch-alignment assertions in `EpochValue` methods (`schedule`, `live_mut`, `replace`, `transition`). These assertions enforce a production invariant: a delta's epoch must equal the entity's current `EpochValue` epoch, which holds because ESTART transitions every entity in lockstep with the ledger epoch. The proptest strategies generated entity and delta with independently random epochs (both drawn from `any_epoch()`), violating the invariant and tripping the strict assertions under `--all-features`. Add epoch-parameterized strategy variants (`any_epoch_value_at`, `any_account_state_at`, `any_pool_state_at`, `any_epoch_state_at`, etc.) and rewire the 14 failing tests to share a single epoch between entity and delta via `prop_flat_map`. For transition deltas, the entity is generated at `epoch` and the delta at `epoch + 1`, matching the `assert_eq!(self.epoch + 1, next_epoch)` invariant. All 14 previously-failing tests now pass; dolos-cardano reports 129 passed, 0 failed.
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The CI already runs clippy with --all-features but tests only with default features. This let 14 strict-feature proptest failures slip through undetected. Add a second test step with --all-features to catch feature-gated code paths.
The --all-features test step exposed a pre-existing bug in the work buffer (crates/cardano/src/work.rs): when blocks jump multiple epochs (e.g. from epoch 0 to epoch 2 during bulk import), the EstartBoundary pop_work arm puts the block into OpenBatch without re-checking if the block is still in a later epoch. This causes EpochStatsUpdate::apply to call live_mut with the wrong epoch, tripping the strict assertion. Fixing this requires passing ChainSummary to pop_work so it can detect multi-epoch jumps — a separate refactor. Revert the CI change until that bug is fixed.
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.
Problem
Running
cargo test --workspace --all-featuresproduced 14 test failures indolos-cardanolib tests (115 passed; 14 failed).All failures panicked at
#[cfg(feature = "strict")]assertions incrates/cardano/src/model/epoch_value.rs(schedule,live_mut,replace,transition), which enforce that a delta's epoch equals the entity's currentEpochValueepoch.Root cause
The
strictfeature (enabled by--all-features) turns on epoch-alignment assertions that guard a production invariant: ESTART transitions every entity in lockstep with the ledger epoch, so a delta constructed at epoch E is always applied to an entity whoseEpochValueis also at epoch E.The proptest strategies violated this invariant by generating the entity and the delta with independently randomized epochs — both drawn from
any_epoch()(3u64..1_000_000u64). When the two epochs disagreed (almost always),applytripped the strict assertion.Failing tests (14)
accountsstake_delegation_roundtrip,stake_delegation_serde_roundtrip,vote_delegation_roundtrip,vote_delegation_serde_roundtrip,stake_deregistration_roundtrip,stake_deregistration_serde_roundtrip,pool_delegator_retire_roundtrip,drep_delegator_drop_roundtrip,account_transition_roundtripepochsepoch_stats_update_roundtrip,epoch_transition_roundtrip,epoch_transition_v2_roundtrippoolspool_registration_roundtrip,pool_transition_roundtripFix
Add epoch-parameterized strategy variants that pin the
EpochValueto a caller-chosen epoch, and rewire the 14 failing tests to share a single epoch between entity and delta viaprop_flat_map.For transition deltas (
AccountTransition,PoolTransition,EpochTransition,EpochTransitionV2), the entity is generated atepochand the delta atepoch + 1, matching theassert_eq!(self.epoch + 1, next_epoch)invariant.New strategies
any_epoch_value_at(epoch, inner)/any_epoch_value_no_next_at(epoch, inner)—epoch_value.rsany_account_state_at(epoch)—accounts.rsany_pool_state_at(epoch)—pools.rsany_epoch_state_at(epoch)/any_epoch_state_no_rolling_next_at(epoch)—epochs.rs*_at(epoch)delta strategies for each affected deltaThis models the production invariant the
strictfeature is meant to guard, rather than disabling the assertions.Verification
The
dolos-minibfworkspace-level failure is pre-existing and unrelated (passes when run independently:212 passed; 0 failed).Summary by CodeRabbit