Skip to content

multi: migrate to btcd v2 modules - #1199

Draft
starius wants to merge 8 commits into
lightninglabs:masterfrom
starius:btcd-v2
Draft

starius wants to merge 8 commits into
lightninglabs:masterfrom
starius:btcd-v2

Conversation

@starius

@starius starius commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

multi: migrate to btcd v2 modules

Migrate Loop to the btcd v2 modules, rebased onto the current master (Go 1.27.3). Exported Bitcoin address, transaction, hash, script, and chain types now use the corresponding v2 packages. Preserve the current swap-fee, withdrawal, and minimum-runtime-lnd behavior while updating the dependency graph.

Use released lndclient v0.21.0-3, the v2-compatible lnd and Aperture revisions, and the matching wallet and chain modules. Keep Taproot Assets on the fixed v0.8.6 code with a v2 compatibility migration rather than switching to main's different API and incomplete v0.8.6 fix set.

Use lnd revision f2963ce1fd19, which contains the released v0.21.4 forwarding-response recovery and replay fixes, rather than the older v2 snapshot. Align the SQL, queue, and result-helper modules with that revision.

The rebase also migrates the code master added since the previous revision: blinded loop-out invoices, static loop-in store tests, withdrawal and deposit hold tests, PostgreSQL pool tests, and sweep batcher retry tests. The previous CI run failed because two of those tests still called btcutil.DecodeAddress; they now use address/v2. Master already requires Go 1.27.3, so this PR no longer changes the Go version.

The v2 address decoder also accepts pay-to-anchor addresses, which anyone can spend; the old decoder rejected them. Loop Out already limited destinations to P2PKH, P2SH, P2WPKH, P2WSH and P2TR, but Instant Out and the autoloop destination relied on the decoder. The first commit moves the Loop Out check into a shared helper and applies it to both, before the migration, so that no commit accepts such a destination. Instant Out now also rejects raw public keys, as Loop Out does. Static address withdrawals and manual HTLC sweeps already rejected these types when estimating the transaction weight.

The next two commits fix destination bugs that master also has. loopd decoded the autoloop destination without chain parameters, so setting it to a P2PKH or P2SH address or a raw public key crashed the daemon; the address is now decoded for the active network. Autoloop, Instant Out, static address withdrawals and manual HTLC sweeps also accepted addresses of other networks, which Loop Out rejects; they now reject them too. If the saved autoloop destination belongs to another network, loopd removes it at startup instead of failing to start. Both commits come before the migration and apply to master unchanged.

Module checks honor the configured Go proxy to avoid Git cache fetch races, while retaining all four tidy checks and the failure on a modified working tree.

Companion migrations

  • Taproot Assets #2366, targeting v0.8: preserves the release fixes, migrates the patched TLV module, and recognizes pgx v5 serialization conflicts so PostgreSQL transactions retry correctly. Loop depends on this migration. Still open.
  • Pool #524: v2 types, regenerated mocks, and the lnd runtime floor required by L402 payments. Merged.
  • Faraday #255: v2 types and matching build dependencies. Merged.
  • Lightning Terminal #1438: integrates all four upgraded subservers. Loop's compatibility jobs select an immutable revision of this branch and replace Loop plus both RPC modules with the current checkout. Still open. With Go 1.27.3 its unit job also needs LiT master's b660f02 ("db: declare mapped SQL errors on the pointer receiver"); the pinned revision predates it.

Temporary fork replacements pin immutable source revisions. Before release, replace these with accepted upstream revisions or tags. Review and land Taproot Assets first; then Loop and its RPC modules; then LiT. Tagged shared dependencies and subservers can be adopted at each stage.

Replace directives apply only in the main module. Until lnd and Taproot Assets publish btcd v2 versions, modules that import Loop's root module must mirror its lnd, sqldb and Taproot Assets replacements, as LiT #1438 does. Without the lnd and Taproot Assets replacements the build fails, because their released versions import btcd packages that btcd v0.26.0 no longer contains. The lnd revision cannot be required directly, because its pseudo-version sorts below the v0.21.3-beta release. looprpc and swapserverrpc are unchanged and keep their current dependencies.

