Skip to content

btcutil: vendor anet instead of depending on a personal fork - #2554

Open
Roasbeef wants to merge 1 commit into
masterfrom
vendor-anet
Open

btcutil: vendor anet instead of depending on a personal fork#2554
Roasbeef wants to merge 1 commit into
masterfrom
vendor-anet

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

In this PR, we vendor the Android networking shim that backs InterfaceAddrs on android into the btcutil module, so we no longer pull it from github.com/kcalvinalvin/anet. The shim exists to work around golang/go#40569, where net.InterfaceAddrs fails with route ip+net: netlinkrib: permission denied on Android 11 and later because of the tightened restrictions on NETLINK sockets. btcutil only ever calls anet.InterfaceAddrs, wired in from net_android.go under the android build tag.

The motivation here is dependency hygiene. The old import pointed at a fork hosted under an individual contributor's account, which isn't a home we want a release dependency to live in. By copying the source into btcutil/internal/anet we drop the external module entirely: the package is now unimportable from outside btcutil, and btcutil/go.mod no longer references the fork.

What's in the vendored copy

The source originates from github.com/wlynxg/anet, and its BSD 3-Clause LICENSE travels with it for attribution. The mobile/ demo subpackage from upstream is dropped since we don't need it.

One nice property of this particular fork: unlike upstream, it doesn't reach into the standard library's net package via //go:linkname. It carries its own ipv6ZoneCache instead, so there's no need for the -ldflags "-checklinkname=0" linker flag that upstream's README calls for on Go 1.23+. I swapped the upstream README for a short provenance note so that misleading build instruction doesn't linger.

Scope

The real change lives in the btcutil module, which is the only consumer of anet. The root and psbt modules still carry anet as a transitive // indirect requirement because they depend on the published btcutil/v2 v2.0.0 (there's no replace or go.work wiring them to the local tree). Those entries will fall away naturally on the next btcutil tag that ships this commit.

Verified that internal/anet and btcutil both build for GOOS=android GOARCH=arm64, the normal host build and go vet pass, and no kcalvinalvin references remain in the module.

In this commit, we vendor the Android networking shim that backs
InterfaceAddrs on android into the btcutil module, rather than
importing it from github.com/kcalvinalvin/anet. The shim works around
golang/go#40569, where net.InterfaceAddrs fails with
"route ip+net: netlinkrib: permission denied" on Android 11 and later
because of the tightened restrictions on NETLINK sockets. btcutil only
ever calls anet.InterfaceAddrs, wired in from net_android.go under the
android build tag.

The motivation is dependency hygiene. The previous import pointed at a
fork hosted under an individual contributor's account, which is not a
home we want a release dependency to live in. By copying the source
into internal/anet we drop the external module entirely: the package is
now unimportable from outside btcutil, and go.mod no longer references
the fork.

The source originates from github.com/wlynxg/anet, and its BSD 3-Clause
LICENSE travels with it. Unlike upstream, this copy does not reach into
the standard library's net package via //go:linkname; it carries its
own ipv6ZoneCache, so no -ldflags "-checklinkname=0" linker flag is
needed to build it. When golang/go#40569 is resolved upstream, both
this package and the net_android.go shim can be removed.
@Roasbeef
Roasbeef requested a review from kcalvinalvin June 18, 2026 23:07
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 27794794665

Coverage decreased (-0.004%) to 51.803%

Details

  • Coverage decreased (-0.004%) from the base build.
  • Patch coverage: 13 uncovered changes across 2 files (0 of 13 lines covered, 0.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
btcutil/internal/anet/interface.go 10 0 0.0%
btcutil/internal/anet/android_api_level.go 3 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 69639
Covered Lines: 36075
Line Coverage: 51.8%
Coverage Strength: 354221.38 hits per line

💛 - Coveralls

@allocz allocz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compared the diff against https://github.com/kcalvinalvin/anet, LGTM.

@kcalvinalvin kcalvinalvin 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.

LGTM ce4e0f5

Verified that the contents of anet/ are the same.

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