Skip to content

Commit 1429f83

Browse files
committed
[block encodings] Make CheckBlock mockable for PartiallyDownloadedBlock
1 parent dbca00e commit 1429f83

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/blockencodings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
197197
return READ_STATUS_INVALID;
198198

199199
BlockValidationState state;
200-
if (!CheckBlock(block, state, Params().GetConsensus())) {
200+
CheckBlockFn check_block = m_check_block_mock ? m_check_block_mock : CheckBlock;
201+
if (!check_block(block, state, Params().GetConsensus(), /*fCheckPoW=*/true, /*fCheckMerkleRoot=*/true)) {
201202
// TODO: We really want to just check merkle tree manually here,
202203
// but that is expensive, and CheckBlock caches a block's
203204
// "checked-status" (in the CBlock?). CBlock should be able to

src/blockencodings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
#include <primitives/block.h>
99

10+
#include <functional>
1011

1112
class CTxMemPool;
13+
class BlockValidationState;
14+
namespace Consensus {
15+
struct Params;
16+
};
1217

1318
// Transaction compression schemes for compact block relay can be introduced by writing
1419
// an actual formatter here.
@@ -129,6 +134,11 @@ class PartiallyDownloadedBlock {
129134
const CTxMemPool* pool;
130135
public:
131136
CBlockHeader header;
137+
138+
// Can be overriden for testing
139+
using CheckBlockFn = std::function<bool(const CBlock&, BlockValidationState&, const Consensus::Params&, bool, bool)>;
140+
CheckBlockFn m_check_block_mock{nullptr};
141+
132142
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
133143

134144
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form

0 commit comments

Comments
 (0)