Skip to content

Commit bfc4e02

Browse files
committed
Remove testBlockValidity() from mining interface
It's very low level and not used by the proposed Template Provider. This method was introduced in d8a3496 and a74b0f9.
1 parent 477b357 commit bfc4e02

File tree

5 files changed

+6
-31
lines changed

5 files changed

+6
-31
lines changed

src/interfaces/mining.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ class Mining
106106
//! used to decide whether to make a new block template.
107107
virtual unsigned int getTransactionsUpdated() = 0;
108108

109-
/**
110-
* Check a block is completely valid from start to finish.
111-
* Only works on top of our current best block.
112-
* Does not check proof-of-work.
113-
*
114-
* @param[in] block the block to validate
115-
* @param[in] check_merkle_root call CheckMerkleRoot()
116-
* @param[out] state details of why a block failed to validate
117-
* @returns false if it does not build on the current tip, or any of the checks fail
118-
*/
119-
virtual bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) = 0;
120-
121109
//! Get internal node context. Useful for RPC and testing,
122110
//! but not accessible across processes.
123111
virtual node::NodeContext* context() { return nullptr; }

src/ipc/capnp/mining.capnp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
2020
createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate);
2121
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
2222
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
23-
testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool);
2423
}
2524

2625
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {

src/node/interfaces.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -989,19 +989,6 @@ class MinerImpl : public Mining
989989
return context()->mempool->GetTransactionsUpdated();
990990
}
991991

992-
bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override
993-
{
994-
LOCK(cs_main);
995-
CBlockIndex* tip{chainman().ActiveChain().Tip()};
996-
// Fail if the tip updated before the lock was taken
997-
if (block.hashPrevBlock != tip->GetBlockHash()) {
998-
state.Error("Block does not connect to current chain tip.");
999-
return false;
1000-
}
1001-
1002-
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
1003-
}
1004-
1005992
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override
1006993
{
1007994
BlockAssembler::Options assemble_options{options};

src/rpc/mining.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,10 @@ static RPCHelpMan generateblock()
384384
RegenerateCommitments(block, chainman);
385385

386386
{
387+
LOCK(::cs_main);
387388
BlockValidationState state;
388-
if (!miner.testBlockValidity(block, /*check_merkle_root=*/false, state)) {
389-
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString()));
389+
if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
390+
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString()));
390391
}
391392
}
392393

@@ -709,12 +710,12 @@ static RPCHelpMan getblocktemplate()
709710
return "duplicate-inconclusive";
710711
}
711712

712-
// testBlockValidity only supports blocks built on the current Tip
713+
// TestBlockValidity only supports blocks built on the current Tip
713714
if (block.hashPrevBlock != tip) {
714715
return "inconclusive-not-best-prevblk";
715716
}
716717
BlockValidationState state;
717-
miner.testBlockValidity(block, /*check_merkle_root=*/true, state);
718+
TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/true);
718719
return BIP22ValidationResult(state);
719720
}
720721

test/functional/rpc_generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_generateblock(self):
8787
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
8888
utxo1 = miniwallet.get_utxo(txid=txid1)
8989
rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex']
90-
assert_raises_rpc_error(-25, 'testBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
90+
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
9191

9292
self.log.info('Fail to generate block with txid not in mempool')
9393
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'

0 commit comments

Comments
 (0)