Commit graph

4437 commits

Author SHA1 Message Date
Oliver Gugger
039baa2520 wire: make own module, use v2 2026-05-14 17:56:18 -07:00
Oliver Gugger
bf8006d8e7 btcec: use new chainhash/v2 module 2026-05-14 17:56:18 -07:00
Oliver Gugger
28c77e7dcf chainhash: move to top-level module, use v2 2026-05-14 17:54:44 -07:00
Olaoluwa Osuntokun
44d51eb043
Merge pull request #2531 from Roasbeef/release-prep-bump-modules
multi: bump in-tree go.mod files to new submodule tags
2026-05-14 17:44:43 -07:00
Olaoluwa Osuntokun
62cc0a6b77 multi: appease go 1.26 vet for non-const format + goroutine Fatalf
In this commit, we fix two go vet errors that go 1.26 now treats as
hard failures during test compilation.

In btcjson/help.go, the final result row of a complex help description
was emitted via fmt.Fprintf with a non-constant format string (the
result text could contain '%' chars). Switch to fmt.Fprint, since
there are no format args here anyway.

In btcec/schnorr/musig2/musig2_test.go, the nonce-registration loop
ran inside a goroutine and called t.Fatalf on failure. Fatalf only
exits the calling goroutine, so the test goroutine would keep running
with stale state. Use t.Errorf + return so the failure is recorded
correctly and the goroutine exits cleanly.
2026-05-14 17:36:51 -07:00
Olaoluwa Osuntokun
1863073cb0 multi: bump Go toolchain to 1.25, build CI with 1.26.3
In this commit, we update every in-tree go.mod to declare go 1.25 and
have CI build with 1.26.3 (Dockerfile uses the golang:1.26-alpine base).
Docs that mention the minimum required Go version are aligned with the
new floor as well.

Fixes #2527, which flagged the README.md / go.mod version mismatch (the
README claimed 1.22 while the root + v2transport go.mod files already
required 1.23.2).
2026-05-14 17:32:02 -07:00
Olaoluwa Osuntokun
e59dfeb949 multi: bump in-tree go.mod files to newly tagged submodule versions
In this commit, we pin every in-tree go.mod to the freshly cut submodule
tags ahead of a btcd point release: btcec/v2.4.0, btcutil/v1.2.0,
btcutil/psbt/v1.2.0, and chaincfg/chainhash/v1.2.0. The btcec bump also
drags secp256k1 up to v4.4.0 (and blake256 to v1.1.0 transitively) for
every module that imports btcec.

v2transport stays at v1.0.1 since no v2transport code changed since the
last tag, but its go.mod is bumped here so the workspace resolves to a
consistent set of internal deps.
2026-05-14 17:02:20 -07:00
Olaoluwa Osuntokun
90540b821e
Merge pull request #2524 from MPins/verifylows
Add VerifyLowS helper function to ECDSA signature
2026-05-14 16:47:38 -07:00
Olaoluwa Osuntokun
c728090e63
Merge pull request #2461 from kcalvinalvin/2025-11-12-fix-android-builds
btcutil, main: fix android builds
2026-05-14 16:31:35 -07:00
Olaoluwa Osuntokun
2c05692401 github: cross-compile android/arm64 in CI
Add a build step to the existing Build job that cross-compiles both the
top-level module and btcutil for GOOS=android GOARCH=arm64.

This catches regressions in the android-specific build path (e.g. the
net_android.go wrapper around anet.InterfaceAddrs) without needing an
emulator or NDK toolchain - android/arm64 builds without cgo.
2026-05-14 16:22:50 -07:00
Olaoluwa Osuntokun
73af4d6f88 btcutil: rename interfaceAddrs to InterfaceAddrs in appengine variant
The previous commit exported the interfaceAddrs helper in net.go but
missed the parallel definition in net_noop.go (build tag: appengine),
which left builds with -tags appengine broken with:

    ./certgen.go:79:16: undefined: InterfaceAddrs

Rename the appengine no-op variant to match, restoring the appengine
build.
2026-05-14 16:22:44 -07:00
Olaoluwa Osuntokun
8bffc8ada8
Merge pull request #2526 from JLSchuler99/rpcclient-httpurl-no-resolve
rpcclient: compute httpURL once at construction time
2026-05-14 16:18:57 -07:00
Calvin Kim
589d7c0ae0 main: use btcutil.InterfaceAddr
We use this as the net.InterfaceAddr is broken from android 11.
2026-05-14 16:16:14 -07:00
Calvin Kim
0f603feffa main: update go.mod and go.sum
We update go.mod and go.sum to point to the local btcutil library.

