aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-11-03 12:16:12 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2014-11-03 12:22:45 +0100
commit84d26d3a36db589cabec2529a6936ad3efa90c6b (patch)
tree8a9e6c0539868013f9a574b49cc97a0100b64734 /src/rpcmining.cpp
parent2a6972133f07382d13e08edc9c2e6c231689b2db (diff)
parent1bea2bbddce6abaf2640c4aab56ad08de53c4b90 (diff)
Merge pull request #5106
1bea2bb Rename ProcessBlock to ProcessNewBlock to indicate change of behaviour, and document it (Luke Dashjr) d29a291 Rename RPC_TRANSACTION_* errors to RPC_VERIFY_* and use RPC_VERIFY_ERROR for submitblock (Luke Dashjr) f877aaa Bugfix: submitblock: Use a temporary CValidationState to determine accurately the outcome of ProcessBlock, now that it no longer does the full block validity check (Luke Dashjr) 24e8896 Add CValidationInterface::BlockChecked notification (Luke Dashjr)
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r--src/rpcmining.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 8af3c46348..0be4e06164 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -527,6 +527,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)
@@ -559,8 +577,22 @@ Value submitblock(const Array& params, bool fHelp)
}
CValidationState state;
- bool fAccepted = ProcessBlock(state, NULL, &pblock);
- if (!fAccepted)
+ submitblock_StateCatcher sc(pblock.GetHash());
+ RegisterValidationInterface(&sc);
+ bool fAccepted = ProcessNewBlock(state, NULL, &pblock);
+ UnregisterValidationInterface(&sc);
+ if (fAccepted)
+ {
+ if (!sc.found)
+ return "inconclusive";
+ state = sc.state;
+ }
+ if (state.IsError())
+ {
+ std::string strRejectReason = state.GetRejectReason();
+ throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
+ }
+ if (state.IsInvalid())
return "rejected"; // TODO: report validation state
return Value::null;