27922 Commits

Author SHA1 Message Date
Greg Sanders
666aec7d49
Mempool: Do not enforce TRUC checks on reorg
Not enforcing TRUC topology on reorg was the intended
behavior, but the appropriate bypass argument was not
checked.

This mistake means we could potentially invalidate a long
chain of perfectly incentive-compatible transactions that
were made historically, including subsequent non-TRUC
transactions, all of which may have been very high feerate.

Lastly, it wastes CPU cycles doing topology checks since
this behavior cannot actually enforce the topology in
general for the reorg setting.

Github-Pull: #33504
Rebased-From: 26e71c237d9d2197824b547f55ee3a0a60149f92
2025-10-02 15:17:31 +01:00
Greg Sanders
6f23ead4a2
fuzz: don't bypass_limits for most mempool harnesses
Using bypass_limits=true is essentially fuzzing part of a
reorg only, and results in TRUC invariants unable to be
checked. Remove most instances of bypassing limits, leaving
one harness able to do so.

Github-Pull: #33504
Rebased-From: bbe8e9063c15dc230553e0cbf16d603f5ad0e4cf
2025-10-02 15:17:10 +01:00
Sebastian Falbesoner
9d9baafc6f
doc: rpc: fix case typo in finalizepsbt help (final_scriptwitness)
Github-Pull: #33484
Rebased-From: ff05bebcc4262966b117082a67dc4c63a3f67d2d
2025-09-29 15:56:02 -04:00
Sjors Provoost
22ab141243
rpc: fix getblock(header) returns target for tip
A target field was added to the getblock and getblockheader RPC calls in bitcoin#31583, but it mistakingly always used the tip value.

Because regtest does not have difficulty adjustment, a test is added for mainnet instead.

Github-Pull: #33446
Rebased-From: bf7996cbc3becf329d8b1cd2f1007fec9b3a3188
2025-09-24 10:34:21 -04:00
Martin Zumsande
61cdc04a83
net: Do not apply whitelist permission to onion inbounds
Tor inbound connections do not reveal the peer's actual network address.
Therefore do not apply whitelist permissions to them.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>

Github-Pull: #33395
Rebased-From: f563ce90818d486d2a199439d2f6ba39cd106352
2025-09-17 10:12:08 +01:00
Eugene Siegel
569ceb0df4
net: check for empty header before calling FillBlock
Previously in debug builds, this would cause an Assume crash if
FillBlock had been called previously. This could happen when multiple
blocktxn messages were received.

Co-Authored-By: Greg Sanders <gsanders87@gmail.com>

Github-Pull: #33296
Rebased-From: 5e585a0fc4fd68dd7b4982054b34deae2e7aeb89
2025-09-12 15:44:03 +01:00
Greg Sanders
4c940d4789
p2p: remove vestigial READ_STATUS_CHECKBLOCK_FAILED
Github-Pull: #32646
Rebased-From: 28299ce77636d7563ec545d043cf1b61bd2f01c1
2025-09-12 15:44:00 +01:00
Greg Sanders
9b95ab5e9d
p2p: Add witness mutation check inside FillBlock
Since #29412, we have not allowed mutated blocks to continue
being processed immediately the block is received, but this
is only done for the legacy BLOCK message.

Extend these checks as belt-and-suspenders to not allow
similar mutation strategies to affect relay by honest peers
by applying the check inside
PartiallyDownloadedBlock::FillBlock, immediately before
returning READ_STATUS_OK.

This also removes the extraneous CheckBlock call.

Github-Pull: #32646
Rebased-From: bac9ee4830664c86c1cb3d38a5b19c722aae2f54
2025-09-12 15:43:53 +01:00
Luke Dashjr
e97588fc3d
trace: Workaround GCC bug compiling with old systemtap
Github-Pull: #33310
Rebased-From: 93a29ff2830162c8129d35c7b9beb43fab984503
2025-09-12 11:52:26 +01:00
Hennadii Stepanov
2717331981
Fix benchmark CSV output
The `SHA256AutoDetect` return output is used, among other use cases, to
name benchmarks. Using a comma breaks the CSV output.

