Skip to content

Sync with Upstream - #1

Open
2a5A1Ghu1 wants to merge 1319 commits into
theohmproject:masterfrom
btcsuite:master
Open

Sync with Upstream#1
2a5A1Ghu1 wants to merge 1319 commits into
theohmproject:masterfrom
btcsuite:master

Conversation

@2a5A1Ghu1

Copy link
Copy Markdown
Member

No description provided.

Roasbeef and others added 30 commits August 19, 2025 18:08
rpcclient: add bitcoind version dependent error matching
Co-authored-by: Oliver Gugger <gugger@gmail.com>
Makefile+workflows: fallback to `GOPATH/bin` on non-existent `GOBIN`
We do this to later add batch put logic into the exported Put()
function.
newTreapNode

The treapNodePool will allow for less memory allocations during
immutable treap operations.  We first change the cloneTreapNode and
newTreapNode to allocate a treapNode from the sync.Pool.

The allocated treapNodes will be put back into the sync.Pool in later
commits.
build: bump version to v0.25.0-beta.rc1
This commit adds a new function to musig2.Session, which allows the caller
to add an external aggregated nonce to the session.
musig2: add WithExternalCombinedNonce option to Sign
Ensure that the dial phase of rpcclient's HTTP posts respects the http.Client's Timeout. It was instead falling back to the OS settings.
The newly created treapNodes in put() are now returned so that the
caller has access to them.  This is done so that the caller can put back
some of the treapNodes to sync.Pool.

For multiple put operations, an immutable treap will allocate many
treapNodes that will immediately be garbage collected.  Let's say
there's 3 key-value pairs that are going to be inserted:

key 1: 50
key 2: 10
key 3: 4

Then the insertion is like so:

1: allocate 50.

        50

2: clone 50, allocate 10.

        50
       /  \
      10

3: clone 50, clone 10, allocate 4

        50
       /  \
      10
     /
    4

In this example, only the nodes allocated during insertion of (3) is
going to be used.  The rest is going to be garbage collected and they
can be safely be put in the sync.Pool if there's a guarantee that the
previous copies are not being accessed.  This is true if the put
operations are going to be called in batches.

By returning the pointers of these allocated treapNodes, we allow the
caller to make such optimizations.
The recycle method resets and puts the treapNode into the treapNodePool
to be recycled at a future date.
…dialcontext

rpcclient: ensure http dial respects timeout
Previously, the Put() function took in a single key-value pair,
resulting in memory allocation overhead as the intermediary treapNodes
got allocated and immediately garbage collected, resulting in
performance loss due to the garbage collection overhead.

We're able to recycle the intermediary treapNodes allocated by taking in
multiple key-value pairs.  This results in better performance of the
node especially during UTXO cache flushes.
Upcoming commits tweak the conditions under which the expensive BIP30
duplicate-coinbase check should run. To unit-test those changes, this
commit moves the decision logic out of BlockChain.checkConnectBlock and
into a dedicated helper, bip0030CheckNeeded. The behaviour is unchanged;
the new helper is covered by tests in bip30_test.go.
Sync the behaviour with Bitcoin Core.

See bitcoin/bitcoin#6931

In Core, the BIP30 flag is cleared only if the previous block's ancestor chain
already contains the BIP34 activation block. For the activation block itself
(height = BIP0034Height), pindex->pprev->GetAncestor(BIP34Height) returns
nullptr, so the flag stays on and BIP30 is still enforced. In other words, Core
enforces BIP30 for the activation block and skips it starting with the following
block.
Mirror BIP34-aware BIP30 skip logic from Bitcoin Core.

PR bitcoin/bitcoin#6931 in Bitcoin Core introduced
an optimization that skips the expensive BIP30 duplicate coinbase check once
BIP34 is active *and* the chain actually contains the recorded activation block.
See the comment in that PR "//Only continue to enforce if we're below BIP34
activation height or the block hash at that height doesn't correspond."

btcd used to drop the check purely based on height. On a fork that lacks the
BIP34 activation block, that difference lets a duplicate coinbase slip through
consensus. This patch ports the missing pieces: we store the activation hash in
chain parameters and only disable BIP30 after we see that block on-chain.
Bitcoin Core PR bitcoin/bitcoin#12204 tightened BIP30
handling: re-enable the check once height 1,983,702 is reached.

