mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-01 09:35:52 -05:00
Remove testBlockValidity() from mining interface
It's very low level and not used by the proposed Template Provider. This method was introduced ind8a3496b5a
anda74b0f93ef
.
This commit is contained in:
parent
477b357460
commit
bfc4e029d4
5 changed files with 6 additions and 31 deletions
|
@ -106,18 +106,6 @@ public:
|
|||
//! used to decide whether to make a new block template.
|
||||
virtual unsigned int getTransactionsUpdated() = 0;
|
||||
|
||||
/**
|
||||
* Check a block is completely valid from start to finish.
|
||||
* Only works on top of our current best block.
|
||||
* Does not check proof-of-work.
|
||||
*
|
||||
* @param[in] block the block to validate
|
||||
* @param[in] check_merkle_root call CheckMerkleRoot()
|
||||
* @param[out] state details of why a block failed to validate
|
||||
* @returns false if it does not build on the current tip, or any of the checks fail
|
||||
*/
|
||||
virtual bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) = 0;
|
||||
|
||||
//! Get internal node context. Useful for RPC and testing,
|
||||
//! but not accessible across processes.
|
||||
virtual node::NodeContext* context() { return nullptr; }
|
||||
|
|
|
@ -20,7 +20,6 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
|
|||
createNewBlock @4 (options: BlockCreateOptions) -> (result: BlockTemplate);
|
||||
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
|
||||
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
|
||||
testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool);
|
||||
}
|
||||
|
||||
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
|
||||
|
|
|
@ -989,19 +989,6 @@ public:
|
|||
return context()->mempool->GetTransactionsUpdated();
|
||||
}
|
||||
|
||||
bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* tip{chainman().ActiveChain().Tip()};
|
||||
// Fail if the tip updated before the lock was taken
|
||||
if (block.hashPrevBlock != tip->GetBlockHash()) {
|
||||
state.Error("Block does not connect to current chain tip.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
|
||||
}
|
||||
|
||||
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override
|
||||
{
|
||||
BlockAssembler::Options assemble_options{options};
|
||||
|
|
|
@ -384,9 +384,10 @@ static RPCHelpMan generateblock()
|
|||
RegenerateCommitments(block, chainman);
|
||||
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
BlockValidationState state;
|
||||
if (!miner.testBlockValidity(block, /*check_merkle_root=*/false, state)) {
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("testBlockValidity failed: %s", state.ToString()));
|
||||
if (!TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/false)) {
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -709,12 +710,12 @@ static RPCHelpMan getblocktemplate()
|
|||
return "duplicate-inconclusive";
|
||||
}
|
||||
|
||||
// testBlockValidity only supports blocks built on the current Tip
|
||||
// TestBlockValidity only supports blocks built on the current Tip
|
||||
if (block.hashPrevBlock != tip) {
|
||||
return "inconclusive-not-best-prevblk";
|
||||
}
|
||||
BlockValidationState state;
|
||||
miner.testBlockValidity(block, /*check_merkle_root=*/true, state);
|
||||
TestBlockValidity(state, chainman.GetParams(), chainman.ActiveChainstate(), block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), /*fCheckPOW=*/false, /*fCheckMerkleRoot=*/true);
|
||||
return BIP22ValidationResult(state);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class RPCGenerateTest(BitcoinTestFramework):
|
|||
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
|
||||
utxo1 = miniwallet.get_utxo(txid=txid1)
|
||||
rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex']
|
||||
assert_raises_rpc_error(-25, 'testBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
|
||||
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
|
||||
|
||||
self.log.info('Fail to generate block with txid not in mempool')
|
||||
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
|
|
Loading…
Add table
Reference in a new issue