This change replaces the comma with a semicolon, which fixes the issue.

Github-Pull: #33340
Rebased-From: 790b440197bde322432a5bab161f1869b667e681
2025-09-09 10:13:49 +01:00
MarcoFalke
6448ebb5a7
doc: Remove wrong and redundant doxygen tag
Remove it in feerate.

Fix it in the other places.

Github-Pull: #33236
Rebased-From: 966666de9a6211b8748f43d682490c924e132e58
2025-08-29 14:53:02 +01:00
Martin Zumsande
16b1710d97
index: don't commit state in BaseIndex::Rewind
The committed state of an index should never
be ahead of the flushed chainstate. Otherwise, in the case
of an unclean shutdown, the blocks necessary to revert
from the prematurely committed state would not be
available, which would corrupt the coinstatsindex in particular.
Instead, the index state will be committed with the next
ChainStateFlushed notification.

Github-Pull: #33212
Rebased-From: 01b95ac6f496e24e525b2fc9d69ee8b543da65ff
2025-08-24 22:48:09 +01:00
glozow
9dd7efc8c3 [policy] lower default minrelaytxfee and incrementalrelayfee to 100sat/kvB
Let's say an attacker wants to use/exhaust the network's bandwidth, and
has the choice between renting resources from a commercial provider and
getting the network to "spam" itself it by sending unconfirmed
transactions. We'd like the latter to be more expensive than the former.

The bandwidth for relaying a transaction across the network is roughly
its serialized size (plus relay overhead) x number of nodes. A 1000vB
transaction is 1000-4000B serialized. With 100k nodes, that's 0.1-0.4GB
If the going rate for commercial services is 10c/GB, that's like 1-4c per kvB
of transaction data, so a 1000vB transaction should pay at least $0.04.

At a price of 120k USD/BTC, 100sat is about $0.12. This price allows us
to tolerate a large decrease in the conversion rate or increase in the
number of nodes.

Github-Pull: #33106
Rebased-From: 6da5de58cabc4133c379baa50845e30e5bc6b3e4
2025-08-20 10:19:23 -04:00
glozow
da30ca0efa [prep/util] help MockMempoolMinFee handle more precise feerates
Use a virtual size of 1000 to keep precision when using a feerate
(which is rounded to the nearest satoshi per kvb) that isn't just an
integer.

Github-Pull: #33106
Rebased-From: 457cfb61b5323a13218b3cfb5a6a6d8b3a7c5f7f
2025-08-20 10:19:23 -04:00
glozow
a0ae3fc8a7 [prep/test] replace magic number 1000 with respective feerate vars
Github-Pull: #33106
Rebased-From: 3eab8b724044dc321f70e5eed66b149713158a04
2025-08-20 10:19:23 -04:00
glozow
1c1970fb45 [miner] lower default -blockmintxfee to 1sat/kvB
Back when we implemented coin age priority as a miner policy, miners
mempools might admit transactions paying very low fees, but then want to
set a higher fee for block inclusion. However, since coin age priority
was removed in v0.15, the block assembly policy is solely based on fees,
so we do not need to apply minimum feerate rules in multiple places. In
fact, the block assembly policy ignoring transactions that are added to
the mempool is likely undesirable as we waste resources accepting and
storing this transaction.

Instead, rely on mempool policy to enforce a minimum entry feerate to
the mempool (minrelaytxfee). Set the minimum block feerate to the
minimum non-zero amount (1sat/kvB) so it collects everything it finds in
mempool into the block.

Github-Pull: #33106
Rebased-From:  5f2df0ef78be7b24798d0983c9b962740608f1f4
2025-08-20 10:19:23 -04:00
glozow
3a7e093f94 [doc] assert that default min relay feerate and incremental are the same
Github-Pull: #33106
Rebased-From: d6213d6aa114aeed6804a585491d741386fd2739
2025-08-20 10:19:23 -04:00
Eugene Siegel
0022e25333
test: modify logging_filesize_rate_limit params
Change time_window from 20s to 1h so Reset is not accidentally called
if the test takes a while.

