Skip to content

multi: make anchor tx version configurable and validate v3 with bitcoind#1857

Draft
bhandras wants to merge 7 commits intolightninglabs:mainfrom
bhandras:v3-temp
Draft

multi: make anchor tx version configurable and validate v3 with bitcoind#1857
bhandras wants to merge 7 commits intolightninglabs:mainfrom
bhandras:v3-temp

Conversation

@bhandras
Copy link
Member

@bhandras bhandras commented Oct 24, 2025

Summary

This PR changes anchor transaction version handling from a blanket default to explicit configuration on the flows that actually create anchor transactions.

The daemon still defaults to v2. Callers can now explicitly request v3 for newly created anchor transactions in the minting, send, supply-commit, and PSBT anchoring paths.

What Changed

  • Add anchor transaction version plumbing in tapsend, tapgarden, tapfreighter, and universe/supplycommit, while keeping v2 as the default.
  • Expose the anchor transaction version on the RPCs that construct anchor transactions and regenerate the protobuf artifacts and related test vectors.
  • Bump lnd to the latest master and update the itest harnesses and helpers to the current lntest miner APIs.
  • Use the new bitcoind miner support in the integration harnesses, install bitcoind in CI, and add a dedicated bitcoind-backed itest-v3 target and workflow job.
  • Add end-to-end v3 anchor coverage that verifies the mined Bitcoin transactions are actually version 3 on chain.
  • Update the mock gRPC TLS helpers to advertise h2 so the courier-related tests keep passing with the newer gRPC stack pulled in by the lnd bump.

Why

  • Keep the existing behavior stable by leaving v2 as the default anchor transaction version.
  • Make v3 available only where new anchor transactions are actually constructed.
  • Validate the v3 path against a bitcoind-backed integration lane instead of only relying on unit-level coverage.

Testing

  • go test ./itest/...
  • make itest-v3
  • go test ./proof ./tapchannel
  • go test ./...

@gemini-code-assist
Copy link

Summary of Changes

Hello @bhandras, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request systematically updates the default Bitcoin transaction version to 3 (TRUC) across various components of the system. This foundational change is implemented to leverage the improved security features of BIP 431, such as enhanced fee-bumping and pinning protection, which are critical for the robustness of Taproot Assets. The update is accompanied by comprehensive testing to confirm the new version's adoption and ensure seamless integration with existing data.

Highlights

  • Transaction Version Upgrade: All newly created Bitcoin transactions within the codebase are now initialized as version 3, moving from previous versions (primarily version 2, with one instance from version 1). This change aligns with BIP 431 (TRUC) to enhance fee-bumping and pinning protection, particularly beneficial for Taproot Assets anchor transactions.
  • New Test Cases for Version 3 Transactions: New tests have been introduced to explicitly verify that newly created transactions are indeed version 3. Additionally, backward compatibility tests ensure that the v3-enabled codebase can correctly load and verify existing proofs that were generated using version 2 transactions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly updates the Bitcoin transaction version from 2 to 3 across the codebase, aligning with BIP 431 for TRUC transactions. The change is consistently applied, and the inclusion of new tests to verify the transaction version and ensure backward compatibility with v2 proofs is a great addition. My review includes a couple of suggestions to improve code clarity and maintainability.

proof := proofs[0]

require.Equal(t, int32(3), proof.AnchorTx.Version,
"Post-commit b3562461: all new transactions should be v3")

Choose a reason for hiding this comment

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

medium

It's great that you've included a commit hash in this assertion message. However, it might be even more helpful to also include a reference to the BIP (BIP 431) that introduces v3 transactions. This would provide more context for future developers.

tapsend/send.go Outdated
}

txTemplate := wire.NewMsgTx(2)
// TODO(bhandras)

Choose a reason for hiding this comment

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

medium

This TODO was added without any context. Could you please clarify what this refers to or remove it if it's not needed?

tapsend/send.go Outdated

txTemplate := wire.NewMsgTx(2)
// TODO(bhandras)
txTemplate := wire.NewMsgTx(3)

Choose a reason for hiding this comment

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

medium

To improve maintainability and avoid the use of magic numbers, it would be beneficial to define a constant for the new transaction version, for example const BitcoinTxVersion3 = 3. This constant could then be used here and in all other places in this PR where the transaction version is set to 3.

Suggested change
txTemplate := wire.NewMsgTx(3)
txTemplate := wire.NewMsgTx(BitcoinTxVersion3)

@coveralls
Copy link

coveralls commented Oct 24, 2025

Pull Request Test Coverage Report for Build 19974072375

Details

  • 6 of 9 (66.67%) changed or added relevant lines in 8 files are covered.
  • 28288 unchanged lines in 197 files lost coverage.
  • Overall coverage decreased (-21.8%) to 34.774%

Changes Missing Coverage Covered Lines Changed/Added Lines %
itest/utils.go 0 1 0.0%
tapchannel/commitment.go 0 1 0.0%
tapgarden/mock.go 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
universe/supplyverifier/util.go 1 98.75%
proof/util.go 2 81.63%
tapdb/cache_logger.go 2 94.44%
tapdb/migrations.go 2 76.19%
address/log.go 3 0.0%
commitment/log.go 3 0.0%
internal/pedersen/commitment.go 3 95.31%
lndservices/log.go 3 0.0%
rfq/log.go 3 0.0%
tapchannel/log.go 3 0.0%
Totals Coverage Status
Change from base Build 19960793390: -21.8%
Covered Lines: 31173
Relevant Lines: 89645

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

