Commit graph

1071 commits

Author SHA1 Message Date
glozow
4307849256 [mempool] delete exists(uint256) function
Allowing callers to pass in a uint256 (which could be txid or wtxid)
but then always assuming that it's a txid is a footgunny interface.
2021-10-21 16:26:59 +01:00
fanquake
0ccf9b2e55
Merge bitcoin/bitcoin#23258: doc: Fix outdated comments referring to ::ChainActive()
a0efe529e4 Fix outdated comments referring to ::ChainActive() (Samuel Dobson)

Pull request description:

  After #21866 there are a few outdated comments referring to `::ChainActive()`, which should instead refer to `ChainstateManager::ActiveChain()`.

ACKs for top commit:
  jamesob:
    ACK a0efe529e4

Tree-SHA512: 80da19c105ed29ac247e6df4c8e916c3bf3f37230b63f07302114eef9c115add673e9649f0bbe237295be0c6da7b1030b5b93e14daf6768f17ce5de7cf2c9ff2
2021-10-20 13:28:28 +08:00
0xb10c
53c9fa9e62
tracing: drop block_connected hash.toString() arg
The tracepoint `validation:block_connected` was introduced in #22006.
The first argument was the hash of the connected block as a pointer
to a C-like String. The last argument passed the hash of the
connected block as a pointer to 32 bytes. The hash was only passed as
string to allow `bpftrace` scripts to print the hash. It was
(incorrectly) assumed that `bpftrace` cannot hex-format and print the
block hash given only the hash as bytes.

The block hash can be printed in `bpftrace` by calling
`printf("%02x")` for each byte of the hash in an `unroll () {...}`.
By starting from the last byte of the hash, it can be printed in
big-endian (the block-explorer format).

```C
  $p = $hash + 31;
  unroll(32) {
      $b = *(uint8*)$p;
      printf("%02x", $b);
      $p -= 1;
  }
```

See also: https://github.com/bitcoin/bitcoin/pull/22902#discussion_r705176691

This is a breaking change to the block_connected tracepoint API, however
this tracepoint has not yet been included in a release.
2021-10-18 14:35:25 +02:00
Samuel Dobson
a0efe529e4 Fix outdated comments referring to ::ChainActive() 2021-10-12 14:36:51 +13:00
Anthony Towns
b5950dd59c validation: put coins cache write log into bench debug log 2021-10-11 21:45:49 +10:00
Anthony Towns
da94ebc2fa validation: move header validation error logging to VALIDATION debug category 2021-10-11 21:45:29 +10:00
Anthony Towns
1d7d835ec3 validation: include block hash when reporting prev block not found errors 2021-10-11 21:45:29 +10:00
W. J. van der Laan
6f0cbc75be
Merge bitcoin/bitcoin#22539: Re-include RBF replacement txs in fee estimation
3b613722f6 Add release notes for fee est with replacement txs (Antoine Poinsot)
4556406562 qa: test fee estimation with replacement transactions (Antoine Poinsot)
053415b297 qa: split run_test into smaller parts (Antoine Poinsot)
06c5ce9714 Re-include RBF replacement txs in fee estimation (Antoine Poinsot)

Pull request description:

  This effectively reverts #9519.

  RBF is now largely in use on the network (signaled for by around 20% of
  all transactions on average) and replacement logic is implemented in
  most end-user wallets. The rate of replaced transactions is also
  expected to rise as fee-bumping techniques are being developed for
  pre-signed transaction ("L2") protocols.

ACKs for top commit:
  prayank23:
    reACK 3b613722f6
  Zero-1729:
    re-ACK 3b613722f6
  benthecarman:
    reACK 3b613722f6
  glozow:
    ACK 3b613722f6
  theStack:
    re-ACK 3b613722f6 🍪

Tree-SHA512: a6146d15c80ff4ba9249314b0ef953a66a15673e61b8f98979642814f1b169b5695e330e3ee069fa9a7e4d1f8aa10e1dcb7f9aa79181cea5a4c4dbcaf5483023
2021-10-07 13:47:36 +02:00
glozow
082c5bf099 [refactor] pass coinsview and height to check()
Removes check's dependency on validation.h
2021-10-04 15:00:28 +01:00
glozow
9e8d7ad5d9 [validation/mempool] use Spend/AddCoin instead of UpdateCoins
UpdateCoins is an unnecessary dependency on validation. All we need to
do is add and remove coins to check inputs. We don't need the extra
logic for checking coinbases and handling TxUndos.

Also remove the wrapper function in validation.h which constructs a
throwaway TxUndo object before calling UpdateCoins because it is now
unused.
2021-10-04 15:00:28 +01:00
fanquake
d09071da5b
[MOVEONLY] consensus: move amount.h into consensus
Move amount.h to consensus/amount.h.
Renames, adds missing and removes uneeded includes.
2021-09-30 07:41:57 +08:00
Antoine Poinsot
06c5ce9714
Re-include RBF replacement txs in fee estimation
This effectively reverts de1ae324bf.

RBF is now largely in use on the network (signaled for by around 20% of
all transactions on average) and replacement logic is implemented in
most end-user wallets. The rate of replaced transactions is also
expected to rise as fee-bumping techniques are being developed for
pre-signed transaction ("L2") protocols.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-09-29 16:13:16 +02:00
Russell Yanofsky
93b9800fec scripted-diff: Rename overloaded int GetArg to GetIntArg
Improve readability of code, simplify future scripted diff cleanup PRs, and be
more consistent with naming for GetBoolArg.

This will also be useful for replacing runtime settings type checking
with compile time checking.

-BEGIN VERIFY SCRIPT-
git grep -l GetArg | xargs sed -i 's/GetArg(\([^)]*\( [0-9]\+\|-1\|port\|BaseParams().RPCPort()\|Params().GetDefaultPort()\|_TIMEOUT\|Height\|_WORKQUEUE\|_THREADS\|_CONNECTIONS\|LIMIT\|SigOp\|Bytes\|_VERSION\|_AGE\|_CHECKS\|Checks() ? 1 : 0\|_BANTIME\|Cache\|BLOCKS\|LEVEL\|Weight\|Version\|BUFFER\|TARGET\|WEIGHT\|TXN\|TRANSACTIONS\|ADJUSTMENT\|i64\|Size\|nDefault\|_EXPIRY\|HEIGHT\|SIZE\|SNDHWM\|_TIME_MS\)\))/GetIntArg(\1)/g'
-END VERIFY SCRIPT-

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2021-09-27 06:57:20 -04:00
merge-script
632be5514c
Merge bitcoin/bitcoin#23061: Fix (inverse) meaning of -persistmempool
faa9c19a4b doc: Add 23061 release notes (MarcoFalke)
faff17bbde Fix (inverse) meaning of -persistmempool (MarcoFalke)

Pull request description:

  Passing `-persistmempool` is currently treated as `-nopersistmempool`

ACKs for top commit:
  jnewbery:
    reACK faa9c19a4b
  hebasto:
    ACK faa9c19a4b, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: f34a89a07745dabe340eb845b2a348b79c093e9056f7a21c17e1ba2e278177c9b4cf30e8095791fd645a7f90eb34850b2eee0c869b4f6ec02bf749c73b0e52ee
