Skip to content

Sync with Upstream#1

Open
2a5A1Ghu1 wants to merge 1141 commits intotheohmproject:masterfrom
btcsuite:master
Open

Sync with Upstream#1
2a5A1Ghu1 wants to merge 1141 commits intotheohmproject:masterfrom
btcsuite:master

Conversation

@2a5A1Ghu1
Copy link
Copy Markdown
Member

No description provided.

kcalvinalvin and others added 30 commits April 30, 2024 17:13
InvalidateBlock() invalidates a given block and marks all its
descendents as invalid as well. The active chain tip changes if the
invalidated block is part of the best chain.
For debug purposes down the road, log that the node is pruned if it's
set to pruned.
This exposes publicly the ability to decode arbitrary-length bech32
strings and return the bech32 version that was used in the encoding. It
provides the underlying functionality for both DecodeNoLimit and
DecodeGeneric.
This is to mitigate CVE-2017-12842. Along the way, also error when
deserializing transactions that have the witness marker flag set
but have no witnesses. This matches Bitcoin Core's behaviour initially
introduced here bitcoin/bitcoin#14039. Allowing
such transactions is benign, but this makes sure that our parsing code
matches Core's exactly.
Update standardness rules congruent to Bitcoin Core
blockchain, fullblocktests, workmath, testhelper: add InvalidateBlock() method to BlockChain
Added DecodeNoLimitGeneric to bech32.go
refactor: set strconv.ParseFloat bitsize to 64
reorganizeChain() used to handle the following:
1: That the blocknodes being disconnected/connected indeed to connect
   properly without errors.
2: Perform the actual disconnect/connect of the blocknodes.

The functionality of 1, the validation that the disconnects/connects can
happen without errors are now refactored out into
verifyReorganizationValidity.

This is an effort made so that ReconsiderBlock() can call
verifyReorganizationValidity and set the block status of the
reconsidered chain and return nil even when an error returns as it's ok
to get an error when reconsidering an invalid branch.
ReconsiderBlock reconsiders the validity of the block for the passed
in blockhash. The behavior of the function mimics that of Bitcoin Core.

The invalid status of the block nodes are reset and if the chaintip that
is being reconsidered has more cumulative work, then we'll validate the
blocks and reorganize to it. If the cumulative work is lesser than the
current active chain tip, then nothing else will be done.
Signed-off-by: coderwander <770732124@qq.com>
blockchain: Add ReconsiderBlock()
invalidateblock and reconsiderblock are added to the rpcclient package
and an integration test is added to test the added functions.
The rpc calls and the rpchelp is added for the invalidateblock
and reconsiderblock methods on BlockChain.
main, rpcclient, integration: add rpccalls for invalidate and reconsiderblock
build: bump version to v0.24.2-beta
Fixes #2199.

Previous to this fix the keytype was only interpreted as a single byte,
even though BIP-0174 states it is to be parsed as a CompactSize/VarInt.
This commit updates the error str to match the same error returned from
`btcd` for both pre-0.24.2 and post-0.24.2.
psbt: decode keytype as compact size
Sending RPC requests through unix sockets
commit 0b2998b
Author: cec489 <173723251+cec489@users.noreply.github.com>
Date:   Mon Jun 24 20:01:13 2024 +0000

    A cleaner fix is to set the startTime in the server Start() function
    which is where the server is actually started.

commit ae6c125
Author: cec489 <173723251+cec489@users.noreply.github.com>
Date:   Mon Jun 24 19:15:23 2024 +0000

    Fix the btcctl uptime command by moving the setting of startupTime
This change lets us test that we don't attempt to delete open files with
unit tests.  On Windows this behavior is not allowed which results in an
error but on linux and osx it's allowed. To better test Windows
compatibilty adding this explicit check in is useful.
This check let's us ensure that attempting to delete open files are
caught during unit tests.
kcalvinalvin and others added 30 commits February 26, 2026 16:40
This tests that after two nodes diverge and reconnect, the shorter
node downloads blocks starting from the fork point rather than its
current height. It verifies the reorg completes, both nodes
converge, and the orphaned fork appears as a side chain via
getchaintips.
ince we now utilize ProcessBlockHeaders, we change the startSync
function to utilize the block index for downloading blocks/headers
instead of using the headerList in SyncManager.
handleBlockMsg is updated to not be based off of the headerList and
sm.nextCheckpoint when doing operations related to checkpoints and
headers.
Since we no longer utilize the headerList for doing headers-first
download and checkpoint tracking, we remove related code.
ibdMode is a more fitting name than headersFirstMode since all blocks
are downloaded headers-first during the initial block download.
Tests the full IBD state machine: startSync → fetchHeaders →
handleHeadersMsg → fetchHeaderBlocks → handleBlockMsg → IBD complete.

Three sub-cases exercise different paths:
- fresh IBD from genesis
- node restart with partially synced blocks
- stalled sync peer recovery via handleStallSample
Verify that startSync skips header download and directly requests
blocks when the header chain is already caught up to the peer's
height but the block chain lags behind.
Verify that startSync does not set syncPeer or ibdMode when the
chain tip is recent and no peer advertises a height above ours.
This issue was discovered through differential fuzzing between btcd and
Bitcoin Core.

