Files
bridge/cmd
zeekay b1c70278ef feat(bridge): signing driver — release-pool rotation + gas pre-check
Wires the static release pool into the MPC signing driver and adds an
eth_getBalance pre-check that short-circuits swaps before the (slow)
ceremony when the release wallet can't cover destination-chain gas.

signing_driver.go:

- SetReleasePool / SetGasProbe inject the pool + balance probe at
  startup. Without a pool, the driver falls back to extracting the
  wallet ID from Swap.DepositAddress (v1 behaviour).
- signOne() now picks the release wallet from the pool when one is
  configured AND has entries, persisting ReleaseWalletID +
  ReleaseAddress on the Swap so the broadcast + refund drivers can
  read them later. The chosen address goes into the assembler's
  PreSign as SenderAddress so the unsigned tx targets the correct
  nonce + signs against the pool wallet.
- AFTER PreSign (which gave us the exact GasPrice * GasLimit + Value),
  the gas pre-check queries the release wallet's destination-chain
  balance. If balance < required cost, the swap moves to
  SwapStatusFailedInsufficientReleaseGas with a clear LastError
  ("Release wallet 0x… has insufficient balance: balance=… required=…
   gasCost=… value=… short=…"). The MPC ceremony is skipped.
  Probe failures are treated as best-effort: log + continue rather
  than refuse to sign a swap we couldn't verify.
- New ShortCircuited counter distinct from Failures (operator
  dashboards differentiate "operator needs to fund a pool wallet"
  from "transient MPC / RPC flake").

main.go:

- --release-pool-size (default 10), --release-pool-mint-network
  (default LUX_TESTNET), --release-balance-threshold-wei
  (default 1e17 wei = 0.1 LUX), --disable-gas-precheck flag, plus
  --mpc-dashboard-url / --mpc-dashboard-token / --mpc-dashboard-api-key
  for the dashboard signing wiring landed in commit 1.
- Bootstrap path: instantiates the balance probe, then the
  ReleasePool, then calls Bootstrap (which lazily mints the
  remaining wallets up to pool size, idempotent across restarts).
  Wires both probe and pool into the signing driver.
- /health endpoint exposes the pool size + threshold for ops triage.

gas_precheck_test.go covers the three core behaviours:
- insufficient balance → swap transitions to
  failed_insufficient_release_gas with no signer call
- sufficient balance → swap proceeds normally to broadcasting
- probe error → swap proceeds (best-effort, broadcast retry still works)

Together with the earlier dashboard-sign + pool foundation commits,
this closes the testnet refund-loop issue: the bridge now (a) speaks
the real /v1/mpc/sign endpoint, (b) rotates through pre-funded
release wallets, and (c) refuses to spend the MPC ceremony on swaps
that would fail on broadcast.
2026-05-27 17:13:57 -07:00
..