0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-04 10:07:27 -05:00
bitcoin-bitcoin-core/src
Andrew Chow 80fc1af096
Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors
47c4b1f52a mempool: log/halt when CalculateMemPoolAncestors fails unexpectedly (stickies-v)
5481f65849 mempool: add AssumeCalculateMemPoolAncestors helper function (stickies-v)
f911bdfff9 mempool: use util::Result for CalculateMemPoolAncestors (stickies-v)
66e028f739 mempool: use util::Result for CalculateAncestorsAndCheckLimits (stickies-v)

Pull request description:

  Upon reviewing the documentation for `CTxMemPool::CalculateMemPoolAncestors`, I noticed `setAncestors` was meant to be an `out` parameter but actually is an `in,out` parameter, as can be observed by adding `assert(setAncestors.empty());` as the first line in the function and running `make check`. This PR fixes this unexpected behaviour and introduces refactoring improvements to make intents and effects of the code more clear.

  ## Unexpected behaviour
  This behaviour occurs only in the package acceptance path, currently only triggered by `testmempoolaccept` and `submitpackage` RPCs.

  In `MemPoolAccept::AcceptMultipleTransactions()`, we first call `PreChecks()` and then `SubmitPackage()` with the same `Workspace ws` reference. `PreChecks` leaves `ws.m_ancestors` in a potentially non-empty state, before it is passed on to `MemPoolAccept::SubmitPackage`. `SubmitPackage` is the only place where `setAncestors` isn't guaranteed to be empty before calling `CalculateMemPoolAncestors`. The most straightforward fix is to just forcefully clear `setAncestors` at the beginning of CalculateMemPoolAncestors, which is done in the first bugfix commit.

  ## Improvements
  ### Return value instead of out-parameters
  This PR updates the function signatures for `CTxMemPool::CalculateMemPoolAncestors` and `CTxMemPool::CalculateAncestorsAndCheckLimits` to use a `util::Result` return type and eliminate both the `setAncestors` `in,out`-parameter as well as the error string. It simplifies the code and makes the intent and effects more explicit.

  ### Observability
  There are 7 instances where we currently call `CalculateMemPoolAncestors` without actually checking if the function succeeded because we assume that it can't fail, such as in [miner.cpp](69b10212ea/src/node/miner.cpp (L399)). This PR adds a new wrapper `AssumeCalculateMemPoolAncestors` function that logs such unexpected failures, or in case of debug builds even halts the program. It's not crucial to the objective, more of an observability improvement that seems sensible to add on here.

ACKs for top commit:
  achow101:
    ACK 47c4b1f52a
  w0xlt:
    ACK 47c4b1f52a
  glozow:
    ACK 47c4b1f52a
  furszy:
    light code review ACK 47c4b1f5
  aureleoules:
    ACK 47c4b1f52a

