From 4b9e23e09b1e61966187602eb2c02b6c40177550 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 27 May 2020 17:44:20 -0400 Subject: [PATCH] Consolidate "Not Synced" Error Messages * Fixes #3269 * The error noClosed as been renamed to notSynced. * Uses of the error noCurrent, noNetwork and lgrIdxsInvalid now use notSynced. --- src/ripple/net/impl/RPCCall.cpp | 4 ++-- src/ripple/protocol/ErrorCodes.h | 8 ++++---- src/ripple/protocol/impl/ErrorCodes.cpp | 5 +---- src/ripple/rpc/handlers/AccountTx.cpp | 4 ++-- src/ripple/rpc/handlers/AccountTxOld.cpp | 4 ++-- src/ripple/rpc/handlers/LedgerRequest.cpp | 2 +- src/ripple/rpc/handlers/RipplePathFind.cpp | 2 +- src/ripple/rpc/impl/Handler.h | 8 ++++---- src/ripple/rpc/impl/RPCHandler.cpp | 4 ++-- src/ripple/rpc/impl/RPCHelpers.cpp | 10 +++++----- src/ripple/rpc/impl/TransactionSign.cpp | 2 +- src/test/rpc/AccountTx_test.cpp | 6 ++---- src/test/rpc/LedgerRequestRPC_test.cpp | 4 ++-- src/test/rpc/RPCCall_test.cpp | 8 ++++---- 14 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index a565d4bc321..a3a05784844 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -314,7 +314,7 @@ class RPCParser if (uLedgerMax != -1 && uLedgerMax < uLedgerMin) { - return rpcError(rpcLGR_IDXS_INVALID); + return rpcError(rpcNOT_SYNCED); } jvRequest[jss::ledger_index_min] = jvParams[1u].asInt(); @@ -384,7 +384,7 @@ class RPCParser if (uLedgerMax != -1 && uLedgerMax < uLedgerMin) { - return rpcError(rpcLGR_IDXS_INVALID); + return rpcError(rpcNOT_SYNCED); } jvRequest[jss::ledger_index_min] = jvParams[1u].asInt(); diff --git a/src/ripple/protocol/ErrorCodes.h b/src/ripple/protocol/ErrorCodes.h index a3fb9e590bb..f68a443c963 100644 --- a/src/ripple/protocol/ErrorCodes.h +++ b/src/ripple/protocol/ErrorCodes.h @@ -61,9 +61,9 @@ enum error_code_i { rpcAMENDMENT_BLOCKED = 14, // Networking - rpcNO_CLOSED = 15, - rpcNO_CURRENT = 16, - rpcNO_NETWORK = 17, + rpcNOT_SYNCED = 15, + // unused 16, + // unused 17, // Ledger state // unused 18, @@ -109,7 +109,7 @@ enum error_code_i { // unused 54, // unused 55, // unused 56, - rpcLGR_IDXS_INVALID = 57, + // unused 57, rpcLGR_IDX_MALFORMED = 58, // unused 59, // unused 60, diff --git a/src/ripple/protocol/impl/ErrorCodes.cpp b/src/ripple/protocol/impl/ErrorCodes.cpp index 9110daf40f7..896596b9cca 100644 --- a/src/ripple/protocol/impl/ErrorCodes.cpp +++ b/src/ripple/protocol/impl/ErrorCodes.cpp @@ -79,7 +79,6 @@ constexpr static ErrorInfo unorderedErrorInfos[]{ {rpcINVALID_LGR_RANGE, "invalidLgrRange", "Ledger range is invalid."}, {rpcINVALID_PARAMS, "invalidParams", "Invalid parameters."}, {rpcJSON_RPC, "json_rpc", "JSON-RPC transport error."}, - {rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid."}, {rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed."}, {rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found."}, {rpcLGR_NOT_VALIDATED, "lgrNotValidated", "Ledger not validated."}, @@ -88,10 +87,8 @@ constexpr static ErrorInfo unorderedErrorInfos[]{ {rpcNOT_IMPL, "notImpl", "Not implemented."}, {rpcNOT_READY, "notReady", "Not ready to handle this request."}, {rpcNOT_SUPPORTED, "notSupported", "Operation not supported."}, - {rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable."}, - {rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable."}, + {rpcNOT_SYNCED, "notSynced", "Not synced to XRP network."}, {rpcNO_EVENTS, "noEvents", "Current transport does not support events."}, - {rpcNO_NETWORK, "noNetwork", "Not synced to Ripple network."}, {rpcNO_PERMISSION, "noPermission", "You don't have permission for this command."}, diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index 42a61df94ea..816929d35eb 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -214,7 +214,7 @@ getLedgerRange( if (!bValidated) { // Don't have a validated ledger range. - return rpcLGR_IDXS_INVALID; + return rpcNOT_SYNCED; } std::uint32_t uLedgerMin = uValidatedMin; @@ -236,7 +236,7 @@ getLedgerRange( uLedgerMax = ls.max; } if (uLedgerMax < uLedgerMin) - return rpcLGR_IDXS_INVALID; + return rpcNOT_SYNCED; } else { diff --git a/src/ripple/rpc/handlers/AccountTxOld.cpp b/src/ripple/rpc/handlers/AccountTxOld.cpp index 472f999b621..97464f5f550 100644 --- a/src/ripple/rpc/handlers/AccountTxOld.cpp +++ b/src/ripple/rpc/handlers/AccountTxOld.cpp @@ -105,7 +105,7 @@ doAccountTxOld(RPC::JsonContext& context) if (!bValidated && (iLedgerMin == -1 || iLedgerMax == -1)) { // Don't have a validated ledger range. - return rpcError(rpcLGR_IDXS_INVALID); + return rpcError(rpcNOT_SYNCED); } uLedgerMin = iLedgerMin == -1 ? uValidatedMin : iLedgerMin; @@ -113,7 +113,7 @@ doAccountTxOld(RPC::JsonContext& context) if (uLedgerMax < uLedgerMin) { - return rpcError(rpcLGR_IDXS_INVALID); + return rpcError(rpcNOT_SYNCED); } } else diff --git a/src/ripple/rpc/handlers/LedgerRequest.cpp b/src/ripple/rpc/handlers/LedgerRequest.cpp index f7b12e95eb9..d9582a98ead 100644 --- a/src/ripple/rpc/handlers/LedgerRequest.cpp +++ b/src/ripple/rpc/handlers/LedgerRequest.cpp @@ -67,7 +67,7 @@ doLedgerRequest(RPC::JsonContext& context) // We need a validated ledger to get the hash from the sequence if (ledgerMaster.getValidatedLedgerAge() > RPC::Tuning::maxValidatedLedgerAge) - return rpcError(rpcNO_CURRENT); + return rpcError(rpcNOT_SYNCED); ledgerIndex = jsonIndex.asInt(); auto ledger = ledgerMaster.getValidatedLedger(); diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 4b03bb93f53..4404fbb71f5 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -49,7 +49,7 @@ doRipplePathFind(RPC::JsonContext& context) if (context.app.getLedgerMaster().getValidatedLedgerAge() > RPC::Tuning::maxValidatedLedgerAge) { - return rpcError(rpcNO_NETWORK); + return rpcError(rpcNOT_SYNCED); } PathRequest::pointer request; diff --git a/src/ripple/rpc/impl/Handler.h b/src/ripple/rpc/impl/Handler.h index 09acd6ba165..0d222957e8a 100644 --- a/src/ripple/rpc/impl/Handler.h +++ b/src/ripple/rpc/impl/Handler.h @@ -83,7 +83,7 @@ conditionMet(Condition condition_required, T& context) JLOG(context.j.info()) << "Insufficient network mode for RPC: " << context.netOps.strOperatingMode(); - return rpcNO_NETWORK; + return rpcNOT_SYNCED; } if (context.app.getOPs().isAmendmentBlocked() && @@ -99,7 +99,7 @@ conditionMet(Condition condition_required, T& context) if (context.ledgerMaster.getValidatedLedgerAge() > Tuning::maxValidatedLedgerAge) { - return rpcNO_CURRENT; + return rpcNOT_SYNCED; } auto const cID = context.ledgerMaster.getCurrentLedgerIndex(); @@ -110,14 +110,14 @@ conditionMet(Condition condition_required, T& context) JLOG(context.j.debug()) << "Current ledger ID(" << cID << ") is less than validated ledger ID(" << vID << ")"; - return rpcNO_CURRENT; + return rpcNOT_SYNCED; } } if ((condition_required & NEEDS_CLOSED_LEDGER) && !context.ledgerMaster.getClosedLedger()) { - return rpcNO_CLOSED; + return rpcNOT_SYNCED; } return rpcSUCCESS; diff --git a/src/ripple/rpc/impl/RPCHandler.cpp b/src/ripple/rpc/impl/RPCHandler.cpp index 9d4885b1ebf..90637d6f551 100644 --- a/src/ripple/rpc/impl/RPCHandler.cpp +++ b/src/ripple/rpc/impl/RPCHandler.cpp @@ -65,7 +65,7 @@ namespace { Failure: { "result" : { - "error" : "noNetwork", + "error" : "notSynced", "error_code" : 16, "error_message" : "Not synced to Ripple network.", "request" : { @@ -95,7 +95,7 @@ namespace { Failure: { - "error" : "noNetwork", + "error" : "notSynced", "error_code" : 16, "error_message" : "Not synced to Ripple network.", "request" : { diff --git a/src/ripple/rpc/impl/RPCHelpers.cpp b/src/ripple/rpc/impl/RPCHelpers.cpp index 1104caa59f2..43e1072be33 100644 --- a/src/ripple/rpc/impl/RPCHelpers.cpp +++ b/src/ripple/rpc/impl/RPCHelpers.cpp @@ -347,7 +347,7 @@ getLedger(T& ledger, uint32_t ledgerIndex, Context& context) isValidatedOld(context.ledgerMaster, context.app.config().standalone())) { ledger.reset(); - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + return {rpcNOT_SYNCED, "InsufficientNetworkMode"}; } return Status::OK; @@ -358,13 +358,13 @@ Status getLedger(T& ledger, LedgerShortcut shortcut, Context& context) { if (isValidatedOld(context.ledgerMaster, context.app.config().standalone())) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + return {rpcNOT_SYNCED, "InsufficientNetworkMode"}; if (shortcut == LedgerShortcut::VALIDATED) { ledger = context.ledgerMaster.getValidatedLedger(); if (ledger == nullptr) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + return {rpcNOT_SYNCED, "InsufficientNetworkMode"}; assert(!ledger->open()); } @@ -386,7 +386,7 @@ getLedger(T& ledger, LedgerShortcut shortcut, Context& context) } if (ledger == nullptr) - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + return {rpcNOT_SYNCED, "InsufficientNetworkMode"}; static auto const minSequenceGap = 10; @@ -394,7 +394,7 @@ getLedger(T& ledger, LedgerShortcut shortcut, Context& context) context.ledgerMaster.getValidLedgerIndex()) { ledger.reset(); - return {rpcNO_NETWORK, "InsufficientNetworkMode"}; + return {rpcNOT_SYNCED, "InsufficientNetworkMode"}; } } return Status::OK; diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index 345d71ffd29..a2b1016bf1e 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -308,7 +308,7 @@ checkTxJsonFields( if (verify && !config.standalone() && (validatedLedgerAge > Tuning::maxValidatedLedgerAge)) { - ret.first = rpcError(rpcNO_CURRENT); + ret.first = rpcError(rpcNOT_SYNCED); return ret; } diff --git a/src/test/rpc/AccountTx_test.cpp b/src/test/rpc/AccountTx_test.cpp index 030fce99e10..264bf1c0a27 100644 --- a/src/test/rpc/AccountTx_test.cpp +++ b/src/test/rpc/AccountTx_test.cpp @@ -174,8 +174,7 @@ class AccountTx_test : public beast::unit_test::suite p[jss::ledger_index_min] = 2; p[jss::ledger_index_max] = 1; BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcLGR_IDXS_INVALID)); + env.rpc("json", "account_tx", to_string(p)), rpcNOT_SYNCED)); } // Ledger index min only @@ -189,8 +188,7 @@ class AccountTx_test : public beast::unit_test::suite p[jss::ledger_index_min] = env.current()->info().seq; BEAST_EXPECT(isErr( - env.rpc("json", "account_tx", to_string(p)), - rpcLGR_IDXS_INVALID)); + env.rpc("json", "account_tx", to_string(p)), rpcNOT_SYNCED)); } // Ledger index max only diff --git a/src/test/rpc/LedgerRequestRPC_test.cpp b/src/test/rpc/LedgerRequestRPC_test.cpp index c7d84009969..dc37cfb723a 100644 --- a/src/test/rpc/LedgerRequestRPC_test.cpp +++ b/src/test/rpc/LedgerRequestRPC_test.cpp @@ -297,10 +297,10 @@ class LedgerRequestRPC_test : public beast::unit_test::suite // date check to trigger env.timeKeeper().adjustCloseTime(weeks{3}); result = env.rpc("ledger_request", "1")[jss::result]; - BEAST_EXPECT(result[jss::error] == "noCurrent"); + BEAST_EXPECT(result[jss::error] == "notSynced"); BEAST_EXPECT(result[jss::status] == "error"); BEAST_EXPECT( - result[jss::error_message] == "Current ledger is unavailable."); + result[jss::error_message] == "Not synced to XRP network."); } void diff --git a/src/test/rpc/RPCCall_test.cpp b/src/test/rpc/RPCCall_test.cpp index 174feb0b7f8..32d671798b8 100644 --- a/src/test/rpc/RPCCall_test.cpp +++ b/src/test/rpc/RPCCall_test.cpp @@ -1441,9 +1441,9 @@ static RPCCallTestData const rpcCallTestArray[] = { "method" : "account_tx", "params" : [ { - "error" : "lgrIdxsInvalid", + "error" : "notSynced", "error_code" : 55, - "error_message" : "Ledger indexes invalid." + "error_message" : "Not synced to XRP network." } ] })", @@ -5909,9 +5909,9 @@ static RPCCallTestData const rpcCallTestArray[] = { "method" : "tx_account", "params" : [ { - "error" : "lgrIdxsInvalid", + "error" : "notSynced", "error_code" : 55, - "error_message" : "Ledger indexes invalid." + "error_message" : "Not synced to XRP network." } ] })",