Skip to content

Commit

Permalink
Add interruptblock RPC (#2982)
Browse files Browse the repository at this point in the history
* Add interruptblock RPC

* Rename setinterruptblock and add usage

* Set interrupt vars under lock
  • Loading branch information
Jouzo authored Jul 29, 2024
1 parent 419a7c3 commit 9181c3e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "eth_getTransactionByBlockNumberAndIndex", 0, "tag"},
{ "eth_getTransactionByBlockNumberAndIndex", 1, "txIndex"},
{ "debug_feeEstimate", 0, "tx"},

{ "setinterruptblock", 0, "height" },
};

/**
Expand Down
61 changes: 61 additions & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <util/strencodings.h>
#include <util/validation.h>

#include <consensus/validation.h>
#include <validation.h>

#include <stdint.h>
#include <tuple>
#ifdef HAVE_MALLOC_INFO
Expand Down Expand Up @@ -580,6 +583,63 @@ static UniValue echo(const JSONRPCRequest& request)
return request.params;
}

static UniValue setinterruptblock(const JSONRPCRequest& request)
{
RPCHelpMan{"setinterruptblock",
"\nSet or update interrupt-block value\n",
{
{"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "block height"},
},
RPCResults{},
RPCExamples{
HelpExampleCli("setinterruptblock", "5000")
+ HelpExampleCli("setinterruptblock", "-1")
+ HelpExampleRpc("setinterruptblock", "5000")
+ HelpExampleRpc("setinterruptblock", "-1")
},
}.Check(request);

RPCTypeCheck(request.params, {UniValue::VNUM});

int height = request.params[0].get_int();
auto previousInterruptHeight = fInterruptBlockHeight;

uint64_t currentHeight;
{
LOCK(cs_main);
currentHeight = ::ChainActive().Height();
fInterruptBlockHeight = height;
fInterrupt = true;
}


// Checks if node has already hit the previous interrupt height.
// If true, resets the invalid blocks to prevent node from being stuck as
// the blocks above would be considered invalid by the previous interrupt height
if (currentHeight + 1 == previousInterruptHeight) {
{
LOCK(cs_main);

const auto hash = ::ChainActive().Tip()->GetBlockHash();
CBlockIndex* pblockindex = LookupBlockIndex(hash);
if (!pblockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}

ResetBlockFailureFlags(pblockindex);
}

CValidationState state;
ActivateBestChain(state, Params());

if (!state.IsValid()) {
throw JSONRPCError(RPC_DATABASE_ERROR, FormatStateMessage(state));
}
}

return NullUniValue;;
}

// clang-format off
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
Expand All @@ -598,6 +658,7 @@ static const CRPCCommand commands[] =
{ "hidden", "setmockcheckpoint", &setmockcheckpoint, {"height","blockhash"}},
{ "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "setinterruptblock", &setinterruptblock, {"height"}}
};
// clang-format on

Expand Down

0 comments on commit 9181c3e

Please sign in to comment.