Change num_lines from 1024 to 10 since LogRateLimiter is parameterized
and does not require logging 1MiB of data.

Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #33211
Rebased-From: 5dda364c4b1965da586db7b81de8be90b6919414
2025-08-20 12:01:59 +01:00
Eugene Siegel
206f5902db
config: add DEBUG_ONLY -logratelimit
Use -nologratelimit by default in functional tests if the bitcoind
version supports it.

Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #33011
Rebased-From: 5c74a0b397cb3db94761bad78801eed4544155b9
2025-08-20 12:01:35 +01:00
stickies-v
dfdd407c42
test: logging_filesize_rate_limit improvements
- Add helper functions and structs to improve readability and
  reusability of test code
- Make tests more specific by comparing all produced log lines with
  expected log lines instead of relying on approximations or proxies.

Github-Pull: #33011
Rebased-From: 9f3b017bcc067bba1d1682a5d4e65b5450dc10c4
2025-08-20 12:01:12 +01:00
stickies-v
11538160b3
test: don't leak log category mask across tests
This ensures log tests behave consistently when other tests modify
the log category mask.

Github-Pull: #33011
Rebased-From: 350193e5e2efabb3eb66197b91869b946ec5428c
2025-08-20 12:00:48 +01:00
stickies-v
4ed7a51642
test: add ReadDebugLogLines helper function
Deduplicates repeated usage of the same functionality.

Github-Pull: #33011
Rebased-From: 05d7c22479bf96bab9f8c8b8fa90368429ad2c88
2025-08-20 12:00:22 +01:00
stickies-v
acfa83d9d0
log: make m_limiter a shared_ptr
This allows us to safely and explicitly manage the dual dependency
on the limiter: one for the Logger, and one for the CScheduler.

Github-Pull: #33011
Rebased-From: 3d630c2544e19480268426cda245796d4ce34ac3
2025-08-20 11:59:45 +01:00
Eugene Siegel
81751341e9
log: clean up LogPrintStr_ and Reset, prefix all logs with "[*]" when there are suppressions
In LogPrintStr_:
- remove an unnecessary BCLog since we are in the BCLog namespace.
- remove an unnecessary \n when rate limiting is triggered since
  FormatLogStrInPlace will add it.
- move the ratelimit bool into an else if block.
- prefix all log lines with [*] when suppressions exist. Previously this
  was only done if should_ratelimit was true.

In Reset:
- remove an unnecessary \n since FormatLogStrInPlace will add it.
- Change Level::Info to Level::Warning.

Github-Pull: #33011
Rebased-From: e8f9c37a3b4c9c88baddb556c4b33a4cbba1f614
2025-08-20 11:55:28 +01:00
Eugene Siegel
7c3820ff63
log: change LogLimitStats to struct LogRateLimiter::Stats
Clean up the noisy LogLimitStats and remove references to the time
window.

Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #33011
Rebased-From: 3c7cae49b692bb6bf5cae5ee23479091bed0b8be
2025-08-20 11:54:59 +01:00
Eugene Siegel
dfe4e19f66
log: clarify RATELIMIT_MAX_BYTES comment, use RATELIMIT_WINDOW
Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #33011
Rebased-From: 8319a134684df2240057a5e8afaa6ae441fb8a58
2025-08-20 11:53:48 +01:00
Eugene Siegel
273ffda2c8
log: remove const qualifier from arguments in LogPrintFormatInternal
Co-Authored-By: l0rinc <pap.lorinc@gmail.com>

Github-Pull: #33011
Rebased-From: 5f70bc80df06ca85d44e8201d47e7086e971fdea
2025-08-20 11:52:01 +01:00
Eugene Siegel
9cde68fa98
log: avoid double hashing in SourceLocationHasher
Co-Authored-By: l0rinc <pap.lorinc@gmail.com>

