Commit graph

1071 commits

Author SHA1 Message Date
Anthony Towns
deffe0df6c deploymentstatus: allow chainman in place of consensusParams 2022-05-10 12:09:33 +10:00
Anthony Towns
eaa2e3f25c validation: move UpdateUncommittedBlockStructures and GenerateCoinbaseCommitment into ChainstateManager 2022-05-10 12:09:33 +10:00
Anthony Towns
5c67e84d37 validation: replace ::Params() calls with chainstate/chainman member 2022-05-10 12:09:33 +10:00
Anthony Towns
38860f93b6 validation: remove redundant CChainParams params from ChainstateManager methods 2022-05-10 12:09:33 +10:00
MacroFake
59ac8bacd5
Merge bitcoin/bitcoin#24804: Sanity assert GetAncestor() != nullptr where appropriate
308dd2e93e Sanity assert GetAncestor() != nullptr where appropriate (Adam Jonas)

Pull request description:

  Re-opening #17232. I have rebased the PR and addressed jonatack's nit suggestions.

  Add sanity asserts for return value of `CBlockIndex::GetAncestor()` where appropriate.

  In validation.cpp `CheckSequenceLocks`, check the return value of `tip->GetAncestor(maxInputHeight)` stored into `lp->maxInputBlock`. If it ever returns `nullptr` because the ancestor isn't found, it's going to be a bad bug to keep going, since a `LockPoints` object with the `maxInputBlock` member set to `nullptr` signifies no relative lock time.

  In the other places, the added asserts would prevent accidental dereferencing of a null pointer which is undefined behavior.

  Co-Authored-By: Adam Jonas <jonas@chaincode.com>
  Co-Authored-By: danra <danra@users.noreply.github.com>

ACKs for top commit:
  jonatack:
    ACK 308dd2e93e

Tree-SHA512: 5bfdaab1499607ae2c3cd3e2e9e8c37850bfd0e327e680f4e36c81f9c6d98a543af78ecfac1ab0e06325d264412615a04d52005875780c7db2a4d81bd2d2259a
2022-05-06 11:46:20 +02:00
MacroFake
fa2deae2a8
Wrap boost::replace_all 2022-05-05 20:50:24 +02:00
Adam Jonas
308dd2e93e Sanity assert GetAncestor() != nullptr where appropriate
Add sanity asserts for return value of `CBlockIndex::GetAncestor()` where appropriate.

In validation.cpp `CheckSequenceLocks`, check the return value of `tip->GetAncestor(maxInputHeight)` stored into `lp->maxInputBlock`. If it ever returns `nullptr` because the ancestor isn't found, it's going to be a bad bug to keep going, since a `LockPoints` object with the `maxInputBlock` member set to `nullptr` signifies no relative lock time.

In the other places, the added asserts would prevent accidental dereferencing of a null pointer which is undefined behavior.

Co-Authored-By: Aurèle Oulès <aurele@oules.com>
Co-Authored-By: danra <danra@users.noreply.github.com>
2022-05-05 15:55:44 +02:00
MacroFake
12455acca2
Merge bitcoin/bitcoin#24470: Disallow more unsafe string->path conversions allowed by path append operators
f64aa9c411 Disallow more unsafe string->path conversions allowed by path append operators (Ryan Ofsky)

Pull request description:

  Add more `fs::path` `operator/` and `operator+` overloads to prevent unsafe string->path conversions on Windows that would cause strings to be decoded according to the current Windows locale & code page instead of the correct string encoding.

  Update application code to deal with loss of implicit string->path conversions by calling `fs::u8path` or `fs::PathFromString` explicitly, or by just changing variable types from `std::string` to `fs::path` to avoid conversions altogether, or make them happen earlier.

  In all cases, there's no change in behavior either (1) because strings only contained ASCII characters and would be decoded the same regardless of what encoding was used, or (2) because of the 1:1 mapping between paths and strings using the `PathToString` and `PathFromString` functions.

  Motivation for this PR was just that I was experimenting with #24469 and noticed that operations like `fs::path / std::string` were allowed, and I thought it would be better not to allow them.

ACKs for top commit:
  hebasto:
    ACK f64aa9c411

Tree-SHA512: 944cce49ed51537ee7a35ea4ea7f5feaf0c8fff2fa67ee81ec5adebfd3dcbaf41b73eb35e49973d5f852620367f13506fd12a7a9b5ae3a7a0007414d5c9df50f
2022-05-03 10:39:42 +02:00
MacroFake
91a6736136
Merge bitcoin/bitcoin#25009: Crash debug builds on PCKG_MEMPOOL_ERROR
fa10c9f5a1 Crash debug builds on PCKG_MEMPOOL_ERROR (MacroFake)