This commit should be updated later on so that we do it right.
2026-05-14 16:16:14 -07:00
Calvin Kim
c90e88ee23 btcutil: export interfaceAddr 2026-05-14 16:16:14 -07:00
Calvin Kim
153bf6d828 btcutil: use anet instead of net for android builds
Golang's net package has been broken for android since android 11
and the node will not be able to call net.InterfaceAddr() without
root.

For android builds, we use anet so that the btcd node can be used
without root.
2026-05-14 16:16:14 -07:00
Jacob Schuler
807cbce3bf rpcclient: compute httpURL once at construction time
httpURL was being recomputed on every JSON-RPC POST. It went through
ParseAddressString to discriminate Unix sockets from TCP, which
called net.ResolveTCPAddr and triggered a DNS lookup whose result
was thrown away.

Both inputs (config.Host and config.DisableTLS) are immutable after
New, so the URL is constant for the life of the Client. Compute it
once and store it on the Client, mirroring the parsedDialAddr cache
already in newHTTPClient.

The httpURL method now uses HasPrefix and runs exactly once per
Client. Drop its (string, error) signature — with the resolve gone
nothing can fail. Add table coverage for the URL strings, plus a
wiring test that catches refactors of New silently dropping the
assignment to Client.httpURL.
2026-05-14 16:04:31 -07:00
Olaoluwa Osuntokun
56613bb876
Merge pull request #2480 from Aharonee/bugfix/peer_race_condition
server: fix peer add/done race between peerHandler and syncManager
2026-05-14 15:59:07 -07:00
Olaoluwa Osuntokun
f2a24d41d1 server: document peerLifecycle channel buffer sizing
The peerLifecycle channel is sized cfg.MaxPeers*2 because each
peer can emit two lifecycle events (peerAdd followed by peerDone).
Without an inline comment a future reader could "simplify" the
factor to cfg.MaxPeers and tighten back-pressure under normal
connect/disconnect churn, causing peerLifecycleHandler goroutines
to block.
2026-05-12 16:20:56 -07:00
Olaoluwa Osuntokun
e6f589e515 server: gate handleDonePeerMsg on peerAdded, not VerAckReceived
peer.processRemoteVerAckMsg sets verAckReceived=true *before* it
invokes the OnVerAck listener that closes verAckCh. If the peer
disconnects in that window, the peerLifecycleHandler select may
pick Peer.Done() over verAckCh and skip the peerAdd send -- yet
VerAckReceived() still returns true. handleDonePeerMsg would then
call syncManager.DonePeer for a peer that was never NewPeer'd
(sync manager logs a warning and discards).

Add an explicit peerAdded atomic.Bool on serverPeer. Set it in
peerLifecycleHandler after peerAdd has been enqueued. Gate the
syncManager.DonePeer + orphan eviction in handleDonePeerMsg on
peerAdded.Load() so those side effects only fire for peers that
were actually registered.

This tightens the "peerAdd precedes peerDone, or peerAdd is
skipped entirely" invariant from this PR into something explicit
rather than something derived from a flag that races OnVerAck.
2026-05-12 16:20:43 -07:00
Olaoluwa Osuntokun
f1b95f8fd9 server: guard OnVerAck with sync.Once
The prior select/default+close() guard on verAckCh is correct only
under the invariant that OnVerAck is invoked from a single goroutine
(peer.processRemoteVerAckMsg on the input handler). The two steps
are not atomic: any future change that invokes listeners off the
input goroutine would let two concurrent callers both observe
default and panic on double-close.

