Rippled Audit

The RPC Subsystem

The RPC subsystem is responsible for handling specific client requests. It is invoked via the RPC::doCommand method called by ServerHandler. At the highest level, control is delegated via a simple dispatch system using a static map of RPC commands to handler objects.

doCommand - src/ripple/rpc/impl/RPCHandler.cpp

doCommand first calls fillHandler to lookup the handler object and then callMethod to actually execute the RPC call.

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
    Status doCommand (
        RPC::Context& context, Json::Value& result)
    {
        Handler const * handler = nullptr;
        if (auto error = fillHandler (context, handler))
        {
            inject_error (error, result);
            return error;
        }

        if (auto method = handler->valueMethod_)
        {
            if (! context.headers.user.empty() ||
                ! context.headers.forwardedFor.empty())
            {
                JLOG(context.j.debug()) << "start command: " << handler->name_ <<
                    ", X-User: " << context.headers.user << ", X-Forwarded-For: " <<
                        context.headers.forwardedFor;

                auto ret = callMethod (context, method, handler->name_, result);

                JLOG(context.j.debug()) << "finish command: " << handler->name_ <<
                    ", X-User: " << context.headers.user << ", X-Forwarded-For: " <<
                        context.headers.forwardedFor;

                return ret;
            }
            else
            {
                return callMethod (context, method, handler->name_, result);
            }
        }

        return rpcUNKNOWN_COMMAND;
    }

fillHandler calls getHandler which uses a static map to associate specified command to the class satisfying it.

src/ripple/rpc/impl/Handler.cpp

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    Handler const handlerArray[] {
        // Some handlers not specified here are added to the table via addHandler()
        // Request-response methods
        {   "account_info",         byRef (&doAccountInfo),         Role::USER,  NO_CONDITION  },
        {   "account_currencies",   byRef (&doAccountCurrencies),   Role::USER,  NO_CONDITION  },
        {   "account_lines",        byRef (&doAccountLines),        Role::USER,  NO_CONDITION  },
        {   "account_channels",     byRef (&doAccountChannels),     Role::USER,  NO_CONDITION  },
        {   "account_objects",      byRef (&doAccountObjects),      Role::USER,  NO_CONDITION  },
        {   "account_offers",       byRef (&doAccountOffers),       Role::USER,  NO_CONDITION  },
        {   "account_tx",           byRef (&doAccountTxSwitch),     Role::USER,  NO_CONDITION  },
        {   "blacklist",            byRef (&doBlackList),           Role::ADMIN,   NO_CONDITION     },
        {   "book_offers",          byRef (&doBookOffers),          Role::USER,  NO_CONDITION  },
        {   "can_delete",           byRef (&doCanDelete),           Role::ADMIN,   NO_CONDITION     },
        {   "channel_authorize",    byRef (&doChannelAuthorize),    Role::USER,  NO_CONDITION  },
        {   "channel_verify",       byRef (&doChannelVerify),       Role::USER,  NO_CONDITION  },
        {   "connect",              byRef (&doConnect),             Role::ADMIN,   NO_CONDITION     },
        {   "consensus_info",       byRef (&doConsensusInfo),       Role::ADMIN,   NO_CONDITION     },
        {   "deposit_authorized",   byRef (&doDepositAuthorized),   Role::USER,  NO_CONDITION  },
        {   "download_shard",       byRef (&doDownloadShard),       Role::ADMIN,   NO_CONDITION     },
        {   "gateway_balances",     byRef (&doGatewayBalances),     Role::USER,  NO_CONDITION  },
        {   "get_counts",           byRef (&doGetCounts),           Role::ADMIN,   NO_CONDITION     },
        {   "feature",              byRef (&doFeature),             Role::ADMIN,   NO_CONDITION     },
        {   "fee",                  byRef (&doFee),                 Role::USER,    NO_CONDITION     },
        {   "fetch_info",           byRef (&doFetchInfo),           Role::ADMIN,   NO_CONDITION     },
        {   "ledger_accept",        byRef (&doLedgerAccept),        Role::ADMIN,   NEEDS_CURRENT_LEDGER  },
        {   "ledger_cleaner",       byRef (&doLedgerCleaner),       Role::ADMIN,   NEEDS_NETWORK_CONNECTION  },
        {   "ledger_closed",        byRef (&doLedgerClosed),        Role::USER,  NO_CONDITION   },
        {   "ledger_current",       byRef (&doLedgerCurrent),       Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "ledger_data",          byRef (&doLedgerData),          Role::USER,  NO_CONDITION  },
        {   "ledger_entry",         byRef (&doLedgerEntry),         Role::USER,  NO_CONDITION  },
        {   "ledger_header",        byRef (&doLedgerHeader),        Role::USER,  NO_CONDITION  },
        {   "ledger_request",       byRef (&doLedgerRequest),       Role::ADMIN,   NO_CONDITION     },
        {   "log_level",            byRef (&doLogLevel),            Role::ADMIN,   NO_CONDITION     },
        {   "logrotate",            byRef (&doLogRotate),           Role::ADMIN,   NO_CONDITION     },
        {   "noripple_check",       byRef (&doNoRippleCheck),       Role::USER,  NO_CONDITION  },
        {   "owner_info",           byRef (&doOwnerInfo),           Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "peers",                byRef (&doPeers),               Role::ADMIN,   NO_CONDITION     },
        {   "path_find",            byRef (&doPathFind),            Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "ping",                 byRef (&doPing),                Role::USER,  NO_CONDITION     },
        {   "print",                byRef (&doPrint),               Role::ADMIN,   NO_CONDITION     },
    //      {   "profile",              byRef (&doProfile),             Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "random",               byRef (&doRandom),              Role::USER,  NO_CONDITION     },
        {   "ripple_path_find",     byRef (&doRipplePathFind),      Role::USER,  NO_CONDITION  },
        {   "sign",                 byRef (&doSign),                Role::USER,  NO_CONDITION     },
        {   "sign_for",             byRef (&doSignFor),             Role::USER,  NO_CONDITION     },
        {   "submit",               byRef (&doSubmit),              Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "submit_multisigned",   byRef (&doSubmitMultiSigned),   Role::USER,  NEEDS_CURRENT_LEDGER  },
        {   "server_info",          byRef (&doServerInfo),          Role::USER,  NO_CONDITION     },
        {   "server_state",         byRef (&doServerState),         Role::USER,  NO_CONDITION     },
        {   "stop",                 byRef (&doStop),                Role::ADMIN,   NO_CONDITION     },
        {   "transaction_entry",    byRef (&doTransactionEntry),    Role::USER,  NO_CONDITION  },
        {   "tx",                   byRef (&doTx),                  Role::USER,  NEEDS_NETWORK_CONNECTION  },
        {   "tx_history",           byRef (&doTxHistory),           Role::USER,  NO_CONDITION     },
        {   "unl_list",             byRef (&doUnlList),             Role::ADMIN,   NO_CONDITION     },
        {   "validation_create",    byRef (&doValidationCreate),    Role::ADMIN,   NO_CONDITION     },
        {   "validation_seed",      byRef (&doValidationSeed),      Role::ADMIN,   NO_CONDITION     },
        {   "validators",           byRef (&doValidators),          Role::ADMIN,   NO_CONDITION     },
        {   "validator_list_sites", byRef (&doValidatorListSites),  Role::ADMIN,   NO_CONDITION     },
        {   "wallet_propose",       byRef (&doWalletPropose),       Role::ADMIN,   NO_CONDITION     },

        // Evented methods
        {   "subscribe",            byRef (&doSubscribe),           Role::USER,  NO_CONDITION     },
        {   "unsubscribe",          byRef (&doUnsubscribe),         Role::USER,  NO_CONDITION     },
    };

