Commit graph

38827 commits

Author SHA1 Message Date
fanquake
f1a9fd627b
Merge bitcoin/bitcoin#28251: validation: fix coins disappearing mid-package evaluation
32c1dd1ad6 [test] mempool coins disappearing mid-package evaluation (glozow)
a67f460c3f [refactor] split setup in mempool_limit test (glozow)
d08696120e [test framework] add ability to spend only confirmed utxos (glozow)
3ea71feb11 [validation] don't LimitMempoolSize in any subpackage submissions (glozow)
d227b7234c [validation] return correct result when already-in-mempool tx gets evicted (glozow)
9698b81828 [refactor] back-fill results in AcceptPackage (glozow)
8ad7ad3392 [validation] make PackageMempoolAcceptResult members mutable (glozow)
03b87c11ca [validation] add AcceptSubPackage to delegate Accept* calls and clean up m_view (glozow)
3f01a3dab1 [CCoinsViewMemPool] track non-base coins and allow Reset (glozow)
7d7f7a1189 [policy] check for duplicate txids in package (glozow)

Pull request description:

  While we are evaluating a package, we split it into "subpackages" for evaluation (currently subpackages all have size 1 except the last one). If a subpackage has size 1, we may add a tx to mempool and call `LimitMempoolSize()`, which evicts transactions if the mempool gets full. We handle the case where the just-submitted transaction is evicted immediately, but we don't handle the case in which a transaction from a previous subpackage (either just submitted or already in mempool) is evicted. Mainly, since the coins created by the evicted transaction are cached in `m_view`, we don't realize the UTXO has disappeared until `CheckInputsFromMempoolAndCache` asserts that they exist. Also, the returned `PackageMempoolAcceptResult` reports that the transaction is in mempool even though it isn't anymore.

  Fix this by not calling `LimitMempoolSize()` until the very end, and editing the results map with "mempool full" if things fall out.

  Pointed out by instagibbs in faeed687e5 on top of the v3 PR.

ACKs for top commit:
  instagibbs:
    reACK 32c1dd1ad6

Tree-SHA512: 61e7f69db4712e5e5bfa27d037ab66bdd97f1bf60a8d9ffb96adb1f0609af012c810d681102ee5c7baec7b5fe8cb7c304a60c63ccc445d00d86a2b7f0e7ddb90
2023-09-13 17:51:00 +01:00
glozow
32c1dd1ad6 [test] mempool coins disappearing mid-package evaluation
Test for scenario(s) outlined in PR 28251.
Test what happens when a package transaction spends a mempool coin which
is fetched and then disappears mid-package evaluation due to eviction or
replacement.
2023-09-13 16:14:18 +01:00
glozow
a67f460c3f [refactor] split setup in mempool_limit test
We want to be able to re-use fill_mempool so that none of the tests
affect each other.

Change the logs from info to debug because they are otherwise repeated
many times in the test output.
2023-09-13 16:14:18 +01:00
glozow
d08696120e [test framework] add ability to spend only confirmed utxos
Useful to ensure that the topologies of packages/transactions are as
expected, preventing bugs caused by having unexpected mempool ancestors.
2023-09-13 16:14:18 +01:00
glozow
3ea71feb11 [validation] don't LimitMempoolSize in any subpackage submissions
Don't do any mempool evictions until package validation is done,
preventing the mempool minimum feerate from changing. Whether we submit
transactions separately or as a package depends on whether they meet the
mempool minimum feerate threshold, so it's best that the value not
change while we are evaluating a package.
This avoids a situation where we have a CPFP package in which
the parents meet the mempool minimum feerate and are submitted by
themselves, but they are evicted before we have submitted the child.
2023-09-13 16:14:18 +01:00
glozow
d227b7234c [validation] return correct result when already-in-mempool tx gets evicted
Bug fix: a transaction may be in the mempool when package evaluation
begins (so it is added to results_final with MEMPOOL_ENTRY or
DIFFERENT_WITNESS), but get evicted due to another transaction
submission.
2023-09-13 16:14:17 +01:00
glozow
9698b81828 [refactor] back-fill results in AcceptPackage
Instead of populating the last PackageMempoolAcceptResult with stuff
from results_final and individual_results_nonfinal, fill results_final
and create a PackageMempoolAcceptResult using that one.