Replace the guard with sync.Once. This makes the close-once
contract obviously correct rather than correct-by-distant-invariant
and drops the dead "called more than once" log path.
2026-05-12 16:20:15 -07:00
Olaoluwa Osuntokun
aacc9882ca
Merge pull request #2491 from btcsuite/block-fix
wire: reject messages with unconsumed trailing payload bytes
2026-05-12 15:04:56 -07:00
Olaoluwa Osuntokun
d12d39dae1
Merge pull request #2433 from Roasbeef/p2a
multi: recognize new standard P2A output type
2026-05-12 15:04:12 -07:00
Olaoluwa Osuntokun
de921aee28 rpctest: add new e2e test for new P2A behavior
We make sure it'll be accepted into the mempool, and can be spent
without a witness.
2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
2682f2c1e3 mempool: add p2a specific policy
P2A is standard if the witness and the sigscript is empty. We make a
smol refactor to be able to write a unit test for the input
standardness.
2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
891bcb2db8 txscript: recognize P2A witness program during script execution
In this commit, we modify the execution logic, such that the P2A witness
program doesn't appear as a unknown witness program version. For
execution, we just make sure the script passes.
2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
053fb4c1d3 txscript: add tests for new P2A awareness 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
f26e6bb718 txscript: recognize P2A scripts in ParsePkScript 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
241bf7cac2 txscript: support trivial signing for P2A 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
e07d161e9b txscript: add initial awareness of new P2A output script 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
939b9394dc btcutil: add new AddressPayToAnchor addr type 2026-05-12 10:56:34 -07:00
Olaoluwa Osuntokun
d9099f6c2a
Merge pull request #2476 from EricGrill/fix/json-marshal-recursion
btcjson: fix StringOrArray JSON marshaling and add warnings to GetBlockChainInfoResult
2026-05-11 17:33:57 -07:00
Olaoluwa Osuntokun
91cf7b241e btcjson: add tests for StringOrArray and Warnings field
Add a regression test for the StringOrArray.MarshalJSON infinite-recursion
fix that exercises both the direct method call and the path through
json.Marshal. Without the fix, the test triggers a goroutine stack
overflow.

Also add a round-trip test and tests for the new Warnings field on
GetBlockChainInfoResult, covering both the legacy single-string form and
the post-bitcoin#29845 array form.
2026-05-11 17:22:00 -07:00
Eric Grill
6392419373 btcjson: add Warnings field to GetBlockChainInfoResult
Bitcoin Core added a warnings field to getblockchaininfo in PR #10858,
and recently changed it from a string to an array in PR #29845. Add
the field using StringOrArray type to handle both formats.

This allows rpcclient to properly unmarshal getblockchaininfo responses
from all Bitcoin Core versions.

Closes #2444

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-11 17:22:00 -07:00
Eric Grill
b528a35303 btcjson: fix infinite recursion in StringOrArray.MarshalJSON
The MarshalJSON method was calling json.Marshal(h) where h is of type
StringOrArray. Since StringOrArray implements json.Marshaler, this
caused json.Marshal to call MarshalJSON again, resulting in infinite
recursion and a stack overflow.

Fix by converting to the underlying []string type before marshaling,
which breaks the interface lookup cycle.

