Fix flaky genTinySurplusTx by computing surplus dynamically#1157
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Tightens the genTinySurplusTx test generator’s surplus range to avoid values near the F2 fee threshold and eliminate flakiness in fee-related tests.
Changes:
- Reduce the generated surplus upper bound from 250 to 246 to stay clearly below F2.
- Update generator comments to document the F1/F2 relationship and boundary-case rationale.
f0a316a to
1567a40
Compare
The hardcoded surplus range assumed a fixed F1 for all inputs, but the fee varies with generated address structure (credential types, staking references). Compute F1 per-test via calcMinFeeTx and set surplus to [F1+4, F1+10]. Also deduplicates genTinySurplusTx — it now lives only in Fee.hs — and adds a deterministic fee gap invariant test.
1567a40 to
3faaf89
Compare
carbolymer
approved these changes
Mar 26, 2026
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.
Changelog
Context
The
genTinySurplusTxgenerator used a hardcoded surplus range (237–250), assuming the 1-output fee (F1) was always ~236. This was flaky because F1 varies with the randomly generated address structure (different credential types and staking references produce different CBOR serialization sizes). A surplus of 237 was observed to balance successfully on Windows GHC 9.12 CI (failure on PR #1156).The fix computes F1 per-test via
calcMinFeeTxon the generated tx and sets surplus to[F1+4, F1+10]— always in the danger zone regardless of address size.Also:
genTinySurplusTxand property test fromExperimental.hs(now lives only inFee.hs)exampleProtocolParamsEra :: Era era -> PParams (LedgerEra era)to keep the generator polymorphicHow to trust this PR
Checklist