feat(sdk-coin-sol): add explicit compute-unit-limit setter to TransactionBuilder - #9851
Draft
ralph-bitgo[bot] wants to merge 1 commit into
Draft
ralph-bitgo[bot] wants to merge 1 commit into
ralph-bitgo[bot] wants to merge 1 commit into
Conversation
What: add setComputeUnitLimit(units) to the Solana TransactionBuilder. It validates an integer between 1 and the on-chain maximum of 1,400,000. When set, buildLegacyTransaction() prepends a SetComputeUnitLimit instruction ahead of every entry of _instructionsData (after the durable-nonce AdvanceNonceAccount, before the optional SetComputeUnitPrice) and records it in _instructionsData the way memo is, so explain and parsing see it. initBuilder() restores the limit from a parsed transaction, so a signing-phase rebuild from raw is byte-identical, and with no limit set the built bytes are unchanged. The per-type instruction parsers (send, staking, ATA and wallet init) now accept compute-budget instructions through a shared helper, and matchTransactionTypeByInstructionsOrder skips leading compute-budget instructions, so raw transactions that carry a limit still classify and round trip for every builder. Why: the priority fee is charged on the requested compute-unit limit rather than the units actually consumed, so every sponsored transaction must set an explicit, intent-sized limit (SOL Gasless Fee Payer TDD section 4.1, invariant 8). The instruction type already existed but no builder emitted it, leaving sponsored transactions without a compute cap. Ticket: CHALO-1650 Session-Id: 3662d15a-5b50-4187-a602-918f68e8ee2f Task-Id: cc1ab97e-1b0c-42f2-8440-deaee2d552b3
Contributor
Contributor
|
|
This branch has not been deployed
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.
What
Adds an explicit compute-unit-limit setter to the Solana
TransactionBuilderinmodules/sdk-coin-sol:setComputeUnitLimit(units)on the baseTransactionBuilder(and therefore every subclass), validating an integer between 1 and the on-chain per-transaction maximum of 1,400,000 (MAX_COMPUTE_UNIT_LIMITinconstants.ts).buildLegacyTransaction()prepends aSetComputeUnitLimitinstruction ahead of every entry of_instructionsData, so the built order is[AdvanceNonce?, SetComputeUnitLimit, SetComputeUnitPrice?, …](web3.js serializes the durable-nonceAdvanceNonceAccountfirst vianonceInfo). The instruction is recorded in_instructionsData, mirroring how memo is recorded, so explain and parsing see it. When no limit is set the built bytes are unchanged.initBuilder()restores_computeUnitLimitfrom a parsed transaction (the waySetPriorityFeeis restored today), so a signing-phase rebuild from raw is byte-identical.parseStakingActivate/Deactivate/Delegate/Withdraw,parseAtaInit/AtaClose,parseWalletInit) now accept leading compute-budget instructions through a sharedparseComputeBudgetInstruction()helper (previously onlyparseSendInstructionsdid), andmatchTransactionTypeByInstructionsOrderskips leading compute-budget instructions like it already skipsAdvanceNonceAccount. Without this, raw transactions carrying a limit would misclassify (staking/ATA types fell through toCustomTx) and the round trip would drop the instruction._instructionsDatafrom their own params beforebuildLegacyTransaction()re-adds the instruction from_computeUnitLimit, so it is added exactly once (covered by a build-twice test per builder).Why
The priority fee is charged on the requested compute-unit limit, not the units actually consumed, so every sponsored transaction must set an explicit, intent-sized limit (SOL Gasless Fee Payer technical design §4.1, invariant 8; PRD CHALO-983). The
SetComputeUnitLimitinstruction type and its parsing already existed, but no builder emitted it. This is a prerequisite for the SOL relayer/gasless fee-payer work (CHALO-1516).Note on reach: wallet-platform consumes this module as
@bitgo-beta/sdk-coin-sol, so the change reaches WP only after a beta release and the bump ticket.Test plan
test/unit/transactionBuilder/computeUnitLimit.ts: for each of the nine builders (transfer, transferV2, token transfer, ATA init, close ATA, staking activate/deactivate/delegate/withdraw) plus wallet init — with a limit the compiled instruction order is[AdvanceNonce?, SetComputeUnitLimit, SetComputeUnitPrice?, …]and the instruction appears exactly once;from(raw)→build()→toBroadcastFormat()is byte-identical and the limit survives the round trip; building twice on the same builder does not duplicate the instruction; without a limit the bytes equal the pinned pre-change fixtures.BITGOJS_TEST_PASSWORD=x npx mocha— 803 passing, 0 failing (baseline 758 + 45 new).npm run lintandtsc --noEmitclean inmodules/sdk-coin-sol.Ticket: CHALO-1650