From a27a2957ed9afbe5a96caa5f0f4cbec730d27460 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 24 Oct 2019 11:35:42 -0400 Subject: [validation] Add CValidationState subclasses Split CValidationState into TxValidationState and BlockValidationState to store validation results for transactions and blocks respectively. --- src/rpc/blockchain.cpp | 6 +++--- src/rpc/mining.cpp | 10 +++++----- src/rpc/rawtransaction.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/rpc') diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4bbd4aaf64..c4ce561fe3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1470,7 +1470,7 @@ static UniValue preciousblock(const JSONRPCRequest& request) } } - CValidationState state; + BlockValidationState state; PreciousBlock(state, Params(), pblockindex); if (!state.IsValid()) { @@ -1495,7 +1495,7 @@ static UniValue invalidateblock(const JSONRPCRequest& request) }.Check(request); uint256 hash(ParseHashV(request.params[0], "blockhash")); - CValidationState state; + BlockValidationState state; CBlockIndex* pblockindex; { @@ -1545,7 +1545,7 @@ static UniValue reconsiderblock(const JSONRPCRequest& request) ResetBlockFailureFlags(pblockindex); } - CValidationState state; + BlockValidationState state; ActivateBestChain(state, Params()); if (!state.IsValid()) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 07c2958635..f294c815f6 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -252,7 +252,7 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request) // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller -static UniValue BIP22ValidationResult(const CValidationState& state) +static UniValue BIP22ValidationResult(const BlockValidationState& state) { if (state.IsValid()) return NullUniValue; @@ -401,7 +401,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; - CValidationState state; + BlockValidationState state; TestBlockValidity(state, Params(), block, pindexPrev, false, true); return BIP22ValidationResult(state); } @@ -668,12 +668,12 @@ class submitblock_StateCatcher : public CValidationInterface public: uint256 hash; bool found; - CValidationState state; + BlockValidationState state; explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {} protected: - void BlockChecked(const CBlock& block, const CValidationState& stateIn) override { + void BlockChecked(const CBlock& block, const BlockValidationState& stateIn) override { if (block.GetHash() != hash) return; found = true; @@ -772,7 +772,7 @@ static UniValue submitheader(const JSONRPCRequest& request) } } - CValidationState state; + BlockValidationState state; ProcessNewBlockHeaders({h}, state, Params(), /* ppindex */ nullptr, /* first_invalid */ nullptr); if (state.IsValid()) return NullUniValue; if (state.IsError()) { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index cdcf0c9971..68024fbe2f 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -893,7 +893,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request) UniValue result_0(UniValue::VOBJ); result_0.pushKV("txid", tx_hash.GetHex()); - CValidationState state; + TxValidationState state; bool missing_inputs; bool test_accept_res; { -- cgit v1.2.3 From c428622a5bb1e37b2e6ab2c52791ac05d9271238 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Sun, 28 Apr 2019 15:46:35 -0500 Subject: [validation] Remove unused first_invalid parameter from ProcessNewBlockHeaders() No callers use the returned value in first_invalid. Remove it from the function signature and don't set it in the function. --- src/rpc/mining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rpc') diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index f294c815f6..78e80195be 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -773,7 +773,7 @@ static UniValue submitheader(const JSONRPCRequest& request) } BlockValidationState state; - ProcessNewBlockHeaders({h}, state, Params(), /* ppindex */ nullptr, /* first_invalid */ nullptr); + ProcessNewBlockHeaders({h}, state, Params()); if (state.IsValid()) return NullUniValue; if (state.IsError()) { throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state)); -- cgit v1.2.3 From 3004d5a12d09d94bfc4dee2a8e8f2291996a4aaf Mon Sep 17 00:00:00 2001 From: John Newbery Date: Sun, 28 Apr 2019 16:26:31 -0500 Subject: [validation] Remove fMissingInputs from AcceptToMemoryPool() Handle this failure in the same way as all other failures: call Invalid() with the reasons for the failure. --- src/rpc/rawtransaction.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/rpc') diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 68024fbe2f..48b26d2a6f 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -894,19 +894,20 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request) result_0.pushKV("txid", tx_hash.GetHex()); TxValidationState state; - bool missing_inputs; bool test_accept_res; { LOCK(cs_main); - test_accept_res = AcceptToMemoryPool(mempool, state, std::move(tx), &missing_inputs, + test_accept_res = AcceptToMemoryPool(mempool, state, std::move(tx), nullptr /* plTxnReplaced */, false /* bypass_limits */, max_raw_tx_fee, /* test_accept */ true); } result_0.pushKV("allowed", test_accept_res); if (!test_accept_res) { if (state.IsInvalid()) { - result_0.pushKV("reject-reason", strprintf("%s", state.GetRejectReason())); - } else if (missing_inputs) { - result_0.pushKV("reject-reason", "missing-inputs"); + if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { + result_0.pushKV("reject-reason", "missing-inputs"); + } else { + result_0.pushKV("reject-reason", strprintf("%s", state.GetRejectReason())); + } } else { result_0.pushKV("reject-reason", state.GetRejectReason()); } -- cgit v1.2.3