Add detection and filtering of IPv6 ORCHIDv2 addresses as defined by
RFC7343 (2001:20::/28). These addresses are overlay routable
cryptographic hash identifiers and should not be treated as routable
peer addresses, consistent with Bitcoin Core's behavior.

Changes:
- Add rfc7343Net variable for the 2001:20::/28 address block
- Add IsRFC7343() function to detect ORCHIDv2 addresses
- Update IsRoutable() to exclude RFC7343 addresses
- Add comprehensive test coverage for RFC7343 detection
- Fix incorrect error message in TestIPTypes (IsRFC1918 -> IsRFC6145)
This issue was discovered through differential fuzzing between btcd and
Bitcoin Core.

IPv4-mapped IPv6 addresses (::ffff:0:0/96, RFC 4291) sent with networkID
0x02 (IPv6) in addrv2 messages are now properly rejected. Per BIP155,
these addresses should use networkID 0x01 (IPv4) instead. This aligns
btcd's behavior with Bitcoin Core's addrv2 handling.

Changes:
- Add ipv4MappedPrefix constant for the ::ffff:0:0/96 prefix
- Add isIPv4Mapped() helper function to detect these addresses
- Update readNetAddressV2() to skip IPv4-mapped addresses with IPv6 networkID
- Add comprehensive test coverage for IPv4-mapped address detection
Add a bounds check against the remaining slab capacity so oversized
witness items return a decode error. Add a regression test for witness
items that overflow the decode slab.
To align with Bitcoin Core, reduce the maximum message payload size from
32MB to 4MB.
Add a recoverFromPanic method that catches panics in peer goroutines,
logs the error with a stack trace, and disconnects the offending peer
instead of crashing the entire node. This provides defense-in-depth
against future unknown panics in message parsing or handling.

Protect two goroutine boundaries:
- The negotiation goroutine in start(), which handles pre-handshake
  message decoding via BtcDecode.
- The inHandler goroutine, which processes all post-handshake messages.

Refactor inHandler cleanup from manual end-of-function calls to
defer-based cleanup, ensuring close(p.inQuit) always runs even on
panic, which prevents stallHandler from hanging.
html/template automatically HTML-escapes special characters to prevent
XSS, which can silently corrupt arbitrary script data. Since the output
is binary script bytes and not HTML, this escaping provides no benefit
and might breaks correctness.
txscript: switch template engine from html/template to text/template
…ock-downloads

blockchain, netsync: implement a complete headers-first download during ibd
In this commit, we fix `IsRoutable` to correctly reject IPv6 addresses
whose first 16-bit group is zero (i.e., in the `0000::/16` reserved
block per RFC 4291). Differential fuzzing between btcd and Bitcoin Core
revealed that addresses like `0:9881:8181:8181:fe00:a:9e:9801` were
slipping through as routable when they shouldn't be.

We add a new `zero6Net` (`0000::/16`) definition alongside the existing
`zero4Net`, and introduce an `IsZero` helper that checks both. The /16
prefix width is intentional: the broader /8 reservation would
incorrectly catch allocated sub-ranges like `0064:ff9b::/96` (RFC 6052,
NAT64). We also carve out an exception for RFC 6145 translated IPv4
addresses (`::ffff:0:0:0/96`), which live within `0000::/16` but are
valid for routing.

Test coverage includes the original bug report address, various
zero-prefix IPv6 addresses, the RFC 6145 exclusion, and corresponding
`GroupKey` entries to confirm they land in the "unroutable" bucket.

Fixes #2431
addrmgr: mark IPv6 zero addresses as non-routable
…chnorr

btcec/schnorr: fix incorrect comment about nonce generation
In this commit, we remove the localhost-only restriction for sync peer
candidates on regtest and simnet. Previously, isSyncCandidate rejected
any regtest peer not on 127.0.0.1 or localhost, which prevented IBD
when nodes run in Docker containers on bridge networks (e.g. 172.18.0.x).

We also replace fragile pointer-equality checks against global chaincfg
params with value-based Name field comparisons, and extend the exception
to simnet since it has the same local-only usage pattern.
Add a test verifying that isSyncCandidate accepts peers from any
address on regtest, including Docker bridge IPs, remote IPs, and IPv6.
netsync: allow sync with non localhost peers
Add a test case that passes a 16-byte IPv4-mapped IPv6 address
(::ffff:127.0.0.1) to NetAddressV2FromBytes and asserts that it
is recognized as IPv4 with networkID 0x01, not IPv6 with 0x02.
Go's net.ParseIP stores IPv4 addresses as 16-byte IPv4-mapped IPv6
addresses (::ffff:x.x.x.x). NetAddressV2FromBytes dispatches on
address length, so these 16-byte addresses were incorrectly matched
as IPv6 and serialized with networkID 0x02 (IPv6) instead of 0x01
(IPv4). BIP-155 doesn't forbid this, but Bitcoin Core silently drops
them anyway (undocumented, naturally). Detect IPv4-mapped IPv6
addresses and extract the 4-byte IPv4 address with the correct
networkID.
Since btcwallet now supports regtest, we add the default port
`18332`. Now `--wallet` command works on regtest.
main: add regtest port for btcwallet
…-ipv6

wire: don't wrap ipv4 in ipv6 addresses
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.