mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-30 02:31:05 +02:00
[block encodings] Make CheckBlock mockable for PartiallyDownloadedBlock
This commit is contained in:
@ -197,7 +197,8 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
|
|||||||
return READ_STATUS_INVALID;
|
return READ_STATUS_INVALID;
|
||||||
|
|
||||||
BlockValidationState state;
|
BlockValidationState state;
|
||||||
if (!CheckBlock(block, state, Params().GetConsensus())) {
|
CheckBlockFn check_block = m_check_block_mock ? m_check_block_mock : CheckBlock;
|
||||||
|
if (!check_block(block, state, Params().GetConsensus(), /*fCheckPoW=*/true, /*fCheckMerkleRoot=*/true)) {
|
||||||
// TODO: We really want to just check merkle tree manually here,
|
// TODO: We really want to just check merkle tree manually here,
|
||||||
// but that is expensive, and CheckBlock caches a block's
|
// but that is expensive, and CheckBlock caches a block's
|
||||||
// "checked-status" (in the CBlock?). CBlock should be able to
|
// "checked-status" (in the CBlock?). CBlock should be able to
|
||||||
|
@ -7,8 +7,13 @@
|
|||||||
|
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
|
class BlockValidationState;
|
||||||
|
namespace Consensus {
|
||||||
|
struct Params;
|
||||||
|
};
|
||||||
|
|
||||||
// Transaction compression schemes for compact block relay can be introduced by writing
|
// Transaction compression schemes for compact block relay can be introduced by writing
|
||||||
// an actual formatter here.
|
// an actual formatter here.
|
||||||
@ -129,6 +134,11 @@ protected:
|
|||||||
const CTxMemPool* pool;
|
const CTxMemPool* pool;
|
||||||
public:
|
public:
|
||||||
CBlockHeader header;
|
CBlockHeader header;
|
||||||
|
|
||||||
|
// Can be overriden for testing
|
||||||
|
using CheckBlockFn = std::function<bool(const CBlock&, BlockValidationState&, const Consensus::Params&, bool, bool)>;
|
||||||
|
CheckBlockFn m_check_block_mock{nullptr};
|
||||||
|
|
||||||
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
|
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
|
||||||
|
|
||||||
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
|
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
|
||||||
|
Reference in New Issue
Block a user