Pull request description:

  Would be nice to allow fuzz targets to meaningfully cover this code

ACKs for top commit:
  glozow:
    utACK fa10c9f5a1
  vincenzopalazzo:
    ACK fa10c9f5a1

Tree-SHA512: 68efacedbf72f67cf3dc0bb9927a698492cdc1b08df91ef6af863ad8828b78058a64e52d64d244a5b2966cb9e63797b2647d1bb222677bf83b26fca6e4b1dbf0
2022-04-29 08:20:04 +02:00
MacroFake
fa10c9f5a1
Crash debug builds on PCKG_MEMPOOL_ERROR 2022-04-27 18:26:47 +02:00
Carl Dong
7ab07e0332 validation: Prune UnloadBlockIndex and callees
In previous commits in this patchset, we've made sure that every
Unload/UnloadBlockIndex member function resets its own members, and does
not reach out to globals.

This means that their corresponding classes' default destructors can now
replace them, and do an even more thorough job without the need to be
updated for every new member variable.

Therefore, we can remove them, and also remove UnloadBlockIndex since
that's not used anymore.

Unfortunately, chainstatemanager_loadblockindex relies on
CChainState::UnloadBlockIndex, so that needs to stay for now.
2022-04-27 11:13:38 -04:00
Carl Dong
7d99d725cd validation: No mempool clearing in UnloadBlockIndex
The only caller that uses this is ~ChainTestingSetup() where we
immediately destroy the mempool afterwards.
2022-04-27 11:13:38 -04:00
Carl Dong
572d831927 Clear {versionbits,warning}cache in ~Chainstatemanager
Also add TODO item to deglobalize the {versionbits,warning}cache, which
should really only need to be cleared if we change the chainparams.
2022-04-27 11:13:38 -04:00
Carl Dong
98f4bdae81 refactor: Convert warningcache to std::array 2022-04-26 18:41:59 -04:00
Fabian Jahr
f08c9fb0c6
Index: Use prune locks for blockfilterindex
Prior to this change blocks could be pruned up to the last block before the blockfilterindex current best block.
2022-04-25 23:22:00 +02:00
Fabian Jahr
2561823531
blockstorage: Add prune locks to BlockManager
This change also introduces an aditional buffer of 10 blocks (PRUNE_LOCK_BUFFER) that will not be pruned before the best block.

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
2022-04-25 23:21:58 +02:00
Ryan Ofsky
f64aa9c411 Disallow more unsafe string->path conversions allowed by path append operators
Add more fs::path operator/ and operator+ overloads to prevent unsafe
string->path conversions on Windows that would cause strings to be
decoded according to the current Windows locale & code page instead of
the correct string encoding.

Update application code to deal with loss of implicit string->path
conversions by calling fs::u8path or fs::PathFromString explicitly, or
by just changing variable types from std::string to fs::path to avoid
conversions altoghther, or make them happen earlier.

In all cases, there's no change in behavior either (1) because strings
only contained ASCII characters and would be decoded the same regardless
of what encoding was used, or (2) because of the 1:1 mapping between
paths and strings using the PathToString and PathFromString functions.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-04-21 12:01:00 -05:00
Carl Dong
f0a2fb3c5d scripted-diff: Rename pindexBestHeader, fHavePruned
...to m_best_header and m_have_pruned

-BEGIN VERIFY SCRIPT-
find_regex="\bpindexBestHeader\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_best_header@g"
find_regex="\bfHavePruned\b" \
    && git grep -l -E "$find_regex" -- src \
        | xargs sed -i -E "s@$find_regex@m_have_pruned@g"
-END VERIFY SCRIPT-
2022-04-19 14:36:18 -04:00
Carl Dong
a401402125 Clear fHavePruned in BlockManager::Unload()
-----

Code Reviewer Notes

Call graph of relevant functions:

UnloadBlockIndex() <-- Moved from
    calls ChainstateManager::Unload()
        which calls BlockManager::Unload() <-- Moved to

So calling UnloadBlockIndex() would still run this moved code. The code
will also now run when ~BlockManager gets called, which makes sense.
2022-04-19 14:34:56 -04:00
Carl Dong
3308ecd3fc move-mostly: Make fHavePruned a BlockMan member
[META] In the next commit, we move the clearing of fHavePruned to
       BlockManager::Unload()
2022-04-19 14:34:56 -04:00
Carl Dong
c96524113c Clear pindexBestHeader in ChainstateManager::Unload()
-----

Code Reviewer Notes

Call graph of relevant functions:

UnloadBlockIndex() <-- Moved from
    calls ChainstateManager::Unload() <-- Moved to

