Repository navigation
Conversation
Transfer proofs share a genesis with the mint but carry a later anchor transaction. upsertAssetGen wrote that transaction into genesis_points.anchor_tx_id for every proof type, so supply pre-commit resolution built commitment inputs against the transfer txid. Only anchor the genesis when the proof transaction spends the genesis outpoint. Migration 61 restores anchors from the chain transaction that spends each genesis outpoint, and abandons never-confirmed supply commitments that spend neither a real pre-commit nor a confirmed commitment outpoint so a restarted node can rebuild them. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
QuerySyncStats treated genesis_points.anchor_tx_id as always set. After transfer proofs stop retargeting that column, a genesis point can have no mint transaction yet, and the stats query returned "invalid hash length of 0". Leave the anchor outpoint empty until the mint transaction is known. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
The second transfer is the issuer's second outbound transfer and the recipient's second receive. The assertion asked for a single transfer and timed out. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
A confirmed commitment stays, and so does an unconfirmed commitment that spends a real pre-commit or a confirmed commitment outpoint. Only a commitment whose inputs match neither is abandoned. After that abandon, a restarted supply-commit manager rebuilds from the pending updates and broadcasts a commitment that spends the caller-selected pre-commit output. A custom-genesis mint at output index 1 is covered, including an anchor that a transfer had retargeted. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Sadiq Jaffer <SadiqJaf@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this exists
Draft in Satscryption/taproot-assets only. Nothing here is filed against lightninglabs/taproot-assets.
A transfer proof upsert retargets
genesis_points.anchor_tx_idfrom the mint transaction to the transfer transaction.FetchUnspentMintSupplyPreCommitsthen joins that column for the minting tx bytes while still usingmint_supply_pre_commits.tx_output_index.newRootCommitmentbuilds input 0 astransfer_txid:precommit_idxand signs it with the mint pre-commit key. Bitcoin Core rejects the Schnorr signature. The supply-commit state machine sits inCommitBroadcastState, later fetches return "no block info available", and later burns become dangling updates.Reproduced on v0.8.0, v0.8.5, and upstream main as of the lightninglabs#2331 head: mint with supply commitments, confirm, send,
UpdateSupplyCommit.This branch is layer 1, cut from stock v0.8.5 (
bb3f1c6b, tagv0.8.5). Head isac101ed0. Layer 2 is the lightninglabs#2331 clone (satscrip/supplycommit-burn-provenance, #12), based on this branch. Fork PR #10 (satscrip/v0.8.5-candidate, the 721 redesign) is planned as layer 3 on top of layer 2. This PR does not rebase or modify #9 or #10.Root cause
upsertAssetGen(tapdb/universe.go) runs for every proof type fromuniverseUpsertProofLeaf. It always callsAnchorGenesisPoint, an unconditionalUPDATE genesis_points SET anchor_tx_id. The schema comment ongenesis_pointssaysanchor_tx_idis the transaction that spendsprev_out, which is the mint, not a later transfer.The local mint path
CommitSignedGenesisTxsets the same column correctly.mint_supply_pre_commits.outpointandtx_output_indexare stored from the real mint tx at funding time and are not retargeted. Only the join key is wrong.Changing only the pre-commit query would leave the other readers of
genesis_points.anchor_tx_idpointed at the transfer:ConfirmChainTxstamps block info onto whateveranchor_tx_idpoints at. If a transfer retargets the pointer before the mint confirms, the mint tx never receives its block. The reported repro confirms first, soConfirmChainTxhas already written the mint row.genesis_info_viewexposesanchor_txidandblock_heightfor universe leaves, balances, and stats.FetchGenesisPointByAnchorTx.The guard is therefore on the write:
AnchorGenesisPointruns only when the proof's anchor transaction spendsasset.Genesis.FirstPrevOut. Transfer transactions are still stored withUpsertChainTx. Re-upserting the real issuance proof heals a pointer a transfer previously overwrote, because only the mint spends that outpoint.QuerySyncStatsparsedgenesis_info_view.anchor_txidwithchainhash.NewHashand failed withinvalid hash length of 0once that column could stay NULL.8f772951leavesAnchorPointempty until a 32-byte mint txid is stored. A present but wrong-length txid is still an error.Repair
Migration 61 (
000061_repair_genesis_anchor.up.sqlplusrepairGenesisAnchorMigration) is programmatic, same pattern as migrations 50 and 51.chain_txnsfor the transaction that spendsprev_out. One spender replaces a pointer that does not already spend the outpoint. Zero spenders (transfer arrived before the issuance tx was stored) leaves the pointer. Two or more spenders returns an error rather than guessing. An anchor that already spends the outpoint is a no-op, including a healthy custom-genesis mint.ConfirmChainTxwrote onto the wrong transaction before the mint confirmed is not moved. Confirm-then-send leaves the mint's ownchain_txnsrow with its block fields.CommitBroadcastStatecommitments whose inputs match none of the stored mint pre-commit outpoints, remote pre-commit outpoints, or confirmed supply-commitment outpoints are abandoned. The transition'snew_commitment_idandpending_commit_txn_idare cleared, the transition is unfrozen,spent_byforeign keys are cleared, thesupply_commitmentsrow is deleted, and the state machine returns toUpdatesPendingState. Supply update events are kept. A valid unconfirmed commitment spends a real pre-commit or prior commitment outpoint and is not abandoned, so it is not double-spent by a rebuild. If no known outpoints exist, nothing is abandoned. A confirmed commitment (block_hashset) is not in the candidate set, even if its input is unknown.startAssetSMcopies the transition's pending updates ontoUpdatesPendingStatewhen that state was loaded empty. The nextUpdateSupplyCommittick rebuilds the tree from those events and broadcasts a commitment that spends the caller-selected pre-commit. A validCommitBroadcastStateis not rehydrated into a second broadcast. Migration runs before RPC, so a restarted node sees the repaired database before the state machine starts. A process already stuck in memory still holds the rejected transaction until restart.Migration 61 does not stop a later unguarded upsert. The write guard is what keeps a transfer from retargeting the anchor after the migration has run.
Fork PR #9 and #10
Read-only. Neither branch is modified.
#9 (
ta/721-slim, custom genesis PSBT, issue 721) does not modifytapdb/universe.go,upsertAssetGen, or theAnchorGenesisPointSQL.CommitSignedGenesisTxis refactored intoCommitSignedGenesisTxWithKeyand still anchorsTxIn[0].PreviousOutPointwith the mint chain tx.assets.sqlchanges the internal-key upsert, notanchor_tx_id. The planter stores a caller-selectedPreCommitOutputIndexin the existingmint_supply_pre_commitsrow.anchoring_site.gowatches mint-tx input scripts viacustomAnchorInputPrevOut, notgenesis_points.anchor_tx_id. No conflict with the write guard. After this fix the pre-commit join still uses the mint tx bytes at that caller-selected index. Repair restores the tx that spends genesis input 0, which is the custom mint tx. A healthy custom-genesis anchor is a no-op.#10 (
satscrip/v0.8.5-candidate) addsFetchSupplySyncerPushedServersonBaseUniverseStoreand does not touchupsertAssetGenorAnchorGenesisPoint. It does not touchasset_minting.goorassets.sql.supply_commit.sqladdsQuerySupplyCommitmentByTxidandQuerySupplyCommitTransitionByNewCommitmentand does not change theFetchUnspentMintSupplyPreCommitsjoin. The caretaker confirmation watch usessignedTx.TxOut[anchorIdx].PkScriptinstead ofTxOut[0]. That is the asset-anchor output watch, notgenesis_points.anchor_tx_id.custom_anchor.goselects the caller pre-commit index on the mint tx. #10 also adds broadcast confirmation recovery (findCommitConfirmation/tryRecoverBroadcastConfirmation). A later textual merge can overlapuniverse/supplycommit/transitions.go,states.go,manager.go, andsupply_commit.sql. Behaviourally, their recovery finalizes aCommitBroadcasttx that actually confirmed. This migration abandons only a never-confirmed tx that does not spend a real pre-commit or prior-commitment outpoint. A valid custom-genesis commitment spendsmint_txid:caller_indexand is not abandoned. On a future merge, abandon invalid commitments first, then run their confirmation recovery for valid in-flight transactions. #10 is planned as layer 3 on top of #12. This PR does not rebase it.Tests
TestTransferProofKeepsCustomGenesisPreCommitupserts a mint tx with an extra input and a pre-commit at output index 1, then a transfer proof that spends a mint output. The genesis anchor andFetchUnspentMintSupplyPreCommitsmust still return that mint txid and index. That is the custom-genesis (lightninglabs#2238 / lightninglabs#721) shape. A full custom-genesis itest is not on this branch:FundBatch/PrepareBatch/FinalizeBatchare not on stock v0.8.5 and live on #9 / #10, which this branch does not depend on.TestRepairGenesisAnchorcovers restore, no-spender, and multiple-spenders.TestAbandonInvalidUnconfirmedSupplyCommitabandons a signed tx that misses the real pre-commit and keeps one that spends it, including the pending update. Those two cases were not weakened.TestMigration61CommitmentSafety(ac101ed0) adds three cases the abandon rule must not touch:CommitBroadcastcommitment, even when its input is an unknown outpointCommitBroadcastTestMigration61RebuildsValidCommitmentabandons a commitment whose input is neither a pre-commit nor a confirmed commitment outpoint, then starts the real supply-commit manager the way a restarted node does. The next tick rebuilds from the pending mint event and broadcasts a transaction that spends the caller-selected pre-commit at index 1. The stored chain tx matches the broadcast tx.TestHydrateInitialStatecovers the restart copy of pending updates.supply commit send before commitmints with supply commitments, sends to a second tapd before the firstUpdateSupplyCommit, syncs the transfer leaf in (SYNC_FULL, thenInsertProofif the sync did not land it), and asserts the confirmed commitment's input 0 ismint_txid:precommit_idx. It then reissues into the group, transfers again before the next commit, and asserts that commitment spends the new mint pre-commit and the previous commitment outpoint. The second send is the issuer's second outbound transfer and the recipient's second receive (edf285de).Verification
make unitthree times onac101ed0, with-test.count=1so the second and third runs re-execute (nocache=1). The first execution is the initialmake unit(PASS, no cached packages). Two later invocations in the same loop were cache hits and are not counted. No package failed, so nothing was classified againstbb3f1c6b.nocache=1)nocache=1)Integration, btcd, this branch's
tapd-itest(v0.8.5-4-gac101ed0).make itestwith the supply and universe cases. Go splits-test.runon a top-level|, so a first filter that listeduniverse_|supply_commit_|...ran only the universe alternative. That run is not the supply result. The re-run puts the alternation in parentheses:(^universe_|supply_commit_|supply_verify_peer_node|fetch_supply_leaves). Exit 0, 518.74s.The full
make itest-parallelsuite, including burn acceptance, is on #12 (a307dc0d). See that PR.Without the write guard,
TestTransferProofKeepsCustomGenesisPreCommitfails: expected anchor chain txn id 1, actual 2. The same tree's send-before-commit itest stops inUpdateAndMineSupplyCommitwithunable to find txns in mempool: wanted 1, found 0. lightninglabs#2331 does not changeupsertAssetGen. The anchor fix has to land first.Upstream-main variant
Prepared on the fork only, not pushed to lightninglabs/taproot-assets, and no upstream PR is open.
Branch
satscrip/supplycommit-anchor-fix-upstream-main, head8ae788eb, based on upstream main9db270f9(Merge pull request lightninglabs#2329). Main'sLatestMigrationVersionis 73, so the port is migration 74, which is after 72 and after the migration already on that main. Signing on main persists throughAnchoringWatcher.RegisterandApplyCommitTxStake; the rebuild test drives that stake against the harness queries.make unit nocache=1on the first port commit failed one expectation:TestSupplyCommitRestart/anchoring_updates_pending_starts_cyclestill expected the restart tick toFetchStatea second time.startAssetSMnow copies the parked updates ontoUpdatesPendingState, so the tick commits that in-memory batch.8ae788ebupdates that expectation. The test still requires the machine to reachCommitBroadcastStatewith the mint event. The follow-upmake unit nocache=1exited 0. No other package failed.Commits
Unsigned. This environment cannot produce a GPG signature (
commit.gpgsignis set; commits were created with--no-gpg-sign).Signed-off-by: Cursor Agent <cursoragent@cursor.com>.187fe043tapdb: keep the genesis anchor on the mint transaction8f772951tapdb: allow universe stats without a mint anchoredf285deitest: count both sends in supply commit send before commitac101ed0tapdb: prove migration 61 leaves valid commitmentsControl: lightninglabs#2331 alone, and stock without the fix
supply commit send before commitis a new test on this branch.git grepfortestSupplyCommitSendBeforeCommitonbb3f1c6bis empty. It was added in187fe043, andedf285desets the second send's transfer counts to1, 2, 2.Two throwaway branches were built locally to run it without the write guard. They are not pushed and have no pull request.
cursor/stock-send-before-commit-ad510ad85408bb3f1c6bplus only the new itestcursor/2331-alone-v085-ad519f72c9e5c21e3386,9a514248,38d7f763,19febe6c,d0c26945) plus the same itest.anchorSpendsGenesisis absenttapd-itestfor the lightninglabs#2331-alone run embedsv0.8.5-6-g9f72c9e5. Cases ran serially withmake itest-only.0ad85408)9f72c9e5)supply_commit_send_before_commitac101ed0) 77.46s. #12 (a307dc0d) includes that fix;make itest-parallelthere exited 0, 117/117supply_commit_mint_burnsupply_commit_ignore_assetBoth send-before-commit failures happen after the send itself succeeds. The harness then looks for the commitment in the mempool and finds nothing, because Bitcoin Core rejected it.
Stock (
0ad85408),itest/utils.go:Stock btcd,
output_btcd_chainbackend.log. Commitment input 0 spends the transfer at the pre-commit index:Stock lnd Alice:
lightninglabs#2331 alone (
9f72c9e5) is the same failure. Serial harness:The following case cleared
itest/regtest, so the Core and lnd lines below are from an immediate rerun of the same commit. That rerun failed the same way (73.27s). btcd:f818ead5was accepted as a witness transaction (2 inputs, 3 outputs) and mined, and the commitment spends output 1 of it:lnd Alice on that tree:
The prevout script on that rejection is
51206dd5210dbecf8c8c0c056b54abb07cc75f14657778a904ce594c5308b2c38847. The commitment witness does not satisfy it. Input 0 istransfer_txid:1becauseupsertAssetGenstill retargetsgenesis_points.anchor_tx_idonto the transfer. lightninglabs#2331 does not change that write, so send-before-commit still blocks when lightninglabs#2331 sits on stock v0.8.5. It passes once the anchor fix is underneath, which is the #12 stack.B1 tapd on #12
Build from
satscrip/supplycommit-burn-provenanceata307dc0de1fe04fbdfa213af62d516a8ae074898(v0.8.5-9-ga307dc0d).make buildtapd-debugsha256e23ca4d86c92709e9e98ae9e72a504f9bdacb6320b117e5798762030fa14aeef. The itesttapd-itestthat passed the 117-case suite is the same commit, sha256bd952fc5d54525449b05e978edcdfc2a4a6c3d43e57126d48f3084afb96fd626.