It'll be a larger change, but rather than may all transactions 3 by default, I think we should expose this on the internal API and also the gRPC level. Until a few months ago, v3 transactions were actually non standard. We want to ensure that our transactions propagate as widely as possible. v3 transactions also opt into new rules which may not always apply in our context.

One good way to this would be to use a functional option for relevant APIs.

@lightninglabs-deploy
Copy link

@bhandras, remember to re-request review from reviewers when ready

@bhandras bhandras marked this pull request as draft March 24, 2026 13:54
@bhandras
Copy link
Member Author

Picking this up again now that lntest supports bitcoind miner.

@bhandras bhandras force-pushed the v3-temp branch 2 times, most recently from b64b41c to c0df0e5 Compare March 24, 2026 15:17
@bhandras bhandras changed the title multi: make all new txes v3 multi: make anchor tx version configurable and validate v3 with bitcoind Mar 24, 2026
@github-project-automation github-project-automation bot moved this from 🆕 New to 👀 In review in Taproot-Assets Project Board Mar 24, 2026
@bhandras bhandras force-pushed the v3-temp branch 7 times, most recently from f38ffdd to b7e498e Compare March 24, 2026 19:19
Update the integration harnesses to the current lnd miner APIs and the
dependency snapshot they require.

- Bump lnd to the latest master snapshot and refresh the dependent
  module graph.
- Replace direct btcd RPC miner usage in the itest harnesses with
  lntest miner helpers.
- Adjust the broad integration test suite and helper code to the new
  miner interfaces.
- Fix the mock gRPC TLS helpers to advertise h2 so courier tests keep
  passing with the newer gRPC stack.
- Keep these changes focused on the harness migration and compatibility
  fallout, leaving the dedicated v3 coverage for a follow-up commit.
Separate the unrelated integration test stabilizations from the harness
migration so the miner API update stays easier to review.

- Wait for canceled custom-channel hodl payments to leave the in-flight
  state before probing the route with a follow-up payment.
- Wait for supply-commit updates to actually reach the mempool before
  mining the follow-on commitment transaction.
- Relax the proof-transfer transfer-list assertions to rely on the
  confirmation height hint instead of the lagging block hash field.
- Keep the coverage focused on existing flaky paths that showed up in
  CI, without changing the anchor-version behavior under test.
- Wait for the shared MultiSubscription to report active subscriptions
  again after the mock server restarts before publishing msg2.
- The test already waited for the two direct clients, but not for the
  multi-subscription, which left a race where the post-restart message
  could be published before that consumer had reconnected.
- Because this subscription uses an empty filter, a missed publish is
  not recovered from backlog delivery and the test times out on
  readMultiSub.
- Keep the fix test-only so mailbox runtime behavior is unchanged.
- This makes TestServerClientAuthAndRestart pass reliably under race
  runs and matches the failure seen in CI shard 0.
Add the RPC surface for choosing the version of newly created anchor
transactions.

- Add the shared AnchorTxVersion enum to the common proto definitions.
- Thread the enum into the mint, send, and
  anchor-virtual-PSBT requests.
- Regenerate the protobuf and swagger artifacts for the updated schemas.
- Parse the requested version in the RPC server and map unspecified to
  the daemon default.
- Leave CommitVirtualPsbts unchanged because callers already control the
  anchor PSBT they submit.
Thread the selected anchor transaction version through the code paths
that actually construct new Bitcoin anchor transactions.

- Add a small tapsend option layer with a default of v2 and explicit v3
  support.
- Pass the selected version through send, mint, and supply-commit
  flows instead of changing every transaction template in the codebase.
- Keep virtual transactions pinned to v2 because existing witness
  signatures depend on that version.
- Carry the selected version through the supply-commit state machine
  while keeping persisted mint events backward compatible.
- Set the daemon-side default for new supply-commit transactions to the
  standard anchor transaction default.
Cover the restored default-v2 behavior and the explicit-v3 paths with
focused unit and subsystem tests.

- Assert that the default proof and anchor construction paths still
  create v2 anchor transactions.
- Add direct tapsend coverage for selecting the anchor transaction
  version.
- Update supply-commit test fixtures to use v3 where the new explicit
  version is exercised.
- Extend the supply-commit manager mock expectations to include the
  propagated anchor transaction version.
- Keep the existing proof compatibility check in place for older v2
  proof files.
Add a dedicated bitcoind-backed integration lane for the explicit v3
anchor transaction paths.

- Add an end-to-end itest that mints, sends, and anchors PSBT
  transfers with v3 anchor transactions.
- Add the helper assertions and mint options needed to request and
  verify v3 anchors in the test harness.
- Register the new case in the itest list and add an itest-v3 make
  target.
- Install bitcoind in CI and add a dedicated workflow job for the v3
  lane.
- Keep the existing broader integration suite unchanged while giving
  the v3 path its own focused coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

4 participants