-
Notifications
You must be signed in to change notification settings - Fork 112
Speed up finding the partial fanout chunk size #2849
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
Open
vrom911
wants to merge
6
commits into
master
Choose a base branch
from
vrom911/optimise-partial-fanout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
72b9bb3
Add test showing current limit
vrom911 a72f4bf
Cap the fanout chunk search at what the CRS can verify
vrom911 080a1db
Reuse the verified accumulator across fanout candidates
vrom911 97d84dd
Update CHANGELOG
vrom911 ba067ba
Fix warnings
vrom911 f001c37
Some code review changes
noonio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Suggestion: don't gate the preferred fanout on laziness
The
preferredFanoutTxoptimisation currently rests on an invisible strictness contract: skipping the doomed whole-set membership proof only works because callers pass(fanout ctx ...)as an unforced thunk, and the gate size computed inmkChain(fullUTxO = utxo <> fold utxoToCommit <> fold utxoToDecommit) must stay in lockstep with the unionfanoutTxderives internally asallToFanout. A bang pattern,$!, or drift in either set definition silently reintroduces the full proof build (or skips valid full fanouts) with no type-level hint — the bottom-based unit test is the only tripwire.A cleaner fix: move the cap check inside the builders, right where the distributed set is defined, so skipping the expensive work is ordinary
Eithershort-circuiting rather than caller-side laziness.1. Guard in
fanoutTx(hydra-txFanout.hs) —allToFanoutis defined here, and the existing comment already says the count, proof, and outputs must all come from this one place; the cap belongs there too:The
Leftreturns beforecomputeFanoutProof, so neither the proof nor thebuildFromUTxO utxoForProofaccumulator is ever built. That's do-block sequencing — forcing the result anywhere costs aUTxO.sizeand a datum decode, not an MSM.2. Same guard in
finalPartialFanoutandpartialFanoutFromPlan(State.hs) — add e.g.ExceedsDeployedBatchSize {requested :: Int}toPartialFanoutErrorand check it first thing in both. This also enforces the cap once, instead of relying on the ad-hocmin ... deployedFanoutBatchSizecurrently repeated at four call sites (Handlers.hs, TxCost.hs ×2, testlib State.hs) — a fifth caller that forgets theminwould otherwise silently reintroduce the O(head-size) doomed-build regression this PR fixes.3. Delete
preferredFanoutTxin Handlers.hs — the call sites become just:(rightToMaybe $ fanout ctx spendableUTxO seedTxIn utxo utxoToCommit utxoToDecommit utxoForProof deadlineSlot)Above the cap the builder returns
Left,rightToMaybegivesNothing, andfindBestfalls through tofindFallback— exactly today's behavior. The "the union is also what fanoutTx counts…" comment and the laziness caveat go away with it.Two details to watch:
min … deployedFanoutBatchSizeinfindFallback'ssearchRange:buildTxroutes builder errors throughorThrow, which throwsFailedToConstructPartialFanoutTx, so without theminthe binary search's first probe above the cap would abort the search instead of settling lower. Theminstays as the efficiency choice; the builderLeftbecomes the invariant.undefinedas the preferred tx doesn't explode") can be replaced by a direct property —fanoutTx/finalPartialFanoutreturnLeftfor sets larger thandeployedFanoutBatchSize— which is much less magical than testing via⊥.If touching
hydra-txis out of scope for this PR, the minimal variant is a syntactic guard at the call site:That removes the strictness contract (the
fanoutcall is syntactically unreachable above the cap), though it still leaves the caller'sfullUTxOcount coupled tofanoutTx's internalallToFanout, so the builder-side check is the more robust fix.