Commit graph

1000 commits

Author SHA1 Message Date
MarcoFalke
fa4e30b0f3
policy: Remove unused locktime flags 2022-01-27 08:46:48 +01:00
fanquake
0147278e37
Merge bitcoin/bitcoin#21464: Mempool Update Cut-Through Optimization
c5b36b1c1b Mempool Update Cut-Through Optimization (Jeremy Rubin)
c49daf9885 [TESTS] Increase limitancestorcount in tournament RPC test to showcase improved algorithm (Jeremy Rubin)

Pull request description:

  Often when we're updating mempool entries we update entries that we ultimately end up removing the updated entries shortly thereafter. This patch makes it so that we filter for such entries a bit earlier in processing, which yields a mild improvement for these cases, and is negligible overhead otherwise.

  There's potential for a better -- but more sophisticated -- algorithm that can be used taking advantage of epochs, but I figured it is better to do something that is simple and works first and upgrade it later as the other epoch mempool work proceeds as it makes the patches for the epoch algorithm simpler to understand, so you can consider this as preparatory work. It could either go in now if it is not controversial, or we could wait until the other patch is ready to go.

ACKs for top commit:
  instagibbs:
    reACK c5b36b1
  sipa:
    utACK c5b36b1c1b
  mzumsande:
    Code Review ACK c5b36b1c1b

Tree-SHA512: 78b16864f77a637d8a68a65e23c019a9757d8b2243486728ef601d212ae482f6084cf8e69d810958c356f1803178046e4697207ba40d6d10529ca57de647fae6
2022-01-25 11:20:18 +08:00
fanquake
417e7503f8
Merge bitcoin/bitcoin#23804: validation: followups for de-duplication of packages
3cd7f693d3 [unit test] package parents are a mix (glozow)
de075a98ea [validation] better handle errors in SubmitPackage (glozow)
9d88853e0c AcceptPackage fixups (glozow)
2db77cd3b8 [unit test] different witness in package submission (glozow)
9ad211c575 [doc] more detailed explanation for deduplication (glozow)
83d4fb7126 [packages] return DIFFERENT_WITNESS for same-txid-different-witness tx (glozow)