Github-Pull: #33011
Rebased-From: b8e92fb3d4137f91fe6a54829867fc54357da648
2025-08-20 11:51:31 +01:00
Eugene Siegel
25f975b8df
test: remove noexcept(false) comment in ~DebugLogHelper
Github-Pull: #33011
Rebased-From: 616bc22f131132b9239ef362dca8c6bce000a539
2025-08-20 11:51:06 +01:00
Eugene Siegel
0b6b096421
log: Add rate limiting to LogPrintf, LogInfo, LogWarning, LogError, LogPrintLevel
To mitigate disk-filling attacks caused by unsafe usages of LogPrintf and
friends, we rate-limit them by passing a should_ratelimit bool that
eventually makes its way to LogPrintStr which may call
LogRateLimiter::Consume. The rate limiting is accomplished by
adding a LogRateLimiter member to BCLog::Logger which tracks source
code locations for the given logging window.

Every hour, a source location can log up to 1MiB of data. Source
locations that exceed the limit will have their logs suppressed for the
rest of the window determined by m_limiter.

This change affects the public LogPrintLevel function if called with
a level >= BCLog::Level::Info.

The UpdateTipLog function has been changed to use the private LogPrintLevel_
macro with should_ratelimit set to false. This allows UpdateTipLog to log
during IBD without hitting the rate limit.

Note that on restart, a source location that was rate limited before the
restart will be able to log until it hits the rate limit again.

Co-Authored-By: Niklas Gogge <n.goeggi@gmail.com>
Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #32604
Rebased-From: d541409a64c60d127ff912dad9dea949d45dbd8c
2025-08-20 11:45:06 +01:00
Eugene Siegel
a0992a842e
log: use std::source_location in place of __func__, __FILE__, __LINE__
The std::source_location conveniently stores the file name, line number,
and function name of a source code location. We switch to using it instead
of the __func__ identifier and the __FILE__ and __LINE__ macros.

BufferedLog is changed to have a std::source_location member, replacing the
source_file, source_line, and logging_function members. As a result,
MemUsage no longer explicitly counts source_file or logging_function as the
std::source_location memory usage is included in the MallocUsage call.

This also changes the behavior of -logsourcelocations as std::source_location
includes the entire function signature. Because of this, the functional test
feature_config_args.py must be changed to no longer include the function
signature as the function signature can differ across platforms.

Co-Authored-By: Niklas Gogge <n.goeggi@gmail.com>
Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #32604
Rebased-From: a6a35cc0c23d0d529bfeb2f40d83d61f15ca7b40
2025-08-20 11:42:01 +01:00
Eugene Siegel
41262cc4d5
log: introduce LogRateLimiter, LogLimitStats, Status
LogRateLimiter will be used to keep track of source locations and our
current time-based logging window. It contains an unordered_map and a
m_suppressions_active bool to track source locations. The map is keyed
by std::source_location, so a custom Hash function (SourceLocationHasher)
and custom KeyEqual function (SourceLocationEqual) is provided.
SourceLocationHasher uses CSipHasher(0,0) under the hood to get a
uniform distribution.

A public Reset method is provided so that a scheduler (e.g. the
"b-scheduler" thread) can periodically reset LogRateLimiter's state when
the time window has elapsed.

The LogRateLimiter::Consume method checks if we have enough available
bytes in our rate limiting budget to log an additional string. It
returns a Status enum that denotes the rate limiting status and can
be used by the caller to emit a warning, skip logging, etc.

The Status enum has three states:
- UNSUPPRESSED     (logging was successful)
- NEWLY_SUPPRESSED (logging was succcesful, next log will be suppressed)
- STILL_SUPPRESSED (logging was unsuccessful)

LogLimitStats counts the available bytes left for logging per source
location for the current logging window. It does not track actual source
locations; it is used as a value in m_source_locations.

Also exposes a SuppressionsActive() method so the logger can use
that in a later commit to prefix [*] to logs whenenever suppressions
are active.

Co-Authored-By: Niklas Gogge <n.goeggi@gmail.com>
Co-Authored-By: stickies-v <stickies-v@protonmail.com>

