Skip to content

Commit 418d323

Browse files
committed
Resolve the checkpoints <-> validation CD.
This commit resolves the checkpoints -> validation -> checkpoints cirular dependency by moving `CheckPoints::GetLastCheckpoint(const CCheckpointData& data)` from `checkpoints.cpp` to `validation.cpp`.
1 parent 7b13c64 commit 418d323

File tree

9 files changed

+18
-68
lines changed

9 files changed

+18
-68
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 \
@@ -247,7 +246,6 @@ libbitcoin_server_a_SOURCES = \
247246
blockencodings.cpp \
248247
blockfilter.cpp \
249248
chain.cpp \
250-
checkpoints.cpp \
251249
consensus/tx_verify.cpp \
252250
flatfile.cpp \
253251
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
@@ -14,7 +14,6 @@
1414
#include <banman.h>
1515
#include <chain.h>
1616
#include <chainparams.h>
17-
#include <checkpoints.h>
1817
#include <compat/sanity.h>
1918
#include <consensus/validation.h>
2019
#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
@@ -9,7 +9,6 @@
99
#include <base58.h>
1010
#include <chain.h>
1111
#include <chainparams.h>
12-
#include <checkpoints.h>
1312
#include <coins.h>
1413
#include <consensus/validation.h>
1514
#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>
@@ -35,6 +34,7 @@
3534
#include <txdb.h>
3635
#include <txmempool.h>
3736
#include <ui_interface.h>
37+
#include <uint256.h>
3838
#include <undo.h>
3939
#include <util/moneystr.h>
4040
#include <util/strencodings.h>
@@ -3196,6 +3196,22 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
31963196
return commitment;
31973197
}
31983198

3199+
//! Returns last CBlockIndex* that is a checkpoint
3200+
static CBlockIndex* GetLastCheckpoint(const CCheckpointData& data)
3201+
{
3202+
const MapCheckpoints& checkpoints = data.mapCheckpoints;
3203+
3204+
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints))
3205+
{
3206+
const uint256& hash = i.second;
3207+
CBlockIndex* pindex = LookupBlockIndex(hash);
3208+
if (pindex) {
3209+
return pindex;
3210+
}
3211+
}
3212+
return nullptr;
3213+
}
3214+
31993215
/** Context-dependent validity checks.
32003216
* By "context", we mean only the previous block headers, but not the UTXO
32013217
* set; UTXO-related validity checks are done in ConnectBlock().
@@ -3220,7 +3236,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta
32203236
// Don't accept any forks from the main chain prior to last checkpoint.
32213237
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
32223238
// MapBlockIndex.
3223-
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(params.Checkpoints());
3239+
CBlockIndex* pcheckpoint = GetLastCheckpoint(params.Checkpoints());
32243240
if (pcheckpoint && nHeight < pcheckpoint->nHeight)
32253241
return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight), REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint");
32263242
}

src/wallet/wallet.cpp

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

66
#include <wallet/wallet.h>
77

8-
#include <checkpoints.h>
98
#include <chain.h>
109
#include <wallet/coincontrol.h>
1110
#include <consensus/consensus.h>

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 -> validation -> policy/policy"

0 commit comments

Comments
 (0)