aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
AgeCommit message (Collapse)Author
2022-04-05[validation] try individual validation before package validationglozow
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[packages/policy] use package feerate in package validationglozow
This allows CPFP within a package prior to submission to mempool.
2022-03-25Merge bitcoin/bitcoin#23536: Enforce Taproot script flags whenever WITNESS ↵laanwj
is set cccc1e70b8a14430cc94143da97936a60d6c83d3 Enforce Taproot script flags whenever WITNESS is set (MarcoFalke) fa422994116a7a053789304d56159760081479eb Remove nullptr check in GetBlockScriptFlags (MarcoFalke) faadc606c7644f2934de390e261d9d65a81a7592 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 0a8b7b4b33c9d78574627fc606267e2d8955cd1c. ### 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 cccc1e70b8a14430cc94143da97936a60d6c83d3 achow101: ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 laanwj: Code review ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 ajtowns: ACK cccc1e70b8a14430cc94143da97936a60d6c83d3 ; 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 cccc1e70b8a14430cc94143da97936a60d6c83d3 ([`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-17Merge bitcoin/bitcoin#24515: Only load BlockMan in BlockMan member functionsMarcoFalke
f865cf8ded2b2fbc82a6fbc41226d991909a6880 Add and use BlockManager::GetAllBlockIndices (Carl Dong) 28ba0313eac37e4a900b7e97af7169ce999c4024 Add and use CBlockIndexHeightOnlyComparator (Carl Dong) 12eb05df63f930969115af6dc66e2e5d02f2a517 move-only: Move CBlockIndexWorkComparator to blockstorage (Carl Dong) c600ee38168a460d3026eae0e289c976194aad14 Only load BlockMan in BlockMan member functions (Carl Dong) 42e56d9b188f97c077ed2269e24acc0be35ece17 style-only: No need for std::pair for vSortedByHeight (Carl Dong) 3bbb6fea051f4e19bd2448e401a6c4e9b4cc7a41 style-only: Various blockstorage.cpp cleanups (Carl Dong) 5be9ee3c54dcb396ff52fc8c8b7e4e6e39ec4a3b 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 f865cf8ded2b2fbc82a6fbc41226d991909a6880 ; code review only MarcoFalke: review ACK f865cf8ded2b2fbc82a6fbc41226d991909a6880 🗂 Tree-SHA512: 7b204d782834e06fd7329d022e2ae860181b4e8105c33bfb928539a4ec24161dc7438a9c4d4ee279dcad77de310c160b997bb8aa18923243d0fd55ccf4ad7c3a
2022-03-15Add and use BlockManager::GetAllBlockIndicesCarl Dong
2022-03-15Add and use CBlockIndexHeightOnlyComparatorCarl Dong
...also use std::sort for clarity
2022-03-15move-only: Move CBlockIndexWorkComparator to blockstorageCarl Dong
...it's declared in blockstorage.h
2022-03-15Only load BlockMan in BlockMan member functionsCarl Dong
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-14Merge bitcoin/bitcoin#24080: policy: Remove unused locktime flagsMarcoFalke
fa8d4d9128c35de0fe715f2e2b99269d23c09cc1 scripted-diff: Clarify CheckFinalTxAtTip name (MarcoFalke) fa4e30b0f36f2e7a09db7d30dca9008ed9dbcb35 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 e30b6ea194fee3bb95a45e7b732a99566b88f1f5. * 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 fa8d4d9128c35de0fe715f2e2b99269d23c09cc1 theStack: Code-review ACK fa8d4d9128c35de0fe715f2e2b99269d23c09cc1 glozow: ACK fa8d4d9128c35de0fe715f2e2b99269d23c09cc1, 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-10Merge bitcoin/bitcoin#24404: refactor: Remove confusing P1008R1 violation in ↵fanquake
ATMPArgs faa1aec26b3f354c832e6b995323c9429b178931 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 faa1aec26b3f354c832e6b995323c9429b178931 glozow: code review ACK faa1aec26b3f354c832e6b995323c9429b178931 Tree-SHA512: 16db2c9959a1996eafbfa533dc4d1483761b9d28295aed5a82b86abd7268da37c51c59ddc67c205165ecb415dbe637b12a0e1b3234d50ab0b3b79de66d7bd73e
2022-03-09refactor: more const annotations for uses of CBlockIndex*Anthony Towns
2022-03-07Merge bitcoin/bitcoin#24050: validation: Give `m_block_index` ownership of ↵MarcoFalke
`CBlockIndex`s 6c23c415613d8b847e6f6a2f872be893da9f4384 refactor: Rewrite AddToBlockIndex with try_emplace (Carl Dong) c05cf7aa1e1c15089753897a10c14762027d4b99 style: Modernize range-based loops over m_block_index (Carl Dong) c2a1655799c5d5dab9b14bd2a6b2d2296efd6964 style-only: Use using instead of typedef for BlockMap (Carl Dong) dd79dad17545424d145e846026518d70da594380 refactor: Rewrite InsertBlockIndex with try_emplace (Carl Dong) 531dce034718523967808a89c18ba69a1e3e5a1f tests: Remove now-unnecessary manual Unload's (Carl Dong) bec86ae32683ac56b4e6ba9c9b7d21cfbdf4ac03 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 6c23c415613d8b847e6f6a2f872be893da9f4384 MarcoFalke: re-ACK 6c23c415613d8b847e6f6a2f872be893da9f4384 🎨 Tree-SHA512: 81b2b5119be27cc0f8a9457b11da60cc60930315d2a5be36be89fe253d32073ffe622348ff153114b9b3212197bddbc791810913a43811b33cc58e7162bd105b
2022-03-07Merge bitcoin/bitcoin#24299: validation, refactor: UnloadBlockIndex and ↵laanwj
ChainstateManager::Reset thread safety cleanups ae9ceed3e23288b163b7d7b1840b06b8d332f4ce validation, refactoring: remove ChainstateManager::Reset() (Jon Atack) daad0093e3d1466789d0ce687902636c80cd74a1 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 ae9ceed3e23288b163b7d7b1840b06b8d332f4ce vasild: ACK ae9ceed3e23288b163b7d7b1840b06b8d332f4ce klementtan: crACK ae9ceed3e23288b163b7d7b1840b06b8d332f4ce Tree-SHA512: cebb782572997cc2dda01590d6bb6c5e479e8202324d8b6ff459b814ce09e818b996c881736bfebd1b8bf4b6d7a0f79faf3ffea176a4699dd7d7429de2db2d13
2022-02-28Merge bitcoin/bitcoin#24403: Avoid implicit-integer-sign-change in ↵MarcoFalke
VerifyLoadedChainstate fa7991601c93761bc12ef33b672a927d48a95569 Fixup style of VerifyDB (MarcoFalke) fa462ea787d124c56d6ba7ef79a9b5b23f0411c5 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 fa7991601c93761bc12ef33b672a927d48a95569 brunoerg: crACK fa7991601c93761bc12ef33b672a927d48a95569 Tree-SHA512: bcbe6becf2fbedd21bbde83a544122e79465937346802039532143b2e4165784905a8852c0ccb088b964874df5e5550931fdde3629cbcee3ae237f2f63c43a8e
2022-02-23Remove confusing P1008R1 violation in ATMPArgsMarcoFalke
2022-02-22style: Modernize range-based loops over m_block_indexCarl Dong
2022-02-22blockstorage: Make m_block_index own CBlockIndex'sCarl Dong
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-22Merge bitcoin/bitcoin#24367: User-facing content and codebase doc fixups ↵laanwj
from transifex translator feedback 48742693acc9de837735674057c9aae2fe90bd1d Replace "can not" with "cannot" in docs, user messages, and tests (Jon Atack) e670edd43441ecb6e5978d65348501c57d856030 User-facing content fixups from transifex translator feedback (Jon Atack) Pull request description: Closes #24366. ACKs for top commit: laanwj: Code review re-ACK 48742693acc9de837735674057c9aae2fe90bd1d hebasto: re-ACK 48742693acc9de837735674057c9aae2fe90bd1d, only suggested change since my previous [review](https://github.com/bitcoin/bitcoin/pull/24367#pullrequestreview-885938219). Tree-SHA512: 4dcdcb417251a413e65fab6070515e13a1267c8e0dbcf521386b842511391f24c84a0c2168fe13458c977682034466509bf2a3453719d4d94d3c568fd9f4adb4
2022-02-22Merge bitcoin/bitcoin#24310: docs / fixups from RBF and packagesfanquake
77202f0554dcbbbb167d0ed3927cca0bf4609ce8 [doc] package deduplication (glozow) d35a3cb3968d7584c7d5c42b121a80f34ea656bf [doc] clarify inaccurate comment about replacements paying higher feerate (glozow) 5ae187f8761f5f85a1ef41d24f75afb7eecf366f [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 https://github.com/bitcoin/bitcoin/pull/24310/commits/77202f0554dcbbbb167d0ed3927cca0bf4609ce8 darosior: ACK 77202f0554dcbbbb167d0ed3927cca0bf4609ce8 LarryRuane: ACK 77202f0554dcbbbb167d0ed3927cca0bf4609ce8 Tree-SHA512: a428e791dfa59c359d3ccc67e8d3a4c1239815d2f6b29898e129700079271c00b3a45f091f70b65a6e54aa00a3d5b678b6da29d2a76b6cd6f946eaa7082ea696
2022-02-21Replace "can not" with "cannot" in docs, user messages, and testsJon Atack
2022-02-21Fixup style of VerifyDBMarcoFalke
2022-02-20Merge bitcoin/bitcoin#23907: tracing: utxocache tracepoints follow up for #22902fanquake
799968e8b38833dc7fd7b6d488a66a14580ef674 tracing: misc follow-ups to 22902 (0xb10c) 36a65847033540cf2203252c7baf42bc5ec97579 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 799968e8b38833dc7fd7b6d488a66a14580ef674 Tree-SHA512: ebb096cbf991c551c81e4339821f10d9768c14cf3d8cb14d0ad851acff5980962228a1c746914c6aba3bdb27e8be53b33349c41efe8bab5542f639916e437b5f
2022-02-17Merge bitcoin/bitcoin#23819: ConnectBlock: don't serialize block hash twicelaanwj
eb8b22d5176d7abc6f93b4473df446105ca595e6 block_connected: re-use previous GetTimeMicros (William Casarin) 80e1c55687aae61767f1ade0826746cda00d6a24 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 eb8b22d5176d7abc6f93b4473df446105ca595e6 laanwj: Code review ACK eb8b22d5176d7abc6f93b4473df446105ca595e6 theStack: re-ACK eb8b22d5176d7abc6f93b4473df446105ca595e6 Tree-SHA512: 92ae585e487554e0f73042a8abaa239f630502c1d198e010bd7c1de252d882bccb627bbf0e4faec09c1253e782b145bcf153f9fee78cdb8456188044a96f8267
2022-02-17Merge bitcoin/bitcoin#24177: validation, refactor: add missing thread safety ↵MarcoFalke
lock assertions f485a0745455b46390f1c14260643ad69c8fe2ad Add missing thread safety lock assertions in validation.h (Jon Atack) 37af8a20cf39ed8ee4b3ba4e1d8d55178eaacb78 Add missing thread safety lock assertions in validation.cpp (Jon Atack) Pull request description: A number of functions in validation.{h,cpp} have a thread safety lock annotation in the declaration but are missing the corresponding run-time lock assertion in the definition. ACKs for top commit: hebasto: re-ACK f485a0745455b46390f1c14260643ad69c8fe2ad, only suggested change since my [previous](https://github.com/bitcoin/bitcoin/pull/24177#pullrequestreview-877810465) review. vasild: ACK f485a0745455b46390f1c14260643ad69c8fe2ad Tree-SHA512: c86c0c0e8fe6ec7ae9ed9890f1dd7d042aa482ecf99feb6679a670aa004f6e9a99f7bc047205a34968fab7f1f841898c59b48c3ed6245c166e3b5abbf0867445
2022-02-14[doc] clarify inaccurate comment about replacements paying higher feerateglozow
Co-authored-by: Suhas Daftuar <sdaftuar@gmail.com>
2022-02-14[validation] look up transaction by txidglozow
GetIter takes a txid, not wtxid.
2022-02-09Add missing thread safety lock assertions in validation.cppJon Atack
Co-authored-by: Shashwat <svangani239@gmail.com>
2022-02-09validation, refactoring: remove ChainstateManager::Reset()Jon Atack
Co-authored-by: Vasil Dimov <vd@FreeBSD.org> Co-authored-by: laanwj <126646+laanwj@users.noreply.github.com>
2022-02-09validation: replace lock with annotation in UnloadBlockIndex()Jon Atack
2022-02-07Fix integer sanitizer suppressions in validation.cppMarcoFalke
2022-02-01Fix unsigned integer overflow in LoadMempoolMarcoFalke
2022-01-31Merge bitcoin/bitcoin#24103: Replace RecursiveMutex `m_cs_chainstate` with ↵MarcoFalke
Mutex, and rename it 020acea99b605c9b5ee7939a6acef131db84ad4a refactor: replace RecursiveMutex m_chainstate_mutex with Mutex (w0xlt) ddeefeef20fa2fe48c3c4563370a6297704d228e refactor: add negative TS annotations for `m_chainstate_mutex` (w0xlt) 1dfd31bc267c54144a7e62ad5a1a5860c032f4d7 scripted-diff: rename m_cs_chainstate -> m_chainstate_mutex (w0xlt) Pull request description: This PR is related to #19303 and gets rid of the `RecursiveMutex m_cs_chainstate`. `m_cs_chainstate` is only held in `ActivateBestChain()` and `InvalidateBlock()`. So apparently there is no recursion involved, so the `m_cs_chainstate` can be a non-recursive mutex. ACKs for top commit: hebasto: ACK 020acea99b605c9b5ee7939a6acef131db84ad4a, I have reviewed the code and it looks OK, I agree it can be merged. theStack: Code-review ACK 020acea99b605c9b5ee7939a6acef131db84ad4a 🌴 shaavan: reACK 020acea99b605c9b5ee7939a6acef131db84ad4a Tree-SHA512: c7c16e727e326df3410514915ce753a2a5e1da78857ef965ef683e36251e1b73c9cced4cd5231b04dbe2be0ea14084f6731b4d7a4d9a8e086e982b985e37e4b4
2022-01-29Enforce Taproot script flags whenever WITNESS is setMarcoFalke
2022-01-27Merge bitcoin/bitcoin#23438: refactor: Use spans of std::byte in serializelaanwj
fa5d2e678c809c26bd40d7e7c171529d3ffb5903 Remove unused char serialize (MarcoFalke) fa24493d6394b3a477535f480664c9596f18e3c5 Use spans of std::byte in serialize (MarcoFalke) fa65bbf217b725ada35107b4ad646d250228355c span: Add BytePtr helper (MarcoFalke) Pull request description: This changes the serialize code (`.read()` and `.write()` functions) to take a `Span` instead of a pointer and size. This is a breaking change for the serialize interface, so at no additional cost we can also switch to `std::byte` (instead of using `char`). The benefits of using `Span`: * Less verbose and less fragile code when passing an already existing `Span`(-like) object to or from serialization The benefits of using `std::byte`: * `std::byte` can't accidentally be mistaken for an integer The goal here is to only change serialize to use spans of `std::byte`. If needed, `AsBytes`, `MakeUCharSpan`, ... can be used (temporarily) to pass spans of the right type. Other changes that are included here: * [#22167](https://github.com/bitcoin/bitcoin/pull/22167) (refactor: Remove char serialize by MarcoFalke) * [#21906](https://github.com/bitcoin/bitcoin/pull/21906) (Preserve const in cast on CTransactionSignatureSerializer by promag) ACKs for top commit: laanwj: Concept and code review ACK fa5d2e678c809c26bd40d7e7c171529d3ffb5903 sipa: re-utACK fa5d2e678c809c26bd40d7e7c171529d3ffb5903 Tree-SHA512: 08ee9eced5fb777cedae593b11e33660bed9a3e1711a7451a87b835089a96c99ce0632918bb4666a4e859c4d020f88fb50f2dd734216b0c3d1a9a704967ece6f
2022-01-27scripted-diff: Clarify CheckFinalTxAtTip nameMarcoFalke
This checks finality at the current Tip, so clarify this in its name. -BEGIN VERIFY SCRIPT- ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; } ren CheckSequenceLocks CheckSequenceLocksAtTip ren CheckFinalTx CheckFinalTxAtTip -END VERIFY SCRIPT-
2022-01-27policy: Remove unused locktime flagsMarcoFalke
2022-01-25Merge bitcoin/bitcoin#21464: Mempool Update Cut-Through Optimizationfanquake
c5b36b1c1b11f04e5da7fb44183f61d09a14e40d Mempool Update Cut-Through Optimization (Jeremy Rubin) c49daf9885e86ba08acdc8332d2a34bc5951a487 [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 c5b36b1c1b11f04e5da7fb44183f61d09a14e40d mzumsande: Code Review ACK c5b36b1c1b11f04e5da7fb44183f61d09a14e40d Tree-SHA512: 78b16864f77a637d8a68a65e23c019a9757d8b2243486728ef601d212ae482f6084cf8e69d810958c356f1803178046e4697207ba40d6d10529ca57de647fae6
2022-01-25Merge bitcoin/bitcoin#23804: validation: followups for de-duplication of ↵fanquake
packages 3cd7f693d3ed1bb7cf9ba3e0c482174df3684972 [unit test] package parents are a mix (glozow) de075a98eaf0b3f7676c5c78b50b66902202b34c [validation] better handle errors in SubmitPackage (glozow) 9d88853e0c85f765f7d982b15e8122ede50110ed AcceptPackage fixups (glozow) 2db77cd3b835d052de678755bcdde5a645ce2d65 [unit test] different witness in package submission (glozow) 9ad211c5753dbd148ba6f0ed56854f6364362ca8 [doc] more detailed explanation for deduplication (glozow) 83d4fb71260f268abd41d083fb3458476aed83ce [packages] return DIFFERENT_WITNESS for same-txid-different-witness tx (glozow) Pull request description: This addresses some comments from review on e12fafda2dfbbdf63f125e5af797ecfaa6488f66 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 3cd7f693d3ed1bb7cf9ba3e0c482174df3684972 t-bast: LGTM, ACK https://github.com/bitcoin/bitcoin/pull/23804/commits/3cd7f693d3ed1bb7cf9ba3e0c482174df3684972 instagibbs: ACK 3cd7f693d3ed1bb7cf9ba3e0c482174df3684972 ariard: ACK 3cd7f69 Tree-SHA512: a5d86ca86edab80a5a05fcbb828901c058b3f2fa2552912ea52f2871e29c3cf4cc34020e7aac2217959c9c3a01856f4bd3d631d844635b98144f212f76c2f3ef
2022-01-24refactor: add negative TS annotations for `m_chainstate_mutex`w0xlt
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-01-19scripted-diff: rename m_cs_chainstate -> m_chainstate_mutexw0xlt
-BEGIN VERIFY SCRIPT- s() { sed -i 's/m_cs_chainstate/m_chainstate_mutex/g' $1; } s src/validation.cpp s src/validation.h -END VERIFY SCRIPT-
2022-01-19Run coin.IsSpent only once in a rowMarcoFalke
Follow-up to commit 64e4963c635ec3a73a5fa3f32f6ec08e70609f60
2022-01-18Replace `struct update_lock_points` with lambdaglozow
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-18document and clean up MaybeUpdateMempoolForReorgglozow
Co-authored-by: John Newbery <john@johnnewbery.com>
2022-01-17[validation] better handle errors in SubmitPackageglozow
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-17AcceptPackage fixupsglozow
No behavior changes, just clarifications.
2022-01-17[doc] more detailed explanation for deduplicationglozow
2022-01-17[packages] return DIFFERENT_WITNESS for same-txid-different-witness txglozow
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-17Merge bitcoin/bitcoin#24033: log: Remove GetAdjustedTime from IBD header ↵MarcoFalke
progress estimation fac22fd36b2d9f55dada31cc0da55520431b972a 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 fac22fd36b2d9f55dada31cc0da55520431b972a vincenzopalazzo: ACK https://github.com/bitcoin/bitcoin/pull/24033/commits/fac22fd36b2d9f55dada31cc0da55520431b972a Tree-SHA512: bf9f5eef66db0110dd268cf6dbfab64b9c11ba776924f5b386ceae3f2d005272cceb87ebcc96e0c8b854c051514854a2a5af39ae43bad008fac685b5aafaabd0
2022-01-12block_connected: re-use previous GetTimeMicrosWilliam Casarin
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>
2022-01-12block_connected: don't serialize block hash twiceWilliam Casarin
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. Signed-off-by: William Casarin <jb55@jb55.com>