A future commit will add LimitMempoolSize() which may change the status
of each of these transactions from "already in mempool" or "submitted to
mempool" to "no longer in mempool". We will change those transactions'
results here.

A future commit also gets rid of the last AcceptSubPackage outside of
the loop. It makes more sense to use results_final as the place where
all results end up.
2023-09-13 16:14:17 +01:00
glozow
8ad7ad3392 [validation] make PackageMempoolAcceptResult members mutable
After the PackageMempoolAcceptResult is returned from
AcceptMultipleTransactions, leave room for results to change due to
LimitMempool() eviction.
2023-09-13 16:14:17 +01:00
glozow
03b87c11ca [validation] add AcceptSubPackage to delegate Accept* calls and clean up m_view
(1) Call AcceptSingleTransaction when there is only 1 transaction in the
  subpackage. This avoids calling PackageMempoolChecks() which enforces
rules that don't need to be applied for a single transaction, i.e.
disabling CPFP carve out.
There is a slight change in the error type returned, as shown in the
txpackage_tests change.  When a transaction is the last one left in the
package and its fee is too low, this returns a PCKG_TX instead of
PCKG_POLICY. This interface is clearer; "package-fee-too-low" for 1
transaction would be a bit misleading.

(2) Clean up m_view and m_viewmempool so that coins created in this
sub-package evaluation are not available for other sub-package
evaluations. The contents of the mempool may change, so coins that are
available now might not be later.
2023-09-13 16:14:17 +01:00
glozow
3f01a3dab1 [CCoinsViewMemPool] track non-base coins and allow Reset
Temporary coins should not be available in separate subpackage submissions.
Any mempool coins that are cached in m_view should be removed whenever
mempool contents change, as they may be spent or no longer exist.
2023-09-13 16:14:17 +01:00
glozow
7d7f7a1189 [policy] check for duplicate txids in package
Duplicates of normal transactions would be found by looking for
conflicting inputs, but this doesn't catch identical empty transactions.
These wouldn't be valid but exiting early is good and AcceptPackage's
result sanity checks assume non-duplicate transactions.
2023-09-13 16:14:17 +01:00
MarcoFalke
fad52baf1e
fuzz: Rework addr fuzzing
* Replace ConsumeDeserializationParams with V1, because V2 is
  unconditionally checked as well.
* Also fuzz CAddress::Format::Disk in the address_deserialize fuzz
  target.
2023-09-13 16:12:51 +02:00
MarcoFalke
fa5b6d29ee
fuzz: Drop unused params from serialize helpers
With the ser-type and ser-version going away, it seems unlikely that
there is need for them in the future, so just remove them.
2023-09-13 16:09:23 +02:00
glozow
4313c77400 make DisconnectedBlockTransactions responsible for its own memory management
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
2023-09-13 13:03:38 +01:00
glozow
cf5f1faa03 MOVEONLY: DisconnectedBlockTransactions to its own file
This struct is only used in validation + tests and has very little to do
with txmempool.
2023-09-13 13:01:59 +01:00
glozow
2765d6f343 rewrite DisconnectedBlockTransactions as a list + map
And encapsulate underlying data structures to avoid misuse.
It's better to use stdlib instead of boost when we can achieve the same thing.

Behavior change: the number returned by DynamicMemoryUsage for the same
transactions is higher (due to change in usage or more accurate
accounting), which effectively decreases the maximum amount of
transactions kept for resubmission in a reorg.

Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
2023-09-13 13:01:39 +01:00
MarcoFalke
fa23c9aa7c
ci: clang-17 for fuzz and tsan 2023-09-13 13:35:39 +02:00
Pieter Wuille
3fcd7fc7ff Do not use std::vector = {} to release memory 2023-09-13 07:20:36 -04:00
glozow
79ce9f0aa4 add std::list to memusage 2023-09-13 11:37:45 +01:00
glozow
59a35a7398 [bench] DisconnectedBlockTransactions 2023-09-13 11:37:13 +01:00
TheCharlatan
d506765199
[refactor] Remove compat.h from kernel headers
This commit makes compat.h no longer a required include for users of the
libbitcoinkernel. Including compat.h imports a bunch of
platform-specific definitions.

