0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00
bitcoin-bitcoin-core/src
Samuel Dobson bdda137878
Merge #16766: wallet: Make IsTrusted scan parents recursively
4671fc3d9e Expand on wallet_balance.py comment from https://github.com/bitcoin/bitcoin/pull/16766\#issuecomment-527563982 (Jeremy Rubin)
91f3073f08 Update release notes to mention changes to IsTrusted and impact on wallet (Jeremy Rubin)
8f174ef112 Systematize style of IsTrusted single line if (Jeremy Rubin)
b49dcbedf7 update variable naming conventions for IsTrusted (Jeremy Rubin)
5ffe0d1449 Update comment in test/functional/wallet_balance.py (Jeremy Rubin)
a550c58267 Update wallet_balance.py test to reflect new behavior (Jeremy Rubin)
5dd7da4ccd Reuse trustedParents in looped calls to IsTrusted (Jeremy Rubin)
595f09d6de Cache tx Trust per-call to avoid DoS (Jeremy Rubin)
dce032ce29 Make IsTrusted scan parents recursively (Jeremy Rubin)

Pull request description:

  This slightly modifies the behavior of IsTrusted to recursively check the parents of a transaction. Otherwise, it's possible that a parent is not IsTrusted but a child is. If a parent is not trusted, then a child should not be either.

  This recursive scan can be a little expensive, so ~it might be beneficial to have a way of caching IsTrusted state, but this is a little complex because various conditions can change between calls to IsTrusted (e.g., re-org).~ I added a cache which works per call/across calls, but does not store the results semi-permanently. Which reduces DoS risk of this change. There is no risk of untrusted parents causing a resource exploitation, as we immediately return once that is detected.

  This is a change that came up as a bug-fix esque change while working on OP_SECURETHEBAG. You can see the branch where this change is important here: https://github.com/bitcoin/bitcoin/compare/master...JeremyRubin:stb-with-rpc?expand=1. Essentially, without this change, we can be tricked into accepting an OP_SECURETHEBAG output because we don't properly check the parents. As this was a change which, on its own, was not dependent on OP_SECURETHEBAG, I broke it out as I felt the change stands on its own by fixing a long standing wallet bug.

  The test wallet_balance.py has been corrected to meet the new behavior. The below comment, reproduced, explains what the issue is and the edge cases that can arise before this change.

          # Before `test_balance()`, we have had two nodes with a balance of 50
          # each and then we:
          #
          # 1) Sent 40 from node A to node B with fee 0.01
          # 2) Sent 60 from node B to node A with fee 0.01
          #
          # Then we check the balances:
          #
          # 1) As is
          # 2) With transaction 2 from above with 2x the fee
          #
          # Prior to #16766, in this situation, the node would immediately report
          # a balance of 30 on node B as unconfirmed and trusted.
          #
          # After #16766, we show that balance as unconfirmed.
          #
          # The balance is indeed "trusted" and "confirmed" insofar as removing
          # the mempool transactions would return at least that much money. But
          # the algorithm after #16766 marks it as unconfirmed because the 'taint'
          # tracking of transaction trust for summing balances doesn't consider
          # which inputs belong to a user. In this case, the change output in
          # question could be "destroyed" by replace the 1st transaction above.
          #
          # The post #16766 behavior is correct; we shouldn't be treating those
          # funds as confirmed. If you want to rely on that specific UTXO existing
          # which has given you that balance, you cannot, as a third party
          # spending the other input would destroy that unconfirmed.
          #
          # For example, if the test transactions were:
          #
          # 1) Sent 40 from node A to node B with fee 0.01
          # 2) Sent 10 from node B to node A with fee 0.01
          #
          # Then our node would report a confirmed balance of 40 + 50 - 10 = 80
          # BTC, which is more than would be available if transaction 1 were
          # replaced.

  The release notes have been updated to note the new behavior.

ACKs for top commit:
  ariard:
    Code Review ACK 4671fc3, maybe extend DoS protection in a follow-up PR.
  fjahr:
    Code review ACK 4671fc3d9e
  ryanofsky:
    Code review ACK 4671fc3d9e. Changes since last review: 2 new commits adding suggested release note and python test comment, also a clean rebase with no changes to the earlier commits. The PR description is more comprehensive now, too. Looks good!
  promag:
    Code review ACK 4671fc3d9e.

