aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-08-15 17:12:14 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2018-08-15 17:52:06 +0200
commitb5591ca0b053623f0d96423b05ad809115a0bdef (patch)
tree4c85ec5c953376386685805a079d2b2e5be0f435 /src/rpc
parentef98e122ca39f1d6dca998b546d69a60dae65ae7 (diff)
parentfa091b001605c4481fb4eca415929a98d3478549 (diff)
Merge #13399: rpc: Add submitheader
fa091b001605c4481fb4eca415929a98d3478549 qa: Add tests for submitheader (MarcoFalke) 36b1b63f20cc718084971d2cadd04497a9b72634 rpc: Expose ProcessNewBlockHeaders (MarcoFalke) Pull request description: This exposes `ProcessNewBlockHeaders` as an rpc called `submitheader`. This can be used to check for invalid block headers and submission of valid block headers via the rpc. Tree-SHA512: a61e850470f15465f88e450609116df0a98d5d9afadf36b2033d820933d8b6a4012f9f2b3246319c08a0e511bef517f5d808cd0f44ffca91d10895a938004f0b
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/mining.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index e751587dc7..623b0bd86a 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -10,7 +10,6 @@
#include <consensus/params.h>
#include <consensus/validation.h>
#include <core_io.h>
-#include <validation.h>
#include <key_io.h>
#include <miner.h>
#include <net.h>
@@ -23,6 +22,7 @@
#include <txmempool.h>
#include <util.h>
#include <utilstrencodings.h>
+#include <validation.h>
#include <validationinterface.h>
#include <warnings.h>
@@ -763,6 +763,42 @@ static UniValue submitblock(const JSONRPCRequest& request)
return BIP22ValidationResult(sc.state);
}
+static UniValue submitheader(const JSONRPCRequest& request)
+{
+ if (request.fHelp || request.params.size() != 1) {
+ throw std::runtime_error(
+ "submitheader \"hexdata\"\n"
+ "\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid."
+ "\nThrows when the header is invalid.\n"
+ "\nArguments\n"
+ "1. \"hexdata\" (string, required) the hex-encoded block header data\n"
+ "\nResult:\n"
+ "None"
+ "\nExamples:\n" +
+ HelpExampleCli("submitheader", "\"aabbcc\"") +
+ HelpExampleRpc("submitheader", "\"aabbcc\""));
+ }
+
+ CBlockHeader h;
+ if (!DecodeHexBlockHeader(h, request.params[0].get_str())) {
+ throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed");
+ }
+ {
+ LOCK(cs_main);
+ if (!LookupBlockIndex(h.hashPrevBlock)) {
+ throw JSONRPCError(RPC_VERIFY_ERROR, "Must submit previous header (" + h.hashPrevBlock.GetHex() + ") first");
+ }
+ }
+
+ CValidationState state;
+ ProcessNewBlockHeaders({h}, state, Params(), /* ppindex */ nullptr, /* first_invalid */ nullptr);
+ if (state.IsValid()) return NullUniValue;
+ if (state.IsError()) {
+ throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state));
+ }
+ throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason());
+}
+
static UniValue estimatefee(const JSONRPCRequest& request)
{
throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee was removed in v0.17.\n"
@@ -940,6 +976,7 @@ static const CRPCCommand commands[] =
{ "mining", "prioritisetransaction", &prioritisetransaction, {"txid","dummy","fee_delta"} },
{ "mining", "getblocktemplate", &getblocktemplate, {"template_request"} },
{ "mining", "submitblock", &submitblock, {"hexdata","dummy"} },
+ { "mining", "submitheader", &submitheader, {"hexdata"} },
{ "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} },