Validation

  • Loop, rebased onto master f3fa5ea: SQLite race suite and PostgreSQL race suite (make unit-race, make unit-postgres-race, all packages); go vet ./...; golangci-lint v2.15.0 with the repository configuration (0 issues); tidy checks for all four modules; make build tags=dev; make rpc-js-compile; generated CLI docs check; commit message lint; release note check. Each commit with Go changes builds and vets on its own. The destination tests fail when the shared type or network check accepts every address, when the autoloop destination is decoded without chain parameters, and when a saved destination of another network is not removed at startup. rpc-check and sqlc-check were not rerun, since this PR does not change protos or SQL. In the SQLite race suite, TestSweepBatcherCloseDuringAdding sometimes exceeds its 5 s test guard; it does the same on master, and the rest of sweepbatcher passes.
  • LiT: lightning-terminal#1438 at 0203039, plus b660f02 from LiT master, with Loop and both RPC modules replaced by this branch. The build with LiT's compile tags and make unit pass. Without b660f02, the session package fails vet under Go 1.27.3. The LiT itests were not rerun locally.
  • Taproot Assets: full unit suite, patched TLV race tests, PostgreSQL conflict regression, and repeated cache-deadline/driver-error checks.
  • Pool and Faraday: unit race suites and their CI checks.

Keep this draft while the coordinated dependency migrations are reviewed and the temporary pins are replaced. The btcd v2 import changes affect Go callers; the runtime lnd minimum remains v0.19.0-beta, based on the actual RPC behavior Loop requires.

Pull Request Checklist

  • Add an entry to docs/release-notes/release-notes-next.md, or apply the no-changelog label.

@levmi levmi assigned levmi and starius and unassigned levmi Aug 13, 2026
@hieblmi
hieblmi self-requested a review August 14, 2026 05:59

@hieblmi hieblmi left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Taproot Assets compatibility

Please bump github.com/lightninglabs/taproot-assets to v0.8.1. This PR already handles its updated rfqmath.UnitsToMilliSatoshi signature, and the bump keeps Loop compatible with litd versions using tapd v0.8.1.

Since v0.8.1 still uses the legacy btcd packages, Loop needs the temporary btcd-v2 replacement. Go does not propagate replace directives to downstream modules, so LiT needs the same replacement until a btcd-v2-compatible Taproot Assets release is available. Please re-run the LiT compatibility jobs with that setup.

@hieblmi
hieblmi self-requested a review October 21, 2026 11:05
@Roasbeef Roasbeef self-assigned this Oct 21, 2026
hieblmi added a commit to hieblmi/loop that referenced this pull request Oct 22, 2026
Port the coordinated source migration from Loop lightninglabs#1199 while keeping
Go 1.27.3 and the existing runtime lnd floor. Pin current lnd master
and matching submodules, tapd v0.8.6's v2 compatibility revision,
and the SDK fixes for proof selection, signing, and activation APIs.

Propagate immutable replacements into LoopRPC and LiT compatibility
builds because dependency replacements are not inherited.

Co-authored-by: Boris Nagaev <bnagaev@gmail.com>
hieblmi added a commit to hieblmi/loop that referenced this pull request Oct 23, 2026
Port the coordinated source migration from Loop lightninglabs#1199 while keeping
Go 1.27.3 and the existing runtime lnd floor. Pin current lnd master
and matching submodules, tapd v0.8.6's v2 compatibility revision,
and the SDK fixes for proof selection, signing, and activation APIs.

Propagate immutable replacements into LoopRPC and LiT compatibility
builds because dependency replacements are not inherited.

Co-authored-by: Boris Nagaev <bnagaev@gmail.com>
hieblmi added a commit to hieblmi/loop that referenced this pull request Oct 23, 2026
Port the coordinated source migration from Loop lightninglabs#1199 while keeping
Go 1.27.3 and the existing runtime lnd floor. Pin current lnd master
and matching submodules, tapd v0.8.6's v2 compatibility revision,
and the SDK fixes for proof selection, signing, and activation APIs.

Propagate immutable replacements into LoopRPC and LiT compatibility
builds because dependency replacements are not inherited.

Co-authored-by: Boris Nagaev <bnagaev@gmail.com>
hieblmi added a commit to hieblmi/loop that referenced this pull request Oct 26, 2026
Port the coordinated source migration from Loop lightninglabs#1199 while keeping
Go 1.27.3 and the existing runtime lnd floor. Pin current lnd master
and matching submodules, tapd v0.8.6's v2 compatibility revision,
and the SDK fixes for proof selection, signing, and activation APIs.