Safe because ChainstateManager::Unload() is called only by
UnloadBlockIndex() and no other callers.
2022-04-19 14:34:56 -04:00
Carl Dong
0d567daf23 move-mostly: Make pindexBestHeader a ChainMan member
[META] In the next commit, we move the clearing of pindexBestHeader to
       ChainstateManager::Unload()
2022-04-19 14:34:55 -04:00
Carl Dong
5d670173a3 validation: Load pindexBestHeader in ChainMan
Now BlockManager::LoadBlockIndex() will ACTUALLY only load BlockMan
members.

[META] In a later commit, pindexBestHeader will be moved to ChainMan as
       a member

-----

Code Reviewer Notes

Call graph of relevant functions:

ChainstateManager::LoadBlockIndex() <-- Moved to
    calls BlockManager::LoadBlockIndexDB()
        which calls BlockManager::LoadBlockIndex() <-- Moved from

There is only one call to each of inner functions, meaning that no
behavior is changing.
2022-04-12 14:37:27 -04:00
fanquake
d844b5e799
Merge bitcoin/bitcoin#24152: policy / validation: CPFP fee bumping within packages
9bebf35e26 [validation] don't package validate if not policy or missing inputs (glozow)
51edcffa0e [unit test] package feerate and package cpfp (glozow)
1b93748c93 [validation] try individual validation before package validation (glozow)
17a8ffd802 [packages/policy] use package feerate in package validation (glozow)
09f32cffa6 [docs] package feerate (glozow)