This commit is part of the libbitcoinkernel project, namely its stage 1
step 3: Decouple most non-consensus headers from libbitcoinkernel.
2023-09-12 22:51:48 +02:00
TheCharlatan
36193af47c
[refactor] Remove netaddress.h from kernel headers
Move functions requiring the netaddress.h include out of
libbitcoinkernel source files.

The netaddress.h file contains many non-consensus related definitions
and should thus not be part of the libbitcoinkernel. This commit makes
netaddress.h no longer a required include for users of the
libbitcoinkernel.

This commit is part of the libbitcoinkernel project, namely its stage 1
step 3: Decouple most non-consensus headers from libbitcoinkernel.
2023-09-12 22:51:46 +02:00
TheCharlatan
2b08c55f01
[refactor] Add CChainParams member to CConnman
This is done in preparation to the next commit, but has the nice
effect of removing one further data structure relying on the global
`Params()`.
2023-09-12 22:51:45 +02:00
TheCharlatan
f0d1d8b35c
[refactor] Add missing includes for next commit 2023-09-12 22:51:42 +02:00
TheCharlatan
534b314a74
kernel: Move MessageStartChars to its own file
The protocol.h file contains many non-consensus related definitions and
should thus not be part of the libbitcoinkernel. This commit makes
protocol.h no longer a required include for users of the
libbitcoinkernel.

This commit is part of the libbitcoinkernel project, namely its stage 1
step 3: Decouple most non-consensus headers from libbitcoinkernel.

Co-Authored-By: Cory Fields <cory-nospam-@coryfields.com>
2023-09-12 22:51:38 +02:00
TheCharlatan
9be330b654
[refactor] Define MessageStartChars as std::array 2023-09-12 22:49:49 +02:00
MarcoFalke
37e2b01113
[refactor] Allow std::array<std::byte, N> in serialize.h
This is already possible for C-style arrays, so allow it for C++11
std::array as well.
2023-09-12 22:44:28 +02:00
Andrew Chow
adc0921ea1
Merge bitcoin/bitcoin#28101: doc, refactor: changing -torcontrol help to specify that a default port is used
9a84200cfc doc, refactor: Changing -torcontrol help to specify that a default port is used (kevkevin)

Pull request description:

  Right now when we get the help for -torcontrol it says that there is a default ip and port we dont specify if there is a specified ip that we would also use port 9051 as default

  Also I create a new const instead of using 9051 directly in the function

  linking this PR because this was discussed here https://github.com/bitcoin/bitcoin/pull/28018

ACKs for top commit:
  jonatack:
    re-ACK 9a84200cfc
  achow101:
    ACK 9a84200cfc
  MarnixCroes:
    utACK 9a84200cfc
  kristapsk:
    utACK 9a84200cfc

Tree-SHA512: 21d9e65f3c280a2853a9cf60d4e93e8d72caccea106206d1862c19535bde7ea6ada7f55e6ea19a1fc0f59dbe791ec6fc4084fdbe7fa6d6991fa89c62070db637
2023-09-12 12:41:30 -04:00
Andrew Chow
8f9c74cb11
Merge bitcoin/bitcoin#28414: wallet rpc: return final tx hex from walletprocesspsbt if complete
2e249b9227 doc: add release note for PR #28414 (Matthew Zipkin)
4614332fc4 test: remove unnecessary finalizepsbt rpc calls (ismaelsadeeq)
e3d484b603 wallet rpc: return final tx hex from walletprocesspsbt if complete (Matthew Zipkin)

Pull request description:

  See https://github.com/bitcoin/bitcoin/pull/28363#discussion_r1315753887

  `walletprocesspsbt` currently returns a base64-encoded PSBT and a boolean indicating if the tx is "complete". If it is complete, the base64 PSBT can be finalized with `finalizepsbt` which returns the hex-encoded transaction suitable for `sendrawtransaction`.

  With this patch, `walletprocesspsbt` return object will ALSO include the broadcast-able hex string if the tx is already final. This saves users the extra step of calling `finalizepsbt` assuming they have already inspected and approve the transaction from earlier steps.

ACKs for top commit:
  ismaelsadeeq:
    re ACK 2e249b9227
  BrandonOdiwuor:
    re ACK 2e249b9
  Randy808:
    Tested ACK 2e249b9227
  achow101:
    ACK 2e249b9227
  ishaanam:
    ACK 2e249b9227

