Skip to content

tapgarden: support caller-defined genesis anchor PSBTs - #2238

Draft
SadiqJaf wants to merge 13 commits into
lightninglabs:mainfrom
SadiqJaf:codex/issue-721-custom-genesis-psbt
Draft

SadiqJaf wants to merge 13 commits into
lightninglabs:mainfrom
SadiqJaf:codex/issue-721-custom-genesis-psbt

Conversation

@SadiqJaf

@SadiqJaf SadiqJaf commented Aug 15, 2026 •

Copy link
Copy Markdown

Summary

This adds a caller-controlled Bitcoin anchor PSBT flow for minting batches. It's a slimmed-down rewrite of the previous revision of this PR (13 commits instead of 35), rebased on main at 10759c4a.

  • FundBatch accepts a caller-funded anchor PSBT.
  • PrepareBatch commits the asset tree and pauses before publication, so an external signer can finalize caller-controlled inputs.
  • FinalizeBatch validates the signed PSBT, persists it in the existing minting_tx_psbt column, and resumes publication and confirmation.
  • Wallet-owned inputs are leased for the batch during the signing pause. External inputs are never unlocked by tapd.
  • The CLI gains assets mint fund/prepare/finalize, with hardened PSBT output-file handling.

Safety properties

  • Mint anchoring is registered before publish, and PkScript is resolved from NonWitnessUtxo. Nothing is broadcast without a watchable trigger set.
  • A prepared batch (Committed after PrepareBatch) can't be cancelled.
  • Final validation requires SIGHASH_ALL or SIGHASH_DEFAULT on finalized inputs.
  • A definitive mempool policy rejection returns the batch to import-pending, where it can be cancelled.

Removed from the previous revision

Historical key repair, the publish-error tokenizer matrix, the MuSig2 itest, the legacy lease markers and the DB migration have all been dropped. NUMS and external anchor keys are still tracked in #2237.

Validation

  • Unit tests for tapgarden, tapdb, lndservices, rpcserver and cmd/commands.
  • New itest testMintCustomAnchorPsbt.
  • Full CI passed on the fork, including the sqlite, postgres and remote-signer itests, the custom channels itests, race tests, cross-compilation, sqlc and lint.
  • All commits are signed.

Fixes #721

@SadiqJaf

SadiqJaf commented Aug 21, 2026 •

Copy link
Copy Markdown
Author

Follow-up e648a343 fixes the CI-reported custom-anchor data races and lint violations. Local gates pass: the two exact race regressions, full ^TestIssue721 under -race, and ./tapgarden ./tapdb ./tapnode ./lndservices.

@SadiqJaf

SadiqJaf commented Sep 5, 2026

Copy link
Copy Markdown
Author

Fork CI rehearsal passed at 7cc9a17 against upstream main 4466280, using unchanged workflows and an identical merge tree: CI — 40 jobs passed and backward compatibility passed. The fork-only release-note check was skipped; the unchanged checker passed separately using PR number 2238. Ready for maintainer approval of official upstream CI; these rehearsal results do not replace upstream checks.

@SadiqJaf

SadiqJaf commented Sep 8, 2026 •

Copy link
Copy Markdown
Author

Synced with upstream main at 643f8714c18f459720af9e02b0874ea0d25d4670 through history-preserving merge 542192bf3cd3274212a5e2c8dd982c5f763fdb36.

The cancellation conflicts with #2262 are resolved through one lease-release dispatcher. Ordinary wallet-funded batches retain upstream cleanup. Custom anchors release only recorded leases using the batch-specific owner ID; foreign inputs never reach the ordinary wallet-unlock fallback. Added mixed-input and all-foreign cancellation regressions. Publication/cancellation boundaries and immutable signed transactions are unchanged.

Validation before updating this PR:

  • Affected-package tests passed: tapgarden, tapdb, lndservices, rpcserver, tapnode/tapnodemock.
  • Targeted batch-cancellation tests and expanded Issue [feature]: Enhance caretaker w/ ability to set user-defined UTXOs and GenesisAmtSats values #721 cancellation/lease lifecycle race tests passed.
  • CI-pinned golangci-lint v2.10.1: 0 issues; formatting and diff checks passed.
  • Fork rehearsal PR: CI succeeded with 40 successful jobs, covering unit/race, PostgreSQL, integration, remote signer, custom channels, generation, Docker and cross-compilation checks. Backward compatibility also passed.
  • CI checked out merge df3141a4d0742a151b0cc85e70e97990d320e4a7; its tree 65bdbe252305da307d0d1eef263fc81d117cead4 equals the local candidate tree. Upstream base and the original PR head were rechecked immediately before this fast-forward update.