Propagate immutable replacements into LoopRPC and LiT compatibility
builds because dependency replacements are not inherited.

Co-authored-by: Boris Nagaev <bnagaev@gmail.com>
starius and others added 8 commits November 8, 2026 05:35
Loop Out accepts only P2PKH, P2SH, P2WPKH, P2WSH and P2TR destination
addresses. Instant Out and the autoloop destination accepted any type
that the address decoder returns, which for Instant Out included raw
public keys. The btcd v2 address package also decodes pay-to-anchor
addresses, which anyone can spend.

Move the Loop Out check into utils.IsSupportedDestAddr. Apply it to
Instant Out before the swap starts and to the autoloop parameters when
they are validated, so that a decoder change can't widen the accepted
destination types.
RpcToParameters decoded the autoloop destination address with nil chain
parameters. For P2PKH and P2SH addresses and raw public keys, the
decoder dereferences the parameters, so a SetLiquidityParams call with
such an address panicked. loopd does not recover from panics in RPC
handlers, so the daemon crashed.

Pass the chain parameters of the active network to RpcToParameters and
decode the address with them. A raw public key now decodes and fails
the destination type check.
Loop Out rejects a destination address that does not belong to the
active network. Autoloop, Instant Out, static address withdrawals and
manual HTLC sweeps did not. The decoder accepts bech32 addresses of all
known networks, and their output scripts don't depend on the network,
so these paths paid to the same witness program on the active network.

Add utils.CheckAddrNetwork and call it after each of these decodes.
Earlier versions saved the autoloop destination without the check. If
the saved destination belongs to another network, loopd removes it at
startup and autoloop pays to wallet addresses, because failing to start
would leave no way to change the parameters.
Update LND, Aperture, and Taproot Assets to revisions using the
btcd v2 modules, and update lndclient to v0.21.0-3. Migrate Loop
chain, transaction, and address types to their corresponding v2
packages.

The lndclient release includes the migration from:
lightninglabs/lndclient#280

Taproot Assets is temporarily replaced with its btcd v2 revision
because the v0.8 release branch has not adopted the new modules.

The v2 address decoder also accepts pay-to-anchor addresses. The
destination type checks reject them, and tests now cover this case.

This changes exported address types.
Use Go's normal module proxy configuration for all four tidy checks.
This avoids concurrent direct VCS fetch failures in CI and removes the
redundant selective prefetch. Keep checksum verification and the final
working-tree consistency check.
@starius

starius commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

Taproot Assets compatibility

Please bump github.com/lightninglabs/taproot-assets to v0.8.1. This PR already handles its updated rfqmath.UnitsToMilliSatoshi signature, and the bump keeps Loop compatible with litd versions using tapd v0.8.1.

Since v0.8.1 still uses the legacy btcd packages, Loop needs the temporary btcd-v2 replacement. Go does not propagate replace directives to downstream modules, so LiT needs the same replacement until a btcd-v2-compatible Taproot Assets release is available. Please re-run the LiT compatibility jobs with that setup.

This was addressed in the October 21 revision, with v0.8.6 in place of v0.8.1. Loop requires taproot-assets v0.8.6, which keeps the RFQ and proof fixes released after v0.8.1. It replaces that version with the btcd v2 migration of v0.8.6 from lightninglabs/taproot-assets#2366. lightninglabs/lightning-terminal#1438 carries the same replacement, and Loop's LiT unit and itest jobs run against a pinned revision of that branch.


I rebased the PR onto current master (Go 1.27.3) and migrated the code master added since then. That code includes the two btcutil.DecodeAddress tests that failed the last CI run.

The rebase also adds a commit before the migration. address/v2 decodes pay-to-anchor addresses, which anyone can spend, and Instant Out and the autoloop destination would have accepted them. Both now use the destination type check that Loop Out already had. Two more commits fix destination bugs that master also has: setting the autoloop destination to a P2PKH or P2SH address crashed loopd, and autoloop, Instant Out, static address withdrawals and manual HTLC sweeps accepted addresses of other networks. This was factored out to #1280

Go 1.27.3 now flags session/sql_store.go in the LiT unit job, because the LiT #1438 branch predates b660f02 ("db: declare mapped SQL errors on the pointer receiver") from LiT master. With that commit cherry-picked onto LiT #1438, LiT builds and its unit tests compile against this branch. Could you add it to LiT #1438 so I can bump LITD_ITEST_BRANCH?

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.

4 participants