This change ports that logic into btcd and adds a regression test.
Set regtest buried heights to match Core: BIP34/65/66 at height 1 and make
CSV/SegWit/Taproot always active. Added regtest coverage for header version
floors, coinbase height enforcement, and deployment state to ensure we now
reject the blocks Core rejects and accept the ones Core accepts.

Updated package fullblocktests to generate BIP34-compliant blocks.

Test helpers now set prev block height to 0 (not the default -1) so generated
blocks start at height 1 and satisfy coinbase height rules.
build: bump version of Go container for release builds
The comments in schnorrSign and Sign incorrectly stated that CustomNonce
triggers RFC6979 nonce generation. The actual behavior is the opposite:

- With CustomNonce: BIP-340 compliant nonce derivation (steps 6-8)
- Without CustomNonce (default): RFC6979 deterministic nonce generation

Also fixes typo "set 14" -> "step 14".
Roasbeef and others added 30 commits July 20, 2026 17:38
In this commit, we extend the lenient database block parser to the remaining call sites that re-read blocks from the node's own database.

The getblock RPC now copies FetchBlock bytes before its read transaction ends, since database buffers are not valid outside that lifetime. We then strip any legacy trailing data and serve the exact block serialization at every verbosity level. A regression database invalidates its buffer as View returns, pinning the required copy.

The index manager uses the same parser while rolling an index tip back to the main chain. We also place DBBlockFromBytes before its first caller and log legacy trailing data at debug level, since a frequently fetched dirty block should not flood operator logs.
In this commit, we extend taproot PSBT serialization and finalization to reject nil script spend signatures, leaf scripts, and BIP32 derivations before any sort or dereference. We return wrapped ErrInvalidPsbtFormat errors so callers can identify malformed packet state without parsing strings.

We also make FindLeafScript reject nil inputs and leaf entries. This keeps both the direct finalizer and MaybeFinalize paths from panicking on malformed in-memory packets.
In this commit, we propagate errors returned while cataloging index
buckets, matching the bucket deletion path fixed by the preceding commit.

We also add fault-injected regression coverage for both paths so neither
error can silently report a successful index drop.
blockchain/indexers: fix dropped error
…idation

btcutil: reject out-of-range private keys in DecodeWIF
BIP-350 requires that segregated witness outputs of version 1 through 16
use the bech32m checksum, while only version 0 uses bech32. decodeSegWitAddress
only special-cased versions 0 and 1, so a witness program with version 2-16
encoded using the legacy bech32 checksum decoded successfully, in violation of
the spec and contrary to the BIP-350 reference decoder (which rejects any
non-zero witness version that is not bech32m).

Generalize the version 1 check to cover all versions >= 1, matching the
reference decode() function. Add the relevant BIP-350 INVALID_ADDRESS vectors
(v2 and v16 encoded with bech32) as a regression test; they decoded
successfully before this change and are now rejected.

Signed-off-by: Lrifton92 <Lrifton92@users.noreply.github.com>
In this commit, we decode base64 PSBT packets as a stream instead of
reading the full encoded input into memory first.

The previous aggregate bound reused wire.MaxMessagePayload, even though
BIP-174 doesn't bind PSBT packet size to the P2P message limit. This made
the base64 path reject packets that the raw path accepted. We now feed
decoded bytes through the same per-field parser used for raw packets,
while retaining strict base64 and trailing-data checks.

We also add a regression test with nine individually valid 4,000,000-byte
unknown values to pin raw and base64 parsing to the same behavior.
In this commit, we keep loopback and whitelisted peers inside the ordinary
pending-handshake and V2 source budgets, while preserving their existing
no-ban behavior.

We also derive the listener reservation from the configured peer mode.
Connect-only and simnet nodes now reserve just their permanent peers, while
automatic mode accounts for both its target and addpeers without exceeding
MaxPeers.

Finally, a bound V2 handshake consumes its rate budgets once, but reacquires
the concurrency slot for each CPU-bound responder phase. This keeps rate
limiting scoped to the handshake while bounding both expensive phases.
In this commit, we send the responder key as soon as the initiator diverges
from the v1 prefix. This avoids the BIP324 deadlock where both sides can wait
for the other to write before the initiator has sent its complete 64-byte
key.

