Skip to content

Commit

Permalink
Consolidate "Not Synced" Error Messages
Browse files Browse the repository at this point in the history
* Fixes XRPLF#3269

* The error noClosed as been renamed to notSynced.
* Uses of the error noCurrent, noNetwork and lgrIdxsInvalid
  now use notSynced.
  • Loading branch information
HowardHinnant committed May 27, 2020
1 parent 9771210 commit 4b9e23e
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/ripple/protocol/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/ripple/protocol/impl/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand All @@ -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."},
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -236,7 +236,7 @@ getLedgerRange(
uLedgerMax = ls.max;
}
if (uLedgerMax < uLedgerMin)
return rpcLGR_IDXS_INVALID;
return rpcNOT_SYNCED;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/rpc/handlers/AccountTxOld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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;
uLedgerMax = iLedgerMax == -1 ? uValidatedMax : iLedgerMax;

if (uLedgerMax < uLedgerMin)
{
return rpcError(rpcLGR_IDXS_INVALID);
return rpcError(rpcNOT_SYNCED);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/handlers/LedgerRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/handlers/RipplePathFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/ripple/rpc/impl/Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand All @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/rpc/impl/RPCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace {
Failure:
{
"result" : {
"error" : "noNetwork",
"error" : "notSynced",
"error_code" : 16,
"error_message" : "Not synced to Ripple network.",
"request" : {
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace {
Failure:
{
"error" : "noNetwork",
"error" : "notSynced",
"error_code" : 16,
"error_message" : "Not synced to Ripple network.",
"request" : {
Expand Down
10 changes: 5 additions & 5 deletions src/ripple/rpc/impl/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
Expand All @@ -386,15 +386,15 @@ getLedger(T& ledger, LedgerShortcut shortcut, Context& context)
}

if (ledger == nullptr)
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
return {rpcNOT_SYNCED, "InsufficientNetworkMode"};

static auto const minSequenceGap = 10;

if (ledger->info().seq + minSequenceGap <
context.ledgerMaster.getValidLedgerIndex())
{
ledger.reset();
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
return {rpcNOT_SYNCED, "InsufficientNetworkMode"};
}
}
return Status::OK;
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/TransactionSign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ checkTxJsonFields(
if (verify && !config.standalone() &&
(validatedLedgerAge > Tuning::maxValidatedLedgerAge))
{
ret.first = rpcError(rpcNO_CURRENT);
ret.first = rpcError(rpcNOT_SYNCED);
return ret;
}

Expand Down
6 changes: 2 additions & 4 deletions src/test/rpc/AccountTx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/rpc/LedgerRequestRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/test/rpc/RPCCall_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
})",
Expand Down Expand Up @@ -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."
}
]
})",
Expand Down

0 comments on commit 4b9e23e

Please sign in to comment.