Pull request description:

  This addresses some comments from review on e12fafda2d from #22674.

  - Improve documentation about de-duplication: [comment](https://github.com/bitcoin/bitcoin/pull/22674/files#r770156708)
  - Fix code looking up same-txid-different-witness transaction in mempool: [comment](https://github.com/bitcoin/bitcoin/pull/22674/files#r770804029)
  - Improve the interface for when a same-txid-different-witness transaction is swapped: [comment](https://github.com/bitcoin/bitcoin/pull/22674/files#r770782822)
  - Add a test for witness swapping: [comment](https://github.com/bitcoin/bitcoin/pull/22674/files#r770804029)
  - Add a test for packages with a mix of duplicate/different witness/new parents: [comment](https://github.com/bitcoin/bitcoin/pull/22674#discussion_r773037608)
  - Fix issue with not notifying `CValidationInterface` when there's a partial submission due to fail-fast: [comment](https://github.com/bitcoin/bitcoin/pull/22674#discussion_r773013162)

ACKs for top commit:
  achow101:
    ACK 3cd7f693d3
  t-bast:
    LGTM, ACK 3cd7f693d3
  instagibbs:
    ACK 3cd7f693d3
  ariard:
    ACK 3cd7f69

Tree-SHA512: a5d86ca86edab80a5a05fcbb828901c058b3f2fa2552912ea52f2871e29c3cf4cc34020e7aac2217959c9c3a01856f4bd3d631d844635b98144f212f76c2f3ef
2022-01-25 10:44:51 +08:00
MarcoFalke
fa2bcc4e42
Run coin.IsSpent only once in a row
Follow-up to commit 64e4963c63
2022-01-19 16:55:53 +01:00
glozow
e177fcab38 Replace struct update_lock_points with lambda
No behavior change.
This code was introduced in 5add7a7 before we required C++11, which is
why the struct was needed. As we are now using more modern C++ and this
is the only place where lockpoints are updated for mempool entries, it
is more idiomatic to call `modify` with a lambda.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-01-18 11:55:15 +00:00
glozow
c7cd98c717 document and clean up MaybeUpdateMempoolForReorg
Co-authored-by: John Newbery <john@johnnewbery.com>
2022-01-18 11:55:06 +00:00
glozow
de075a98ea [validation] better handle errors in SubmitPackage
Behavior change: don't quit right after LimitMempoolSize() when a
package is partially submitted. We should still send
TransactionAddedToMempool notifications for
transactions that were submitted.

Not behavior change: add a new package validation result for mempool logic errors.
2022-01-17 12:24:43 +00:00
glozow
9d88853e0c AcceptPackage fixups
No behavior changes, just clarifications.
2022-01-17 12:24:43 +00:00
glozow
9ad211c575 [doc] more detailed explanation for deduplication 2022-01-17 12:17:51 +00:00
glozow
83d4fb7126 [packages] return DIFFERENT_WITNESS for same-txid-different-witness tx
The previous interface required callers to guess that the tx had been
swapped and look up the tx again by txid to find a `MEMPOOL_ENTRY`
result. This is a confusing interface.

Instead, explicitly tell the caller that this transaction was
`DIFFERENT_WITNESS` in the result linked to the mempool entry's wtxid.
This gives the caller all the information they need in 1 lookup, and
they can query the mempool for the other transaction if needed.
2022-01-17 12:17:50 +00:00
MarcoFalke
dfe1341c57
Merge bitcoin/bitcoin#24033: log: Remove GetAdjustedTime from IBD header progress estimation
fac22fd36b log: Remove GetAdjustedTime from IBD header progress estimation (MarcoFalke)

Pull request description:

  This is a "refactor" that shouldn't change behaviour, because the two times are most likely equal. A minimum of 5 outbound peers are needed to adjust the time. And if the time is adjusted, it will be by at most 70 minutes (`DEFAULT_MAX_TIME_ADJUSTMENT`). Thus, the progress estimate should differ by at most 7 blocks.

ACKs for top commit:
  laanwj:
    Code review ACK fac22fd36b
  vincenzopalazzo:
    ACK fac22fd36b

Tree-SHA512: bf9f5eef66db0110dd268cf6dbfab64b9c11ba776924f5b386ceae3f2d005272cceb87ebcc96e0c8b854c051514854a2a5af39ae43bad008fac685b5aafaabd0
2022-01-17 08:46:47 +01:00
MarcoFalke
fac22fd36b
log: Remove GetAdjustedTime from IBD header progress estimation 2022-01-11 13:04:12 +01:00
Ryan Ofsky
ce95fb36af Remove cs_main lock annotation from ChainstateManager.m_blockman
BlockManager is a large data structure, and cs_main is not required to
take its address or access every part of it. Individual BlockManager
fields and methods which do require cs_main like m_block_index and
LookupBlockIndex are already annotated separately, and these other
annotations describe locking requirements more accurately and do a
better job enforcing thread safety.

Since cs_main is not needed to access the address of the m_block object,
this commit drops cs_main LOCK calls which were added pointlessly to
satisfy this annotation in the past.

Co-authored-by: Carl Dong <contact@carldong.me>
2022-01-11 05:11:00 -05:00
Russell Yanofsky
90fc8b089d Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
MarcoFalke
fa68a6c2fc
scripted-diff: Rename touched member variables
-BEGIN VERIFY SCRIPT-

 ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; }

 ren vinfoBlockFile     m_blockfile_info
 ren nLastBlockFile     m_last_blockfile
 ren fCheckForPruning   m_check_for_pruning
 ren setDirtyBlockIndex m_dirty_blockindex
 ren setDirtyFileInfo   m_dirty_fileinfo

-END VERIFY SCRIPT-
2022-01-05 16:19:11 +01:00
MarcoFalke
facd3df21f
Make blockstorage globals private members of BlockManager 2022-01-05 16:18:50 +01:00
MarcoFalke
fab262174b
Move blockstorage-related unload to BlockManager::Unload
This is a refactor and safe to do because:
* UnloadBlockIndex calls ChainstateManager::Unload, which calls
  BlockManager::Unload
* Only unit tests call Unload directly
2022-01-05 16:15:04 +01:00
MarcoFalke
fa467f3913
move-only: Create WriteBlockIndexDB helper
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2022-01-05 15:08:06 +01:00
MarcoFalke
fa88cfd3f9
Move functions to BlockManager
Needed for a later commit
2022-01-05 15:07:28 +01:00
fanquake
2f37b221d1
Merge bitcoin/bitcoin#23581: Move BlockManager to node/blockstorage
fa7efc915b Fixup style of moved code (MarcoFalke)
fade2a44f4 Move BlockManager to node/blockstorage (MarcoFalke)

Pull request description:

  `BlockManager` is responsible for reading and writing block(headers). So move it to the existing `blockstorage` module in `node`. Also, move validation code unrelated to block-storage out from `BlockManager`.

ACKs for top commit:
  ryanofsky:
    Code review obvious ACK fa7efc915b

Tree-SHA512: 0197943d818e5f59e743b07fbb92e7661bff90081127a41e35e5692ce49d6f6a7872448670b0da282f7714580a45c8d93e571a67177c8b5f785ce9edefe834c5
2022-01-04 10:49:38 +08:00
MarcoFalke
75a227e39e
Merge bitcoin/bitcoin#23683: bug fix: valid but different LockPoints after a reorg
b4adc5ad67 [bugfix] update lockpoints correctly during reorg (glozow)
b6002b07a3 MOVEONLY: update_lock_points to txmempool.h (glozow)

Pull request description:

  I introduced a bug in #22677 (sorry! 😅)

  Mempool entries cache `LockPoints`, containing the first height/blockhash/`CBlockIndex*` at which the transaction becomes valid. During a reorg, we re-check timelocks on all mempool entries using `CheckSequenceLocks(useExistingLockPoints=false)` and remove any now-invalid entries. `CheckSequenceLocks()` also mutates the `LockPoints` passed in, and we update valid entries' `LockPoints` using `update_lock_points`. Thus, `update_lock_points(lp)` needs to be called right after `CheckSequenceLocks(lp)`, otherwise we lose the data in `lp`. I incorrectly assumed they could be called in separate loops.

  The incorrect behavior introduced is: if we have a reorg in which a timelocked mempool transaction is still valid but becomes valid at a different block, the cached `LockPoints` will be incorrect.

  This PR fixes the bug, adds a test, and adds an assertion at the end of `removeForReorg()` to check that all mempool entries' lockpoints are valid. You can reproduce the bug by running the test added in the [test] commit on the code before the [bugfix] commit.

ACKs for top commit:
  jnewbery:
    ACK b4adc5ad67
  vasild:
    ACK b4adc5ad67
  mzumsande:
    Code Review ACK b4adc5ad67
  hebasto:
    ACK b4adc5ad67
  MarcoFalke:
    re-ACK b4adc5ad67 🏁

Tree-SHA512: 16b59f6ff8140d0229079ca1c6b04f2f4a00a2e49931275150e4f3fe5ac4ec109698b083fa6b223ba9511f328271cc1ab081263669d5da020af7fee83c13e401
2022-01-03 14:34:39 +01:00
MarcoFalke
fade2a44f4
Move BlockManager to node/blockstorage
Can be reviewed with --color-moved=dimmed-zebra
2022-01-02 17:05:14 +01:00
MarcoFalke
8b5a4de904
Merge bitcoin/bitcoin#23795: refactor: Remove implicit-integer-sign-change suppressions in validation
fadd73037e refactor: Remove implicit-integer-sign-change suppressions in validation.cpp (MarcoFalke)

Pull request description:

  A file-wide suppression is problematic because it will wave through future violations, potentially bugs.

  Fix that by using per-statement casts.

ACKs for top commit:
  shaavan:
    ACK fadd73037e
  theStack:
    Code-review ACK fadd73037e

Tree-SHA512: a8a05613be35382b92d7970f958a4e8f4332432056eaa9d72f6719495134b93aaaeea692899d9035654d0e0cf56bcd759671eeeacfd0535582c0ea048ab58a56
2022-01-02 10:24:02 +01:00
fanquake
6535772510
Merge bitcoin/bitcoin#23882: doc: testnet3 was not reset and is doing BIP30 checks again
fa1a51cbc1 doc: testnet3 was not reset and is doing BIP30 checks again (MarcoFalke)

Pull request description:

ACKs for top commit:
  theStack:
    ACK fa1a51cbc1

Tree-SHA512: 793eccda583a3edb056b142c36a09a5c867f61d90b96e15e6643417d62eb651eb2f3429c5f245bdb062d18ab9bb05b5048c0888aa5a492cb7bb21a2f3f52324e
2022-01-02 08:14:34 +08:00
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
MarcoFalke
fa1a51cbc1
doc: testnet3 was not reset and is doing BIP30 checks again 2021-12-27 18:56:54 +01:00
MarcoFalke
fadd73037e
refactor: Remove implicit-integer-sign-change suppressions in validation.cpp 2021-12-16 17:23:47 +01:00
MarcoFalke
8c0bd871fc
Merge bitcoin/bitcoin#23785: refactor: Move stuff to ChainstateManager
fab6d6b2d1 Move pindexBestInvalid to ChainstateManager (MarcoFalke)
facd2137ec Move m_failed_blocks to ChainstateManager (MarcoFalke)
fa47b5c100 Move AcceptBlockHeader to ChainstateManager (MarcoFalke)
fa3d62cf7b Move FindForkInGlobalIndex from BlockManager to CChainState (MarcoFalke)

Pull request description:

  Move globals or members of the wrong class to the right class.

ACKs for top commit:
  naumenkogs:
    ACK fab6d6b2d1
  Sjors:
    ACK fab6d6b2d1
  shaavan:
    ACK fab6d6b2d1

Tree-SHA512: 926cbdfa22838517497bacb79ed5f521f64117c2aacf96a0176f62831b4713314a32abc0213df5ee067edf63e4a4300f752a26006d36e5aab415bb91209a271f
2021-12-16 15:13:31 +01:00
W. J. van der Laan
216f4ca9e7
Merge bitcoin/bitcoin#22674: validation: mempool validation and submission for packages of 1 child + parents
046e8ff264 [unit test] package submission (glozow)
e12fafda2d [validation] de-duplicate package transactions already in mempool (glozow)
8310d942e0 [packages] add sanity checks for package vs mempool limits (glozow)
be3ff151a1 [validation] full package accept + mempool submission (glozow)
144a29099a [policy] require submitted packages to be child-with-unconfirmed-parents (glozow)
d59ddc5c3d [packages/doc] define and document package rules (glozow)
ba26169f60 [unit test] context-free package checks (glozow)
9b2fdca7f0 [packages] add static IsChildWithParents function (glozow)

Pull request description:

  This is 1 chunk of [Package Mempool Accept](https://gist.github.com/glozow/dc4e9d5c5b14ade7cdfac40f43adb18a); it restricts packages to 1 child with its parents, doesn't allow conflicts, and doesn't have CPFP (yet).  Future PRs (see #22290) will add RBF and CPFP within packages.

ACKs for top commit:
  laanwj:
    Code review ACK 046e8ff264

Tree-SHA512: 37dbba37d527712f8efef71ee05c90a8308992615af35f5e0cfeafc60d859cc792737d125aac526e37742fe7683ac8c155ac24af562426213904333c01260c95
2021-12-15 20:42:33 +01:00
MarcoFalke
fab6d6b2d1
Move pindexBestInvalid to ChainstateManager
A private member is better than a global.
2021-12-15 17:46:39 +01:00
MarcoFalke
facd2137ec
Move m_failed_blocks to ChainstateManager
The member is unrelated to block storage (BlockManager). It is related
to validation.

Fix the confusion by moving it.

Can be reviewed with
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
2021-12-15 17:46:08 +01:00
MarcoFalke
fa47b5c100
Move AcceptBlockHeader to ChainstateManager
This is needed for the next commit.
2021-12-15 17:46:01 +01:00
MarcoFalke
fa3d62cf7b
Move FindForkInGlobalIndex from BlockManager to CChainState
The helper was moved in commit b026e318c3,
which also mentioned that it could be moved to CChainState. So do that,
as the functionality is not block-storage related.

This also allows to drop one function argument.
2021-12-15 17:45:48 +01:00
MarcoFalke
b67115dd04
Merge bitcoin/bitcoin#23174: validation: have LoadBlockIndex account for snapshot use
2283b9cd1e test: add tests for LoadBlockIndex when using multiple chainstates (James O'Beirne)
0fd599a51a validation: have LoadBlockIndex account for snapshot use (James O'Beirne)
d0c6e61f5d validation: don't modify genesis during snapshot load (James O'Beirne)

Pull request description:

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

  ---

  Currently, `BlockManager::LoadBlockIndex` adds all blocks that have downloaded transactions to the active chain state's `setBlockIndexCandidates` set, ignoring the background chain state.

  This PR changes ChainstateManager::LoadBlockIndex to update `setBlockIndexCandidates` in the background chain, not just the active chain. In the active chain, the same blocks are added as before. In the background chain, only blocks that have actually been validated, not blocks marked assumed-valid are added so the background chain will continue to download and validate assumed-valid blocks.

ACKs for top commit:
  MarcoFalke:
    Concept ACK 2283b9cd1e 🤽
  Sjors:
    utACK 2283b9cd1e

Tree-SHA512: 7c9a80802df4722d85d12b78d2e7f628ac5f11cb8be66913d5c3230339bd1220c6723805509d4460826a17d1dc04b0ae172eb7d09ac0ea5dc5e41d77975cbd5e
2021-12-15 11:05:31 +01:00
James O'Beirne
0fd599a51a
validation: have LoadBlockIndex account for snapshot use
Ensure that blocks past the snapshot base block (i.e. the end of the
assumed-valid region of the chain) are not included in
setBlockIndexCandidates for the background validation chainstate. These
blocks, while fully validated and lacking the BLOCK_ASSUMED_VALID flag,
*rely* on blocks which are assumed-valid, and so shouldn't be added to
the IBD chainstate.

Co-authored-by: Russ Yanofsky <russ@yanofsky.org>
2021-12-13 13:45:27 -05:00
James O'Beirne
d0c6e61f5d
validation: don't modify genesis during snapshot load
Avoid modifying the genesis block index entry during snapshot load. This
is because, in a future change that fixes LoadBlockIndex for UTXO
snapshots, we detect block index entries that are reliant on
assumed-valid ancestors and treat them specially.

Since the genesis block doesn't have BLOCK_VALID_SCRIPTS, it would be
erroneously marked BLOCK_ASSUMED_VALID during snapshot load if we didn't
skip it here. This would cause a "setBlockIndexCandidates() empty"
assertion to be tripped since all block index entries would be marked
assume-valid due to genesis, which is never re-validated.

There's probably no good reason to modify the genesis block index entry
during snapshot load anyway...
2021-12-13 13:45:22 -05:00
Jon Atack
50209a42ad validation, doc: remove TODO comment
It would make for sense for the TODO to be done in PR 17487
(or noted in the review feedback for a follow-up),
no need to continue maintaining the TODO in the codebase.
2021-12-11 12:45:19 +01:00
Jon Atack
8e37fa8393 validation, log: improve logging in FlushSnapshotToDisk()
Use the `LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE` macro to improve the
logging of snapshot persistance and no longer manually track the duration.

before

[snapshot] flushing coins cache (0 MB)... done (0.00ms)

[snapshot] flushing snapshot chainstate to disk (0 MB)... done (0.00ms)

after

FlushSnapshotToDisk: flushing coins cache (0 MB) started
FlushSnapshotToDisk: completed (0.00ms)

FlushSnapshotToDisk: saving snapshot chainstate (0 MB) started
FlushSnapshotToDisk: completed (0.00ms)

The logging can be observed in the output of

./src/test/test_bitcoin -t validation_chainstate_tests -- DEBUG_LOG_OUT
2021-12-10 22:32:41 +01:00
Jon Atack
271252c0bd validation, log: extract FlushSnapshotToDisk() function
This moves the flushing and logging into one method and adds logging
of time duration and memory for the snapshot chainstate flushing.
2021-12-10 22:32:28 +01:00
MarcoFalke
a063647413
Merge bitcoin/bitcoin#23280: init: Coalesce Chainstate loading sequence between {,non-}unittest codepaths
7f15eff2dd style-only: Remove redundant scope in *Chainstate (Carl Dong)
89bec827fd Collapse the 2 cs_main locks in LoadChainstate (Carl Dong)
3b1584b794 Remove all #include // for * comments (Carl Dong)
9a5a5a3d08 test/setup: Use LoadChainstate (Carl Dong)
c541da0d62 node/chainstate: Add options for in-memory DBs (Carl Dong)
ceb9790341 node/caches: Remove intermediate variables (Carl Dong)
ac4bf138b8 node/caches: Extract cache calculation logic (Carl Dong)
15f2e33bb3 validation: VerifyDB only needs Consensus::Params (Carl Dong)
4da9c076d1 node/chainstate: Decouple from ShutdownRequested (Carl Dong)
05441c2dc5 node/chainstate: Decouple from GetTime (Carl Dong)
2414ebc18b init: Delay RPC block notif until warmup finished (Carl Dong)
8d466a8504 Move -checkblocks LogPrintf to AppInitMain (Carl Dong)
aad8d59789 node/chainstate: Reduce coupling of LogPrintf (Carl Dong)
b345979a2b node/chainstate: Decouple from concept of uiInterface (Carl Dong)
ca7c0b934d Split off VerifyLoadedChainstate (Carl Dong)
adf4912d77 node/chainstate: Remove do/while loop (Carl Dong)
975235ca0a Move init logistics message for BAD_GENESIS_BLOCK to init.cpp (Carl Dong)
8715658983 Move mempool nullptr Assert out of LoadChainstate (Carl Dong)
9162a4f93e node/chainstate: Decouple from concept of NodeContext (Carl Dong)
c7a5c46e6f node/chainstate: Decouple from ArgsManager (Carl Dong)
ae9121f958 node/chainstate: Decouple from stringy errors (Carl Dong)
cbac28b72f node/chainstate: Decouple from GetTimeMillis (Carl Dong)
cb64af9635 node: Extract chainstate loading sequence (Carl Dong)

Pull request description:

  This PR:
  1. Coalesce the Chainstate loading sequence between `AppInitMain` and `*TestingSetup` (which makes it more tested)
  2. Makes the Chainstate loading sequence reusable in preparation for future work extracting out our consensus engine.

  Code-wise, this PR:
  1. Extracts `AppInitMain`'s Chainstate loading sequence into a `::LoadChainstateSequence` function
  2. Makes this `::LoadChainstateSequence` function reusable by
      1. Decoupling it from various concepts (`ArgsManager`, `uiInterface`, etc)
      2. Making it report errors using an `enum` rather than by setting a `bilingual_str`
  3. Makes `*TestingSetup` use this new `::LoadChainstateSequence`

  Reviewers: Aside from commentary, I've also included `git diff` flags of interest in the commit messages which I hope will aid review!

ACKs for top commit:
  ryanofsky:
    Code review ACK 7f15eff2dd. Thanks for updates!
  MarcoFalke:
    review ACK 7f15eff2dd 💳

Tree-SHA512: fb9a6cbd1c511a52b477c62a5e68e53a8be5dec2fff0e44a279966afb91efbab44bf1fe7c6b1519f8464ecc25f42dd4bae8e1efbf55ee91fc90fa0b92e3a83e2
2021-12-10 17:17:43 +01:00
Jeremy Rubin
c5b36b1c1b Mempool Update Cut-Through Optimization
Often when we're updating mempool entries we update entries that we
ultimately end up removing the updated entries shortly thereafter. This
patch makes it so that we filter for such entries a bit earlier in
processing, which yields a mild improvement for these cases, and is
negligible overhead otherwise.
2021-12-08 23:07:56 -08:00
MarcoFalke
f6013265b7
Merge bitcoin/bitcoin#20295: rpc: getblockfrompeer
dce8c4c381 rpc: getblockfrompeer (Sjors Provoost)
b884ababc2 rpc: move Ensure* helpers to server_util.h (Sjors Provoost)

Pull request description:

  This adds an RPC method to fetch a block directly from a peer. This can used to fetch stale blocks with lower proof of work that are normally ignored by the node (`headers-only` in `getchaintips`).

  Usage:
  ```
  bitcoin-cli getblockfrompeer HASH peer_n
  ```

  Closes #20155

  Limitations:
  * you have to specify which peer to fetch the block from
  * the node must already have the header

ACKs for top commit:
  jnewbery:
    ACK dce8c4c381
  fjahr:
     re-ACK dce8c4c381

Tree-SHA512: 843ba2b7a308f640770d624d0aa3265fdc5c6ea48e8db32269b96a082b7420f7953d1d8d1ef2e6529392c7172dded9d15639fbc9c24e7bfa5cfb79e13a5498c8
2021-12-08 10:39:37 +01:00
MarcoFalke
84d921e79c
Merge bitcoin/bitcoin#23465: Remove CTxMemPool params from ATMP
f1f10c0514 Remove CTxMemPool params from ATMP (lsilva01)

Pull request description:

  Remove `CTxMemPool` parameter from `AcceptToMemoryPool` function, as suggested in https://github.com/bitcoin/bitcoin/pull/23437#issuecomment-962536149 .

  This requires that `CChainState` has access to `MockedTxPool` in  `tx_pool.cpp` as mentioned https://github.com/bitcoin/bitcoin/pull/23173#discussion_r731895386. So the `MockedTxPool` is attributed to `CChainState::m_mempool` before calling `AcceptToMemoryPool`.

  Requires #23437.

ACKs for top commit:
  jnewbery:
    utACK f1f10c0514
  MarcoFalke:
    review ACK f1f10c0514 🔙

Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
2021-12-08 10:00:55 +01:00
lsilva01
f1f10c0514 Remove CTxMemPool params from ATMP
Co-authored-by: John Newbery <1063656+jnewbery@users.noreply.github.com>
Co-authored-by: Jon Atack <jon@atack.com>
2021-12-07 18:56:29 -03:00
Carl Dong
15f2e33bb3 validation: VerifyDB only needs Consensus::Params
Previously we were passing in CChainParams, when VerifyDB only needed
the Consensus::Params subset.
2021-12-07 14:48:49 -05:00
glozow
b4adc5ad67 [bugfix] update lockpoints correctly during reorg
During a reorg, we re-check timelocks on all mempool entries using
CheckSequenceLocks(useExistingLockPoints=false) and remove any
now-invalid entries. CheckSequenceLocks() also mutates the LockPoints
passed in, and we update valid entries' LockPoints using
update_lock_points. Thus, update_lock_points(lp) needs to be called
right after CheckSequenceLocks(lp), otherwise we lose the data in lp.
commit bedf246 introduced a bug by separating those two loops.
2021-12-06 15:30:06 +00:00
James O'Beirne
7da4a8ffb3
cover DisconnectBlock with lock annotation
CoinsTip() access requires cs_main and therefore so should this function.
2021-12-03 10:34:07 -05:00
fanquake
345c8180d7
Merge bitcoin/bitcoin#23630: Remove GetSpendHeight
fa3942fc4c Remove GetSpendHeight (MarcoFalke)

Pull request description:

  It is unclear what the goal of the helper is, as the caller already
  knows the spend height before calling the helper.

  Also, in case the coins view is corrupted, LookupBlockIndex will return
  nullptr. Dereferencing a nullptr is UB.

  Fix both issues by removing it. Also, add a sanity check, which aborts
  if the coins view is corrupted.

ACKs for top commit:
  laanwj:
    Code review ACK fa3942fc4c
  ryanofsky:
    Code review ACK fa3942fc4c. I'm not aware of cases where coins GetBestBlock could be different from active chain tip, and asset seems sufficient to guarantee PR doesn't change behavior if that doesn't happen.

Tree-SHA512: 29f65d72e116ec5a4509e0947ceeaa5bb6b7dfd5d174d3c7945cb15fa266d590c4f8b48e6385de74ef7d7c84ebd2255de902ad9c87c24955348a91b12e5bffd5
2021-12-03 19:09:58 +08:00
MarcoFalke
fa3942fc4c
Remove GetSpendHeight
It is unclear what the goal of the helper is, as the caller already
knows the spend height before calling the helper.

Also, in case the coins view is corrupted, LookupBlockIndex will return
nullptr. Dereferencing a nullptr is UB.

Fix both issues by removing it. Also, add a sanity check, which aborts
if the coins view is corrupted.
2021-12-02 15:59:53 +01:00
glozow
c4efc4db54 change TestLockPointValidity to take a const reference
The lockpoints are not changed in this function.
There is no reason to pass a pointer.
2021-12-02 14:45:18 +00:00