Skip to content

l1/wallet: make funded tx builders fallible instead of panicking on insufficient funding #103

Description

@biryukovmaxim

The build::* transaction builders in l1/wallet panic via assert! when the chosen funding UTXO can't cover the outputs plus the node's minimum mass-based fee:

  • build::signed_carrier_transactionamount > extra_value, amount > extra_value + fee
  • build::pay_to_address_transactionamount > payout, amount > payout + fee
  • build::activity_transactionamount > fee
  • build::settlement_transactionfee_entry.amount > fee

These are pub and used in production through Wallet, which selects the UTXO to fund from (build_signed_carrier/build_covenant_bootstrap_transaction take utxos.into_iter().next(); pay_to_address the largest). A UTXO smaller than the required outputs+fee is a reachable runtime condition, not a programmer error, so it should surface as a recoverable error rather than crash the issuer.

Proposed change

  • Add a thiserror BuildError (e.g. InsufficientFunds { available, required }) in l1/wallet/src/build.rs; have the builders above return Result<Transaction, BuildError>. Fold the zero-fee probe's underflow guard into a single post-probe sufficiency check by probing the change output with a placeholder value (its value doesn't affect the byte layout / mass), the way activity_transaction already does.
  • Propagate through the Wallet methods (build_payload_transactions, build_subnet_payload_transactions, build_signed_carrier, build_covenant_bootstrap_transaction, prepare_settlement_transaction/_excluding, pay_to_address, build_activity_excluding) via a WalletError folding RpcError + BuildError + a no-spendable-UTXO case; the fetch .expect(...)s become ?.
  • Update callers (settler, examples/tn10-flow, sim driver, node/test-utils, e2e tests).

build::covenant_bootstrap_transaction does no fee math and has no funding-insufficiency path, so its builder stays infallible; only its Wallet wrapper gains the UTXO-selection error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions