mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
Fix RPC ledger synchronization requirements:
* Better rules specific to each lookup case: * By hash: Any ledger found by hash is valid. * By numeric index: If rippled is out of sync, and the index is after the * validated ledger, return "InsufficientNetworkMode" error. * By named index: If rippled is out of sync, or closed/current is requested and significantly older than the validated ledger, return "InsufficientNetworkMode" error.
This commit is contained in:
committed by
Nik Bougalis
parent
4ad07bb6b2
commit
9cded76cf0
@@ -25,34 +25,13 @@ namespace RPC {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool
|
bool isValidatedOld ()
|
||||||
synced (NetworkOPs& netOps, Ledger::pointer ledger)
|
|
||||||
{
|
{
|
||||||
static auto const minSequenceGap = 10;
|
|
||||||
|
|
||||||
if (getConfig ().RUN_STANDALONE)
|
if (getConfig ().RUN_STANDALONE)
|
||||||
return true;
|
|
||||||
|
|
||||||
if (ledger == netOps.getValidatedLedger ())
|
|
||||||
{
|
|
||||||
return getApp ().getLedgerMaster ().getValidatedLedgerAge () <=
|
|
||||||
Tuning::maxValidatedLedgerAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ledger != netOps.getCurrentLedger () &&
|
|
||||||
ledger != netOps.getClosedLedger ())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getApp ().getLedgerMaster ().getValidatedLedgerAge () >
|
|
||||||
Tuning::maxValidatedLedgerAge)
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return ledger->getLedgerSeq () >
|
return getApp ().getLedgerMaster ().getValidatedLedgerAge () >
|
||||||
(netOps.getValidatedSeq () + minSequenceGap);
|
Tuning::maxValidatedLedgerAge;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ledgerFromRequest (
|
Status ledgerFromRequest (
|
||||||
@@ -60,6 +39,8 @@ Status ledgerFromRequest (
|
|||||||
Ledger::pointer& ledger,
|
Ledger::pointer& ledger,
|
||||||
NetworkOPs& netOps)
|
NetworkOPs& netOps)
|
||||||
{
|
{
|
||||||
|
static auto const minSequenceGap = 10;
|
||||||
|
|
||||||
ledger.reset();
|
ledger.reset();
|
||||||
|
|
||||||
auto indexValue = params[jss::ledger_index];
|
auto indexValue = params[jss::ledger_index];
|
||||||
@@ -83,46 +64,67 @@ Status ledgerFromRequest (
|
|||||||
uint256 ledgerHash;
|
uint256 ledgerHash;
|
||||||
if (! ledgerHash.SetHex (hashValue.asString ()))
|
if (! ledgerHash.SetHex (hashValue.asString ()))
|
||||||
return {rpcINVALID_PARAMS, "ledgerHashMalformed"};
|
return {rpcINVALID_PARAMS, "ledgerHashMalformed"};
|
||||||
|
|
||||||
ledger = netOps.getLedgerByHash (ledgerHash);
|
ledger = netOps.getLedgerByHash (ledgerHash);
|
||||||
|
if (ledger == nullptr)
|
||||||
|
return {rpcLGR_NOT_FOUND, "ledgerNotFound"};
|
||||||
}
|
}
|
||||||
else if (indexValue.isNumeric())
|
else if (indexValue.isNumeric())
|
||||||
{
|
{
|
||||||
ledger = netOps.getLedgerBySeq (indexValue.asInt ());
|
ledger = netOps.getLedgerBySeq (indexValue.asInt ());
|
||||||
|
if (ledger == nullptr)
|
||||||
|
return {rpcLGR_NOT_FOUND, "ledgerNotFound"};
|
||||||
|
|
||||||
|
if (ledger->getLedgerSeq () > netOps.getValidatedSeq () &&
|
||||||
|
isValidatedOld ())
|
||||||
|
{
|
||||||
|
ledger.reset();
|
||||||
|
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (isValidatedOld ())
|
||||||
|
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||||
|
|
||||||
auto const index = indexValue.asString ();
|
auto const index = indexValue.asString ();
|
||||||
auto const isCurrent = index.empty() || index == "current";
|
if (index == "validated")
|
||||||
if (isCurrent)
|
{
|
||||||
ledger = netOps.getCurrentLedger ();
|
|
||||||
else if (index == "closed")
|
|
||||||
ledger = netOps.getClosedLedger ();
|
|
||||||
else if (index == "validated")
|
|
||||||
ledger = netOps.getValidatedLedger ();
|
ledger = netOps.getValidatedLedger ();
|
||||||
|
if (ledger == nullptr)
|
||||||
|
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||||
|
|
||||||
|
assert (ledger->isClosed ());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
|
{
|
||||||
|
if (index.empty () || index == "current")
|
||||||
|
{
|
||||||
|
ledger = netOps.getCurrentLedger ();
|
||||||
|
assert (! ledger->isClosed ());
|
||||||
|
}
|
||||||
|
else if (index == "closed")
|
||||||
|
{
|
||||||
|
ledger = netOps.getClosedLedger ();
|
||||||
|
assert (ledger->isClosed ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
|
||||||
|
}
|
||||||
|
|
||||||
if (ledger == nullptr)
|
if (ledger == nullptr)
|
||||||
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||||
|
|
||||||
assert (ledger->isImmutable());
|
if (ledger->getLedgerSeq () + minSequenceGap <
|
||||||
assert (ledger->isClosed() == !isCurrent);
|
netOps.getValidatedSeq ())
|
||||||
}
|
{
|
||||||
|
ledger.reset ();
|
||||||
|
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ledger == nullptr)
|
assert (ledger->isImmutable ());
|
||||||
{
|
|
||||||
auto cl = netOps.getCurrentLedger ();
|
|
||||||
if (cl == nullptr || ! synced (netOps, cl))
|
|
||||||
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
|
||||||
|
|
||||||
return {rpcLGR_NOT_FOUND, "ledgerNotFound"};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! synced (netOps, ledger))
|
|
||||||
{
|
|
||||||
ledger.reset ();
|
|
||||||
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user