Github-Pull: #32604
Rebased-From: afb9e39ec5552e598a5febaa81820d5509b7c5d2
2025-08-20 11:37:48 +01:00
Eugene Siegel
4987c03531
test: Mark ~DebugLogHelper as noexcept(false)
We mark ~DebugLogHelper as noexcept(false) to be able to catch the
exception it throws. This lets us use it in test in combination with
BOOST_CHECK_THROW and BOOST_CHECK_NO_THROW to check that certain log
messages are (not) logged.

Co-Authored-By: Niklas Gogge <n.goeggi@gmail.com>

Github-Pull: #32604
Rebased-From: df7972a6cfd919b972bcbba07de85f7797898529
2025-08-20 11:37:17 +01:00
Chris Stewart
2b9738a083
test: Fix 'getdescriptoractivity' RPCHelpMan, add test to verify 'spend_vin' is the correct field
Github-Pull: #33119
Rebased-From: 3543bfdfec345cf2c952143c31674ef02de2a64b
2025-08-06 11:17:38 +01:00
0xb10c
4e8abca445
rpc: fix getpeerinfo ping duration unit docs
The getpeerinfo docs incorrectly specified the ping durations as
milliseconds. This was incorrectly changed in a3789c700b5a43efd4b366b4241ae840d63f2349
(released in v25; master since Sept. 2022). The correct duration unit
is seconds.

Also, remove the documentation of the getpeerinfo RPC response from the
ping RPC since it's incomplete. Better to just reference the getpeerinfo
RPC and it's documenation for this.

Github-Pull: #33133
Rebased-From: 1252eeb997df2eb12c33d92eb1a5c9d6643a67ff
2025-08-05 09:44:47 +01:00
Antoine Poinsot
0a4671d5eb
qa: unit test standardness of inputs packed with legacy sigops
Check bounds and different output types.

Github-Pull: bitcoin/bitcoin#32521
Rebased-From: 367147954d16c961bbd28c361abf27b4cb665f10
2025-07-18 16:51:54 -04:00
Antoine Poinsot
204b965915
policy: make pathological transactions packed with legacy sigops non-standard.
The Consensus Cleanup soft fork proposal includes a limit on the number of legacy signature
operations potentially executed when validating a transaction. If this change is to be implemented
here and activated by Bitcoin users in the future, we should prevent the ability for someone to
broadcast a transaction through the p2p network that is not valid according to the new rules. This
is because if it was possible it would be a trivial DoS to potentially unupgraded miners after the
soft fork activates.

We do not know for sure whether users will activate the Consensus Cleanup. However if they do such
transactions must have been made non-standard long in advance, due to the time it takes for most
nodes on the network to upgrade. In addition this limit may only be run into by pathological
transactions which pad the Script with sigops but do not use actual signatures when spending, as
otherwise they would run into the standard transaction size limit.

Github-Pull: bitcoin/bitcoin#32521
Rebased-From: 5863315e33ba9b75a1e5189ee3da3d7311bbf193
2025-07-18 16:51:53 -04:00
Jameson Lopp
58b1a65ab0
add more bad p2p ports
Github-Pull: #32826
Rebased-From: 6967e8e8abbc35ac98e8e3745a8bbed56e77526f
2025-07-04 16:35:35 +01:00
brunoerg
222fbfcc6a
test: check P2SH sigop count for coinbase tx
Github-Pull: #32850
Rebased-From: d6aaffcb11adcf47480fcc5081af9dcb732decf3
2025-07-03 11:58:03 +01:00
Antoine Poinsot
1c0e19b93a
node: cap -dbcache to 1GiB on 32-bit architectures
32-bit architecture is limited to 4GiB, so it doesn't make sense to set a too
high value. Since this setting is performance critical, pick an arbitrary value
higher than for -maxmempool but still reasonable.

Github-Pull: #32530
Rebased-From: 9f8e7b0b3b787b873045a4a8194e77d0b0a2b3b6
2025-06-26 17:36:06 +01:00
Antoine Poinsot
eafea2393d
init: cap -maxmempool to 500 MB on 32-bit systems
32-bit architecture is limited to 4GiB, so it doesn't make sense to set a too high value. 500 MB is
chosen as an arbitrary maximum value that seems reasonable.

Github-Pull: #32530
Rebased-From: 2c43b6adebbfabb3c8dd82fe821ce0a5d6173b3b
2025-06-26 17:36:02 +01:00
furszy
a18085a18b
wallet: fix crash on double block disconnection
The wallet crashes if it processes the same block disconnection event twice in a row due
to an incompatible coinbase transaction state.
This happens because 'disconnectBlock' provides 'TxStateInactive' without the "abandoned"
flag for coinbase transactions to 'SyncTransaction', while 'AddToWallet()' internally
modifies it to retain the abandoned state.

The flow is as follows:
1) On the first disconnection, the transaction state transitions from "confirmed" to
"inactive," bypassing the state equality check since the provided state differs. Then,
'AddToWallet' internally updates the state to "inactive + abandoned"

2) On the second disconnection, as we provide only the "inactive" state
to 'SyncTransaction()', the state equality assertion fails and crashes the wallet.

Github-Pull: #31757
Rebased-From: 9ef429b6ae65f6ad3e9ac11c2d9c0a6c52beb865
2025-06-19 10:39:27 +01:00
Hodlinator
27c533052c
doc, windows: CompanyName "Bitcoin" => "Bitcoin Core project"
Matches /share/setup.nsi.in:14

Github-Pull: #32719
Rebased-From: 239fc4d62e73511b3ef5117706d4c5131a921955
2025-06-19 10:39:27 +01:00
rkrux
78688c8413
rpc, doc: update listdescriptors RCP help
This RPC lists all the descriptors present in the wallet, not only
the ones that were imported, but also the ones generated when a
new wallet is created.

It can be verified by creating a new wallet and calling the
`listdescriptors` RPC, which will contain 8 ranged descriptors that
are created for every new wallet.

Github-Pull: #32708
Rebased-From: b44514b876333a94ae242da8b1e4cee439c2d37e
2025-06-10 11:31:10 +01:00
benthecarman
c899334e36
rpc: Note in fundrawtransaction doc, fee rate is for package
Github-Pull: #32607
Rebased-From: f98e1aaf34e347088caa54403521e3b5cb55dd40
2025-06-09 16:13:01 +01:00
nervana21
17b31fc802
doc: Add missing top-level description to pruneblockchain RPC
Previously, the `pruneblockchain` RPC help output included only the method signature and arguments, with no top-level description explaining its purpose or constraints.

This PR adds a concise top-level description, improving documentation consistency and alerting users to the potential impacts of using the command.

Github-Pull: #32333
Rebased-From: 135a0f0aa711b95c50aa4cbe0c38d82d647f1c8b
2025-05-29 12:15:57 +01:00
Hennadii Stepanov
142153ee42
cmake: Add missed SSE41_CXXFLAGS
Github-Pull: #32551
Rebased-From: 800b7cc42ca63f2a6b245a4d327c7092289da6e1
2025-05-22 14:55:42 +01:00
Ava Chow
25aa15ee7f
walletdb: Log the wallet version after it has been read from disk
Logging the wallet version before anything has been read from disk results
in the wrong version being logged.

Also split the last client version logging as it may not always be
present to be logged.

Github-Pull: #32553
Rebased-From: 359ecd3704993422eb53e3da2a7d0bea2f575ab0
2025-05-20 12:29:18 +01:00
fanquake
caec3cc41b
crypto: disable ASan for sha256_sse4 with Clang
This can alsofail to compile when optimisations are being used, see:
https://github.com/bitcoin/bitcoin/issues/31913.
So disable just ASan for this function under any optimisation level.

Github-Pull: #32437
Rebased-From: 4e8ab5e00fa72016a7ec0e0505ca025d4e59e4d8
2025-05-12 14:25:16 +01:00
monlovesmango
6ed087dede
doc: Fix test_bitcoin path
This commit fixes a couple command paths for interacting with the
test_bitcoin binary within the Unit Test documentation.

Github-Pull: #32389
Rebased-From: 6cbc28b8dd629062950f195facc009fd8ba86310
2025-05-06 18:04:28 +01:00