Tree-SHA512: d908dad00d1a5645eb865c4877cc0bae74b9cd3332a3641eb4a285431aef119f9fc78172d38b55c592168a73dae83242e6af3348815f7b37cbe2d448a3a58648
2023-01-03 16:30:55 -05:00
..
bench Merge bitcoin/bitcoin#26481: bench: Suppress output when running with -sanity-check option 2022-12-29 11:42:03 +01:00
common scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
compat scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
config
consensus scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
crc32c Update crc32c subtree to latest upstream master 2022-08-13 13:55:38 +01:00
crypto scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
index scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
init scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
interfaces scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
ipc scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
kernel refactor: Move txmempool_entry.h --> kernel/mempool_entry.h 2022-11-30 10:37:57 +00:00
leveldb Update leveldb-subtree subtree to latest upstream 2022-09-29 16:43:30 +01:00
logging scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
minisketch Update minisketch subtree to latest upstream 2022-10-23 15:03:04 +01:00
node Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
policy Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
primitives scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
qt scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
rpc Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
script scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
secp256k1
support scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
test Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
univalue scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
util scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
wallet Merge bitcoin/bitcoin#26192: rpc: Improve error when wallet is already loaded 2023-01-03 13:02:20 -05:00
zmq scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
.bear-tidy-config
.clang-format
.clang-tidy Merge bitcoin/bitcoin#25872: Fix issues when calling std::move(const&) 2022-08-31 08:38:24 +01:00
addrdb.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
addrdb.h
addrman.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
addrman.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
addrman_impl.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
arith_uint256.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
arith_uint256.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
attributes.h
banman.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
banman.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
base58.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
base58.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bech32.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bech32.h
bitcoin-chainstate.cpp scripted-diff: rename CChainState -> Chainstate 2022-09-09 11:47:27 -04:00
bitcoin-cli-res.rc
bitcoin-cli.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bitcoin-tx-res.rc
bitcoin-tx.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bitcoin-util-res.rc
bitcoin-util.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bitcoin-wallet-res.rc
bitcoin-wallet.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bitcoind-res.rc
bitcoind.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
blockencodings.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
blockencodings.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
blockfilter.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
blockfilter.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
chain.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
chain.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
chainparams.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
chainparams.h
chainparamsbase.cpp
chainparamsbase.h
chainparamsseeds.h Merge bitcoin/bitcoin#25853: net: update testnet torv3 hardcoded seeds for 24.x 2022-09-09 10:07:39 +02:00
checkqueue.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
clientversion.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
clientversion.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
coins.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
coins.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
compressor.cpp
compressor.h
core_io.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
core_memusage.h
core_read.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
core_write.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
cuckoocache.h validationcaches: Use size_t for sizes 2022-08-03 12:03:28 -04:00
dbwrapper.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
dbwrapper.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
deploymentinfo.cpp
deploymentinfo.h
deploymentstatus.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
deploymentstatus.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
dummywallet.cpp
external_signer.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
external_signer.h
flatfile.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
flatfile.h
fs.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
fs.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
hash.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
hash.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
headerssync.cpp Move headerssync logging to BCLog::NET 2022-08-30 12:09:04 -04:00
headerssync.h Track headers presync progress and log it 2022-08-29 08:10:35 -04:00
httprpc.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
httprpc.h
httpserver.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
httpserver.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
i2p.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
i2p.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
indirectmap.h
init.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
init.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
key.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
key.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
key_io.cpp
key_io.h
logging.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
logging.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
Makefile.am Merge bitcoin/bitcoin#26298: refactor: Move src/interfaces/*.cpp files to libbitcoin_common.a 2022-12-07 14:54:23 +00:00
Makefile.bench.include Merge bitcoin/bitcoin#16981: Improve runtime performance of --reindex 2022-11-15 19:23:39 -05:00
Makefile.crc32c.include
Makefile.leveldb.include
Makefile.minisketch.include
Makefile.qt.include build: extract $(BOOST_CPPFLAGS) from $(BITCOIN_INCLUDES) 2022-09-13 17:15:17 +01:00
Makefile.qt_locale.include
Makefile.qttest.include build: extract $(BOOST_CPPFLAGS) from $(BITCOIN_INCLUDES) 2022-09-13 17:15:17 +01:00
Makefile.test.include Merge bitcoin/bitcoin#25789: test: clean and extend availablecoins_tests coverage 2023-01-03 12:52:40 -05:00
Makefile.test_fuzz.include [fuzz] Move ConsumeNetAddr to fuzz/util/net.h 2022-11-17 14:52:45 +00:00
Makefile.test_util.include refactor: unify test/util/wallet.h with wallet/test/util.h 2022-11-21 17:30:00 -03:00
Makefile.univalue.include
mapport.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
mapport.h
memusage.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
merkleblock.cpp
merkleblock.h
net.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net_permissions.cpp
net_permissions.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net_processing.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net_processing.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net_types.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
net_types.h
netaddress.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
netaddress.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
netbase.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
netbase.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
netgroup.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
netgroup.h
netmessagemaker.h
noui.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
noui.h
outputtype.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
outputtype.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
pow.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
pow.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
prevector.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
protocol.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
protocol.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
psbt.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
psbt.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
pubkey.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
pubkey.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
random.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
random.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
randomenv.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
randomenv.h
rest.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
rest.h
reverse_iterator.h
scheduler.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
scheduler.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
serialize.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
shutdown.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
shutdown.h
signet.cpp
signet.h
span.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
streams.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
sync.cpp
sync.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
threadsafety.h
timedata.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
timedata.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
tinyformat.h clang-tidy: Fix modernize-use-nullptr in headers 2022-12-15 20:58:19 +00:00
torcontrol.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
torcontrol.h
txdb.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
txdb.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
txmempool.cpp Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
txmempool.h Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
txorphanage.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
txorphanage.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
txrequest.cpp
txrequest.h
uint256.cpp
uint256.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
undo.h
validation.cpp Merge bitcoin/bitcoin#26289: Use util::Result in for calculating mempool ancestors 2023-01-03 16:30:55 -05:00
validation.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
validationinterface.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
validationinterface.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
version.h
versionbits.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
versionbits.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
walletinitinterface.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
warnings.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
warnings.h