Tree-SHA512: 6b183ff425304fef49724290053514cb2770f4a2350dcb83660ef24af5c54f7c4c2c345b0f62bba60eb2d2f70625ee61a7fab76a7f491bb5a84be5c4cc86b92f
2019-11-05 21:59:27 +13:00
..
bench Merge #17349: Remove redundant copy constructors 2019-11-04 08:32:22 -05:00
compat compat: remove bswap_* check on macOS 2019-10-24 16:01:44 -04:00
config
consensus [validation] Remove fMissingInputs from AcceptToMemoryPool() 2019-10-29 15:46:45 -04:00
crypto Fix occurences of c_str() used with size() to data() 2019-10-28 13:41:45 +01:00
index Remove unused includes 2019-10-15 22:56:43 +00:00
interfaces Merge #17297: refactor: Remove addrdb.h dependency from node.h 2019-11-04 13:18:27 +01:00
leveldb Pull leveldb subtree 2019-01-26 12:45:48 -05:00
node doc: Fix some misspellings 2019-11-04 04:22:53 -05:00
policy refactor: Remove redundant c_str() calls in formatting 2019-10-28 13:31:33 +01:00
primitives Remove unused includes 2019-10-15 22:56:43 +00:00
qt Merge #17351: doc: Fix some misspellings 2019-11-04 08:03:48 -05:00
rpc Merge #17318: replace asserts in RPC code with CHECK_NONFATAL and add linter 2019-11-04 11:33:41 -05:00
script doc: Fix some misspellings 2019-11-04 04:22:53 -05:00
secp256k1 Update the secp256k1 subtree to the latest upstream version 2019-03-31 11:41:05 -07:00
support Improve documentation of memory_cleanse() 2019-07-01 12:59:44 +02:00
test test: Reset global args between test suites 2019-11-04 10:59:55 -05:00
univalue Update univalue subtree 2019-10-30 16:24:02 -04:00
util Merge #17285: doc: Bip70 removal follow-up 2019-11-02 14:47:41 +01:00
wallet Merge #16766: wallet: Make IsTrusted scan parents recursively 2019-11-05 21:59:27 +13:00
zmq Remove unused includes 2019-10-15 22:56:43 +00:00
.clang-format util: Add AllowShortCaseLabelsOnASingleLine option 2019-10-14 13:24:54 +03:00
addrdb.cpp addrdb: Remove temporary files created in SerializeFileDB. Fixes non-determinism in unit tests. 2019-06-14 08:30:43 +02:00
addrdb.h refactor: Remove addrdb.h dependency from node.h 2019-10-29 11:30:12 +02:00
addrman.cpp Make reasoning about dependencies easier by not including unused dependencies 2019-06-02 17:15:23 +02:00
addrman.h [addrman] Ensure collisions eventually get resolved 2019-02-27 16:53:44 -05:00
amount.h Update copyright headers to 2018 2018-12-29 10:15:01 +01:00
arith_uint256.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
arith_uint256.h Remove unused includes 2019-10-15 22:56:43 +00:00
attributes.h Add NODISCARD to all {Decode,Parse}[...](...) functions returning bool. Sort includes. 2018-11-05 17:03:11 +01:00
banman.cpp scripted-diff: Make translation bilingual 2019-07-24 16:33:20 +03:00
banman.h Merge #17297: refactor: Remove addrdb.h dependency from node.h 2019-11-04 13:18:27 +01:00
base58.cpp scripted-diff: Move util files to separate directory. 2018-11-04 22:46:07 -08:00
base58.h Add NODISCARD to all {Decode,Parse}[...](...) functions returning bool. Sort includes. 2018-11-05 17:03:11 +01:00
bech32.cpp Add some general std::vector utility functions 2019-10-16 08:56:57 -07:00
bech32.h Assert that the HRP is lowercase in Bech32::Encode 2019-09-05 13:25:11 +12:00
bitcoin-cli-res.rc
bitcoin-cli.cpp Merge #17302: cli: Add "headers" and "verificationprogress" to -getinfo 2019-10-30 12:38:31 +01:00
bitcoin-tx-res.rc
bitcoin-tx.cpp refactor: Remove redundant c_str() calls in formatting 2019-10-28 13:31:33 +01:00
bitcoin-wallet-res.rc [tools] Add wallet inspection and modification tool 2019-01-30 16:26:52 -05:00
bitcoin-wallet.cpp refactor: Remove redundant c_str() calls in formatting 2019-10-28 13:31:33 +01:00
bitcoind-res.rc
bitcoind.cpp Merge #16839: Replace Connman and BanMan globals with NodeContext local 2019-10-30 12:35:41 +01:00
blockencodings.cpp [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
blockencodings.h Remove unused includes 2019-10-15 22:56:43 +00:00
blockfilter.cpp init: Add CLI option to enable block filter index. 2019-04-06 12:10:55 -07:00
blockfilter.h init: Add CLI option to enable block filter index. 2019-04-06 12:10:55 -07:00
bloom.cpp refactor: Improve CRollingBloomFilter::reset by using std::fill 2019-05-22 15:55:50 +01:00
bloom.h p2p: Avoid allocating memory for addrKnown where we don't need it 2019-10-16 17:06:20 -04:00
chain.cpp refactor: combine Chain::findFirstBlockWithTime/findFirstBlockWithTimeAndHeight 2019-03-27 18:29:48 -04:00
chain.h chain: Set all CBlockIndex members to null, remove SetNull helper 2019-10-16 13:06:50 -04:00
chainparams.cpp Chainparams: Use name constants in chainparams initialization 2019-10-29 20:27:30 +01:00
chainparams.h doc: Remove explicit network name references 2019-11-01 12:06:35 +01:00
chainparamsbase.cpp Testchains: Generic selection with -chain=<str> in addition of -testnet and -regtest 2019-09-06 22:05:33 +02:00
chainparamsbase.h doc: Remove explicit network name references 2019-11-01 12:06:35 +01:00
chainparamsseeds.h contrib: Remove invalid nodes from seeds list 2019-10-02 08:51:12 +02:00
checkqueue.h
clientversion.cpp
clientversion.h
coins.cpp move-onlyish: move CCoinsViewErrorCatcher out of init.cpp 2019-07-21 21:00:31 -04:00
coins.h make SaltedOutpointHasher noexcept 2019-09-25 20:56:38 +02:00
compat.h windows: Set _WIN32_WINNT to 0x0601 (Windows 7) 2019-01-23 16:28:27 +08:00
compressor.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
compressor.h
core_io.h Move PSBT decoding functions from core_io to psbt.cpp 2019-03-26 17:38:00 -07:00
core_memusage.h
core_read.cpp Include core_io.h from core_read.cpp 2019-06-06 08:00:33 +02:00
core_write.cpp Don't show addresses or P2PK in decoderawtransaction 2019-08-30 11:29:21 +09:00
cuckoocache.h doc: Doxygen-friendly CuckooCache comments 2019-10-10 15:47:39 -04:00
dbwrapper.cpp Replace deprecated Boost Filesystem function 2019-04-30 10:05:54 +03:00
dbwrapper.h Remove unused includes 2019-10-15 22:56:43 +00:00
dummywallet.cpp scripted-diff: Rename InitInterfaces to NodeContext 2019-10-28 10:30:51 -04:00
flatfile.cpp Style cleanup. 2019-02-22 17:38:45 -08:00
flatfile.h Style cleanup. 2019-02-22 17:38:45 -08:00
fs.cpp Fix occurences of c_str() used with size() to data() 2019-10-28 13:41:45 +01:00
fs.h Replace deprecated Boost Filesystem function 2019-04-30 10:05:54 +03:00
hash.cpp Extract CSipHasher to it's own file in crypto/ directory. 2018-11-05 09:25:15 -08:00
hash.h Squashed 'src/secp256k1/' changes from 0b70241850..b19c000063 2019-03-31 11:41:05 -07:00
httprpc.cpp Fix occurences of c_str() used with size() to data() 2019-10-28 13:41:45 +01:00
httprpc.h Remove unused includes 2019-10-15 22:56:43 +00:00
httpserver.cpp http: add missing header bootlegged by boost < 1.72 2019-10-25 13:11:09 +00:00
httpserver.h Remove unused includes 2019-10-15 22:56:43 +00:00
indirectmap.h
init.cpp Merge #17286: Fix help-debug -checkpoints 2019-11-01 11:41:45 +01:00
init.h Pass NodeContext, ConnMan, BanMan references more places 2019-10-28 10:30:51 -04:00
key.cpp Make reasoning about dependencies easier by not including unused dependencies 2019-06-02 17:15:23 +02:00
key.h refactor: Remove unused CExt{Pub,}Key (de)serialization methods 2019-10-22 00:07:31 +02:00
key_io.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
key_io.h
limitedmap.h
logging.cpp util: Filter control characters out of log messages 2019-10-15 10:53:17 +02:00
logging.h Replace the LogPrint function with a macro 2019-10-22 13:44:51 -07:00
Makefile.am Merge #17297: refactor: Remove addrdb.h dependency from node.h 2019-11-04 13:18:27 +01:00
Makefile.bench.include Merge #17292: Add new mempool benchmarks for a complex pool 2019-11-01 18:08:41 -04:00
Makefile.leveldb.include build: Remove WINVER pre define in Makefile.leveldb.inlcude 2019-01-26 09:28:48 +08:00
Makefile.qt.include Remove BIP70 Support 2019-10-24 16:01:43 -04:00
Makefile.qt_locale.include qt: Periodic translations update 2019-09-30 09:41:11 +02:00
Makefile.qttest.include Remove BIP70 Support 2019-10-24 16:01:43 -04:00
Makefile.test.include test: move-only ComputeFilter to src/test/lib/blockfilter 2019-10-30 13:19:30 -04:00
memusage.h
merkleblock.cpp Make reasoning about dependencies easier by not including unused dependencies 2019-06-02 17:15:23 +02:00
merkleblock.h
miner.cpp [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
miner.h [rpc] mining: Omit uninitialized currentblockweight, currentblocktx 2019-02-12 11:34:57 -05:00
net.cpp Merge #17164: p2p: Avoid allocating memory for addrKnown where we don't need it 2019-11-04 11:17:20 -05:00
net.h Merge #17164: p2p: Avoid allocating memory for addrKnown where we don't need it 2019-11-04 11:17:20 -05:00
net_permissions.cpp util: Move ResolveErrMsg to util/error 2019-08-15 10:05:32 -04:00
net_permissions.h Make whitebind/whitelist permissions more flexible 2019-08-11 11:33:27 +09:00
net_processing.cpp Merge #17164: p2p: Avoid allocating memory for addrKnown where we don't need it 2019-11-04 11:17:20 -05:00
net_processing.h [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
net_types.h refactor: Remove addrdb.h dependency from node.h 2019-10-29 11:30:12 +02:00
netaddress.cpp Fix spelling errors identified by codespell 1.15.0 2019-06-11 17:18:16 +02:00
netaddress.h Remove unused includes 2019-10-15 22:56:43 +00:00
netbase.cpp doc: Fix some misspellings 2019-11-04 04:22:53 -05:00
netbase.h util: refactor upper/lowercase functions 2019-08-08 11:35:14 +09:00
netmessagemaker.h
noui.cpp refactor: Remove redundant c_str() calls in formatting 2019-10-28 13:31:33 +01:00
noui.h Suppress output in test_bitcoin for expected errors 2019-07-03 14:03:21 +02:00
optional.h Remove 'boost::optional'-related gcc warnings 2019-01-30 22:44:28 +02:00
outputtype.cpp Add some general std::vector utility functions 2019-10-16 08:56:57 -07:00
outputtype.h Move various SigningProviders to signingprovider.{cpp,h} 2019-07-09 16:20:18 -04:00
pow.cpp
pow.h
prevector.h Remove unused includes 2019-10-15 22:56:43 +00:00
protocol.cpp p2p: Remove BIP61 reject messages 2019-10-02 10:39:14 -04:00
protocol.h Remove unused includes 2019-10-15 22:56:43 +00:00
psbt.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
psbt.h refactor: Remove redundant PSBT copy constructor 2019-11-01 18:12:57 -04:00
pubkey.cpp
pubkey.h refactor: Remove unused CExt{Pub,}Key (de)serialization methods 2019-10-22 00:07:31 +02:00
random.cpp random: remove call to RAND_screen() (Windows only) 2019-10-18 14:24:21 -04:00
random.h Add assertion to randrange that input is not 0 2019-10-28 16:42:39 -07:00
rest.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
reverse_iterator.h
reverselock.h
scheduler.cpp Switch all RNG code to the built-in PRNG. 2019-01-16 16:34:56 -08:00
scheduler.h trivial: correct parameter name in comments 2019-02-10 17:17:32 -05:00
serialize.h Remove unused includes 2019-10-15 22:56:43 +00:00
shutdown.cpp
shutdown.h
span.h
streams.h Remove unused includes 2019-10-15 22:56:43 +00:00
sync.cpp refactor: Remove redundant c_str() calls in formatting 2019-10-28 13:31:33 +01:00
sync.h refactor: consolidate PASTE macros 2019-09-25 10:56:00 -04:00
threadinterrupt.cpp
threadinterrupt.h Remove unused includes 2019-10-15 22:56:43 +00:00
threadsafety.h Move LockAnnotation from threadsafety.h (imported code) to sync.h (our code) 2019-05-17 13:29:04 +02:00
timedata.cpp scripted-diff: Make translation bilingual 2019-07-24 16:33:20 +03:00
timedata.h
tinyformat.h tinyformat: Add doc to Bitcoin Core specific strprintf 2019-06-13 09:30:40 -04:00
torcontrol.cpp fix: tor: Call event_base_loopbreak from the event's callback 2019-07-17 15:32:38 +01:00
torcontrol.h Remove unused includes 2019-10-15 22:56:43 +00:00
txdb.cpp Add some general std::vector utility functions 2019-10-16 08:56:57 -07:00
txdb.h Remove unused includes 2019-10-15 22:56:43 +00:00
txmempool.cpp Merge #17316: refactor: Replace all uses of boost::optional with our own Optional type 2019-10-30 14:20:17 -04:00
txmempool.h refactor: Replace all uses of boost::optional with our own Optional type 2019-10-30 14:27:31 +01:00
ui_interface.cpp Merge #16092: Don't use global (external) symbols for symbols that are used in only one translation unit 2019-06-18 15:59:53 -04:00
ui_interface.h Remove unused includes 2019-10-15 22:56:43 +00:00
uint256.cpp Remove unused includes 2019-10-15 22:56:43 +00:00
uint256.h Remove unused includes 2019-10-15 22:56:43 +00:00
undo.h Extract CSipHasher to it's own file in crypto/ directory. 2018-11-05 09:25:15 -08:00
validation.cpp doc: Fix some misspellings 2019-11-04 04:22:53 -05:00
validation.h [validation] Remove fMissingInputs from AcceptToMemoryPool() 2019-10-29 15:46:45 -04:00
validationinterface.cpp [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
validationinterface.h [validation] Add CValidationState subclasses 2019-10-29 15:46:45 -04:00
version.h
versionbits.cpp doc: Improve versionbits.h documentation 2019-08-15 11:02:55 -04:00
versionbits.h doc: Improve versionbits.h documentation 2019-08-15 11:02:55 -04:00
versionbitsinfo.cpp [Consensus] Bury segwit deployment 2019-08-14 15:52:52 -04:00
versionbitsinfo.h MOVEONLY: Move versionbits info out of versionbits.o 2018-09-23 22:55:11 +02:00
walletinitinterface.h scripted-diff: Rename InitInterfaces to NodeContext 2019-10-28 10:30:51 -04:00
warnings.cpp scripted-diff: Make translation bilingual 2019-07-24 16:33:20 +03:00
warnings.h Remove unused includes 2019-10-15 22:56:43 +00:00