Skip to content

fix(transaction): select a given collateral UTxO for payment - #880

Merged
twwu123 merged 2 commits into
mainfrom
fix/collateral-selection
Nov 30, 2026
Merged

twwu123 merged 2 commits into
mainfrom
fix/collateral-selection

Conversation

@lisicky

@lisicky lisicky commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What

TxBuilder no longer keeps a UTxO named by a collateral(...) part out of coin selection. When the payer's UTxOs hold it (a snapshot's utxos, a wallet's getUtxos), selection may spend it for payment too, and it is still put up as collateral: the ledger accepts an input that is also a collateral input. To keep it unspent, an application leaves it out of the payer's UTxOs, or refuses it with canSelect, which is now asked about it as well.

Until now, a payer whose funds were in its collateral UTxO, such as a wallet with a single UTxO, got INSUFFICIENT_FUNDS for a transaction those funds cover.

Contents

  • tx-builder/balance.ts: paymentPool and refusedBy no longer pass over the UTxOs that collateral parts put up.
  • tx-builder/builder.ts, mesh-tx-builder/index.ts: the internal selectableCollateral declaration is removed. MeshTxBuilder passed it so that selection could spend its txInCollateral inputs. That is now the default, so MeshTxBuilder builds as before.
  • README, Collateral: the rule, and the two ways to keep such a UTxO unspent.
  • Tests:
    • builder.test.ts: the pool counts of INSUFFICIENT_FUNDS, and selection with the UTxO listed, left out, or refused by canSelect.
    • traps-emulator.test.ts: the same cases, built against the emulator and submitted to it.

A sweep (sendAllTo) now spends a listed collateral UTxO too. UTxOs that the parts read are still never selected. The consolidation steps of a plan still leave alone the collateral of the step they serve.

Validation

cd packages/mesh-transaction
npx tsc --noEmit -p tsconfig.json
npx prettier --check src/tx-builder/balance.ts src/tx-builder/builder.ts src/mesh-tx-builder/index.ts README.md test/tx-builder/builder.test.ts test/tx-builder/traps-emulator.test.ts
npm test -- --maxWorkers=8   # 167 suites, 5233 tests pass
npm run build:mesh
npm run build:docs

@twwu123
twwu123 added this pull request to stack #885 November 30, 2026 03:53
@twwu123
twwu123 merged commit ba7c099 into main Nov 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants