66
77#include < rpc/server.h>
88
9- #include < chainparams.h>
10- #include < node/context.h>
11- #include < rpc/blockchain.h>
12- #include < rpc/server_util.h>
139#include < rpc/util.h>
1410#include < shutdown.h>
1511#include < sync.h>
2016
2117#include < boost/signals2/signal.hpp>
2218
23- #include < algorithm>
2419#include < atomic>
2520#include < cassert>
2621#include < chrono>
@@ -37,10 +32,7 @@ static RPCTimerInterface* timerInterface = nullptr;
3732/* Map of name to timer. */
3833static Mutex g_deadline_timers_mutex;
3934static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY (g_deadline_timers_mutex);
40- static bool ExecuteCommand (const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler, const std::multimap<std::string, std::vector<UniValue>>& mapPlatformRestrictions);
41-
42- // Any commands submitted by this user will have their commands filtered based on the mapPlatformRestrictions
43- static const std::string defaultPlatformUser = " platform-user" ;
35+ static bool ExecuteCommand (const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
4436
4537struct RPCCommandExecutionInfo
4638{
@@ -150,21 +142,6 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
150142 return strRet;
151143}
152144
153- void CRPCTable::InitPlatformRestrictions ()
154- {
155- mapPlatformRestrictions = {
156- {" getassetunlockstatuses" , {}},
157- {" getbestblockhash" , {}},
158- {" getblockhash" , {}},
159- {" getblockcount" , {}},
160- {" getbestchainlock" , {}},
161- {" quorum sign" , {static_cast <uint8_t >(Params ().GetConsensus ().llmqTypePlatform )}},
162- {" quorum verify" , {}},
163- {" submitchainlock" , {}},
164- {" verifyislock" , {}},
165- };
166- }
167-
168145static RPCHelpMan help ()
169146{
170147 return RPCHelpMan{" help" ,
@@ -507,10 +484,10 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
507484 return out;
508485}
509486
510- static bool ExecuteCommands (const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result, const std::multimap<std::string, std::vector<UniValue>>& mapPlatformRestrictions )
487+ static bool ExecuteCommands (const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result)
511488{
512489 for (const auto & command : commands) {
513- if (ExecuteCommand (*command, request, result, &command == &commands.back (), mapPlatformRestrictions )) {
490+ if (ExecuteCommand (*command, request, result, &command == &commands.back ())) {
514491 return true ;
515492 }
516493 }
@@ -542,78 +519,15 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
542519 if (it != mapCommands.end ()) {
543520 UniValue result;
544521 const JSONRPCRequest new_request{subcommand.empty () ? request : request.squashed () };
545- if (ExecuteCommands (it->second , new_request, result, mapPlatformRestrictions )) {
522+ if (ExecuteCommands (it->second , new_request, result)) {
546523 return result;
547524 }
548525 }
549526 throw JSONRPCError (RPC_METHOD_NOT_FOUND, " Method not found" );
550527}
551528
552- static bool ExecuteCommand (const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler, const std::multimap<std::string, std::vector<UniValue>>& mapPlatformRestrictions)
553- {
554- const NodeContext& node = EnsureAnyNodeContext (request.context );
555- // Before executing the RPC Command, filter commands from platform rpc user
556- if (node.mn_activeman && request.authUser == gArgs .GetArg (" -deprecated-platform-user" , defaultPlatformUser)) {
557- // replace this with structured binding in c++20
558- std::string command_name = command.name ;
559- const auto & it = mapPlatformRestrictions.equal_range (command_name);
560- const auto & allowed_begin = it.first ;
561- const auto & allowed_end = it.second ;
562- /* *
563- * allowed_begin and allowed_end are iterators that represent a range of [method_name, vec_params]
564- * For example, assume allowed = `quorum sign platformLlmqType`, `quorum verify` and `verifyislock`
565- * this range will look like:
566- *
567- * if request.strMethod == "quorum":
568- * [
569- * "quorum sign", [platformLlmqType],
570- * "quorum verify", []
571- * ]
572- * if request.strMethod == "verifyislock"
573- * [
574- * "verifyislock", []
575- * ]
576- */
577-
578- // If the requested method is not available in mapPlatformRestrictions
579- if (allowed_begin == allowed_end) {
580- throw JSONRPCError (RPC_PLATFORM_RESTRICTION, strprintf (" Method \" %s\" prohibited" , request.strMethod ));
581- }
582-
583- auto isValidRequest = [&request, &allowed_begin, &allowed_end]() {
584- for (auto itRequest = allowed_begin; itRequest != allowed_end; ++itRequest) {
585- // This is an individual group of parameters that is valid
586- // This will look something like `["sign", platformLlmqType]` from above.
587- const auto & vecAllowedParam = itRequest->second ;
588- // An empty vector of allowed parameters represents that any parameter is allowed.
589- if (vecAllowedParam.empty ()) {
590- return true ;
591- }
592- if (request.params .empty ()) {
593- throw JSONRPCError (RPC_PLATFORM_RESTRICTION, strprintf (" Method \" %s\" has parameter restrictions." , request.strMethod ));
594- }
595-
596- if (request.params .size () < vecAllowedParam.size ()) {
597- continue ;
598- }
599-
600- if (std::equal (vecAllowedParam.begin (), vecAllowedParam.end (),
601- request.params .getValues ().begin (),
602- [](const UniValue& left, const UniValue& right) {
603- return left.type () == right.type () && left.getValStr () == right.getValStr ();
604- })) {
605- return true ;
606- }
607- }
608- return false ;
609- };
610-
611- // Try if any of the mapPlatformRestrictions entries matches the current request
612- if (!isValidRequest ()) {
613- throw JSONRPCError (RPC_PLATFORM_RESTRICTION, " Request doesn't comply with the parameter restrictions." );
614- }
615- }
616-
529+ static bool ExecuteCommand (const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
530+ {
617531 try
618532 {
619533 RPCCommandExecution execution (request.strMethod );
@@ -647,7 +561,7 @@ UniValue CRPCTable::dumpArgMap(const JSONRPCRequest& args_request) const
647561 // TODO: implement mapping argument to type for composite commands
648562 if (cmd.first .find (' ' ) != std::string::npos) continue ;
649563 UniValue result;
650- if (ExecuteCommands (cmd.second , request, result, mapPlatformRestrictions )) {
564+ if (ExecuteCommands (cmd.second , request, result)) {
651565 for (const auto & values : result.getValues ()) {
652566 ret.push_back (values);
653567 }
0 commit comments