We split key generation and key agreement into separate admission leases,
and release each lease before the intervening network I/O. The regression
test stops after the first mismatch, requires the responder to make
progress, then completes key agreement and verifies the resulting packet
ciphers interoperate.
In this commit, we make each stress wave establish its full set of peers
before disconnecting them together. A ping/pong barrier proves the server
processed each verack, while RPC connection-count barriers prove
registration and removal completed before the next wave starts.

We bound concurrent handshakes from the shared source, drain every worker on
failure, and wait for server-side cleanup. This keeps the test compatible
with the admission limits it exercises and makes a passing run evidence of
the intended NewPeer/DonePeer ordering.
In this commit, we define TargetOutbound as the number of automatic
connections and treat explicit Connect requests as additional peers.

Permanent requests could previously consume connection IDs before Start
sampled the shared counter. The resulting automatic count depended on
goroutine scheduling, while the listener reserved the worst-case total.
We now start the configured automatic count directly and cap it by the
peer budget left after permanent peers.

The composition test covers permanent requests on both sides of Start and
pins the same automatic+permanent total for either ordering.
In this commit, we reject maxpeers values that cannot represent a usable
peer budget.

A zero value reached connmgr as TargetOutbound=0, where zero means to use
the default target of eight. The server then rejected every completed
peer and immediately created a replacement request. Rejecting the value
during configuration avoids that outbound reconnect loop.
In this commit, we make the pre-verack lifecycle test count only peers that
btcd has admitted and processed through version exchange.

The source handshake limit can close a rapid follow-up socket while the
previous disconnect is still unwinding. This made the client-side version
write fail with EPIPE before the intended lifecycle path ran. We now wait for
a version response from btcd, retry rejected attempts under a deadline, and
still disconnect without sending verack.

This preserves all 50 peerDone without peerAdd cycles while removing the
scheduler-dependent admission race from the test.
multi: tighten inbound connection admission
address: reject v2-v16 segwit addresses encoded with bech32 (BIP-350)
multi: relax trailing byte handling for DB blocks and PSBT readers
Add a DisableAuth field to ConnConfig that, when set to true, skips
setting the Authorization header on RPC requests.

This enables connecting to third-party RPC providers (e.g. Alchemy,
GetBlock) that authenticate via API key in the URL path and reject
requests containing an Authorization header with 401 errors.

Previously, getAuth() unconditionally set BasicAuth or attempted
cookie auth, leaving no way to disable authentication entirely.

Fixes #2505
Add table-driven tests that verify:
- Authorization header is omitted when DisableAuth is true
- Authorization header is present when DisableAuth is false
- Default (zero value) behavior includes Authorization header

Suggested by @TechLateef in #2514.
In this commit, we wrap the new DisableAuth regression tests to the
btcd 80-column formatting convention. We also split the nested handler
setup and assertions into logical stanzas so the tests match the
surrounding style.
In this commit, we make the DisableAuth tests observe successful
requests instead of inferring them from an empty header. This closes a
false-positive path where credential lookup could fail before the
request reached the server.

We also cover the WebSocket handshake, cookie bypass, and
caller-provided headers across enabled and disabled auth. The public
comment now makes clear that DisableAuth only suppresses
rpcclient-generated Basic auth.
rpcclient: make HTTP Basic Auth optional via DisableAuth
In this commit, we bump the root module requirement to the freshly tagged
v2transport v1.1.0 release. This exposes the responder handshake admission
APIs added in #2576 when btcd is built as a downstream module, where the
repository-local replace directive does not apply.
In this commit, we pin btcutil and wire to their freshly tagged v2.0.1
releases. We also remove the root module's remaining local replace
directives now that all three in-tree modules have published versions.

This makes local builds and downstream module consumers resolve the same
btcutil, v2transport, and wire code. The regenerated checksums cover each
published module.
In this commit, we include periods in the alphabet accepted by
normalizeVerString. SemVer uses periods to separate pre-release identifiers,
but the old filter silently collapsed beta.rc1 into betarc1.

We add a focused test for the dotted RC suffix before using it for the next
release candidate.
In this commit, we bump btcd from v0.26.0-beta to
v0.26.1-beta.rc1 for the next release candidate. This puts the version
reported by the daemon and RPC server in sync with the release series
prepared by this PR.
In this commit, we move btcd past the v0.26.1 release candidate and set
the development version to v0.26.2-beta. This keeps the daemon and RPC
server version on the next patch series as work resumes on master.
build: bump version to v0.26.2-beta
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.