aboutsummaryrefslogtreecommitdiff
path: root/src/chain.h
AgeCommit message (Collapse)Author
2022-08-03Remove unused SetTip(nullptr) codeMacroFake
2022-07-22refactor: move CBlockIndex#ToString() from header to implementationJon Atack
which allows dropping tinyformat.h from the header file.
2022-07-22CDiskBlockIndex: rename GetBlockHash() to ConstructBlockHash()Jon Atack
and mark the inherited CBlockIndex#GetBlockHash public interface member as deleted, to disallow calling it in the derived CDiskBlockIndex class. Here is a failing test on master demonstrating the inconsistent behavior of the current design: calling the same inherited public interface functions on the same CDiskBlockIndex object should yield identical behavior. ```diff diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 6dc522b421..dac3840f32 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -240,6 +240,15 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup) const CBlockIndex* tip = chainman.ActiveTip(); BOOST_CHECK_EQUAL(tip->nChainTx, au_data.nChainTx); + // CDiskBlockIndex "is a" CBlockIndex, as it publicly inherits from it. + // Test that calling the same inherited interface functions on the same + // object yields identical behavior. + CDiskBlockIndex index{tip}; + CBlockIndex *pB = &index; + CDiskBlockIndex *pD = &index; + BOOST_CHECK_EQUAL(pB->GetBlockHash(), pD->GetBlockHash()); + BOOST_CHECK_EQUAL(pB->ToString(), pD->ToString()); + ``` The GetBlockHash() test assertion only passes on master because the different methods invoked by the current design happen to return the same result. If one of the two is changed, it fails like the ToString() assertion does. Redefining inherited non-virtual functions is well-documented as incorrect design to avoid inconsistent behavior (see Scott Meyers, "Effective C++", Item 36). Class usage is confusing when the behavior depends on the pointer definition instead of the object definition (static binding happening where dynamic binding was expected). This can lead to unsuspected or hard-to-track bugs. Outside of critical hot spots, correctness usually comes before optimisation, but the current design dates back to main.cpp and it may possibly have been chosen to avoid the overhead of dynamic dispatch. This solution does the same: the class sizes are unchanged and no vptr or vtbl is added. There are better designs for doing this that use composition instead of inheritance or that separate the public interface from the private implementations. One example of the latter would be a non-virtual public interface that calls private virtual implementation methods, i.e. the Template pattern via the Non-Virtual Interface (NVI) idiom.
2022-07-22CDiskBlockIndex: remove unused ToString() class memberJon Atack
and mark its inherited CBlockIndex#ToString public interface member as deleted, to disallow calling it in the derived CDiskBlockIndex class.
2022-07-22CBlockIndex: ensure phashBlock is not nullptr before dereferencingJon Atack
and remove a now-redundant assert preceding a GetBlockHash() caller. This protects against UB here, and in case of failure (which would indicate a consensus bug), the debug log will print bitcoind: chain.h:265: uint256 CBlockIndex::GetBlockHash() const: Assertion `phashBlock != nullptr' failed. Aborted instead of Segmentation fault
2022-02-15Add doc/design/libraries.mdRyan Ofsky
2022-01-31Merge bitcoin/bitcoin#24146: Avoid integer sanitizer warnings in chain.oMarcoFalke
fa832103aaa61e93b78ece9dd68c245a41afa6b6 Avoid integer sanitizer warnings in chain.o (MarcoFalke) Pull request description: The two changes make the code more self-documenting and also allow to remove 5 file-wide suppressions for the module ACKs for top commit: PastaPastaPasta: utACK fa832103aaa61e93b78ece9dd68c245a41afa6b6 jonatack: ACK fa832103aaa61e93b78ece9dd68c245a41afa6b6 Tree-SHA512: d32a06099c56eed9f69130a3209f989872acc593f849528acd7746ee6caa96688cc32de37e8e59ad5d25dcb8912e341f1a43e50642dadeff6ca7624d0873ad10
2022-01-25Guard CBlockIndex::nStatus/nFile/nDataPos/nUndoPos by cs_mainJon Atack
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
2022-01-25Require CBlockIndex::IsValid() to hold cs_mainVasil Dimov
2022-01-25Require CBlockIndex::RaiseValidity() to hold cs_mainVasil Dimov
2022-01-25Require CBlockIndex::IsAssumedValid() to hold cs_mainVasil Dimov
2022-01-25Require CBlockIndex::GetUndoPos() to hold mutex cs_mainJon Atack
2022-01-25Require CBlockIndex::GetBlockPos() to hold mutex cs_mainJon Atack
2022-01-25Avoid integer sanitizer warnings in chain.oMarcoFalke
2021-12-30scripted-diff: Bump copyright headersHennadii Stepanov
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT- Commits of previous years: * 2020: fa0074e2d82928016a43ca408717154a1c70a4db * 2019: aaaaad6ac95b402fe18d019d67897ced6b316ee0
2021-12-14style: Use 4 spaces for indendation, not 5MarcoFalke
Also, other whitespace fixes in the touched file. Can be trivially reviewed with "--ignore-all-space --word-diff-regex=. -U0".
2021-12-14Disallow copies of CChainMarcoFalke
2021-10-20Merge bitcoin/bitcoin#13875: [doc] nChainTx needs to become a 64-bit earlier ↵W. J. van der Laan
due to SegWit ef72e9bd4124645fe2d00521a71c1c298d760225 doc: nChainTx needs to become a 64-bit earlier due to SegWit (Sjors Provoost) Pull request description: As of block 597,379 txcount is 460,596,047 (see `chainparams.cpp`), while `uint32` can handle up to 4,294,967,296. Pre segwit the [minimum transaction size](https://en.bitcoin.it/wiki/Maximum_transaction_rate) was 166 bytes, so the worst case number of transactions per block was ~6000. As the original source comment for `unsigned int nChainTx` says, that should last until the year 2030. With SegWit the smallest possible transaction is 60 bytes (potentially increased to 65 with a future soft fork, see #15482), without a witness: ``` 4 bytes version 1 byte input count 36 bytes outpoint 1 byte scriptSigLen (0x00) 0 bytes scriptSig 4 bytes sequence 1 byte output count 8 bytes value 1 byte scriptPubKeyLen 1 byte scriptPubKey (OP_TRUE) 4 bytes locktime ``` That puts the maximum number of transactions per block at 16,666 so we might have to deal with this as early as a block 827,450 in early 2024. Given that it's a memory-only thing and we want to allow users many years to upgrade, I would suggest fixing this in v0.20 and back-porting it. ACKs for top commit: practicalswift: re-ACK ef72e9bd4124645fe2d00521a71c1c298d760225 jarolrod: ACK ef72e9bd4124645fe2d00521a71c1c298d760225 theStack: ACK ef72e9bd4124645fe2d00521a71c1c298d760225 Tree-SHA512: d8509ba7641796cd82af156354ff3a12ff7ec0f7b11215edff6696e95f8ca0e3596f719f3492ac3acb4b0884ac4e5bddc76f107b656bc2ed95a8ef1b2b5d4f71
2021-09-15chain: add BLOCK_ASSUMED_VALID for use with assumeutxoJames O'Beirne
Instead of (ab)using the existing BLOCK_VALID_* flags to mark CBlockIndex entries which we haven't yet fully validated (but assume validity for use with UTXO snapshot loading), introduce a status flag that specifically marks an assumed-valid state. This state is then removed in RaiseValidity() when the block has actually been validated. This distinction will allow us to make the necessary changes to various parts of the system to facilitate assumeutxo/background chainstate validation but without leaking details like snapshot height, as we had done previously. Changes that actually make use of this flag follow in future commits.
2021-06-03doc: Various validation doc fixupsMarcoFalke
* Rename RewindBlockIndex -> NeedsRedownload (follow-up to commit d831e711cab83c70bf2ded62fe33f484844e73dd) * Fix typos * Inline comments about faking chain data to avoid duplicating them
2021-02-17doc: nChainTx needs to become a 64-bit earlier due to SegWitSjors Provoost
2021-02-12simplify ChainstateManager::SnapshotBlockhash() return semanticsJames O'Beirne
Don't return null snapshotblockhash values to avoid caller complexity/confusion.
2020-08-27chain: Remove UB CChain comparisonCarl Dong
It was unused, and had UB
2020-04-16scripted-diff: Bump copyright headersMarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2020-02-10Get rid of VARINT default argumentPieter Wuille
This removes the need for the GNU C++ extension of variadic macros.
2020-01-13Convert chain to new serializationPieter Wuille
2019-12-30scripted-diff: Bump copyright of files changed in 2019MarcoFalke
-BEGIN VERIFY SCRIPT- ./contrib/devtools/copyright_header.py update ./ -END VERIFY SCRIPT-
2019-10-16chain: Set all CBlockIndex members to null, remove SetNull helperMarcoFalke
2019-08-05[doc] chain: Declare BLOCK_VALID_HEADER reservedMarcoFalke
2019-03-27refactor: combine Chain::findFirstBlockWithTime/findFirstBlockWithTimeAndHeightAntoine Riard
As suggested in #14711, pass height to CChain::FindEarliestAtLeast to simplify Chain interface by combining findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into one Extend findearliestatleast_edge_test in consequence
2019-02-22scripted-diff: Rename CBlockDiskPos to FlatFilePos.Jim Posen
-BEGIN VERIFY SCRIPT- sed -i 's/CDiskBlockPos/FlatFilePos/g' $(git ls-files 'src/*.h' 'src/*.cpp') -END VERIFY SCRIPT-
2019-02-22Move CDiskBlockPos from chain to flatfile.Jim Posen
2019-01-03Don't label transactions "Open" while catching upHennadii Stepanov
Since the default `nSequence` is `0xFFFFFFFE` and locktime is enabled, the checking `wtx.is_final` is meaningless until the syncing has completed.
2018-12-04validation: Add and use HaveTxsDownloaded where appropriateMarcoFalke
2018-08-14[trivial] Fix typo in CDiskBlockPos struct's ToStringJon Layton
2018-07-27Update copyright headers to 2018DrahtBot
2018-05-14Break circular dependency: chain -> pow -> chainBen Woosley
chain.h does not actually depend on the methods defined in pow.h, just its include of consensus/params.h, which is standalone and can be included instead. Confirmed by inspection and successful build.
2018-03-15Add static_assert to prevent VARINT(<signed value>)Russell Yanofsky
Using VARINT with signed types is dangerous because negative values will appear to serialize correctly, but then deserialize as positive values mod 128. This commit changes the VARINT macro to trigger an error by default if called with an signed value, and updates broken uses of VARINT to pass a special flag that lets them keep working with no change in behavior.
2018-01-03Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa
2017-11-16scripted-diff: Replace #include "" with #include <> (ryanofsky)MeshCollider
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
2017-11-11Merge #10749: Use compile-time constants instead of unnamed enumerations ↵MarcoFalke
(remove "enum hack") 1e65f0f33 Use compile-time constants instead of unnamed enumerations (remove "enum hack") (practicalswift) Pull request description: Use compile-time constants instead of unnamed enumerations (remove "enum hack"). Tree-SHA512: 1b6ebb2755398c5ebab6cce125b1dfc39cbd1504d98d55136b32703fe935c4070360ab3b2f52b1da48ba9f3b01082d204f3d87c92ccb5c8c333731f7f972e128
2017-09-07Ensure that data types are consistentjjz
1. nStatus of CBlockIndex is consistent with the definition of Enum(BlockStatus) 2. The BlockHeader is consistent with the type of variable defined in CBlockHeader
2017-08-16Declare single-argument (non-converting) constructors "explicit"practicalswift
In order to avoid unintended implicit conversions.
2017-08-16Merge #10956: Fix typosMarcoFalke
9d5e98ff8 Fix typos. (practicalswift) Pull request description: Fix some typos not covered by #10705. Tree-SHA512: f06e9541f6ae13ef5d6731399b61795997b21a8816abeb1749c93e99a5c47354e6cbd4a3d145f4dc6ef8a13db179799a3121ecbb7288abf3e8d81cdf81500d37
2017-08-08Fix typos.practicalswift
2017-08-07scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal ↵practicalswift
instead of the macro NULL -BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
2017-07-26Use compile-time constants instead of unnamed enumerations (remove "enum hack")practicalswift
2017-06-26[MOVEONLY] Move LastCommonAncestor to chainPieter Wuille
2017-03-06Merge #9908: Define 7200 second timestamp window constantWladimir J. van der Laan
e57a1fd Define 7200 second timestamp window constant (Russell Yanofsky) Tree-SHA512: 449d20e4fd23905cd96be36f717c55a0a2360aba1002aaf55a3699cce4a41f6e94acc2fbe511a93c5cbe8f8e68386995a76cad67620ebb66ba9283e6080ab567
2017-03-03Define 7200 second timestamp window constantRussell Yanofsky