Tree-SHA512: 229c1103265a9b4248f080935a7ad5607c3be3f9a096a9ab6554093b2cd8aa8b4d1fa55b1b97d3925ba208dbc3ccba4e4d37c40e1491db0d27ba3d9fe98f931e
2023-09-12 12:28:13 -04:00
Andrew Chow
ad0c469d98 wallet: Use CTxDestination in CRecipient rather than scriptPubKey 2023-09-12 12:14:31 -04:00
Andrew Chow
07d3bdf4eb Add PubKeyDestination for P2PK scripts
P2PK scripts are not PKHash destinations, they should have their own
type.

This also results in no longer showing a p2pkh address for p2pk outputs.
However for backwards compatibility, ListCoinst will still do this
conversion.
2023-09-12 12:14:31 -04:00
Andrew Chow
1a98a51c66 Allow CNoDestination to represent a raw script
Even if a script is not a standard destination type, it can still be
useful to have a CTxDestination that stores the script.
2023-09-12 12:14:31 -04:00
Andrew Chow
8dd067088d Make WitnessUnknown members private
Make sure that nothing else can change WitnessUnknown's data members by
making them private. Also change the program to use a vector rather than
C-style array.
2023-09-12 12:14:31 -04:00
dergoegge
97e2e1d641 [fuzz] Use afl++ shared-memory fuzzing
Using shared-memory is faster than reading from stdin, see
7d2122e059/instrumentation/README.persistent_mode.md
2023-09-12 15:07:07 +01:00
fanquake
7649431637
Merge bitcoin/bitcoin#28105: doc: Clarify that -fstack-reuse=all bugs exist on all versions of GCC
fabb419a3c doc: Clarify that -fstack-reuse=all bugs exist on all versions of GCC (MarcoFalke)

Pull request description:

  This is a follow-up to commit 7b850bc2a1. While the test case no longer reproduces, the general class of `-fstack-reuse` bugs still exists in all versions of GCC. The workaround can never be removed, unless the whole class of bugs is fixed.

ACKs for top commit:
  fanquake:
    ACK fabb419a3c

Tree-SHA512: 566e14fe82d13dda4f7b8cca90c6de75006d14828906b936780716d5b5b31de9b36a904aa7cfc9820ccdfb4d3224a8437f502f25f7230da5abe87c927123f0c8
2023-09-12 15:00:25 +01:00
fanquake
578f50fc48
Merge bitcoin/bitcoin#28448: rpc: Deprecate rpcserialversion=0
971bae9174 rpc: Deprecate rpcserialversion=0 (Anthony Towns)

Pull request description:

  This option was introduced in #9194 to ease the transition to segwit; now that most libraries and apps have been updated it should no longer be necessary.

ACKs for top commit:
  MarcoFalke:
    review ACK 971bae9174
  Randy808:
    Code Review ACK 971bae9174
  glozow:
    ACK 971bae9174, seems appropriate to remove. Thanks for looking at usage in https://github.com/bitcoin/bitcoin/pull/28448#issuecomment-1714699556

Tree-SHA512: 6880314504281e9d7c288bd159f8cadefb3e653ac2dd148396810f7f5a27ba352ecfe720eb2dbc6172b57820cb9a2a254dcb2585881abae43811013505f0e09a
2023-09-12 14:26:57 +01:00
MarcoFalke
fabb419a3c
doc: Clarify that -fstack-reuse=all bugs exist on all versions of GCC 2023-09-12 13:41:19 +02:00
MarcoFalke
fa19c914f7
scripted-diff: Rename CBufferedFile to BufferedFile
While touching all constructors in the previous commit, the class name
can be adjusted to comply with the style guide.

-BEGIN VERIFY SCRIPT-
 sed -i 's/CBufferedFile/BufferedFile/g' $( git grep -l CBufferedFile )
