Skip to content

Commit ae2c19f

Browse files
author
MarcoFalke
committed
Merge #15655: Resolve the checkpoints <-> validation circular dependency
418d323 Resolve the checkpoints <-> validation CD. (251) Pull request description: This pull request attempts to resolve the `checkpoints -> validation -> checkpoints` circular dependency. The circular dependency is resolved by moving the `CheckPoints::GetLastCheckpoint(const CCheckpointData& data)` function to `validation.cpp` where it used exclusively by the private function `ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& params, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)`. ACKs for commit 418d32: promag: utACK 418d323, only `GetLastCheckpoint` usage is in `validation.cpp` and so makes sense to move it there. practicalswift: utACK 418d323 MarcoFalke: utACK 418d323 sipa: utACK 418d323 Tree-SHA512: 03c3556bc192e65f5e3fa76fd545d4ee7d63d3fb06b132f7a1fa6131aa21ddd2e5b2d19e2222dfe524f422daaca30efde219bed188db8c74ff4b088876b5bc16
2 parents d1c2ed8 + 418d323 commit ae2c19f

File tree

8 files changed

+18
-67
lines changed

8 files changed

+18
-67
lines changed

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ BITCOIN_CORE_H = \
113113
chainparams.h \
114114
chainparamsbase.h \
115115
chainparamsseeds.h \
116-
checkpoints.h \
117116
checkqueue.h \
118117
clientversion.h \
119118
coins.h \
@@ -258,7 +257,6 @@ libbitcoin_server_a_SOURCES = \
258257
blockencodings.cpp \
259258
blockfilter.cpp \
260259
chain.cpp \
261-
checkpoints.cpp \
262260
consensus/tx_verify.cpp \
263261
flatfile.cpp \
264262
httprpc.cpp \

src/checkpoints.cpp

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/checkpoints.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <blockfilter.h>
1616
#include <chain.h>
1717
#include <chainparams.h>
18-
#include <checkpoints.h>
1918
#include <compat/sanity.h>
2019
#include <consensus/validation.h>
2120
#include <fs.h>

src/qt/clientmodel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <chain.h>
1313
#include <chainparams.h>
14-
#include <checkpoints.h>
1514
#include <clientversion.h>
1615
#include <interfaces/handler.h>
1716
#include <interfaces/node.h>

src/rpc/blockchain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <blockfilter.h>
1111
#include <chain.h>
1212
#include <chainparams.h>
13-
#include <checkpoints.h>
1413
#include <coins.h>
1514
#include <consensus/validation.h>
1615
#include <core_io.h>

src/validation.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <arith_uint256.h>
99
#include <chain.h>
1010
#include <chainparams.h>
11-
#include <checkpoints.h>
1211
#include <checkqueue.h>
1312
#include <consensus/consensus.h>
1413
#include <consensus/merkle.h>
@@ -37,6 +36,7 @@
3736
#include <txdb.h>
3837
#include <txmempool.h>
3938
#include <ui_interface.h>
39+
#include <uint256.h>
4040
#include <undo.h>
4141
#include <util/moneystr.h>
4242
#include <util/rbf.h>
@@ -3188,6 +3188,22 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
31883188
return commitment;
31893189
}
31903190

3191+
//! Returns last CBlockIndex* that is a checkpoint
3192+
static CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
3193+
{
3194+
const MapCheckpoints& checkpoints = data.mapCheckpoints;
3195+
3196+
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
3197+
{
3198+
const uint256& hash = i.second;
3199+
CBlockIndex* pindex = LookupBlockIndex(hash);
3200+
if (pindex) {
3201+
return pindex;
3202+
}
3203+
}
3204+
return nullptr;
3205+
}
3206+
31913207
/** Context-dependent validity checks.
31923208
* By "context", we mean only the previous block headers, but not the UTXO
31933209
* set; UTXO-related validity checks are done in ConnectBlock().
@@ -3212,7 +3228,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
32123228
// Don't accept any forks from the main chain prior to last checkpoint.
32133229
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
32143230
// MapBlockIndex.
3215-
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(params.Checkpoints());
3231+
CBlockIndex* pcheckpoint = GetLastCheckpoint(params.Checkpoints());
32163232
if (pcheckpoint && nHeight < pcheckpoint->nHeight)
32173233
return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight), REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint");
32183234
}

test/lint/lint-circular-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export LC_ALL=C
1010

1111
EXPECTED_CIRCULAR_DEPENDENCIES=(
1212
"chainparamsbase -> util/system -> chainparamsbase"
13-
"checkpoints -> validation -> checkpoints"
1413
"index/txindex -> validation -> index/txindex"
1514
"policy/fees -> txmempool -> policy/fees"
1615
"policy/policy -> policy/settings -> policy/policy"

0 commit comments

Comments
 (0)