fillHandler is also responsible for verifying the client has sufficient privileges to execute the specified command (if admin access is required) as well as performing other sanity checks against the command context

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    error_code_i fillHandler (Context& context,
                              Handler const * & result)
    {
        if (! isUnlimited (context.role))
        {
            // VFALCO NOTE Should we also add up the jtRPC jobs?
            //
            int jc = context.app.getJobQueue ().getJobCountGE (jtCLIENT);
            if (jc > Tuning::maxJobQueueClients)
            {
                JLOG (context.j.debug()) << "Too busy for command: " << jc;
                return rpcTOO_BUSY;
            }
        }

        if (!context.params.isMember(jss::command) && !context.params.isMember(jss::method))
            return rpcCOMMAND_MISSING;
        if (context.params.isMember(jss::command) && context.params.isMember(jss::method))
        {
            if (context.params[jss::command].asString() !=
                context.params[jss::method].asString())
                return rpcUNKNOWN_COMMAND;
        }

        std::string strCommand  = context.params.isMember(jss::command) ?
                                  context.params[jss::command].asString() :
                                  context.params[jss::method].asString();

        JLOG (context.j.trace()) << "COMMAND:" << strCommand;
        JLOG (context.j.trace()) << "REQUEST:" << context.params;
        auto handler = getHandler(strCommand);

        if (!handler)
            return rpcUNKNOWN_COMMAND;

        if (handler->role_ == Role::ADMIN && context.role != Role::ADMIN)
            return rpcNO_PERMISSION;

        if ((handler->condition_ & NEEDS_NETWORK_CONNECTION) &&
            (context.netOps.getOperatingMode () < NetworkOPs::omSYNCING))
        {
            JLOG (context.j.info())
                << "Insufficient network mode for RPC: "
                << context.netOps.strOperatingMode ();

            return rpcNO_NETWORK;
        }

        if (context.app.getOPs().isAmendmentBlocked() &&
             (handler->condition_ & NEEDS_CURRENT_LEDGER ||
              handler->condition_ & NEEDS_CLOSED_LEDGER))
        {
            return rpcAMENDMENT_BLOCKED;
        }

        if (!context.app.config().standalone() &&
            handler->condition_ & NEEDS_CURRENT_LEDGER)
        {
            if (context.ledgerMaster.getValidatedLedgerAge () >
                Tuning::maxValidatedLedgerAge)
            {
                return rpcNO_CURRENT;
            }

            auto const cID = context.ledgerMaster.getCurrentLedgerIndex ();
            auto const vID = context.ledgerMaster.getValidLedgerIndex ();

            if (cID + 10 < vID)
            {
                JLOG (context.j.debug()) << "Current ledger ID(" << cID <<
                    ") is less than validated ledger ID(" << vID << ")";
                return rpcNO_CURRENT;
            }
        }

        if ((handler->condition_ & NEEDS_CLOSED_LEDGER) &&
            !context.ledgerMaster.getClosedLedger ())
        {
            return rpcNO_CLOSED;
        }

        result = handler;
        return rpcSUCCESS;
    }

Above we see the admin check on line 149, the persistent network connection check on line 152, the amendment check on line 162, the current ledger check on line 169, and the closed ledger check on line 169

Documentation pertaining to the specific RPC methods can be found on the rippled website

We will now explore the core subsystems responsible for primary rippled functionality, starting with the Overlay Network. In each will will touch upon the RPC methods that access & affect these subsystems.

<<Back Home >>Next