-END VERIFY SCRIPT-
2023-09-12 12:55:29 +02:00
MarcoFalke
fa2f2413b8
Remove unused GetType() from CBufferedFile and CAutoFile
GetType() is only called in tests, so it is unused and can be removed.
2023-09-12 12:35:13 +02:00
TheCharlatan
5c2b3cd4b8 dbwrapper: Use DataStream for batch operations 2023-09-12 12:07:39 +02:00
fanquake
fd69ffbbfb
Merge bitcoin/bitcoin#28427: index: coinstats reorg, fail when block cannot be reversed
c0bf667912 index: add [nodiscard] attribute to functions writing to the db (furszy)
eef595560e index: coinstats reorg, fail when block cannot be reversed (furszy)

Pull request description:

  Found it while reviewing https://github.com/bitcoin/bitcoin/pull/24230#discussion_r1310863359.

  During a reorg, continuing execution when a block cannot be reversed leaves the
  coinstats index in an inconsistent state.
  This was surely overlooked when 'CustomRewind' was implemented.

ACKs for top commit:
  ryanofsky:
    Code review ACK c0bf667912. Only change since last review is new commit adding [[nodiscard]]

Tree-SHA512: f4fc8522508d23e4fff09a29c935971819b1bd3b2a260e08e2e2b72f9340980d74fbec742a58fe216baf61d27de057c7c8300e8fa075f8507cd1227f128af909
2023-09-12 09:44:55 +01:00
Hennadii Stepanov
befb42f146
qt: Silence -Wcast-function-type warning
Required for https://github.com/bitcoin/bitcoin/pull/25972.
Picked from https://trac.nginx.org/nginx/ticket/1865.
2023-09-11 16:30:58 +01:00
fanquake
8f7b9eb871
Merge bitcoin/bitcoin#28433: Follow-up to BIP324 connection support
64704386b2 doc: fix typos and mistakes in BIP324 code comments (Pieter Wuille)
9bde93df2c net: do not use send buffer to store/cache garbage (Pieter Wuille)
b6934fd03f net: merge V2Transport constructors, move key gen (Pieter Wuille)