2021-09-27 10:12:14 +02:00
W. J. van der Laan
b7e3600815
Merge bitcoin/bitcoin#21526: validation: UpdateTip/CheckBlockIndex assumeutxo support
673a5bd337 test: validation: add unittest for UpdateTip behavior (James O'Beirne)
2705570109 test: refactor: separate CreateBlock in TestChain100Setup (James O'Beirne)
298bf5d563 test: refactor: declare NoMalleation const auto (James O'Beirne)
071200993f move-only: unittest: add test/util/chainstate.h (James O'Beirne)
8f5710fd0a validation: fix CheckBlockIndex for multiple chainstates (James O'Beirne)
5a807736da validation: insert assumed-valid block index entries into candidates (James O'Beirne)
01a9b8fe71 validation: set BLOCK_ASSUMED_VALID during snapshot load (James O'Beirne)
42b2520db9 chain: add BLOCK_ASSUMED_VALID for use with assumeutxo (James O'Beirne)
b217020df7 validation: change UpdateTip for multiple chainstates (James O'Beirne)
665072a36d doc: add comment for g_best_block (James O'Beirne)
ac4051d891 refactor: remove unused assumeutxo methods (James O'Beirne)
9f6bb53935 validation: add chainman ref to CChainState (James O'Beirne)

Pull request description:

  This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11) (parent PR: #15606)

  ---

  Modify UpdateTip and CheckBlockIndex for use with multiple chainstates. Includes a new unittest verifying `g_best_block` behavior (previously untested at the unit level) and various changes necessary for running and testing `ProcessNewBlock()`-like behavior on the background validation chainstate.

  This changeset introduces a new block index `nStatus` flag called `BLOCK_ASSUMED_VALID`, and it is applied to block index entries that are beneath the UTXO snapshot base block upon snapshot load. Once each block is validated (during async background validation), the flag is removed. This allows us to avoid (ab)using `BLOCK_VALID_*` flags for snapshot chain block entries, and preserves the original meaning of those flags.

  Note: this PR previously incorporated changes to `LoadBlockIndex()` and `RewindBlockIndex()` as noted in Russ' comments below, but once I generated the changes necessary to test the UpdateTip change, I decided to split this changes out into another PR due to the size of this one.

ACKs for top commit:
  achow101:
    ACK 673a5bd337
  jonatack:
    Code-review re-ACK 673a5bd337 reviewed diff, rebased to master/debug build/ran unit+functional tests
  naumenkogs:
    ACK 673a5bd337
  fjahr:
    Code review ACK 673a5bd337
  ariard:
    utACK 673a5bd3
  ryanofsky:
    Code review ACK 673a5bd337. Just linker fix and split commit changes mentioned https://github.com/bitcoin/bitcoin/pull/21526#issuecomment-921064563 since last review
  benthecarman:
    ACK 673a5bd337

Tree-SHA512: 0a6dc23d041b27ed9fd0ee1f3e5971b92fb1d2df2fc9b655d5dc48594235321ab1798d06de2ec55482ac3966a9ed56de8d56e9e29cae75bbe8690bafc2dda383
2021-09-23 22:22:07 +02:00
merge-script
95b16e70a8
Merge bitcoin/bitcoin#23072: log: Remove unnecessary timing of Callbacks bench
ab27800799 log: Remove unnecessary timing logs for Callbacks bench (Douglas Chimento)

Pull request description:

  Logging of Callbacks are no longer needed and records times that are not relevant for performance analysis.
  resolves #23071

ACKs for top commit:
  laanwj:
    Thanks. re-ACK ab27800799
  jonatack:
    Code review ACK ab27800799

Tree-SHA512: be1ea780c4db9407a8799065a8824b9d3610abac72af5907809ed62d493d5a54e65735de45ec5fdd0edb85ef21ec6036105abe8ca00093942980f6f92e7fec50
2021-09-23 15:07:16 +02:00
Douglas Chimento
ab27800799 log: Remove unnecessary timing logs for Callbacks bench
Logging of Callbacks are no longer needed and records events that are not relevant for performance analysis.
2021-09-23 14:36:16 +03:00
fanquake
8bda5e0988
Merge bitcoin/bitcoin#22855: RBF move 3/3: move followups + improve RBF documentation
0ef08f8bed add missing includes in policy/rbf (glozow)
c6abeb76fb make MAX_BIP125_RBF_SEQUENCE constexpr (glozow)
3cf46f6055 [doc] improve RBF documentation (glozow)
c78eb8651b [policy/refactor] pass in relay fee instead of using global (glozow)

Pull request description:

  Followups to #22675 and documentation-only changes intended to clarify the code/logic concerning mempool Replace-by-Fee.

ACKs for top commit:
  jnewbery:
    utACK 0ef08f8bed
  fanquake:
    ACK 0ef08f8bed

Tree-SHA512: 6797ae758beca0c9673cb00ce85da48e9a4ac5cb5100074ca93e004cdb31d24d91a1a7721b57fc2f619addfeb4950d8caf45fee0f5b7528defbbd121eb4d271f
2021-09-23 16:40:41 +08:00
MarcoFalke
faff17bbde
Fix (inverse) meaning of -persistmempool 2021-09-22 11:29:44 +02:00
MarcoFalke
fa45a1338a
refactor: Remove unused validation includes 2021-09-20 12:16:20 +02:00
W. J. van der Laan
71bdf0bff1
Merge bitcoin/bitcoin#22626: Remove txindex migration code
fa20f815a9 Remove txindex migration code (MarcoFalke)
fae8786033 doc: Fix validation typo (MarcoFalke)
fab89006d6 Add missing includes and forward declarations, remove unused ones (MarcoFalke)

Pull request description:

  No supported version of Bitcoin Core used the legacy txindex, so all relevant nodes can be assumed to have upgraded. Thus, there is no need to keep this code any longer.

  As a temporary courtesy, provide a one-time warning on how to free the disk space used by the legacy txindex.

  Fixes #22615

ACKs for top commit:
  laanwj:
    Code review ACK fa20f815a9
  hebasto:
    ACK fa20f815a9, tested on Linux Mint 20.2 (x86_64).
  Zero-1729:
    crACK fa20f815a9
  theStack:
    Approach ACK fa20f815a9

Tree-SHA512: 68aa32d064d1e3932e6e382816a4b5de417bd7e82861fea1ee50660e8c397f4efeb88ae4ed54a8ad1952c3563eb0b8449d7ccf883c353cc4d4dc7e15c53d78e8
2021-09-16 19:53:28 +02:00
James O'Beirne
8f5710fd0a
validation: fix CheckBlockIndex for multiple chainstates
Adjust CheckBlockIndex to account for
- assumed-valid block indexes lacking transaction data, and
- setBlockIndexCandidates for the background chainstate not containing certain entries
  which rely on assumed-valid ancestors.
2021-09-15 15:46:47 -04:00
James O'Beirne
5a807736da
validation: insert assumed-valid block index entries into candidates 2021-09-15 15:46:46 -04:00
James O'Beirne
01a9b8fe71
validation: set BLOCK_ASSUMED_VALID during snapshot load
Mark the block index entries that are beneath the snapshot base block as
assumed-valid.  Subsequent commits will make use of this flag in other
parts of the system.
2021-09-15 15:46:45 -04:00
James O'Beirne
b217020df7
validation: change UpdateTip for multiple chainstates
Only perform certain behavior (namely that related to servicing
the getblocktemplate RPC call) for the active chainstate when
calling UpdateTip.

Co-authored-by: Jon Atack <jon@atack.com>
2021-09-15 15:46:43 -04:00
glozow
3cf46f6055 [doc] improve RBF documentation
Document a few non-obvious things and delete no-longer-relevant comments
(e.g. about taking a lock that we're already holding).
No change in behavior.
2021-09-10 10:32:29 +01:00
glozow
c78eb8651b [policy/refactor] pass in relay fee instead of using global 2021-09-10 09:38:01 +01:00
fanquake
b8336b22d3
Merge bitcoin/bitcoin#22675: RBF move 2/3: extract RBF logic into policy/rbf
32748da0f4 whitespace fixups after move and scripted-diff (glozow)
fa47622e8d scripted-diff: rename variables in policy/rbf (glozow)
ac761f0a23 MOVEONLY: fee checks (Rules 3 and 4) to policy/rbf (glozow)
9c2f9f8984 MOVEONLY: check that fees > direct conflicts to policy/rbf (glozow)
3f033f01a6 MOVEONLY: check for disjoint conflicts and ancestors to policy/rbf (glozow)
7b60c02b7d MOVEONLY: BIP125 Rule 2 to policy/rbf (glozow)
f8ad2a57c6 Make GetEntriesForConflicts return std::optional (glozow)

Pull request description:

  This PR does not change behavior. It extracts the BIP125 logic into helper functions (and puts them in the policy/rbf* files). This enables three things - I think each one individually is pretty good:

  - Implementation of package RBF (see #22290). I want it to be as close to BIP125 as possible so that it doesn't become a distinct fee-bumping mechanism. Doing these move-only commits first means the diff is mostly mechanical to review, and I just need to create a function that mirrors the single transaction validation.
  - We will be able to isolate and test our RBF logic alone. Recently, there have been some discussions on discrepancies between our code and BIP125, as well as proposals for improving it. Generally, I think making this code more modular and de-bloating validation.cpp is probably a good idea.
  - Witness Replacement (replacing same-txid-different-wtxid when the witness is significantly smaller and therefore higher feerate) in a BIP125-similar way. Hopefully it can just be implemented with calls to the rbf functions (i.e. `PaysForRBF`) and an edit to the relevant mempool entries.

ACKs for top commit:
  mjdietzx:
    ACK 32748da0f4
  theStack:
    Code-review ACK 32748da0f4 📐
  MarcoFalke:
    review ACK 32748da0f4 🦇

Tree-SHA512: d89985c8b4b42b54861018deb89468e04968c85a3fb1113bbcb2eb2609577bc4fd9bf254593b5bd0e7ab059a0fa8192d1a903b00f77e6f120c7a80488ffcbfc0
2021-09-10 14:44:54 +08:00
MarcoFalke
fa57fa1a2e
Enable clang-tidy bugprone-argument-comment and fix violations 2021-09-07 09:11:10 +02:00
glozow
ac761f0a23 MOVEONLY: fee checks (Rules 3 and 4) to policy/rbf 2021-09-02 16:23:27 +01:00
glozow
9c2f9f8984 MOVEONLY: check that fees > direct conflicts to policy/rbf 2021-09-02 16:23:27 +01:00
glozow
3f033f01a6 MOVEONLY: check for disjoint conflicts and ancestors to policy/rbf
This checks that a transaction isn't trying to replace something it
supposedly depends on.
2021-09-02 16:23:27 +01:00
glozow
7b60c02b7d MOVEONLY: BIP125 Rule 2 to policy/rbf 2021-09-02 16:23:26 +01:00
glozow
f8ad2a57c6 Make GetEntriesForConflicts return std::optional
Avoids reusing err_string.
2021-09-02 16:23:25 +01:00
fanquake
81f4a3e84d
Merge bitcoin/bitcoin#22796: RBF move (1/3): extract BIP125 Rule 5 into policy/rbf
f293c68be0 MOVEONLY: getting mempool conflicts to policy/rbf (glozow)
8d71796335 [validation] quit RBF logic earlier and separate loops (glozow)
badb9b11a6 call SignalsOptInRBF instead of checking all inputs (glozow)
e0df41d7d5 [validation] default conflicting fees and size to 0 (glozow)
b001b9f6de MOVEONLY: BIP125 max conflicts limit to policy/rbf.h (glozow)

Pull request description:

  See #22675 for motivation, this is one chunk of it. It extracts some BIP125 logic into policy/rbf:

  - Defines a constant for specifying the maximum number of mempool entries we'd consider replacing by RBF
  - Calls the available `SignalsOptInRBF` function instead of manually iterating through inputs
  - Moves the logic for getting the list of conflicting mempool entries to a helper function
  - Also does a bit of preparation for future moves - moving declarations around, etc
  Also see #22677 for addressing the circular dependency.

ACKs for top commit:
  jnewbery:
    Code review ACK f293c68be0
  theStack:
    Code-review ACK f293c68be0 📔
  ariard:
    ACK f293c68b

Tree-SHA512: a60370994569cfc91d4b2ad5e94542d4855a48927ae8b174880216074e4fa50d4523dd4ee36efdd6edf2bf7adb87a8beff9c3aaaf6dd323b286b287233e63790
2021-08-31 22:34:25 +08:00
Sebastian Falbesoner
0bd882b740 refactor: remove RecursiveMutex cs_nBlockSequenceId
The RecursiveMutex cs_nBlockSequenceId is only used at one place in
CChainState::ReceivedBlockTransactions() to atomically read-and-increment the
nBlockSequenceId member. At this point, the cs_main lock is set, hence we can
use a plain int for the member and mark it as guarded by cs_main.
2021-08-29 13:31:00 +02:00
glozow
f293c68be0 MOVEONLY: getting mempool conflicts to policy/rbf 2021-08-24 15:51:54 +01:00
glozow
8d71796335 [validation] quit RBF logic earlier and separate loops
No behavior change.
While we're looking through the descendants and calculating how many
transactions we might replace, quit early, as soon as we hit 100.
Since we're failing faster, we can also separate the loops - yes, we
loop through more times, but this helps us detangle the different BIP125
rules later.
2021-08-24 15:47:21 +01:00
glozow
badb9b11a6 call SignalsOptInRBF instead of checking all inputs 2021-08-24 15:47:21 +01:00
glozow
e0df41d7d5 [validation] default conflicting fees and size to 0
This should have no effect in practice, since we only ever call
PreChecks once per transaction.
2021-08-24 15:47:21 +01:00
glozow
b001b9f6de MOVEONLY: BIP125 max conflicts limit to policy/rbf.h
A circular dependency is added because policy now depends on txmempool and
txmempool depends on validation. It is natural for [mempool] policy to
rely on mempool; the problem is caused by txmempool depending on
validation. #22677 will resolve this.
2021-08-24 15:47:21 +01:00
MarcoFalke
fae8786033
doc: Fix validation typo 2021-08-20 16:55:34 +02:00
glozow
3cd663a5d3 [policy] ancestor/descendant limits for packages 2021-08-06 10:04:59 +01:00
MarcoFalke
4b1fb50def
Merge bitcoin/bitcoin#22528: refactor: move GetTransaction to node/transaction.cpp
f685a13bef doc: GetTransaction()/getrawtransaction follow-ups to #22383 (John Newbery)
abc57e1f08 refactor: move `GetTransaction(...)` to node/transaction.cpp (Sebastian Falbesoner)

Pull request description:

  ~This PR is based on #22383, which should be reviewed first~ (merged by now).

  In [yesterday's PR review club session to PR 22383](https://bitcoincore.reviews/22383), the idea of moving the function `GetTransaction(...)` from src/validation.cpp to src/node/transaction.cpp came up. With this, the circular dependency "index/txindex -> validation -> index/txindex" is removed (see change in `lint-circular-dependencies.sh`). Thanks to jnewbery for suggesting and to sipa for providing historical background.

  Relevant IRC log:
  ```
  17:52 <jnewbery> Was anyone surprised that GetTransaction() is in validation.cpp? It seems to me that node/transaction.cpp would be a more appropriate place for it.
  17:53 <raj_> jnewbery, +1
  17:53 <stickies-v> agreed!
  17:54 <glozow> jnewbery ya
  17:54 <jnewbery> seems weird that validation would call into txindex. I wonder if we remove this function, then validation would no longer need to #include txindex
  17:54 <sipa> GetTransaction predates node/transaction.cpp, and even the generic index framework itself :)
  17:55 <sipa> (before 0.8, validation itself used the txindex)
  17:55 <jnewbery> (and GetTransaction() seems like a natural sibling to BroadcastTransaction(), which is already in node/transaction.cpp)
  17:55 <jnewbery> sipa: right, this is not meant as a criticism of course. Just wondering if we can organize things a bit more rationally now that we have better separation between things.
  17:55 <sipa> jnewbery: sure, just providing background
  17:56 <sipa> seems very reasonable to move it elsewhere now
  ```

  The commit should be trivial to review with `--color-moved`.

ACKs for top commit:
  jnewbery:
    Code review ACK f685a13bef
  rajarshimaitra:
    tACK f685a13bef
  mjdietzx:
    crACK f685a13bef
  LarryRuane:
    Code review, test ACK f685a13bef

Tree-SHA512: 0e844a6ecb1be04c638b55bc4478c2949549a4fcae01c984eee078de74d176fb19d508fc09360a62ad130677bfa7daf703b67870800e55942838d7313246248c
2021-07-28 18:19:50 +02:00
0xb10c
8f37f5c2a5
tracing: Tracepoint for connected blocks
Can, for example, be used to benchmark block connections.
2021-07-27 17:12:38 +02:00
MarcoFalke
7925f3aba8
Merge bitcoin/bitcoin#22383: rpc: Prefer to use txindex if available for GetTransaction
78f4c8b98e prefer to use txindex if available for GetTransaction (Jameson Lopp)

Pull request description:

  Fixes #22382

  Motivation: prevent excessive disk reads if txindex is enabled.

  Worth noting that this could be argued to be less of a bug and more of an issue of undefined behavior. If a user calls GetTransaction with the wrong block hash, what should happen?

ACKs for top commit:
  jonatack:
    ACK 78f4c8b98e
  theStack:
    Code review ACK 78f4c8b98e
  LarryRuane:
    tACK 78f4c8b98e
  luke-jr:
    utACK 78f4c8b98e
  jnewbery:
    utACK 78f4c8b98e
  rajarshimaitra:
    Code review ACK 78f4c8b98e
  lsilva01:
    Code Review ACK and Tested ACK 78f4c8b98e on Ubuntu 20.04

Tree-SHA512: af7db5b98cb2ae4897b28476b2fa243bf7e6f850750d9347062fe8013c5720986d1a3c808f80098e5289bd84b085de03c81a44e584dc28982f721c223651bfe0
2021-07-22 20:13:43 +02:00
W. J. van der Laan
5d83e7d714
Merge bitcoin/bitcoin#21090: Default to NODE_WITNESS in nLocalServices
a806647d26 [validation] Always include merkle root in coinbase commitment (Dhruv Mehta)
189128c220 [validation] Set witness script flag with p2sh for blocks (Dhruv Mehta)
ac82b99db7 [p2p] remove redundant NODE_WITNESS checks (Dhruv Mehta)
6f8b198b82 [p2p] remove unused segwitheight=-1 option (Dhruv Mehta)
eba5b1cd64 [test] remove or move tests using `-segwitheight=-1` (Dhruv Mehta)

Pull request description:

  Builds on #21009 and makes progress on remaining items in #17862

  Removing `RewindBlockIndex()` in #21009 allows the following:

  - removal of tests using `segwitheight=-1` in `p2p_segwit.py`.
  - move `test_upgrade_after_activation()` out of `p2p_segwit.py` reducing runtime
  - in turn, that allows us to drop support for `-segwitheight=-1`, which is only supported for that test.
  - that allows us to always set `NODE_WITNESS` in our local services. The only reason we don't do that is to support `-segwitheight=-1`.
  - that in turn allows us to drop all of the `GetLocalServices() & NODE_WITNESS` checks inside `net_processing.cpp`, since our local services would always include `NODE_WITNESS`

ACKs for top commit:
  mzumsande:
    Code-Review ACK a806647d26
  laanwj:
    Code review ACK a806647d26, nice cleanup
  jnewbery:
    utACK a806647d26
  theStack:
    ACK a806647d26

Tree-SHA512: 73e1a69d1d7eca1f5c38558ec6672decd0b60b16c2ef6134df6f6af71bb159e6eea160f9bb5ab0eb6723c6632d29509811e29469d0d87abbe9b69a2890fbc73e
2021-07-22 17:36:38 +02:00
Sebastian Falbesoner
abc57e1f08 refactor: move GetTransaction(...) to node/transaction.cpp
can be reviewed with --color-moved
2021-07-22 15:53:17 +02:00
James O'Beirne
ac4051d891
refactor: remove unused assumeutxo methods
After feedback from Russ, I realized that there are some extraneous assumeutxo methods
that are not necessary and probably just overly confusing. These include

- `Validated*()`
- `IsBackgroundIBD()`

and they can be removed.
2021-07-16 12:45:23 -04:00
James O'Beirne
9f6bb53935
validation: add chainman ref to CChainState
Add an upwards reference to chainstate instances to the owning
ChainstateManager. This is necessary because there are a number
of `this_chainstate == chainman.ActiveChainstate()` checks that
will happen (as a result of assumeutxo) in functions that otherwise
don't have an easily-accessible reference to the chainstate's
ChainManager.
2021-07-16 12:45:20 -04:00
MarcoFalke
faa54e3757
Move pblocktree global to BlockManager 2021-07-15 13:54:09 +02:00
MarcoFalke
fa27f03b49
Move LoadBlockIndexDB to BlockManager 2021-07-15 13:52:41 +02:00
MarcoFalke
c0224bc962
Merge bitcoin/bitcoin#22415: Make m_mempool optional in CChainState
ceb7b35a39 refactor: move UpdateTip into CChainState (James O'Beirne)
4abf0779d6 refactor: no mempool arg to GetCoinsCacheSizeState (James O'Beirne)
46e3efd1e4 refactor: move UpdateMempoolForReorg into CChainState (James O'Beirne)
617661703a validation: make CChainState::m_mempool optional (James O'Beirne)

Pull request description:

  Make `CChainState::m_mempool` optional by making it a pointer instead of a reference. This will allow a simplification to assumeutxo semantics (see https://github.com/bitcoin/bitcoin/pull/15606#pullrequestreview-692965905) and help facilitate the `-nomempool` option.

ACKs for top commit:
  jnewbery:
    ACK ceb7b35a39
  naumenkogs:
    ACK ceb7b35a39
  ryanofsky:
    Code review ACK ceb7b35a39 (just minor style and test tweaks since last review)
  lsilva01:
    Code review ACK and tested on Signet ACK ceb7b35a39
  MarcoFalke:
    review ACK ceb7b35a39 😌

Tree-SHA512: cc445ad33439d5918cacf80a6354eea8f3d33bb7719573ed5b970fad1a0dab410bcd70be44c862b8aba1b71263b82d79876688c553e339362653dfb3d8ec81e6
2021-07-15 13:40:03 +02:00
James O'Beirne
ceb7b35a39
refactor: move UpdateTip into CChainState
Makes sense and saves on arguments.

Co-authored-by: John Newbery <john@johnnewbery.com>
2021-07-13 11:16:37 -04:00
James O'Beirne
4abf0779d6
refactor: no mempool arg to GetCoinsCacheSizeState
Unnecessary argument since we can make use of this->m_mempool

Co-authored-by: John Newbery <john@johnnewbery.com>
2021-07-13 11:16:30 -04:00
James O'Beirne
46e3efd1e4
refactor: move UpdateMempoolForReorg into CChainState
Allows fewer arguments and simplification of call sites.

Co-authored-by: John Newbery <john@johnnewbery.com>
2021-07-13 11:12:16 -04:00
James O'Beirne
617661703a
validation: make CChainState::m_mempool optional
Since we now have multiple chainstate objects, only one of them is active at any given
time. An active chainstate has a mempool, but there's no point to others having one.

This change will simplify proposed assumeutxo semantics. See the discussion here:
https://github.com/bitcoin/bitcoin/pull/15606#pullrequestreview-692965905

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
2021-07-13 11:11:35 -04:00
glozow
fdb48163bf [validation] distinguish same txid different wtxid in mempool
Changes behavior.
2021-07-08 09:31:45 +01:00
Dhruv Mehta
a806647d26 [validation] Always include merkle root in coinbase commitment 2021-07-07 22:13:01 -07:00
Dhruv Mehta
189128c220 [validation] Set witness script flag with p2sh for blocks 2021-07-07 22:13:01 -07:00
Jameson Lopp
78f4c8b98e
prefer to use txindex if available for GetTransaction
Fixes #22382
2021-07-03 07:31:27 -04:00
Anthony Towns
c5f36725e8 [refactor] Move ComputeBlockVersion into VersionBitsCache
This also changes ComputeBlockVersion to take the versionbits cache
mutex once, rather than once for each versionbits deployment.
2021-06-30 08:19:12 +10:00
Anthony Towns
4a69b4dbe0 [move-only] Move ComputeBlockVersion from validation to versionbits 2021-06-30 08:19:12 +10:00
Anthony Towns
0cfd6c6a8f [refactor] versionbits: make VersionBitsCache a full class
Moves the VersionBits* functions to be methods of the cache class,
and makes the cache and its lock private to the class.
2021-06-30 08:19:12 +10:00
Anthony Towns
c64b2c6a0f scripted-diff: rename versionbitscache
-BEGIN VERIFY SCRIPT-
sed -i -e 's/versionbitscache/g_versionbitscache/g' $(git grep -l versionbitscache)
-END VERIFY SCRIPT-
2021-06-30 08:19:12 +10:00
Anthony Towns
de55304f6e [refactor] Add versionbits deployments to deploymentstatus.h
Adds support for versionbits deployments to DeploymentEnabled,
DeploymentActiveAfter and DeploymentActiveAt. Also moves versionbitscache
from validation to deploymentstatus.
2021-06-30 08:18:58 +10:00
Anthony Towns
2b0d291da8 [refactor] Add deploymentstatus.h
Provides DeploymentEnabled, DeploymentActiveAt, and DeploymentActiveAfter
helpers for checking the status of buried deployments. Can be overloaded
so the same syntax works for non-buried deployments, allowing future
soft forks to be changed from signalled to buried deployments without
having to touch the implementation code.

Replaces IsWitnessEnabled and IsScriptWitnessEnabled.
2021-06-29 17:11:12 +10:00
Anthony Towns
eccd736f3d versionbits: Use dedicated lock instead of cs_main 2021-06-29 17:11:12 +10:00
fanquake
8071ec179d
Merge bitcoin/bitcoin#21789: refactor: Remove ::Params() global from CChainState
fa0d9211ef refactor: Remove chainparams arg from CChainState member functions (MarcoFalke)
fa38947125 refactor: Remove ::Params() global from inside CChainState member functions (MarcoFalke)

Pull request description:

  The `::Params()` global is verbose and confusing. Also it makes tests a bit harder to write because they'd have to mock a global.

  Fix all issues by simply using a member variable that points to the right params.

  (Can be reviewed with `--word-diff-regex=.`)

ACKs for top commit:
  jnewbery:
    ACK fa0d9211ef
  kiminuo:
    utACK fa0d9211
  theStack:
    ACK fa0d9211ef 🍉

Tree-SHA512: 44676b19c9ed471ccb536331d3029bad192d7d50f394fd7b8527ec431452aeec8c4494164b9cf8e16e0123c4463b16be864366c6b599370032c17262625a0356
2021-06-29 11:22:57 +08:00
MarcoFalke
3f56ef7bef
Merge bitcoin/bitcoin#22146: Reject invalid coin height and output index when loading assumeutxo
fa9ebedec3 Reject invalid coin height and output index when loading assumeutxo (MarcoFalke)

Pull request description:

  It should be impossible to have a coin at a height higher than the height of the snapshot block, so reject those early to avoid integer wraparounds and hash collisions later on.

  Same for the outpoint index.

  Both issues were found by fuzzing:

  * The height issue by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34793
  * The outpoint issue by my fuzz server: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34793#c2

ACKs for top commit:
  practicalswift:
    cr ACK fa9ebedec3: patch looks correct
  jamesob:
    crACK fa9ebedec3
  theStack:
    Code review ACK fa9ebedec3
  benthecarman:
    crACK fa9ebedec3

Tree-SHA512: dae7caee4b3862b23ebdf2acb7edec4baf75b0dbf1409b370b1a73aa6b632b317ebfac596dcbaf4edfb1301b513f45465ea75328962460f35e2af0d7e547c9ac
2021-06-28 16:11:44 +02:00
MarcoFalke
fa0d9211ef
refactor: Remove chainparams arg from CChainState member functions
Passing this is confusing and redundant with the m_params member.
2021-06-13 09:43:54 +02:00
MarcoFalke
fa38947125
refactor: Remove ::Params() global from inside CChainState member functions
It is confusing and verbose to repeatedly access the global when a
member variable can simply refer to it.
2021-06-13 09:39:37 +02:00
MarcoFalke
9c1ec689f3
Merge bitcoin/bitcoin#22102: Remove Warning: from warning message printed for unknown new rules
6d7e46ce23 Remove `Warning:` (Prayank)

Pull request description:

  Reason: I noticed that `Warning` is printed 2 times in `-getinfo` while reviewing https://github.com/bitcoin/bitcoin/pull/21832#issuecomment-851004943

  Same string is used for GUI, log and stderr. If we need to add `Warning:` in GUI or other place we can always prepend to this string.

  CLI:

  ```
  Warnings: Unknown new rules activated (versionbit 28)

  ```

  GUI:

  ![image](https://user-images.githubusercontent.com/13405205/120110401-e36ab180-c18a-11eb-8031-4d52287dc263.png)

ACKs for top commit:
  MarcoFalke:
    review ACK 6d7e46ce23

Tree-SHA512: 25760cf6d850f6c2216d651fa46574d2d21a9d58f4577ecb58f9566ea8cd07bfcd6679bb8a1f53575e441b02d295306f492c0c99a48c909e60e5d977ec1861f6
2021-06-13 09:21:46 +02:00
Carl Dong
6f994882de validation: Farewell, global Chainstate! 2021-06-10 15:05:25 -04:00
Carl Dong
6c3b5dc0c1 scripted-diff: tree-wide: Remove all review-only assertions
-BEGIN VERIFY SCRIPT-
find_regex='((assert|CHECK_NONFATAL)\(std::addressof|TODO: REVIEW-ONLY)' \
    && git grep -l -E "$find_regex" -- . \
        | xargs sed -i -E "/${find_regex}/d"
-END VERIFY SCRIPT-
2021-06-10 15:05:24 -04:00
fanquake
ef8f2966ac
Merge bitcoin/bitcoin#22084: package testmempoolaccept followups
ee862d6efb MOVEONLY: context-free package policies (glozow)
5cac95cd15 disallow_mempool_conflicts -> allow_bip125_replacement and check earlier (glozow)
e8ecc621be [refactor] comment/naming improvements (glozow)
7d91442461 [rpc] reserve space in txns (glozow)
6c5f19d9c4 [package] static_assert max package size >= max tx size (glozow)

Pull request description:

  various followups from #20833

ACKs for top commit:
  jnewbery:
    utACK ee862d6efb
  ariard:
    Code Review ACK ee862d6

Tree-SHA512: 96ecb41f7bbced84d4253070f5274b7267607bfe4033e2bb0d2f55ec778cc41e811130b6321131e0418b5835894e510a4be8a0f822bc9d68d9224418359ac837
2021-06-10 19:09:54 +08:00
MarcoFalke
fa9ebedec3
Reject invalid coin height and output index when loading assumeutxo 2021-06-09 22:20:01 +02:00
MarcoFalke
82bc7faec8
Merge bitcoin/bitcoin#21946: Document and test lack of inherited signaling in RBF policy
2eb0eeda39 validation: document lack of inherited signaling in RBF policy (Antoine Riard)
906b6d9da6 test: Extend feature_rbf.py with no inherited signaling (Antoine Riard)

Pull request description:

  Contrary to BIP125 or other full-node implementation (e.g btcd), Bitcoin Core's mempool policy doesn't implement inherited signaling.

  This PR documents our mempool behavior on this and add a test demonstrating the case.

ACKs for top commit:
  jonatack:
    ACK 2eb0eeda39
  benthecarman:
    ACK 2eb0eeda39

Tree-SHA512: d41453d3b49bae3c1eb532a968f43bc047084913bd285929d4d9cba142777ff2be38163d912e28dfc635f4ecf446de68effad799c6e71be52f81e83410c712fb
2021-06-08 17:00:28 +02:00
Prayank
6d7e46ce23 Remove Warning:
+ Remove `Warning:` from warning message printed for unknown new rules
+ Change warning message in test

Author:    Prayank <prayank@tutanota.de>
2021-06-07 20:19:18 +05:30
fanquake
346e52afd6
Merge bitcoin/bitcoin#22121: doc: Various validation doc fixups
fa4245d884 doc: Various validation doc fixups (MarcoFalke)

Pull request description:

ACKs for top commit:
  michaelfolkson:
    Re-ACK fa4245d884
  jnewbery:
    ACK fa4245d884

Tree-SHA512: fa1086b09941247a4ffcbc1d7d27dc77a17a3ae093a5146dbb703db9ff4ba5d73ea77bd5b7747af79ea8a7dfe2c4c56a7e19ac5aac3417090e9ae127836022ae
2021-06-04 20:42:28 +08:00
Sjors Provoost
3d552b0d78
[doc] explain why CheckBlock() is called before AcceptBlock()
Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
2021-06-03 19:09:28 +02:00
MarcoFalke
fa4245d884
doc: Various validation doc fixups
* Rename RewindBlockIndex -> NeedsRedownload (follow-up to commit
  d831e711ca)
* Fix typos
* Inline comments about faking chain data to avoid duplicating them
2021-06-03 13:53:31 +02:00
glozow
ee862d6efb MOVEONLY: context-free package policies
Co-authored-by: ariard <antoine.riard@gmail.com>
2021-06-02 17:26:44 +01:00
glozow
5cac95cd15 disallow_mempool_conflicts -> allow_bip125_replacement and check earlier 2021-06-02 09:52:50 +01:00
glozow
e8ecc621be [refactor] comment/naming improvements 2021-06-02 09:40:40 +01:00
fanquake
610151f5b0
validation: change ProcessNewBlock() to take a CBlock reference
Update ProcessNewBlock arguments to newer style.
2021-05-31 14:36:46 +08:00
W. J. van der Laan
7257e50dba
Merge bitcoin/bitcoin#20833: rpc/validation: enable packages through testmempoolaccept
13650fe2e5 [policy] detect unsorted packages (glozow)
9ef643e21b [doc] add release note for package testmempoolaccept (glozow)
c4259f4b7e [test] functional test for packages in RPCs (glozow)
9ede34a6f2 [rpc] allow multiple txns in testmempoolaccept (glozow)
ae8e6df709 [policy] limit package sizes (glozow)
c9e1a26d1f [fuzz] add ProcessNewPackage call in tx_pool fuzzer (glozow)
363e3d916c [test] unit tests for ProcessNewPackage (glozow)
cd9a11ac96 [test] make submit optional in CreateValidMempoolTransaction (glozow)
2ef187941d [validation] package validation for test accepts (glozow)
578148ded6 [validation] explicit Success/Failure ctors for MempoolAcceptResult (glozow)
b88d77aec5 [policy] Define packages (glozow)
249f43f3cc [refactor] add option to disable RBF (glozow)
897e348f59 [coins/mempool] extend CCoinsViewMemPool to track temporary coins (glozow)
42cf8b25df [validation] make CheckSequenceLocks context-free (glozow)

Pull request description:

  This PR enables validation dry-runs of packages through the `testmempoolaccept` RPC. The expectation is that the results returned from `testmempoolaccept` are what you'd get from test-then-submitting each transaction individually, in that order (this means the package is expected to be sorted in topological order, for now at least). The validation is also atomic: in the case of failure, it immediately halts and may return "unfinished" `MempoolAcceptResult`s for transactions that weren't fully validated. The API for 1 transaction stays the same.

  **Motivation:**
  - This allows you to test validity for transaction chains (e.g. with multiple spending paths and where you don't want to broadcast yet); closes #18480.
  - It's also a first step towards package validation in a minimally invasive way.
  - The RPC commit happens to close #21074 by clarifying the "allowed" key.

  There are a few added restrictions on the packages, mostly to simplify the logic for areas that aren't critical to main package use cases:
  - No package can have conflicts, i.e. none of them can spend the same inputs, even if it would be a valid BIP125 replacement.
  - The package cannot conflict with the mempool, i.e. RBF is disabled.
  - The total count of the package cannot exceed 25 (the default descendant count limit), and total size cannot exceed 101KvB (the default descendant size limit).

  If you're looking for review comments and github isn't loading them, I have a gist compiling some topics of discussion [here](https://gist.github.com/glozow/c3acaf161c95bba491fce31585b2aaf7)

ACKs for top commit:
  laanwj:
    Code review re-ACK 13650fe2e5
  jnewbery:
    Code review ACK 13650fe2e5
  ariard:
    ACK 13650fe

Tree-SHA512: 8c5cbfa91a6c714e1c8710bb281d5ff1c5af36741872a7c5df6b24874d6272b4a09f816cb8a4c7de33ef8e1c2a2c252c0df5105b7802f70bc6ff821ed7cc1a2f
2021-05-27 22:40:24 +02:00
glozow
13650fe2e5 [policy] detect unsorted packages 2021-05-24 15:48:32 +01:00
glozow
ae8e6df709 [policy] limit package sizes
Maximum number of transactions allowed in a package is 25, equal to the
default mempool descendant limit: if a package has more transactions
than this, either it would fail default mempool descendant limit or the
transactions don't all have a dependency relationship (but then they
shouldn't be in a package together). Same rationale for 101KvB virtual
size package limit.

Note that these policies are only used in test accepts so far.
2021-05-24 14:42:10 +01:00
glozow
2ef187941d [validation] package validation for test accepts
Only allow test accepts for now. Use the CoinsViewTemporary to keep
track of coins created by each transaction so that subsequent
transactions can spend them. Uncache all coins since we only
ever do test accepts (Note this is different from ATMP which doesn't
uncache for valid test_accepts) to minimize impact on the coins cache.

Require that the input txns have no conflicts and be ordered
topologically. This commit isn't able to detect unsorted packages.
2021-05-24 14:42:10 +01:00
Kiminuo
4c3a5dcbfc scripted-diff: Replace GetDataDir() calls with gArgs.GetDataDirNet() calls
-BEGIN VERIFY SCRIPT-
git ls-files -- 'src' ':(exclude)src/util/system.h' ':(exclude)src/util/system.cpp' | xargs sed -i 's/GetDataDir()/gArgs.GetDataDirNet()/g';
-END VERIFY SCRIPT-
2021-05-24 10:29:58 +02:00
glozow
578148ded6 [validation] explicit Success/Failure ctors for MempoolAcceptResult
Makes code more clear and prevents accidentally calling the wrong ctor.
2021-05-20 21:34:31 +01:00
glozow
249f43f3cc [refactor] add option to disable RBF
This is a mere refactor for now. We will use this to disable RBFing in
package validation.
2021-05-20 21:34:31 +01:00
glozow
42cf8b25df [validation] make CheckSequenceLocks context-free
Allow CheckSequenceLocks to use heights and coins from any CoinsView and
CBlockIndex provided. This means that CheckSequenceLocks() doesn't need
to hold the mempool lock or cs_main. The caller is responsible for
ensuring the CoinsView and CBlockIndex are consistent before passing
them in. The typical usage is still to create a CCoinsViewMemPool from
the mempool and grab the CBlockIndex from the chainstate tip.
2021-05-20 21:34:31 +01:00
Antoine Riard
2eb0eeda39 validation: document lack of inherited signaling in RBF policy 2021-05-14 14:27:30 -04:00
MarcoFalke
fa340b8794
refactor: Avoid magic value of all-zeros in assumeutxo base_blockhash
Just use std::optional
2021-05-11 11:21:05 +02:00
MarcoFalke
fae33f98e6
Fix assumeutxo crash due to invalid base_blockhash
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-05-11 10:41:03 +02:00
MarcoFalke
fa5668bfb3
refactor: Use type-safe assumeutxo hash
This avoids accidentally mixing it up with other hashes (like block
hashes).
2021-05-11 10:40:40 +02:00
W. J. van der Laan
f8176b768a
Merge bitcoin/bitcoin#21836: scripted-diff: Replace three dots with ellipsis in the UI strings
d66f283ac0 scripted-diff: Replace three dots with ellipsis in the UI strings (Hennadii Stepanov)

Pull request description:

  This PR is split from #21463.
  The change was suggested on [Transifex.com](https://www.transifex.com/bitcoin/bitcoin/), and it does not touch `LogPrint` and `LogPrintf` calls.

  The only comment on #21463 [was](9030e4b5a6 (r597220100)):
  > Mind that these messages also end up in the log. In principle the log is already UTF-8 (as are all strings and text in bitcoind). But, just noting, that it might make browsing the log a less pleasant experience on systems with misconfigured locale like some BSDs by default.

ACKs for top commit:
  laanwj:
    ACK d66f283ac0

Tree-SHA512: 5ab1cb3160f3f996f1ad7d7486662da3eb7f06a857f4a1874963ce10caed5b86b0ad6151b1b9ebeb2b8aa5f0c85efad3b768ea9cafe5db86f78f88912b756d1e
2021-05-10 14:02:46 +02:00
MarcoFalke
128b98fce3
Merge bitcoin/bitcoin#21681: validation: fix ActivateSnapshot to use hardcoded nChainTx
91d93aac4e validation: remove nchaintx from assumeutxo metadata (James O'Beirne)
931684b24a validation: fix ActivateSnapshot to use hardcoded nChainTx (James O'Beirne)

Pull request description:

  This fixes an oversight from the move of nChainTx from the user-supplied
  snapshot metadata into the hardcoded assumeutxo chainparams.

  Since the nChainTx is now unused in the metadata, it should be removed
  in a future commit.

  See: https://github.com/bitcoin/bitcoin/pull/19806#discussion_r612165410

ACKs for top commit:
  Sjors:
    utACK 91d93aac4e
  ryanofsky:
    Code review ACK 91d93aac4e. No change to previous commit, just new commit removing now unused utxo snapshot field and updating tests.

Tree-SHA512: 445bdd738faf007451f40bbcf360dd1fb4675e17a4c96546e6818c12e33dd336dadd95cf8d4b5f8df1d6ccfbc4bf5496864bb5528e416cea894857b6b732140c
2021-05-05 18:34:16 +02:00
W. J. van der Laan
3275c6e578
Merge bitcoin/bitcoin#21727: refactor: Move more stuff to blockstorage
fa09a9eac8 style: Add { } to multi-line if (MarcoFalke)
fadafab833 move-only: Move functions to blockstorage (MarcoFalke)
fa7e64d586 move-only: Move constants to blockstorage (MarcoFalke)
fa247a327f refactor: Move block storage globals to blockstorage (MarcoFalke)
fa81c30c6f refactor: Move pruning/reindex/importing globals to blockstorage (MarcoFalke)

Pull request description:

  See #21575

ACKs for top commit:
  Sjors:
    ACK fa09a9eac8
  kiminuo:
    ACK fa09a9e
  laanwj:
    Code review ACK fa09a9eac8
  promag:
    Code review ACK fa09a9eac8. Since last review

Tree-SHA512: 2eb6962ff44da6b77f3058fc02ec66ab742e25ae8dcc8ec62b062896571910d43ca7c4bb16fb3ccb5e5245195b8dec6384b6c8d442fa97ca28d93bdff347d677
2021-05-05 16:03:03 +02:00
Hennadii Stepanov
d66f283ac0
scripted-diff: Replace three dots with ellipsis in the UI strings
-BEGIN VERIFY SCRIPT-
sed -i -E -e 's/\.\.\."\)(\.|,|\)| )/…"\)\1/' -- $(git ls-files -- 'src' ':(exclude)src/qt/bitcoinstrings.cpp')
sed -i -e 's/\.\.\.\\"/…\\"/' src/qt/sendcoinsdialog.cpp
sed -i -e 's|\.\.\.</string>|…</string>|' src/qt/forms/*.ui
sed -i -e 's|\.\.\.)</string>|…)</string>|' src/qt/forms/sendcoinsdialog.ui
-END VERIFY SCRIPT-
2021-05-02 22:17:16 +03:00
W. J. van der Laan
2b45cf0bcd
Merge bitcoin/bitcoin#19521: Coinstats Index
5f96d7d22d rpc: gettxoutsetinfo rejects hash_serialized_2 for specific height (Fabian Jahr)
23fe50436b test: Add test for coinstatsindex behavior in reorgs (Fabian Jahr)
90c966b0f3 rpc: Allow gettxoutsetinfo and getblockstats for stale blocks (Fabian Jahr)
b9362392ae index, rpc: Add use_index option for gettxoutsetinfo (Fabian Jahr)
bb7788b121 test: Test coinstatsindex robustness across restarts (Fabian Jahr)
e0938c2909 test: Add tests for block_info in gettxoutsetinfo (Fabian Jahr)
2501576ecc rpc, index: Add verbose amounts tracking to Coinstats index (Fabian Jahr)
655d929836 test: add coinstatsindex getindexinfo coverage, improve current tests (Jon Atack)
ca01bb8d68 rpc: Add Coinstats index to getindexinfo (Fabian Jahr)
57a026c30f test: Add unit test for Coinstats index (Fabian Jahr)
6a4c0c09ab test: Add functional test for Coinstats index (Fabian Jahr)
3f166ecc12 rpc: gettxoutsetinfo can be requested for specific blockheights (Fabian Jahr)
3c914d58ff index: Coinstats index can be activated with command line flag (Fabian Jahr)
dd58a4de21 index: Add Coinstats index (Fabian Jahr)
a8a46c4b3c refactor: Simplify ApplyStats and ApplyHash (Fabian Jahr)
9c8a265fd2 refactor: Pass hash_type to CoinsStats in stats object (Fabian Jahr)
2e2648a902 crypto: Make MuHash Remove method efficient (Fabian Jahr)

Pull request description:

  This is part of the coinstats index project tracked in #18000

  While the review of the new UTXO set hash algorithm (MuHash) takes longer recently #19328 was merged which added the possibility to run `gettxoutsetinfo` with a specific hash type. As the first type it added `hash_type=none` which skips the hashing of the UTXO set altogether. This alone did not make `gettxoutsetinfo` much faster but it allows the use of an index for the remaining coin statistics even before a new hashing algorithm has been added. Credit to Sjors for the idea to take this intermediate step.

  Features summary:
  - Users can start their node with the option `-coinstatsindex` which syncs the index in the background
  - After the index is synced the user can  use `gettxoutsetinfo` with `hash_type=none` or `hash_type=muhash` and will get the response instantly out of the index
  - The user can specify a height or block hash when calling `gettxoutsetinfo` to see coin statistics at a specific block height

ACKs for top commit:
  Sjors:
    re-tACK 5f96d7d22d
  jonatack:
    Code review re-ACK 5f96d7d22d per `git range-diff 13d27b4 07201d3 5f96d7d`
  promag:
    Tested ACK 5f96d7d22d. Light code review ACK 5f96d7d22d.

Tree-SHA512: cbca78bee8e9605c19da4fbcd184625fb280200718396c694a56c7daab6f44ad23ca9fb5456d09f245d8b8d9659fdc2b3f3ce5e953c1c6cf4003dbc74c0463c2
2021-04-30 17:27:19 +02:00
MarcoFalke
c6d6bc8abb
Merge bitcoin/bitcoin#21523: validation: run VerifyDB on all chainstates
844ad0ecca doc: IsSnapshotActive (James O'Beirne)
9b604c0207 validation: prepare VerifyDB for assumeutxo (James O'Beirne)
7901647d72 refactor: rename active_chainstate in VerifyDB (James O'Beirne)

Pull request description:

  This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11) (parent PR: #15606)

  ---

  ~~Pretty cut and dry; parameterizes `CVerifyDB` methods so that we can run the verify procedure on multiple chainstates.~~

  Two minor tweaks to ensure that `VerifyDB` can be run on multiple chainstates and a corresponding rename.

ACKs for top commit:
  fjahr:
    Code review re-ACK 844ad0ecca
  MarcoFalke:
    review ACK 844ad0ecca 🐥

Tree-SHA512: 26a398cf4dabc1aa0850743921dba0452b4813848a3c777586dc981716737e98e17b8110254a5c41af95dd236e0c00dc8b4eee891d69bef825a5e1911fc499d0
2021-04-27 13:31:29 +02:00
MarcoFalke
fadafab833
move-only: Move functions to blockstorage 2021-04-27 10:36:23 +02:00
MarcoFalke
fa7e64d586
move-only: Move constants to blockstorage 2021-04-27 10:32:54 +02:00
MarcoFalke
fa247a327f
refactor: Move block storage globals to blockstorage
However, keep a declaration in validation to make it possible to move
smaller chunks to blockstorage without breaking compilation.

Also, expose AbortNode in the header.

Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-04-27 10:32:30 +02:00
MarcoFalke
fa81c30c6f
refactor: Move pruning/reindex/importing globals to blockstorage
Can be reviewed with --color-moved=dimmed-zebra
2021-04-27 10:32:24 +02:00
W. J. van der Laan
19a56d1519
Merge bitcoin/bitcoin#21009: Remove RewindBlockIndex logic
d831e711ca [validation] RewindBlockIndex no longer needed (Dhruv Mehta)

Pull request description:

  Closes #17862

  Context from [original comment](https://github.com/bitcoin/bitcoin/issues/17862#issuecomment-744285188) (minor edits):

  `RewindBlockIndex()` is a mechanism to allow nodes to be upgraded after segwit activation, while still keeping their chainstate/datadir in a consistent state. It works as follows:

  - A pre-segwit (i.e. v0.13.0 or older) node is running.
  -  Segwit activates. The pre-segwit node remains sync'ed to the tip, but is not enforcing the new segwit rules.
  - The user upgrades the node to a segwit-aware version (v0.13.1 or newer).
  - On startup, in `AppInitMain()`, `RewindBlockIndex()` is called. This walks the chain backwards from the tip, disconnecting and erasing blocks that from after segwit activation that weren't validated with segwit rules.
  - those blocks are then redownloaded (with witness data) and validated with segwit rules.

  This logic probably isn't required any more since:

  - Segwit activated at height 481824, when the block chain was 130GB and the total number of txs was 250 million. Today, we're at height 667704, the blockchain is over 315GB and the total number of txs is over 600 million. Even if 20% of that added data is witness data (a high estimate), then around 150GB of transactions would need to be rewound to get back to segwit activation height. It'd probably be faster to simply validate from genesis, especially since we won't be validating any scripts before the assumevalid block. It's also unclear whether rewinding 150GB of transactions would even work. It's certainly never been tested.
  - Bitcoin Core v0.13 is hardly used any more. https://luke.dashjr.org/programs/bitcoin/files/charts/software.html shows less than 50 nodes running it. The software was EOL on Aug 1st 2018. It's very unlikely that anyone is running 0.13 and will want to upgrade to 0.22.

  This PR introduces `NeedsRedownload()` which merely checks for insufficiently validated segwit blocks and requests that the user restarts the node with `-reindex`. Reindexing the block files upon restart will make the node rebuild chain state and block index from the `blk*.dat` files on disk. The node won't be able to index the blocks with `BLOCK_OPT_WITNESS`, so they will be missing from the chain and be re-downloaded, with witness data.

  Removing this code allows the following (done in follow-up #21090):

  - removal of tests using `segwitheight=-1` in `p2p_segwit.py`.
  - in turn, that allows us to drop support for `-segwitheight=-1`, which is only supported for that test.
  - that allows us to always set `NODE_WITNESS` in our local services. The only reason we don't do that is to support `-segwitheight=-1`.
  - that in turn allows us to drop all of the `GetLocalServices() & NODE_WITNESS` checks inside `net_processing.cpp`, since our local services would always include `NODE_WITNESS`

ACKs for top commit:
  jnewbery:
    utACK d831e711ca
  jamesob:
    ACK d831e711ca
  laanwj:
    Cursory code review ACK d831e711ca. Agree with the direction of the change, thanks for simplifying the logic here.
  glozow:
    utACK d831e711ca

Tree-SHA512: 3eddf5121ccd081ad7f15a5c6478ef867083edc8ba0bf1ee759e87bc070ee3d2f0698a3feba8db8dc087987c8452887b6f72cff05b3e178f41cb10a515fb8053
2021-04-27 10:14:52 +02:00
James O'Beirne
9b604c0207
validation: prepare VerifyDB for assumeutxo
Removes assumptions of use only on the active chainstate.
2021-04-23 15:06:48 -04:00
James O'Beirne
7901647d72
refactor: rename active_chainstate in VerifyDB
To prepare VerifyDB semantics for multiple
chainstate use.
2021-04-23 15:02:35 -04:00
Dhruv Mehta
d831e711ca [validation] RewindBlockIndex no longer needed
Instead of rewinding blocks, we request that the user restarts with
-reindex
2021-04-21 16:09:14 -07:00
Fabian Jahr
9c8a265fd2
refactor: Pass hash_type to CoinsStats in stats object 2021-04-19 20:28:48 +02:00
Kiminuo
b4190eff72 Change GetBlocksDir() to ArgsManager.GetBlocksDirPath(). 2021-04-18 11:59:28 +02:00
James O'Beirne
931684b24a
validation: fix ActivateSnapshot to use hardcoded nChainTx
This fixes an oversight from the move of nChainTx from the user-supplied
snapshot metadata into the hardcoded assumeutxo chainparams.

Since the nChainTx is now unused in the metadata, it should be removed
in a future commit.
2021-04-14 13:29:27 -04:00
MarcoFalke
a12962ca89
Merge #21585: Fix assumeutxo crash due to truncated file
fa73ce6e65 Fix assumeutxo crash due to truncated file (MarcoFalke)

Pull request description:

ACKs for top commit:
  jamesob:
    ACK fa73ce6e65
  ryanofsky:
    Code review ACK fa73ce6e65. Easy fix. It seems like this could have been caught in review, though.

Tree-SHA512: 3a98687c386e3995114ddf0ad7194fadd9520989290681ef703b578e3ca21aee51eadfb83aa38a489bac13d12709ea137b9b184b08e5bfa2919cca177aab90be
2021-04-14 15:12:14 +02:00
fanquake
1f14130cb0
Merge #21575: refactor: Create blockstorage module
fadcd3f78e doc: Remove irrelevant link to GitHub (MarcoFalke)
fa121b628d blockstorage: [refactor] Use chainman reference where possible (MarcoFalke)
fa0c7d9ad2 move-only: Move *Disk functions to blockstorage (MarcoFalke)
fa91b2b2b3 move-only: Move AbortNode to shutdown (MarcoFalke)
fa413f07a1 move-only: Move ThreadImport to blockstorage (MarcoFalke)
faf843c07f refactor: Move load block thread into ChainstateManager (MarcoFalke)

Pull request description:

  This picks up the closed pull request #21030 and is the first step toward fixing #21220.

  The basic idea is to move all disk access into a separate module with benefits:
  * Breaking down the massive files init.cpp and validation.cpp into logical units
  * Creating a standalone-module to reduce the mental complexity
  * Pave the way to fix validation related circular dependencies
  * Pave the way to mock disk access for testing, especially where it is performance critical (like fuzzing)

ACKs for top commit:
  promag:
    Code review ACK fadcd3f78e, checked (almost) moved only changes. This is a nice tidy up change and doesn't change behavior. Easily reviewed commit by commit.
  jamesob:
    ACK fadcd3f78e ([`jamesob/ackr/21575.1.MarcoFalke.refactor_create_blocksto`](https://github.com/jamesob/bitcoin/tree/ackr/21575.1.MarcoFalke.refactor_create_blocksto))
  ryanofsky:
    Code review ACK fadcd3f78e. New organization makes sense, moves extraneous things outside of validation.cpp. PR is also easy to review with helpfully split up moveonly commits.

Tree-SHA512: 917996592b6d8f9998289d8cb2b1b78b23d1fdb3b07216c9caec1380df33baa09dc2c1e706da669d440b497e79c9c62a01ca20dc202df5ad974a75f3ef7a143b
2021-04-13 22:00:28 +08:00
MarcoFalke
fa0c7d9ad2
move-only: Move *Disk functions to blockstorage
Can be reviewed with the git options
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-04-05 20:26:14 +02:00
MarcoFalke
fa91b2b2b3
move-only: Move AbortNode to shutdown
Can be reviewed with the git option
--color-moved=dimmed-zebra
2021-04-04 18:08:36 +02:00
MarcoFalke
fa9b74f5ea
Fix assumeutxo crash due to missing base_blockhash 2021-04-04 07:38:02 +02:00
MarcoFalke
fa73ce6e65
Fix assumeutxo crash due to truncated file 2021-04-03 17:52:58 +02:00
W. J. van der Laan
66daf4cb3b
Merge #21567: docs: fix various misleading comments
4eca20d6f7 [doc] correct comment about ATMPW (glozow)
8fa74aeb5b [doc] correct comment in chainparams (glozow)
2f8272c2a4 [doc] GetBestBlock() doesn't do nothing (gzhao408)

Pull request description:

  Came across a few misleading comments, wanted to fix them

ACKs for top commit:
  jnewbery:
    ACK 4eca20d6f7
  MarcoFalke:
    ACK 4eca20d6f7
  laanwj:
    Code review ACK 4eca20d6f7

Tree-SHA512: 5bef1f1e7703f304128cf0eb8945e139e031580c99062bbbe15bf4db8443c2ba5a8c65844833132e6646c8980c678fc1d2ab0c63e17105585d583570ee350fd0
2021-04-01 19:12:10 +02:00
glozow
4eca20d6f7 [doc] correct comment about ATMPW
ATMPW stands for AcceptToMemoryPoolWorker, which was removed in #16400.
2021-04-01 08:35:34 -07:00
gzhao408
2f8272c2a4 [doc] GetBestBlock() doesn't do nothing
This has tripped people up multiple times because it looks like
GetBestBlock is a const function returning the value of hashBlock.
2021-04-01 08:33:11 -07:00
Carl Dong
7e8b5ee814 validation: Make BlockManager::LookupBlockIndex const 2021-03-30 13:52:22 -04:00
fanquake
5294f0d5a9
refactor: return std::nullopt instead of {}
In #21415 we decided to return `std::optional` rather than `{}` for
uninitialized values. This PR repalces the two remaining usages of `{}`
with `std::nullopt`.

As a side-effect, this also quells the spurious GCC 10.2.x warning that
we've had reported quite a few times. i.e #21318, #21248, #20797.

```bash
txmempool.cpp: In member function ‘CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>&) const’:
txmempool.cpp:898:13: warning: ‘<anonymous>’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  898 |     return {};
      |             ^
```
2021-03-22 11:22:06 +08:00
MarcoFalke
63952f73b3
Merge #20921: validation: don't try to invalidate genesis block in CChainState::InvalidateBlock
787df19b09 validation: don't try to invalidate genesis block (Sebastian Falbesoner)

Pull request description:

  In the block invalidation method (`CChainState::InvalidateBlock`), the code for creating the candidate block map assumes that the passed block's previous block (`pindex->pprev`) is available and otherwise segfaults due to null-pointer deference in `CBlockIndexWorkComparator()` (see analysis by practicalswift in #20914), i.e. it doesn't work with the genesis block. Rather than analyzing all possible code paths and implications for this corner case, simply fail early if the genesis block is passed.

  Fixes #20914.

ACKs for top commit:
  sipa:
    ACK 787df19b09. Tested invalidation of generic on regtest.
  practicalswift:
    Tested ACK 787df19b09

Tree-SHA512: 978be7cf2bd1c1faebfe945d191ac77dea72791bea826459abd308f77c74c5991efee495a38817c306e488ecd5208b5c888df7d9d044132dd9a06bbbdb256b6c
2021-03-20 12:46:11 +01:00
Wladimir J. van der Laan
a9d1b40d53
Merge #21415: refactor: remove Optional & nullopt
ebc4ab721b refactor: post Optional<> removal cleanups (fanquake)
57e980d13c scripted-diff: remove Optional & nullopt (fanquake)

Pull request description:

  Same rationale & motivation as #21404, which turned out to be quite low in the number of potential conflicts. Lets see what the bot has to say here.

ACKs for top commit:
  practicalswift:
    cr ACK ebc4ab721b: patch looks correct
  jnewbery:
    utACK ebc4ab721b
  laanwj:
    Code review ACK ebc4ab721b

Tree-SHA512: 550fbeef09b9d35ddefaa805d1755c18c8fd499c4b0f77ebfece8c20296a7abd1cf6c699e2261f92fe3552deeb7555ec2a2287ffe3ab9e98bb9f8612a4d43be3
2021-03-17 12:17:33 +01:00
fanquake
ebc4ab721b
refactor: post Optional<> removal cleanups 2021-03-17 14:56:20 +08:00
MarcoFalke
67ec26cacf
Merge #19259: fuzz: Add fuzzing harness for LoadMempool(...) and DumpMempool(...)
68afd3eeec tests: Add fuzzing harness for LoadMempool(...) and DumpMempool(...) (practicalswift)
91af6b97c9 validation: Make DumpMempool(...) and LoadMempool(...) easier to test/fuzz/mock (practicalswift)
af322c7494 tests: Set errno in FuzzedFileProvider. Implement seek(..., ..., SEEK_END). (practicalswift)

Pull request description:

  Add fuzzing harness for `LoadMempool(...)` and `DumpMempool(...)`.

  See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets).

  Happy fuzzing :)

ACKs for top commit:
  jonatack:
    Tested re-ACK 68afd3eeec

Tree-SHA512: 4b5fcaa87e6eb478611d3b68eb6859645a5e121e7e3b056ad2815699dace0a6123706ff542def371b47f4ab3ce2b8a29782026d84fb505827121e9b4cc7dac31
2021-03-15 18:56:06 +01:00
fanquake
57e980d13c
scripted-diff: remove Optional & nullopt
-BEGIN VERIFY SCRIPT-
git rm src/optional.h

sed -i -e 's/Optional</std::optional</g' $(git grep -l 'Optional<' src)

sed -i -e 's/{nullopt}/{std::nullopt}/g' $(git grep -l 'nullopt' src)
sed -i -e 's/ nullopt;/ std::nullopt;/g' $(git grep -l 'nullopt' src)
sed -i -e 's/ nullopt)/ std::nullopt)/g' $(git grep -l 'nullopt' src)
sed -i -e 's/(nullopt)/(std::nullopt)/g' $(git grep -l 'nullopt' src)
sed -i -e 's/ nullopt,/ std::nullopt,/g' $(git grep -l 'nullopt' src)
sed -i -e 's/? nullopt :/? std::nullopt :/g' $(git grep -l 'nullopt' src)
sed -i -e 's/: nullopt}/: std::nullopt}/g' $(git grep -l 'nullopt' src)

sed -i -e '/optional.h \\/d' src/Makefile.am

sed -i -e '/#include <optional.h>/d' src/test/fuzz/autofile.cpp src/test/fuzz/buffered_file.cpp src/test/fuzz/node_eviction.cpp

sed -i -e 's/#include <optional.h>/#include <optional>/g' $(git grep -l '#include <optional.h>' src)
-END VERIFY SCRIPT-
2021-03-15 10:41:30 +08:00
MarcoFalke
e0bc27a14c
Merge #21404: refactor: Remove MakeUnique<T>()
1a6323bdbe doc: update developer notes for removal of MakeUnique (fanquake)
3ba2840e7e scripted-diff: remove MakeUnique<T>() (fanquake)

Pull request description:

  Since requiring C++17, this is just pointless abstraction. I think we should just "tear the band-aid off" and remove it. Similar to the changes happening in #21366.

  Also, having a comment saying this is deprecated doesn't prevent it's usage in new code. i.e : https://github.com/bitcoin/bitcoin/pull/20946#discussion_r561949731.

  The repository is fairly quiet at the moment, so any potential complaints about having to rebase should be minimal. Might as well get this over and done with.

ACKs for top commit:
  jnewbery:
    utACK 1a6323bdbe
  practicalswift:
    cr ACK 1a6323bdbe: patch looks correct
  ajtowns:
    ACK 1a6323bdbe -- code review only
  glozow:
    ACK 1a6323bdbe looks correct

Tree-SHA512: 4a14b9611b60b9b3026b54d6f5a2dce4c5d9b63a7b93d7de1307512df736503ed84bac66e7b93372c76e3117f49bf9f29cd473d3a47cb41fb2775bc10234736f
2021-03-12 08:34:15 +01:00
practicalswift
91af6b97c9 validation: Make DumpMempool(...) and LoadMempool(...) easier to test/fuzz/mock 2021-03-11 22:34:39 +00:00
fanquake
3ba2840e7e
scripted-diff: remove MakeUnique<T>()
-BEGIN VERIFY SCRIPT-
git rm src/util/memory.h
sed -i -e 's/MakeUnique/std::make_unique/g' $(git grep -l MakeUnique src)
sed -i -e '/#include <util\/memory.h>/d' $(git grep -l '#include <util/memory.h>' src)
sed -i -e '/util\/memory.h \\/d' src/Makefile.am
-END VERIFY SCRIPT-
2021-03-11 13:45:14 +08:00
Carl Dong
106bcd4f39 node/coinstats: Pass in BlockManager to GetUTXOStats 2021-03-08 15:54:31 -05:00
Carl Dong
e11b649650 validation: CVerifyDB::VerifyDB: Use locking annotation
...instead of recursively locking unconditionally
2021-03-03 14:56:26 -05:00
Carl Dong
03f75c42e1 validation: Use existing chain member in CChainState::LoadGenesisBlock 2021-03-03 14:49:30 -05:00
Carl Dong
5e4af77380 validation: Use existing chain member in CChainState::AcceptBlock 2021-03-03 14:49:30 -05:00
Carl Dong
fee73347c0 validation: Pass in chain to FindBlockPos+SaveBlockToDisk 2021-03-03 14:49:30 -05:00
Carl Dong
a9d28bcd8d validation: Use *this in CChainState::ActivateBestChainStep 2021-03-03 14:49:30 -05:00
Carl Dong
4744efc9ba validation: Pass in chainstate to CTxMemPool::check
This is the only instance where validation reaches for something outside
of it.
2021-03-03 14:49:29 -05:00
Carl Dong
1fb7b2c595 validation: Use *this in CChainState::InvalidateBlock 2021-03-01 17:56:23 -05:00
Carl Dong
8cdb2f7e58 validation: Move LoadBlockIndexDB to CChainState
CChainState needed cuz setBlockIndexCandidates
2021-03-01 17:56:22 -05:00
Carl Dong
8b99efbcc0 validation: Move invalid block handling to CChainState
- InvalidChainFound
- CheckForkWarningConditions
2021-03-01 17:56:07 -05:00
Carl Dong
2bdf37fe18 validation: Pass in chainstate to CVerifyDB::VerifyDB 2021-03-01 17:56:07 -05:00
Carl Dong
31eac50c72 validation: Remove global ::VersionBitsTip{State,SinceHeight,Statistics}
Tip: versionbitscache is currently a global so we didn't need to pass it
     in to any of ::VersionBitsTip*'s callers
2021-03-01 17:56:07 -05:00
Carl Dong
63e4c7316a validation: Pass in chainstate to ::PruneBlockFilesManual 2021-03-01 17:56:07 -05:00
Carl Dong
4bada76237 validation: Pass in chainstate to UpdateTip 2021-03-01 17:56:07 -05:00
Carl Dong
a3ba08ba7d validation: Remove global ::{{Precious,Invalidate}Block,ResetBlockFailureFlags} 2021-02-22 11:48:39 -05:00
Carl Dong
4927c9e699 validation: Remove global ::LoadGenesisBlock 2021-02-22 11:48:39 -05:00
Carl Dong
9da106be4d validation: Check chain tip is non-null in CheckFinalTx
...also update comments to remove mention of ::ChainActive()

From: https://github.com/bitcoin/bitcoin/pull/20750#discussion_r579400663

> Also, what about passing a const reference instead of a pointer? I
> know this is only theoretical, but previously if the tip was nullptr,
> then Height() evaluated to -1, now it evaluates to UB
2021-02-22 11:46:37 -05:00
MarcoFalke
34d7030063
Merge #21202: [validation] Two small clang lock annotation improvements
25c57d6409 [doc] Add a note about where lock annotations should go. (Amiti Uttarwar)
ad5f01b960 [validation] Move the lock annotation from function definition to declaration (Amiti Uttarwar)

Pull request description:

  Based on reviewing #21188

  the first commit switches the lock annotations on `CheckInputScripts` to be on the function declaration instead of on the function definition. this ensures that all call sites are checked, not just ones that come after the definition.

  the second commit adds a note to the developer-notes section to clarify where the annotations should be applied.

ACKs for top commit:
  MarcoFalke:
    ACK 25c57d6409 🥘
  promag:
    Code review ACK 25c57d6409.

Tree-SHA512: 61b6ef856bf6c6016d535fbdd19daf57b9e59fe54a1f30d47282a071b9b9d60b2466b044ee57929e0320cb1bdef52e7a1687cacaa27031bbc43d058ffffe22ba
2021-02-22 09:47:15 +01:00
Carl Dong
e8ae1db864 style-only: Make AcceptToMemoryPool signature readable 2021-02-18 14:49:10 -05:00
Carl Dong
8f5c100064 style-only: Make CheckSequenceLock signature readable 2021-02-18 14:49:10 -05:00
Carl Dong
8c824819c8 validation: Use *this in CChainState::LoadMempool 2021-02-18 14:49:10 -05:00
Carl Dong
0a9a24d8c7 validation: Pass in chainstate to UpdateMempoolForReorg 2021-02-18 14:49:10 -05:00
Carl Dong
7142018812 validation: Pass in chainstate to CTxMemPool::removeForReorg
Several other parameters are now redundant since they can be safely
obtained from the chainstate given that ::cs_main is locked. These are
now removed.
2021-02-18 14:49:10 -05:00
Carl Dong
71734c65dc validation: Pass in chain to ::TestLockPointValidity 2021-02-18 14:49:10 -05:00
Carl Dong
417dafc1ee validation: Remove old AcceptToMemoryPool w/o chainstate param 2021-02-18 14:49:10 -05:00
Carl Dong
229bc37b5f validation: Pass in chainstate to ::AcceptToMemoryPool 2021-02-18 14:43:28 -05:00
Carl Dong
d0da7ea57a validation: Pass in chainstate to ::LoadMempool 2021-02-18 14:43:28 -05:00
Carl Dong
3a205c43dc validation: Pass in chainstate to AcceptToMemoryPoolWithTime 2021-02-18 14:43:28 -05:00
Carl Dong
d8a816329c validation: Add chainstate member to MemPoolAccept 2021-02-18 14:43:28 -05:00
Carl Dong
4c15942b79 validation: Pass in chainstate to ::CheckSequenceLocks 2021-02-18 14:43:28 -05:00
Carl Dong
577b774d0c validation: Remove old CheckFinalTx w/o chain tip param 2021-02-18 14:43:28 -05:00
Carl Dong
d015eaa550 validation: Pass in chain tip to ::CheckFinalTx 2021-02-18 14:43:28 -05:00
Carl Dong
252b489c9f validation: Pass in coins tip to CheckInputsFromMempoolAndCache 2021-02-18 14:43:28 -05:00
Carl Dong
73a6d2b7be validation: Pass in chainstate to IsCurrentForFeeEstimation 2021-02-18 14:43:28 -05:00
Carl Dong
d1f932b0b0 validation: Pass in coins cache to ::LimitMempoolSize 2021-02-18 14:43:28 -05:00
Jonas Schnelli
9017d55e7c
Merge #15946: Allow maintaining the blockfilterindex when using prune
84716b134e Add "index/blockfilterindex -> validation -> index/blockfilterindex" to expected circular dependencies (Jonas Schnelli)
ab3a0a2fb9 Add functional test for blockfilterindex in prune-mode (Jonas Schnelli)
c286a22f7b Add debug startup parameter -fastprune for more effective pruning tests (Jonas Schnelli)
5e112269c3 Avoid pruning below the blockfilterindex sync height (Jonas Schnelli)
00d57ff768 Avoid accessing nullpointer in BaseIndex::GetSummary() (Jonas Schnelli)
6abe9f5b11 Allow blockfilter in conjunction with prune (Jonas Schnelli)

Pull request description:

  Maintaining the blockfilterindexes in prune mode is possible and may lead to efficient p2p based rescans of wallets (restore backups, import/sweep keys) beyond the prune height (rescans not part of that PR).

  This PR allows running the blockfilterindex(es) in conjunction with pruning.
  * Bitcoind/Qt will shutdown during startup when missing block data has been detected ([re]enable `-blockfilterindex` when we already have pruned)
  * manual block pruning is disabled during blockfilterindex sync
  * auto-pruning is delayed during blockfilterindex sync

  ToDos:
  * [x] Functional tests

ACKs for top commit:
  fjahr:
    Code review ACK 84716b1
  ryanofsky:
    Code review ACK 84716b134e. Only changes since last review were suggested new FindFilesToPrune argument and test.
  benthecarman:
    tACK 84716b134e

Tree-SHA512: 91d832c6c562c463f7ec7655c08956385413a99a896640b9737bda0183607fac530435d03d87c3c0e70c61ccdfe73fe8f3639bc7d26d33ca7e60925ebb97d77a
2021-02-18 09:40:42 +01:00
Amiti Uttarwar
25c57d6409 [doc] Add a note about where lock annotations should go. 2021-02-17 15:58:23 -08:00
Amiti Uttarwar
ad5f01b960 [validation] Move the lock annotation from function definition to declaration
When the annotation is on the definition, it does not check call sites between
the declaration and the definition.
2021-02-17 15:45:11 -08:00
Jonas Schnelli
c286a22f7b Add debug startup parameter -fastprune for more effective pruning tests 2021-02-16 10:26:17 +01:00
Jonas Schnelli
5e112269c3 Avoid pruning below the blockfilterindex sync height 2021-02-16 10:26:15 +01:00
James O'Beirne
f6e2da5fb7
simplify ChainstateManager::SnapshotBlockhash() return semantics
Don't return null snapshotblockhash values to avoid caller complexity/confusion.
2021-02-12 07:53:29 -06:00
James O'Beirne
7a6c46b37e
chainparams: add allowed assumeutxo values
Values for mainnet and testnet will be specified in a follow-up PR that can be
scrutinized accordingly. This structure is required for use in snapshot activation
logic.
2021-02-12 07:53:22 -06:00
Wladimir J. van der Laan
937dfa8398
Merge #21041: log: Move "Pre-allocating up to position 0x[…] in […].dat" log message to debug category
25f899cc23 log: Move "Pre-allocating up to position 0x[...] in [...].dat" log message to debug category (practicalswift)
acd7980b37 log: Move "Leaving block file [...]: [...]" log message to debug category (practicalswift)

Pull request description:

  Move `Pre-allocating up to position 0x[…] in […].dat` log message to debug category.

  After the cleanup of `-debug=net` log messages PR (#20724) was merged recently the console log now has very high signal to noise ratio. That's great! :)

  This PR increases the signal to noise ratio slightly more by moving the most common remaining implementation detail log message (`Pre-allocating up to position 0x[…] in […].dat`) to the debug category where it belongs :)

  Expected standard output from `bitcoind` (when in steady state) before this patch:

  ```
  $ src/bitcoind
  …
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z Pre-allocating up to position 0x0000000 in blk00000.dat
  0000-00-00T00:00:00Z Pre-allocating up to position 0x000000 in rev00000.dat
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  ```

  Expected standard output from `bitcoind` (when in steady state) after this patch:

  ```
  $ src/bitcoind
  …
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  0000-00-00T00:00:00Z UpdateTip: new best=0000000000000000000000000000000000000000000000000000000000000000 height=000000 version=0x00000000 log0_work=00.000000 tx=000000000 date='0000-00-00T00:00:00Z' progress=0.000000 cache=000.0MiB(0000000txo)
  ```

  I find the latter alternative much easier to visually scan for anomalies (and more aesthetically pleasing TBH!).

  Non-GUI users deserve nice interfaces too :)

ACKs for top commit:
  laanwj:
    ACK 25f899cc23

Tree-SHA512: 5970798c41b041527ebdcbd843c5e136c257c28c3b21fc74102da8970406ca5c0c7e406305c5e6e67de5c1708dc1858af07a77a2e05f44159b7103423e8ab32f
2021-02-11 19:58:20 +01:00
MarcoFalke
8e1913ae02
Merge #21062: refactor: return MempoolAcceptResult from ATMP
53e716ea11 [refactor] improve style for touched code (gzhao408)
174cb5330a [refactor] const ATMPArgs and non-const Workspace (gzhao408)
f82baf0762 [refactor] return MempoolAcceptResult (gzhao408)
9db10a5506 [refactor] clean up logic in testmempoolaccept (gzhao408)

Pull request description:

  This is the first 4 commits of #20833, and does refactoring only. It should be relatively simple to review, and offers a few nice things:
  - It makes accessing values that don't make sense (e.g. fee) when the tx is invalid an error.
  - Returning `MempoolAcceptResult` from ATMP makes the interface cleaner. The caller can get a const instead of passing in a mutable "out" param.
  - We don't have to be iterating through a bunch of lists for package validation, we can just return a `std::vector<MempoolAcceptResult>`.
  - We don't have to refactor all ATMP call sites again if/when we want to return more stuff from it.

ACKs for top commit:
  MarcoFalke:
    ACK 53e716ea11 💿
  jnewbery:
    Code review ACK 53e716ea11
  ariard:
    Code Review ACK 53e716e, I did tweak a bit the touched paths to see if we had good test coverage. Didn't find holes.

Tree-SHA512: fa6ec324a08ad9e6e55948615cda324cba176255708bf0a0a0f37cedb7a75311aa334ac6f223be7d8df3c7379502b1081102b9589f9a9afa1713ad3d9ab3c24f
2021-02-11 14:45:41 +01:00
practicalswift
acd7980b37 log: Move "Leaving block file [...]: [...]" log message to debug category 2021-02-10 20:40:42 +00:00
Sebastian Falbesoner
787df19b09 validation: don't try to invalidate genesis block 2021-02-10 00:14:18 +01:00
gzhao408
53e716ea11 [refactor] improve style for touched code 2021-02-09 07:01:52 -08:00
gzhao408
174cb5330a [refactor] const ATMPArgs and non-const Workspace
ATMPArgs should contain const arguments for validation.
The Workspace should contain state that may change
throughout validation.
2021-02-09 07:01:52 -08:00
gzhao408
f82baf0762 [refactor] return MempoolAcceptResult
This creates a cleaner interface with ATMP, allows us to make results const,
and makes accessing values that don't make sense (e.g. fee when tx is
invalid) an error.
2021-02-09 07:01:52 -08:00
Carl Dong
20677ffa22 validation: Guard all chainstates with cs_main
Since these chainstates are:

1. Also vulnerable to the race condition described in the previous
   commit
2. Documented as having similar semantics as m_active_chainstate

we should also protect them with ::cs_main.
2021-02-01 22:09:03 -05:00
Wladimir J. van der Laan
44f4bcd302
Merge #20749: [Bundle 1/n] Prune g_chainman usage related to ::LookupBlockIndex
67c9a83df1 style-only: Remove redundant sentence in ActivateBestChain comment (Carl Dong)
b8e95658d5 style-only: Make TestBlockValidity signature readable (Carl Dong)
0cdad75390 validation: Use accessible chainstate in ChainstateManager::ProcessNewBlock (Carl Dong)
ea4fed9021 validation: Use existing chainstate in ChainstateManager::ProcessNewBlockHeaders (Carl Dong)
e0dc305727 validation: Move LoadExternalBlockFile to CChainState (Carl Dong)
5f8cd7b3a5 validation: Remove global ::ActivateBestChain (Carl Dong)
2a696472a1 validation: Pass in chainstate to ::NotifyHeaderTip (Carl Dong)
9c300cc8b3 validation: Pass in chainstate to TestBlockValidity (Carl Dong)
0e17c833cd validation: Make CChainState.m_blockman public (Carl Dong)
d363d06bf7 validation: Pass in blockman to ContextualCheckBlockHeader (Carl Dong)
f11d11600d validation: Move GetLastCheckpoint to BlockManager (Carl Dong)
e4b95eefbc validation: Move GetSpendHeight to BlockManager (Carl Dong)
b026e318c3 validation: Move FindForkInGlobalIndex to BlockManager (Carl Dong)
3664a150ac validation: Remove global LookupBlockIndex (Carl Dong)
eae54e6e60 scripted-diff: Use BlockManager::LookupBlockIndex (Carl Dong)
15d20f40e1 validation: Move LookupBlockIndex to BlockManager (Carl Dong)
f92dc6557a validation: Guard the active_chainstate with cs_main (Carl Dong)

Pull request description:

  Overall PR: #20158 (tree-wide: De-globalize ChainstateManager)

  Note to reviewers:
  1. This bundle may _apparently_ introduce usage of `g_chainman` or `::Chain(state|)Active()` globals, but these are resolved later on in the overall PR. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits)
  2. There may be seemingly obvious local references to `ChainstateManager` or other validation objects which are not being used in callers of the current function in question, this is done intentionally to **_keep each commit centered around one function/method_** to ease review and to make the overall change systematic. We don't assume anything about our callers. Rest assured that once we are considering that particular caller in later commits, we will use the obvious local references. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits)
  3. When changing a function/method that has many callers (e.g. `LookupBlockIndex` with 55 callers), it is sometimes easier (and less error-prone) to use a scripted-diff. When doing so, there will be 3 commits in sequence so that every commit compiles like so:
  1. Add `new_function`, make `old_function` a wrapper of `new_function`, divert all calls to `old_function` to `new_function` **in the local module only**
  2. Scripted-diff to divert all calls to `old_function` to `new_function` **in the rest of the codebase**
  3. Remove `old_function`

ACKs for top commit:
  jnewbery:
    utACK 67c9a83df1
  laanwj:
    re-ACK 67c9a83df1
  ryanofsky:
    Code review ACK 67c9a83df1. Changes since last review:

Tree-SHA512: 8744aba2dd57a40cd2fedca809b0fe24d771bc60da1bffde89601999384aa0df428057a86644a3f72fbeedbc8b04db6c4fd264ea0db2e73c279e5acc6d056cbf
2021-02-01 13:09:46 +01:00
MarcoFalke
87394b6741
Merge #20868: validation: remove redundant check on pindex
c943282b5e validation: remove redundant check on pindex (jarolrod)

Pull request description:

  This removes a redundant check on `pindex` being a `nullptr`. By the time we get to this step `pindex` is always a `nullptr` as the branch where it has been set would have already returned.

  Closes #19223

ACKs for top commit:
  Zero-1729:
    re-ACK c943282
  ajtowns:
    ACK c943282b5e - code review only
  MarcoFalke:
    review ACK c943282b5e 📨
  theStack:
    re-ACK c943282b5e

Tree-SHA512: d2dc58206be61d2897b0703ee93af67abed492a80e84ea03dcfbf7116833173da3bdafa18ff80422d5296729d5254d57cc1db03fdaf817c8f57c62c3abef673c
2021-02-01 10:56:23 +01:00
Carl Dong
b8e95658d5 style-only: Make TestBlockValidity signature readable 2021-01-28 14:15:26 -05:00
Carl Dong
0cdad75390 validation: Use accessible chainstate in ChainstateManager::ProcessNewBlock
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
2021-01-28 14:15:26 -05:00
Carl Dong
ea4fed9021 validation: Use existing chainstate in ChainstateManager::ProcessNewBlockHeaders
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
2021-01-28 14:15:26 -05:00
Carl Dong
e0dc305727 validation: Move LoadExternalBlockFile to CChainState
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.

LoadExternalBlockFile mainly acts on CChainState.
2021-01-28 14:15:26 -05:00
Carl Dong
5f8cd7b3a5 validation: Remove global ::ActivateBestChain
Instead use CChainState::ActivateBestChain, which is what the global one
calls anyway.
2021-01-28 14:15:26 -05:00
Carl Dong
2a696472a1 validation: Pass in chainstate to ::NotifyHeaderTip
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
2021-01-28 14:15:26 -05:00
Carl Dong
9c300cc8b3 validation: Pass in chainstate to TestBlockValidity
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
2021-01-28 14:15:26 -05:00
Carl Dong
0e17c833cd validation: Make CChainState.m_blockman public 2021-01-28 14:15:26 -05:00
Carl Dong
d363d06bf7 validation: Pass in blockman to ContextualCheckBlockHeader
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
2021-01-28 14:15:26 -05:00
Carl Dong
f11d11600d validation: Move GetLastCheckpoint to BlockManager
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.

GetLastCheckPoint mainly acts on BlockManager.
2021-01-28 14:15:26 -05:00
Carl Dong
e4b95eefbc validation: Move GetSpendHeight to BlockManager
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.

GetSpendHeight only acts on BlockManager.
2021-01-28 14:15:26 -05:00
Carl Dong
b026e318c3 validation: Move FindForkInGlobalIndex to BlockManager
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.

FindForkInGlobalIndex only acts on BlockManager.

Note to reviewers: Since FindForkInGlobalIndex is always called with
::ChainActive() as its first parameter, it is possible to move
FindForkInGlobalIndex to CChainState and remove this const CChain&
parameter to instead use m_chain. However, it seems like the original
intention was for FindForkInGlobalIndex to work with _any_ chain, not
just the current active chain. Let me know if this should be changed.
2021-01-28 14:15:26 -05:00
Carl Dong
3664a150ac validation: Remove global LookupBlockIndex 2021-01-28 14:15:26 -05:00
Carl Dong
15d20f40e1 validation: Move LookupBlockIndex to BlockManager
[META] This commit should be followed up by a scripted-diff commit which
       fixes calls to LookupBlockIndex tree-wide.
[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.

LookupBlockIndex only acts on BlockManager.
2021-01-28 14:15:26 -05:00