Closes #2369

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-11 17:21:14 -07:00
Olaoluwa Osuntokun
edaf2845bd
Merge pull request #2500 from starius/rpcclient-fixes
rpcclient: fix several synchronization bugs
2026-05-11 16:12:02 -07:00
Boris Nagaev
74f48480e0
tests: fix stale regtest assumptions after #2467
PR #2467 changed regtest to match Core's BIP34/65/66 activation rules, and
the merged stack carries that (commit cd4e5426 "regtest: align activations
with Bitcoin Core"). Height-1 regtest blocks now need a BIP34-compliant
coinbase height and a post-BIP66 block version.

The failing tests came from commits added after PR #2467 was opened on
December 25, 2025 but before it merged on April 30, 2026:

- c1a46122 ("blockchain: add ProcessBlockHeader")
- f9645f07 ("blockchain: reuse existing header node in maybeAcceptBlock")
- dc6e096c ("netsync: add TestSyncStateMachine for end-to-end IBD sync flow")
- ce094262 ("netsync: add TestStartSyncBlockFallback for block-only sync path")
- 2aae8a6d ("netsync: add TestStartSyncChainCurrent for chain-current noop path")

Because those tests landed later, they kept the old regtest assumptions even
though #2467 had already been authored and tested against the older tree.
Once #2467 finally merged, these newer tests started building invalid regtest
blocks and headers.

Fix them by setting the genesis tip height to 0 before generating descendants,
using Version 4 in the regtest block/header helpers, and encoding the test
coinbase height with a minimal BIP34 push plus padding for the generic coinbase
script-length rule.
2026-05-06 17:16:25 -05:00
Boris Nagaev
51944b270c
make fmt 2026-05-06 16:32:51 -05:00
Boris Nagaev
1f00e1a31f
rpcclient: avoid duplicate batch POST handlers
NewBatch called New() and then called start() again. In HTTP POST mode that
created a second sendPostHandler and another shutdown-cancel goroutine, which
broke the expected single-flight serialization of POST sends.

Keep NewBatch as a semantic toggle only: rely on New() to start handlers
once, then set batch=true. A regression test now checks that batch POST
requests stay serialized through one active transport call.
2026-05-06 16:29:19 -05:00
Boris Nagaev
fac1a225f9
rpcclient: resolve all batch futures if Send fails
Batch requests were only clearing batchList on Send() errors. The
per-request futures remained unresolved, so callers waiting on Receive
could block forever after a failed batch round trip.

Add failBatchRequests to fan out the Send() error to every queued batch
request and clear tracking state in one place. A regression test now
verifies queued futures complete with the same error returned by Send().
2026-05-06 16:29:19 -05:00
Boris Nagaev
13ccec2c9a
rpcclient: avoid double-resolving POST requests on shutdown
When shutdown races with sendPostRequest, a request could be marked
as ErrClientShutdown and still be enqueued. The sendPostHandler cleanup
loop would then try to send a second terminal response and could block
forever on a full response channel.

Fix this by prioritizing the shutdown path. First check shutdown with a
non-blocking select and return immediately when it is already closed.
Then use a second select to choose between enqueue and shutdown for the
remaining race window.

A regression test verifies a shutdown request is failed immediately and
never enqueued.
2026-05-06 16:29:19 -05:00
Matt Leon
5b189f5f6c
rpcclient: support canceling in-flight http requests
Use a shutdown-aware context for HTTP POST handling so shutdown can
interrupt in-flight requests.

Centralize shutdown error remapping in sendPostRequestAndRespond so all
error exits consistently return ErrClientShutdown when shutdown causes a
context cancellation. Move the retrying HTTP POST path into
sendPostRequestWithRetry and cover it with shutdown regression tests.
2026-05-06 16:29:19 -05:00
Olaoluwa Osuntokun
e4fe5985f8
Merge pull request #2520 from starius/strict-chainhash-parsing-1
chaincfg/chainhash: add strict parsing
2026-05-06 16:17:52 -05:00
Olaoluwa Osuntokun
c794769dc2
Merge pull request #2489 from guggero/gettxoutproof
rpcclient: add GetTxOutProof{,Async} methods, speed up string parsing
2026-04-30 15:16:26 -04:00
Olaoluwa Osuntokun
ac0394ffe2
Merge pull request #2467 from starius/bip30bypassfix
Sync BIP30/BIP34 Handling With Bitcoin Core
2026-04-30 15:08:50 -04:00
Olaoluwa Osuntokun
24e3318ec4
Merge pull request #2485 from Roasbeef/fix-codesep-unexecuted-branch
txscript: reject OP_CODESEPARATOR in unexecuted branches for non-segwit
2026-04-30 13:56:54 -04:00
Olaoluwa Osuntokun
ee91afcf57 txscript: refactor CalcScriptInfo for nested P2SH analysis
Extract the nested P2SH analysis from CalcScriptInfo into a dedicated
calcP2SHScriptInfo helper, and switch it to use finalOpcodeData for
redeem-script extraction (matching the consolidation in NewEngine and
GetWitnessSigOpCount). The helper also threads the inner witness-script
expected-input contribution for nested P2WSH spends, which the previous
inline code did not account for.
2026-04-28 22:44:05 -07:00
Olaoluwa Osuntokun
63772e521b txscript: use finalOpcodeData for nested P2SH redeem script extraction
Both NewEngine and GetWitnessSigOpCount used sigScript[1:] (a raw byte
suffix of the scriptSig) to identify the candidate redeem script for
nested P2SH witness detection. GetPreciseSigOpCount and the existing
P2SH execution path already get the redeem script as the final pushed
element of the push-only scriptSig (via finalOpcodeData and
savedFirstStack[len-1] respectively). This commit consolidates the
nested-witness detection sites to use finalOpcodeData(0, scriptSig) so
all three places agree on what the redeem script is.

As a side effect of using the actual redeem script for detection, the
len(witness) != 0 precondition in NewEngine becomes redundant — the
redeem script's shape alone determines whether the spend is nested
witness, and verifyWitnessProgram already enforces the required
witness-stack shape downstream.
2026-04-28 22:44:05 -07:00
Olaoluwa Osuntokun
af7f379215 txscript: align empty CHECKSIG pubkey validation with Core
The refreshed Bitcoin Core script reference tests cover cases where an
empty CHECKSIG input must still fail pubkey encoding checks before the
interpreter falls back to a generic false result.
2026-04-28 22:44:05 -07:00
Olaoluwa Osuntokun
0235896053 txscript: return ErrCleanStack for witness cleanstack failures
The refreshed Bitcoin Core script reference tests expect witness
clean-stack failures to report CLEANSTACK rather than a generic
EVAL_FALSE result.
2026-04-28 22:44:05 -07:00