aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2014-10-20 04:18:00 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2014-10-21 04:48:31 +0000
commitf877aaaf16e40254bf685b4195b809138501feab (patch)
treecbf08970eda85cd4a33cdc73d8abd738015ac17a /src
parent24e8896430ca73f0642ed1c5f3bdd1406cdd66f6 (diff)
Bugfix: submitblock: Use a temporary CValidationState to determine accurately the outcome of ProcessBlock, now that it no longer does the full block validity check
Diffstat (limited to 'src')
-rw-r--r--src/rpcmining.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index c767835a27..a6494163aa 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -526,6 +526,24 @@ Value getblocktemplate(const Array& params, bool fHelp)
return result;
}
+class submitblock_StateCatcher : public CValidationInterface
+{
+public:
+ uint256 hash;
+ bool found;
+ CValidationState state;
+
+ submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {};
+
+protected:
+ virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) {
+ if (block.GetHash() != hash)
+ return;
+ found = true;
+ state = stateIn;
+ };
+};
+
Value submitblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
@@ -558,8 +576,22 @@ Value submitblock(const Array& params, bool fHelp)
}
CValidationState state;
+ submitblock_StateCatcher sc(pblock.GetHash());
+ RegisterValidationInterface(&sc);
bool fAccepted = ProcessBlock(state, NULL, &pblock);
- if (!fAccepted)
+ UnregisterValidationInterface(&sc);
+ if (fAccepted)
+ {
+ if (!sc.found)
+ return "inconclusive";
+ state = sc.state;
+ }
+ if (state.IsError())
+ {
+ std::string strRejectReason = state.GetRejectReason();
+ throw JSONRPCError(RPC_MISC_ERROR, strRejectReason);
+ }
+ if (state.IsInvalid())
return "rejected"; // TODO: report validation state
return Value::null;