Check transaction count early in submitblock.

There is no point in even hashing a submitted block which doesn't have
 a coinbase transaction.

This also results in more useful error reporting on corrupted input.

Thanks to rawodb for the bug report.

Github-Pull: #10146
Rebased-From: 4f15ea102d
This commit is contained in:
Gregory Maxwell 2017-04-02 21:39:32 +00:00 committed by Wladimir J. van der Laan
parent 2fea10ad03
commit a44a6a15f9
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
1 changed files with 4 additions and 0 deletions

View File

@ -748,6 +748,10 @@ UniValue submitblock(const JSONRPCRequest& request)
if (!DecodeHexBlk(block, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase");
}
uint256 hash = block.GetHash();
bool fBlockPresent = false;
{