Skip to content

tapgarden: support caller-defined genesis anchor PSBTs (issue 721, rebased from upstream #2238) - #5

Open
SadiqJaf wants to merge 31 commits into
mainfrom
ta/721-custom-genesis-psbt-main
Open

SadiqJaf wants to merge 31 commits into
mainfrom
ta/721-custom-genesis-psbt-main

Conversation

@SadiqJaf

@SadiqJaf SadiqJaf commented Oct 4, 2026

Copy link
Copy Markdown

Rebase of lightninglabs#2238 onto current upstream main (85679bf). Tree matches lightninglabs#2238 head ed563e0 merged with main. Fork PR for Macroscope, Security Reviewer and CI before any upstream PR. Not for upstream until approved.

SadiqJaf and others added 24 commits October 4, 2026 14:22
Use MintingBatch.Copy to avoid copying atomic state, cover staging isolation and error paths, and wrap wallet-anchor lines to satisfy CI lint.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 4, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Manual reviews triggered for commit c41dbf2:

All prior checks · these links stay valid even if you push more commits.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go Resolved
@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR adds a substantial caller-defined anchor and external-signing workflow across minting, wallet leases, persistence, publication recovery, and public RPC/CLI interfaces. Its broad runtime side effects, combined with an unresolved high-severity risk that preparation may commit without producing the requested PSBT file, require human review.

Not approved because:

  • automatic approval is not enabled for this workspace
  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Enable approvability here. Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

assets mint fund ignored --no_change_output, --pre_commit_output_index,
and the other custom-anchor output indexes when --anchor_psbt was
omitted, then sent a normal wallet funding request. Reject that
combination in the CLI before the RPC call.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 4, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go Resolved
cursoragent and others added 2 commits October 4, 2026 18:22
assets mint fund treated a zero-length --anchor_psbt file as wallet
funding because os.ReadFile succeeds and FundBatch selects custom
mode only when anchor_psbt is non-empty. Reject that file before
the RPC call.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
assets mint finalize treated a zero-length --signed_psbt file as wallet
finalization because os.ReadFile succeeds and FinalizeBatch selects the
externally signed anchor only when signed_psbt is non-empty. Reject
that file before the RPC call.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 4, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go Resolved
assets mint prepare called PrepareBatch before writing --output_psbt.
An unwritable path left the custom batch committed and returned an
error without printing the response. Check that the path can be
written first, and print the response whenever PrepareBatch succeeds.

fund, seal, and finalize do not write an output file after their
RPCs. Proof export, ownership proofs, backup export, and macaroon
baking write after calls that can be repeated, so they are unchanged.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 4, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go Resolved
Comment thread cmd/commands/assets.go Resolved
assets mint fund and finalize read --anchor_psbt and --signed_psbt
with os.ReadFile, so a huge file or a device such as /dev/zero is
allocated before the server's 4 MiB check. Open the file, reject
non-regular files, and stop at that same limit.

assets mint prepare used os.WriteFile for --output_psbt, which
truncates an existing file before the packet is fully written. Write
a temp file in the destination directory, sync and close it, then
rename it over the target.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 5, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 5, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go Resolved
cursoragent and others added 2 commits October 5, 2026 07:48
--anchor_psbt alone sent ChangeOutputIndex 0 because the Int64 flag
defaults to 0. That collides with the default asset anchor output and
customGenesisPsbt rejects the batch. Copy the index only when the flag
is set, and otherwise mark the request as having no change output so
the server stores -1. An explicit 0 still selects output 0.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
TestPrepareBatchPreservesOutputOnWriteError re-execs with
RLIMIT_FSIZE. Under go test -cover the child still has that limit when
the coverage runtime writes its meta file, which fails with "file too
large". Drop GOCOVERDIR from the child and restore the soft limit
before the test returns.

Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
@SadiqJaf

SadiqJaf commented Oct 5, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 5, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

Comment thread cmd/commands/assets.go

case err == nil:
var f *os.File
f, err = os.OpenFile(path, os.O_WRONLY, 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High commands/assets.go:739

An existing writable --output_psbt can still make PrepareBatch commit successfully while the requested PSBT is never produced: writePreparedBatchPsbt needs to create and rename a sibling temporary file, but this branch only opens the target file. It also opens existing FIFOs, which can block indefinitely and cannot be written by the later rename. Probe create/rename access in the parent directory and reject existing non-regular paths before calling PrepareBatch.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @cmd/commands/assets.go around line 739:

An existing writable `--output_psbt` can still make `PrepareBatch` commit successfully while the requested PSBT is never produced: `writePreparedBatchPsbt` needs to create and rename a sibling temporary file, but this branch only opens the target file. It also opens existing FIFOs, which can block indefinitely and cannot be written by the later rename. Probe create/rename access in the parent directory and reject existing non-regular paths before calling `PrepareBatch`.

SadiqJaf commented Oct 7, 2026

Copy link
Copy Markdown
Author

@macroscope-app review this PR

@macroscopeapp

macroscopeapp Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review started; results will be posted as check runs.

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