Failure history: attempt 1 had one PostgreSQL integration partition fail during daemon startup near the harness's 10-second readiness deadline. The retained logs show incomplete migrations/connection closure and one node opening RPC just after the deadline. The failed-only retry passed on the identical source and binary artifacts, without timeout or workflow changes. The initial failure remains recorded on the rehearsal PR; the underlying resource/timing cause is not conclusively established.

The rehearsal retains its existing fork-only release-note metadata skip because its PR number differs from upstream #2238. The unchanged release-note script passed locally with GITHUB_REF=refs/pull/2238/merge. No workflow definitions or validation checks were weakened. Fork results do not replace upstream maintainer approval or official upstream checks. No force push or PR merge was performed.

@SadiqJaf

SadiqJaf commented Sep 9, 2026

Copy link
Copy Markdown
Author

Resolved the new merge conflict after upstream #2265 and fast-forwarded this PR to c78723d2fb6b89f4c1ca05542f7df2796d436725, incorporating upstream 7deef4bd8bf7ca8888f062c9cb05f03822f68931.

The conflict was two independent additions at the same position in tapdb/sqlc/queries/assets.sql. The merge retains both custom-anchor repair queries and upstream's orphan-UTXO candidate query, without changing either's SQL semantics. SQLC 1.29.0 regeneration reproduces the merged bindings exactly. Existing custom-anchor behavior, upstream orphan-validation regressions, and workflow definitions are preserved.

Validation before this update:

  • Full local tapdb and tapgarden suites passed (204.655s / 213.499s).
  • Race-enabled orphan-query and custom-anchor persistence regressions passed (27.411s).
  • SQL generation, formatting, diff checks and pinned golangci-lint v2.10.1 on tapdb passed (0 issues).
  • Fork CI passed on attempt 1: 40 successful jobs, including SQLite/PostgreSQL integration, remote signer, custom channels, coverage and race tests. No failed-job retries.
  • Backward compatibility passed.

The fork's existing release-note metadata job remains skipped because its PR number differs; the unchanged checker passed locally using GITHUB_REF=refs/pull/2238/merge. Redundant events from updating fork base/head, and this sync's separate fork-main run, were cancelled and are not counted as validation passes. Full rehearsal history is retained in fork PR #1.

The tested fork merge 190b3243f81c44258eb935fde561045e6f93da3e, the local candidate and this PR's current merge d20faac291516d68ee4660e4cc91d06d07f562ae all have tree 374dc5b26fe9f78baee0725f7a3c7bd864998acd. The SQLC CI checkout log confirms the fork merge revision. Upstream base/source refs were refreshed and checked immediately before the fast-forward update.

GitHub now reports this PR as conflict-free (MERGEABLE). Official upstream checks and maintainer requirements remain separate. No force push or PR merge was performed; Satscrip branches/worktrees were untouched.

@SadiqJaf

SadiqJaf commented Oct 1, 2026

Copy link
Copy Markdown
Author

Merged current upstream main (6709c118) into this branch (ed563e0f, fast-forward on top of b26b0bdf). The merge was clean, with no conflicts.

Verified: make unit passes, and so do the custom-genesis itests mint_custom_anchor_psbt and mint_custom_anchor_foreign_musig2_psbt.

Two caveats:

  1. Protobuf files were not regenerated (no Docker or protoc in the test environment). The mint generated files match the pre-merge commit; the other proto changes came in with upstream.
  2. In make itest-parallel, tranches 6 and 7 complete every case but then fail in miner-log teardown (open .../.tempminerlogs/regtest: no such file or directory). The same two reorg test pairs fail with the same error on plain upstream main, where they sit in tranches 4 and 5. This PR's two new itests shift the tranche numbering by 2, so the failure shows up in 6 and 7 here. It looks like an existing upstream teardown bug and not something this PR introduced.

cursoragent and others added 13 commits October 7, 2026 10:38
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

Copy link
Copy Markdown
Author

Converting this to draft for now. I'm reworking the caller-defined genesis anchor flow natively on the current mint flow (v0.8.5 caretaker) instead of rebasing this revision, since PrepareBatch no longer maps cleanly onto main. I'll either update this PR or open a replacement and link it here once the redesign is ready.

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

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

[feature]: Enhance caretaker w/ ability to set user-defined UTXOs and GenesisAmtSats values

2 participants