Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/avalanche.cpp
Show All 24 Lines | static UniValue getavalanchekey(const Config &config, | ||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Avalanche is not initialized"); | "Avalanche is not initialized"); | ||||
} | } | ||||
return HexStr(g_avalanche->getSessionPubKey()); | return HexStr(g_avalanche->getSessionPubKey()); | ||||
} | } | ||||
static UniValue addavalanchepeer(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | |||||
throw std::runtime_error( | |||||
RPCHelpMan{ | |||||
"addavalanchepeer", | |||||
"\nAdd a peer to the set of peer to poll for avalanche.\n", | |||||
{ | |||||
{"nodeid", RPCArg::Type::NUM, false}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments\n" + | |||||
"1. nodeid (number, required) Node to be added to avalanche.\n" + | |||||
"\nExamples:\n" + HelpExampleRpc("addavalanchepeer", "5")); | |||||
} | |||||
if (!g_avalanche) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
Fabien: The error code is unrelated to the actual error. | |||||
"Avalanche is not initialized"); | |||||
} | |||||
if (!request.params[0].isNum()) { | |||||
throw JSONRPCError( | |||||
RPC_INVALID_PARAMETER, | |||||
std::string("Invalid parameter, nodeid must be an integer")); | |||||
} | |||||
NodeId nodeid = request.params[0].get_int64(); | |||||
g_avalanche->addPeer(nodeid, 0); | |||||
FabienUnsubmitted Not Done Inline ActionsLooking at the avalanche code, I think an invalid nodeId could remain in the peer list. Fabien: Looking at the avalanche code, I think an invalid nodeId could remain in the peer list.
There… | |||||
deadalnixAuthorUnsubmitted Done Inline ActionsNode can disconnect anyways, so nodeid can become stale. This is to be fixed within AvalancheProcessor. deadalnix: Node can disconnect anyways, so nodeid can become stale. This is to be fixed within… | |||||
FabienUnsubmitted Not Done Inline ActionsFair enough. Fabien: Fair enough. | |||||
return {}; | |||||
} | |||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "avalanche", "getavalanchekey", getavalanchekey, {}}, | { "avalanche", "getavalanchekey", getavalanchekey, {}}, | ||||
{ "avalanche", "addavalanchepeer", addavalanchepeer, {"nodeid"}}, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterAvalancheRPCCommands(CRPCTable &t) { | void RegisterAvalancheRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |
The error code is unrelated to the actual error.