Pull request description:

  Part of #22290, aka [Package Mempool Accept](https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a).

  This enables CPFP fee bumping in child-with-unconfirmed-parents packages by introducing [package feerate](https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a#fee-related-checks-use-package-feerate) (total modified fees divided by total virtual size) and using it in place of individual feerate. We also always [validate individual transactions first](https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a#always-try-individual-submission-first) to avoid incentive-incompatible policies like "parents pay for children" or "siblings pay for siblings" behavior.

ACKs for top commit:
  instagibbs:
    reACK 9bebf35e26
  mzumsande:
    Code review ACK 9bebf35e26
  t-bast:
    ACK 9bebf35e26

Tree-SHA512: 5117cfcc3ce55c00384d9e8003a0589ceac1e6f738b1c299007d9cd9cdd2d7c530d31cfd23658b041a6604d39073bcc6e81f0639a300082a92097682a6ea8c8f
2022-04-07 10:05:43 +01:00
MarcoFalke
ffffb7a25a
doc: Convert remaining comments to clang-tidy format 2022-04-06 15:37:07 +02:00
glozow
9bebf35e26 [validation] don't package validate if not policy or missing inputs
Package validation policy only differs from individual policy in its
evaluation of feerate. Minimize DoS surface; don't validate all over
again if we know the result will be the same.
2022-04-05 18:51:37 -04:00
glozow
1b93748c93 [validation] try individual validation before package validation
This avoids "parents pay for children" and "siblings pay for siblings"
behavior, since package feerate is calculated with totals and is
topology-unaware.

It also ensures that package validation never causes us to reject a
transaction that we would have otherwise accepted in single-tx
validation.
2022-04-05 18:51:37 -04:00
glozow
17a8ffd802 [packages/policy] use package feerate in package validation
This allows CPFP within a package prior to submission to mempool.
2022-04-05 18:51:37 -04:00
laanwj
9ce1c506a3
Merge bitcoin/bitcoin#24216: validation: improve connect bench logging
304ef73c83 validation: improve connect bench logging (Sjors Provoost)

Pull request description:

  * mention when we're using a cached block rather than actually loading it from disk
  * add ms/blk to load block from disk
  * log writing of Undo data, so it's tracked separate from writing indexes

  Example outputs from `src/bitcoind -debug=bench` during IBD.

  When the pass the block in memory:

  ```
  2022-01-31T14:21:35Z - Connect block: 251.79ms [59.59s (419.65ms/blk)]
  2022-01-31T14:21:35Z   - Using cached block
  2022-01-31T14:21:35Z   - Load block from disk: 0.07ms [9.67s (68.12ms/blk)]
  2022-01-31T14:21:35Z     - Sanity checks: 0.00ms [0.27s (1.87ms/blk)]
  2022-01-31T14:21:35Z     - Fork checks: 0.02ms [0.26s (1.84ms/blk)]
  2022-01-31T14:21:35Z       - Connect 597 transactions: 154.84ms (0.259ms/tx, 0.022ms/txin) [34.89s (243.96ms/blk)]
  2022-01-31T14:21:35Z     - Verify 7043 txins: 169.60ms (0.024ms/txin) [35.67s (249.46ms/blk)]
  2022-01-31T14:21:35Z     - Write undo data: 19.72ms [10.68s (74.68ms/blk)]
  2022-01-31T14:21:35Z     - Index writing: 0.05ms [0.73s (5.12ms/blk)]
  2022-01-31T14:21:35Z   - Connect total: 189.66ms [48.18s (336.93ms/blk)]
  2022-01-31T14:21:35Z   - Flush: 5.23ms [1.19s (8.30ms/blk)]
  2022-01-31T14:21:35Z   - Writing chainstate: 0.04ms [0.58s (4.03ms/blk)]
  2022-01-31T14:21:35Z UpdateTip: new best=0000000000000000000b94a079a58d64f640f66b0cc338b5831b94c8739439a6 height=660135 version=0x20a00000 log2_work=92.494955 tx=593512887 date='2020-12-06T01:43:07Z' progress=0.850804 cache=138.8MiB(1031560txo)
  2022-01-31T14:21:35Z   - Connect postprocess: 0.26ms [0.17s (1.17ms/blk)]
  ```

  When we have to load the block from disk (when blocks are received out of order, they are saved after initial validation steps and then loaded again for the final validation steps and connecting to tip):

  ```
  2022-01-31T14:21:35Z - Connect block: 195.27ms [59.79s (418.08ms/blk)]
  2022-01-31T14:21:38Z   - Load block from disk: 23.35ms [9.70s (67.80ms/blk)]
  2022-01-31T14:21:38Z     - Sanity checks: 1.96ms [0.27s (1.87ms/blk)]
  2022-01-31T14:21:38Z     - Fork checks: 0.05ms [0.26s (1.83ms/blk)]
  2022-01-31T14:21:38Z       - Connect 404 transactions: 116.03ms (0.287ms/tx, 0.017ms/txin) [35.00s (243.07ms/blk)]
  2022-01-31T14:21:38Z     - Verify 7031 txins: 119.58ms (0.017ms/txin) [35.79s (248.56ms/blk)]
  2022-01-31T14:21:38Z     - Write undo data: 23.54ms [10.70s (74.33ms/blk)]
  2022-01-31T14:21:38Z     - Index writing: 1.42ms [0.73s (5.09ms/blk)]
  2022-01-31T14:21:38Z   - Connect total: 146.84ms [48.33s (335.61ms/blk)]
  2022-01-31T14:21:38Z   - Flush: 4.84ms [1.19s (8.28ms/blk)]
  2022-01-31T14:21:38Z   - Writing chainstate: 0.04ms [0.58s (4.00ms/blk)]
  2022-01-31T14:21:38Z UpdateTip: new best=00000000000000000004c2cad14fec645807ce236f8e1cc43fe106ee4f27692e height=660136 version=0x2000e000 log2_work=92.494972 tx=593513291 date='2020-12-06T01:46:08Z' progress=0.850804 cache=139.4MiB(1036010txo)
  2022-01-31T14:21:38Z   - Connect postprocess: 0.16ms [0.17s (1.16ms/blk)]
  ```

ACKs for top commit:
  laanwj:
    Code review ACK 304ef73c83
  theStack:
    Concept and code-review ACK 304ef73c83
  jonatack:
    re-ACK 304ef73c83 per `git range-diff 4faf7a1d8 cfb027d 304ef7` rebase only since my last review

Tree-SHA512: 2009e1db3c30eacd15c11629903334eda4f016da614afe2a1275d00c2a80d42e37edb10e79ceb58b3bd8855e7c6915e67d455aec15f73a25f48f48f64aa51a29
2022-04-05 16:18:42 +02:00
laanwj
7c08d81e11
Merge bitcoin/bitcoin#23536: Enforce Taproot script flags whenever WITNESS is set
cccc1e70b8 Enforce Taproot script flags whenever WITNESS is set (MarcoFalke)
fa42299411 Remove nullptr check in GetBlockScriptFlags (MarcoFalke)
faadc606c7 refactor: Pass const reference instead of pointer to GetBlockScriptFlags (MarcoFalke)

Pull request description:

  Now that Taproot is active, it makes sense to enforce its rules on all blocks, even historic ones, regardless of the deployment status.

  ### Benefits:

  (With "script flags" I mean "taproot script verification flags".)

  * Script flags are known ahead for all blocks (even blocks not yet created) and do not change. This may benefit static analysis, code review, and development of new script features that build on Taproot.
  * Any future bugs introduced in the deployment code won't have any effect on the script flags, as they are independent of deployment.
  * Enforcing the taproot rules regardless of the deployment status makes testing easier because invalid blocks after activation are also invalid before activation. So there is no need to differentiate the two cases.
  * It gives belt-and-suspenders protection against a practically expensive and theoretically impossible IBD reorg attack where the node is eclipsed. While `nMinimumChainWork` already protects against this, the cost for a few months worth of POW might be lowered until a major version release of Bitcoin Core reaches EOL. The needed work for the attack is the difference between `nMinimumChainWork` and the work at block 709632.

  For reference, previously the same was done for P2SH and WITNESS in commit 0a8b7b4b33.

  ### Implementation:

  I found one block which fails verification with the flags applied, so I added a `TaprootException`, similar to the `BIP16Exception`.

  For reference, the debug log:

  ```
  ERROR: ConnectBlock(): CheckInputScripts on b10c007c60e14f9d087e0291d4d0c7869697c6681d979c6639dbd960792b4d41 failed with non-mandatory-script-verify-flag (Witness program was passed an empty witness)
  BlockChecked: block hash=0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad state=non-mandatory-script-verify-flag (Witness program was passed an empty witness)
  InvalidChainFound: invalid block=0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad  height=692261  log2_work=92.988459  date=2021-07-23T08:24:20Z
  InvalidChainFound:  current best=0000000000000000000067b17a4c0ffd77c29941b15ad356ca8f980af137a25d  height=692260  log2_work=92.988450  date=2021-07-23T07:47:31Z
  ERROR: ConnectTip: ConnectBlock 0000000000000000000f14c35b2d841e986ab5441de8c585d5ffe55ea1e395ad failed, non-mandatory-script-verify-flag (Witness program was passed an empty witness)
  ```

  Hint for testing, make sure to set `-noassumevalid`.

  ### Considerations

  Obviously this change can lead to consensus splits on the network in light of massive reorgs. Currently the last block before Taproot activation, that is the last block without the Taproot script flags set, is only buried by a few days of POW. However, when and if this patch is included in the next major release, it will be buried by a few months of POW. BIP90 considerations apply when looking at reorgs this large.

ACKs for top commit:
  Sjors:
    tACK cccc1e70b8
  achow101:
    ACK cccc1e70b8
  laanwj:
    Code review ACK cccc1e70b8
  ajtowns:
    ACK cccc1e70b8 ; code review; wrote a "getblockscriptflags" rpc to quickly check that blocks just had bit 17 (taproot) added; review of earlier revisions had established non-exception blocks do validate with taproot rules enabled.
  jamesob:
    ACK cccc1e70b8 ([`jamesob/ackr/23536.1.MarcoFalke.enforce_taproot_script_f`](https://github.com/jamesob/bitcoin/tree/ackr/23536.1.MarcoFalke.enforce_taproot_script_f))

Tree-SHA512: 00044de68939caef6420ffd588c1291c041a8b397c80a3df1e3e3487fbeae1821d23975c51c95e44e774558db76f943b00b4e27cbd0213f64a9253116dc6edde
2022-03-25 14:11:18 +01:00
MarcoFalke
601bfc417d
Merge bitcoin/bitcoin#24515: Only load BlockMan in BlockMan member functions
f865cf8ded Add and use BlockManager::GetAllBlockIndices (Carl Dong)
28ba0313ea Add and use CBlockIndexHeightOnlyComparator (Carl Dong)
12eb05df63 move-only: Move CBlockIndexWorkComparator to blockstorage (Carl Dong)
c600ee3816 Only load BlockMan in BlockMan member functions (Carl Dong)
42e56d9b18 style-only: No need for std::pair for vSortedByHeight (Carl Dong)
3bbb6fea05 style-only: Various blockstorage.cpp cleanups (Carl Dong)
5be9ee3c54 refactor: more const annotations for uses of CBlockIndex* (Anthony Towns)

Pull request description:

  The only important commit is "Only load BlockMan in BlockMan member functions", everything else is all just small style changes.

  Here's the commit message, reproduced:
  ```
  This commit effectively splits the "load block index itself" logic from
  "derive Chainstate variables from loaded block index" logic.

  This means that BlockManager::LoadBlockIndex{,DB} will only load what's
  relevant to the BlockManager.
  ```

ACKs for top commit:
  ajtowns:
    ACK f865cf8ded ; code review only
  MarcoFalke:
    review ACK f865cf8ded 🗂

Tree-SHA512: 7b204d782834e06fd7329d022e2ae860181b4e8105c33bfb928539a4ec24161dc7438a9c4d4ee279dcad77de310c160b997bb8aa18923243d0fd55ccf4ad7c3a
2022-03-17 07:23:43 +01:00
Carl Dong
f865cf8ded Add and use BlockManager::GetAllBlockIndices 2022-03-15 19:42:43 -04:00
Carl Dong
28ba0313ea Add and use CBlockIndexHeightOnlyComparator
...also use std::sort for clarity
2022-03-15 19:42:43 -04:00
Carl Dong
12eb05df63 move-only: Move CBlockIndexWorkComparator to blockstorage
...it's declared in blockstorage.h
2022-03-15 19:42:43 -04:00
Carl Dong
c600ee3816 Only load BlockMan in BlockMan member functions
This commit effectively splits the "load block index itself" logic from
"derive Chainstate variables from loaded block index" logic.

This means that BlockManager::LoadBlockIndex{,DB} will only load what's
relevant to the BlockManager.

I strongly recommend reviewing with the following git-diff flags:
  --color-moved=dimmed_zebra --color-moved-ws=allow-indentation-change
2022-03-15 19:42:41 -04:00
MarcoFalke
28bdaa3f76
Merge bitcoin/bitcoin#24080: policy: Remove unused locktime flags
fa8d4d9128 scripted-diff: Clarify CheckFinalTxAtTip name (MarcoFalke)
fa4e30b0f3 policy: Remove unused locktime flags (MarcoFalke)

Pull request description:

  The locktime flags have many issues:
  * They are passed in by a default argument, which is fragile. It has already lead to bugs like the one fixed in commit e30b6ea194.
  * They are negative (signed), which doesn't make sense for flags (unsigned in general). According to the review comments when the code was added: "The max on the flags is a fairly weird operation." (https://github.com/bitcoin/bitcoin/pull/6566#issuecomment-150310861)
  * No call site relies on the default argument and they all pass in a single compile-time constant, rendering most of the code dead and untested.
  * The dead code calls `GetAdjustedTime` (network adjusted time), which has its own issues. See https://github.com/bitcoin/bitcoin/issues/4521

  Fix all issues by removing them

ACKs for top commit:
  ajtowns:
    ACK  fa8d4d9128
  theStack:
    Code-review ACK fa8d4d9128
  glozow:
    ACK fa8d4d9128, agree the default arg `flags` is a massive footgun and just setting max flags is weird. Adding `AtTip` to the names makes sense to me, since they're both testing for *next* block and only ever used for {,re}addition to mempool.

Tree-SHA512: 79f4a52f34909eb598d88bbae7afe8abe5f85f45c128483d16aa83dacd0e5579e561b725d01b1e9a931d1821012a51ad2bc6fb2867f8d09ee541f9d234d696f8
2022-03-14 16:32:23 +01:00
fanquake
6c37eae0ad
Merge bitcoin/bitcoin#24404: refactor: Remove confusing P1008R1 violation in ATMPArgs
faa1aec26b Remove confusing P1008R1 violation in ATMPArgs (MarcoFalke)

Pull request description:

  The `= delete` doesn't achieve the stated goal and it is also redundant, since it is not possible to default construct the `ATMPArgs` type.

  This can be tested with:

  ```diff
  diff --git a/src/validation.cpp b/src/validation.cpp
  index 2813b62462..1c939c0b8a 100644
  --- a/src/validation.cpp
  +++ b/src/validation.cpp
  @@ -519,6 +519,7 @@ public:
           /** Parameters for child-with-unconfirmed-parents package validation. */
           static ATMPArgs PackageChildWithParents(const CChainParams& chainparams, int64_t accept_time,
                                                   std::vector<COutPoint>& coins_to_uncache) {
  +            ATMPArgs{};
               return ATMPArgs{/* m_chainparams */ chainparams,
                               /* m_accept_time */ accept_time,
                               /* m_bypass_limits */ false,
  ```

  Which fails on current master *and* this pull with the following error:

  ```
  validation.cpp:525:22: error: reference member of type 'const CChainParams &' uninitialized
              ATMPArgs{};
                      ~^
  validation.cpp:470:29: note: uninitialized reference member is here
          const CChainParams& m_chainparams;
                              ^
  1 error generated.
  ```

  Further reading (optional):
  * http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1008r1.pdf

ACKs for top commit:
  achow101:
    ACK faa1aec26b
  glozow:
    code review ACK faa1aec26b

Tree-SHA512: 16db2c9959a1996eafbfa533dc4d1483761b9d28295aed5a82b86abd7268da37c51c59ddc67c205165ecb415dbe637b12a0e1b3234d50ab0b3b79de66d7bd73e
2022-03-10 13:57:36 +00:00
Anthony Towns
5be9ee3c54 refactor: more const annotations for uses of CBlockIndex* 2022-03-09 14:32:47 -05:00
MarcoFalke
5e49b2a252
Merge bitcoin/bitcoin#24050: validation: Give m_block_index ownership of CBlockIndexs
6c23c41561 refactor: Rewrite AddToBlockIndex with try_emplace (Carl Dong)
c05cf7aa1e style: Modernize range-based loops over m_block_index (Carl Dong)
c2a1655799 style-only: Use using instead of typedef for BlockMap (Carl Dong)
dd79dad175 refactor: Rewrite InsertBlockIndex with try_emplace (Carl Dong)
531dce0347 tests: Remove now-unnecessary manual Unload's (Carl Dong)
bec86ae326 blockstorage: Make m_block_index own CBlockIndex's (Carl Dong)

Pull request description:

  Part of: #24303
  Split off from: #22564

  ```
  Instead of having CBlockIndex's live on the heap, which requires manual
  memory management, have them be owned by m_block_index. This means that
  they will live and die with BlockManager.
  ```

  The second commit demonstrates how this makes calls to `Unload()` to satisfy the address sanitizer unnecessary.

ACKs for top commit:
  ajtowns:
    ACK 6c23c41561
  MarcoFalke:
    re-ACK 6c23c41561 🎨

Tree-SHA512: 81b2b5119be27cc0f8a9457b11da60cc60930315d2a5be36be89fe253d32073ffe622348ff153114b9b3212197bddbc791810913a43811b33cc58e7162bd105b
2022-03-07 13:15:27 +01:00
laanwj
cba41db327
Merge bitcoin/bitcoin#24299: validation, refactor: UnloadBlockIndex and ChainstateManager::Reset thread safety cleanups
ae9ceed3e2 validation, refactoring: remove ChainstateManager::Reset() (Jon Atack)
daad0093e3 validation: replace lock with annotation in UnloadBlockIndex() (Jon Atack)

Pull request description:

  Thread safety refactoring seen in #24177:
  - replace re-acquiring lock cs_main with a thread safety annotation in UnloadBlockIndex()
  - remove ChainstateManager::Reset(), as it is currently unused (can be reintroduced in the test utilities if needed for unit testing)

ACKs for top commit:
  laanwj:
    Code review ACK ae9ceed3e2
  vasild:
    ACK ae9ceed3e2
  klementtan:
    crACK ae9ceed3e2

Tree-SHA512: cebb782572997cc2dda01590d6bb6c5e479e8202324d8b6ff459b814ce09e818b996c881736bfebd1b8bf4b6d7a0f79faf3ffea176a4699dd7d7429de2db2d13
2022-03-07 12:13:32 +01:00
MarcoFalke
c7da61dcc3
Merge bitcoin/bitcoin#24403: Avoid implicit-integer-sign-change in VerifyLoadedChainstate
fa7991601c Fixup style of VerifyDB (MarcoFalke)
fa462ea787 Avoid implicit-integer-sign-change in VerifyLoadedChainstate (MarcoFalke)

Pull request description:

  This happens when checking all blocks (`-1`).

  To test:

  ```
  ./configure CC=clang CXX=clang++ --with-sanitizers=undefined,integer
  make
  UBSAN_OPTIONS="suppressions=$(pwd)/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1" ./test/functional/rpc_blockchain.py

ACKs for top commit:
  theStack:
    Code-review ACK fa7991601c
  brunoerg:
    crACK fa7991601c

Tree-SHA512: bcbe6becf2fbedd21bbde83a544122e79465937346802039532143b2e4165784905a8852c0ccb088b964874df5e5550931fdde3629cbcee3ae237f2f63c43a8e
2022-02-28 12:33:32 +01:00
MarcoFalke
faa1aec26b
Remove confusing P1008R1 violation in ATMPArgs 2022-02-23 10:15:26 +01:00
Carl Dong
c05cf7aa1e style: Modernize range-based loops over m_block_index 2022-02-22 11:56:49 -05:00
Carl Dong
bec86ae326 blockstorage: Make m_block_index own CBlockIndex's
Instead of having CBlockIndex's live on the heap, which requires manual
memory management, have them be owned by m_block_index. This means that
they will live and die with BlockManager.

A change to BlockManager::LookupBlockIndex:
- Previously, it was a const member function returning a non-const CBlockIndex*
- Now, there's are const and non-const versions of
  BlockManager::LookupBlockIndex returning a CBlockIndex with the same
  const-ness as the member function:
    (e.g. const CBlockIndex* LookupBlockIndex(...) const)

See next commit for some weirdness that this eliminates.

The range based for-loops are modernize (using auto + destructuring) in
a future commit.
2022-02-22 11:52:19 -05:00
laanwj
8add59d77d
Merge bitcoin/bitcoin#24367: User-facing content and codebase doc fixups from transifex translator feedback
48742693ac Replace "can not" with "cannot" in docs, user messages, and tests (Jon Atack)
e670edd434 User-facing content fixups from transifex translator feedback (Jon Atack)

Pull request description:

  Closes #24366.

ACKs for top commit:
  laanwj:
    Code review re-ACK 48742693ac
  hebasto:
    re-ACK 48742693ac, only suggested change since my previous [review](https://github.com/bitcoin/bitcoin/pull/24367#pullrequestreview-885938219).

Tree-SHA512: 4dcdcb417251a413e65fab6070515e13a1267c8e0dbcf521386b842511391f24c84a0c2168fe13458c977682034466509bf2a3453719d4d94d3c568fd9f4adb4
2022-02-22 13:08:08 +01:00
fanquake
bc49650b7c
Merge bitcoin/bitcoin#24310: docs / fixups from RBF and packages
77202f0554 [doc] package deduplication (glozow)
d35a3cb396 [doc] clarify inaccurate comment about replacements paying higher feerate (glozow)
5ae187f876 [validation] look up transaction by txid (glozow)

Pull request description:

  - Use txid, not wtxid, for `mempool.GetIter()`: https://github.com/bitcoin/bitcoin/pull/22674#discussion_r772934994
  - Fix a historically inaccurate comment about RBF during the refactors: https://github.com/bitcoin/bitcoin/pull/22855#discussion_r777130441
  - Add a section about package deduplication to policy/packages.md: https://github.com/bitcoin/bitcoin/pull/24152#discussion_r802955759 and https://github.com/bitcoin/bitcoin/pull/24152#discussion_r802723149

  (I'm intending for this to be in v23 since it's fixups for things that are already merged, which is why I split it from #24152)

ACKs for top commit:
  t-bast:
    LGTM, ACK 77202f0554
  darosior:
    ACK 77202f0554
  LarryRuane:
    ACK 77202f0554

Tree-SHA512: a428e791dfa59c359d3ccc67e8d3a4c1239815d2f6b29898e129700079271c00b3a45f091f70b65a6e54aa00a3d5b678b6da29d2a76b6cd6f946eaa7082ea696
2022-02-22 09:17:02 +00:00
Jon Atack
48742693ac
Replace "can not" with "cannot" in docs, user messages, and tests 2022-02-21 19:07:29 +01:00
MarcoFalke
fa7991601c
Fixup style of VerifyDB 2022-02-21 10:39:41 +01:00
fanquake
2b0735d183
Merge bitcoin/bitcoin#23907: tracing: utxocache tracepoints follow up for #22902
799968e8b3 tracing: misc follow-ups to 22902 (0xb10c)
36a6584703 tracing: correctly scope utxocache:flush tracepoint (Arnab Sen)

Pull request description:

  This PR is a follow-up to the [#22902](https://github.com/bitcoin/bitcoin/pull/22902).

  Previously, the tracepoint `utxocache:flush` was called, even when it was not flushing. So, the tracepoint is now scoped to write only when coins cache to disk.

ACKs for top commit:
  0xB10C:
    ACK 799968e8b3

Tree-SHA512: ebb096cbf991c551c81e4339821f10d9768c14cf3d8cb14d0ad851acff5980962228a1c746914c6aba3bdb27e8be53b33349c41efe8bab5542f639916e437b5f
2022-02-20 11:27:54 +00:00
laanwj
922c49a138
Merge bitcoin/bitcoin#23819: ConnectBlock: don't serialize block hash twice
eb8b22d517 block_connected: re-use previous GetTimeMicros (William Casarin)
80e1c55687 block_connected: don't serialize block hash twice (William Casarin)

Pull request description:

  In the validation:block_connected tracepoint, we call block->GetHash(), which
  ends up calling CBlockHeader::GetHash(), executing around 8000 serialization
  instructions. We don't need to do this extra work, because block->GetHash() is
  already called further up in the function. Let's save that value as a local
  variable and re-use it in our tracepoint so there is no unnecessary tracepoint
  overhead.

  Shave off an extra 100 or so instructions from the validation:block_connected
  tracepoint by reusing a nearby GetTimeMicros(). This brings the tracepoint down
  to 54 instructions.  Still high, but much better than the previous ~154 and
  8000 instructions which it was originally.

  Signed-off-by: William Casarin <jb55@jb55.com>

ACKs for top commit:
  0xB10C:
    ACK eb8b22d517
  laanwj:
    Code review ACK eb8b22d517
  theStack:
    re-ACK eb8b22d517

Tree-SHA512: 92ae585e487554e0f73042a8abaa239f630502c1d198e010bd7c1de252d882bccb627bbf0e4faec09c1253e782b145bcf153f9fee78cdb8456188044a96f8267
2022-02-17 14:10:13 +01:00