Pull request description:

  This addresses a few remaining comments on #28196:

  * Deduplicate the `V2Transport` constructors (https://github.com/bitcoin/bitcoin/pull/28196#discussion_r1318573111)
  * Do not use the send buffer to store garbage (https://github.com/bitcoin/bitcoin/pull/28196#discussion_r1319134141)
  * Fix typo (https://github.com/bitcoin/bitcoin/pull/28196#discussion_r1315179378)

  In addition, also fix an incorrect description in `V2Transport::SendState` (it claimed garbage was sent in the `READY` state, but it's in the `AWAITING_KEY` state).

ACKs for top commit:
  naumenkogs:
    ACK 64704386b2
  theStack:
    Code-review ACK 64704386b2

Tree-SHA512: 4bf6d2fe73c8054502d0b60e9de1722f8b3dd269c2dd6bf67197c3fb6eabcf047b6360cdab3c1fd5504215c2ac4ac2890a022780efc30ff583776242c8112451
2023-09-11 09:44:38 +01:00
Anthony Towns
971bae9174 rpc: Deprecate rpcserialversion=0 2023-09-11 17:21:53 +10:00
Pieter Wuille
64704386b2 doc: fix typos and mistakes in BIP324 code comments 2023-09-10 16:12:30 -04:00
Pieter Wuille
9bde93df2c net: do not use send buffer to store/cache garbage
Before this commit the V2Transport::m_send_buffer is used to store the
garbage:
* During MAYBE_V1 state, it's there despite not being sent.
* During AWAITING_KEY state, while it is being sent.
* At the end of the AWAITING_KEY state it cannot be wiped as it's still
  needed to compute the garbage authentication packet.

Change this by introducing a separate m_send_garbage field, taking over
the first and last role listed above. This means the garbage is only in
the send buffer when it's actually being sent, removing a few special
cases related to this.
2023-09-10 16:12:27 -04:00
Pieter Wuille
b6934fd03f net: merge V2Transport constructors, move key gen
This removes the ability for BIP324Cipher to generate its own key, moving that
responsibility to the caller (mostly, V2Transport). This allows us to write
the random-key V2Transport constructor by delegating to the explicit-key one.
2023-09-10 16:11:52 -04:00
fanquake
c5a63ea56f
Merge bitcoin/bitcoin#27944: test: various USDT functional test cleanups (27831 follow-ups)
9f55773a37 test: refactor: usdt_mempool: store all events (stickies-v)
bc43270450 test: refactor: remove unnecessary nonlocal (stickies-v)
326db63a68 test: log sanity check assertion failures (stickies-v)
f5525ad680 test: store utxocache events (stickies-v)
f1b99ac94f test: refactor: deduplicate handle_utxocache_* logic (stickies-v)
ad90ba36bd test: refactor:  rename inbound to is_inbound (stickies-v)
afc0224cdb test: refactor: remove unnecessary blocks_checked counter (stickies-v)

Pull request description:

  Various cleanups to the USDT functional tests, largely (but not exclusively) follow-ups to https://github.com/bitcoin/bitcoin/pull/27831#pullrequestreview-1491438045. Except for slightly different logging behaviour in "test: store utxocache events" and "test: log sanity check assertion failures", this is a refactor PR, removing unnecessary code and (imo) making it more readable and maintainable.

  The rationale for each change is in the corresponding commit message.

  Note: except for "test: store utxocache events" (which relies on its parent, and I separated into two commits because we may want the parent but not the child), all commits are stand-alone and I'm okay with dropping one/multiple commits if they turn out to be controversial or undesired.

ACKs for top commit:
  0xB10C:
    ACK 9f55773a37. Reviewed the code and ran the USDT interface tests. I stepped through the commits and think all changes are reasonable.

Tree-SHA512: 6c37a0265b6c26d4f9552a056a690b8f86f7304bd33b4419febd8b17369cf6af799cb87c16df35d0c2a1b839ad31de24661d4384eafa88816c2051c522fd3bf5
2023-09-10 14:10:16 +01:00
fanquake
e25af11225
Merge bitcoin/bitcoin#28431: Remove needless GetTransactionOutputWeight helper
8d6228fc1f consensus/validation.h: remove needless GetTransactionOutputWeight helper (Antoine Poinsot)

Pull request description:

  Introduced in #26567. My bad. Thanks AJ for noticing.

ACKs for top commit:
  ajtowns:
    utACK 8d6228fc1f

Tree-SHA512: cf13647b4aac82fb6a54ae0338e3928e9bdf226ed4f5e91d529996328471744132db2bee9676e0b3f40a8bbe0e0ca51a9e5f91560a84e0f33597290551a1ee18
2023-09-09 11:45:15 +01:00
fanquake
579c49b3a6
Merge bitcoin/bitcoin#28428: Hard-code version number value for CBlockLocator and CDiskBlockIndex
e73d2a8018 refactor: remove clientversion include from dbwrapper.h (Cory Fields)
4240a082b8 refactor: Use DataStream now that version/type are unused (Cory Fields)
f15f790618 Remove version/hashing options from CBlockLocator/CDiskBlockIndex (Cory Fields)

Pull request description:

  This is also a much simpler replacement for #28327.

  There are version fields in `CBlockLocator` and `CDiskBlockIndex` that have always been written but discarded when read.

  I intended to convert them to use SerParams as introduced by #25284, which [ended up looking like this](3e3af45165). However because we don't currently have any definition of what a hash value would mean for either one of those, and we've never assigned the version field any meaning, I think it's better to just not worry about them.

  If we ever need to assign meaning in the future, we can introduce `SerParams` as was done for `CAddress`.

  As for the dummy values chosen:

  `CDiskBlockIndex::DUMMY_VERSION` was easy as the highest ever client version, and I don't expect any objection there.

  `CBlockLocator::DUMMY_VERSION` is hard-coded to the higest _PROTOCOL_ version ever used. This is to avoid a sudden bump that would be visible on the network if CLIENT_VERSION were used instead. In the future, if we ever need to use the value, we can discard anything in the CLIENT_VERSION range (for a few years as needed), as it's quite a bit higher.

  While reviewing, I suggest looking at the throwaway `SerParams` commit above as it shows where the call-sites are. I believe that should be enough to convince one's self that hashing is never used.

ACKs for top commit:
  TheCharlatan:
    Re-ACK e73d2a8018
  ajtowns:
    reACK e73d2a8018

Tree-SHA512: 45b0dd7c2e918493e2ee92a8e35320ad17991cb8908cb811150a96c5fd584ce177c775baeeb8675a602c90b9ba9203b8cefc0a2a0c6a71078b1d9c2b41e1f3ba
2023-09-09 11:30:57 +01:00