mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Bugfix: submitblock: Use a temporary CValidationState to determine accurately the outcome of ProcessBlock, now that it no longer does the full block validity check
This commit is contained in:
parent
24e8896430
commit
f877aaaf16
@ -526,6 +526,24 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
|||||||
return result;
|
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)
|
Value submitblock(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
@ -558,8 +576,22 @@ Value submitblock(const Array& params, bool fHelp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
|
submitblock_StateCatcher sc(pblock.GetHash());
|
||||||
|
RegisterValidationInterface(&sc);
|
||||||
bool fAccepted = ProcessBlock(state, NULL, &pblock);
|
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 "rejected"; // TODO: report validation state
|
||||||
|
|
||||||
return Value::null;
|
return Value::null;
|
||||||
|
Loading…
Reference in New Issue
Block a user