feat(payment): single-approval merkle payments via payForMerkleTrees with legacy fallback - #217
Draft
Nic-dorman wants to merge 1 commit into
Draft
feat(payment): single-approval merkle payments via payForMerkleTrees with legacy fallback#217Nic-dorman wants to merge 1 commit into
Nic-dorman wants to merge 1 commit into
Conversation
…with legacy fallback Multi-tree uploads now settle in groups of up to MERKLE_TREES_PER_PAYMENT (4) trees per payForMerkleTrees transaction — one wallet confirmation per ~4 GiB instead of one per ~1 GiB tree (V2-949). The vault is feature-probed once per upload via its MAX_TREES_PER_PAYMENT() getter (definitive answers cached per chain+vault, transport failures not cached); old deployments keep the legacy per-tree loop unchanged. Winner hashes align to trees by log order — the contract emits one MerklePaymentMade per tree in input order — and a failed group pays nothing (atomic), so the existing partial-finalize path carries over at group granularity. stageDone/ stageTotal now count wallet confirmations, not trees. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Linear issue
V2-991 — https://linear.app/autonominetwork/issue/V2-991 (parent V2-949)
What
One wallet confirmation per ≤4 merkle trees (≈4 GiB) instead of one per tree, with a runtime fallback that keeps every released vault working:
utils/payment.ts: newpayForMerkleTrees(config, batches)— singlewriteContracton the batched entry point, single receipt, allMerklePaymentMadeevents decoded in log order (the contract emits one per tree in input order, so index i belongs to tree i) →winnerPoolHashesaligned to input; throws on event-count mismatch.extractMerklePaymentEventsis shared with the legacypayForMerkleTree(which previously stopped at the first event).batchedMerkleTreesPerTx(): reads the vault'sMAX_TREES_PER_PAYMENT()getter once per chain+vault. Old deployments revert → 0 → legacy per-tree loop, cached (definitive). Transport failures are not cached — the current upload degrades to legacy, the next one re-probes. Supported vaults returnmin(MERKLE_TREES_PER_PAYMENT = 4, on-chain max).stores/files.ts: the merkle payment loop iterates contiguous groups (merklePaymentGroups) — batched call for multi-tree groups, legacy call for singletons (including a trailing remainder group, e.g. 5 trees → 4 batched + 1 legacy).stageDone/stageTotalnow count wallet confirmations, so the existingapprove_payment_n_of_m/approve_in_walletlabel logic and locale strings carry over with correct semantics — no i18n changes needed. Single-tree uploads skip the probe RPC entirely.null, so the existing k-of-N partial-finalize path (confirm_upload_merklewith nulls) works unchanged at group granularity.ensureAllowanceForMerkleBatchesstill runs once up front over all batches.assets/abi/IPaymentVault.jsongainspayForMerkleTrees+MAX_TREES_PER_PAYMENT(from evmlib's ABI on feat(payment): pay N merkle trees in one tx (payForMerkleTrees) evmlib#15). Harmless against old vaults.Compatibility / rollout
No Rust/
src-taurichanges — this is frontend-only and has no build dependency on the evmlib release chain. Against today's production vaults the probe fails and behavior is byte-identical to 0.9.7 (legacy loop). The batched path activates automatically when the V2-992 vault redeployment lands. Safe in either release order by construction.Test evidence
npx vitest run: 87/87 across 8 files, including new coverage: real-ABI event log round-trip (encode viaviem/utils, decode through the production path) asserting log-order alignment and count-mismatch failure; probe clamp/caching/transport semantics; grouping math; and a store-level flow test (5 trees → one batched 4-tree call + one legacy singleton →confirm_upload_merklereceives all five winner hashes on the right positions).npx nuxi typecheckclean.decodeEventLog(from unmockedviem/utils) — the receipt-decoding path was previously untestable under the identity-shim mock.Draft until
Mitigation / rollback
Revert = back to the per-tree loop. At runtime the probe's transport-failure path already degrades to legacy per upload; a vault without the getter never takes the batched path at all.
🤖 Generated with Claude Code