RPC fee command checks open ledger rules (RIPD-1183):

* Matches internal getMetric() to avoid races.
This commit is contained in:
Edward Hennis
2016-05-27 18:33:49 -04:00
committed by Nik Bougalis
parent 05d98f4380
commit 7295d7f4bb
3 changed files with 50 additions and 4 deletions

View File

@@ -1151,6 +1151,7 @@ TxQ::doRPC(Application& app) const
auto const view = app.openLedger().current();
auto const metrics = getMetrics(app, *view);
assert(metrics);
if (!metrics)
return{};

View File

@@ -25,6 +25,7 @@
#include <ripple/basics/Log.h>
#include <ripple/basics/mulDiv.h>
#include <ripple/basics/TestSuite.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/JsonFields.h>
#include <ripple/protocol/STTx.h>
@@ -1529,6 +1530,42 @@ public:
}
}
void testRPC()
{
using namespace jtx;
{
Env env(*this, features(featureFeeEscalation));
auto fee = env.rpc("fee");
if (expect(fee.isMember(jss::result) &&
!RPC::contains_error(fee[jss::result])))
{
auto const& result = fee[jss::result];
expect(result.isMember(jss::drops));
expect(result.isMember(jss::levels));
expect(result.isMember(jss::current_ledger_size));
expect(result.isMember(jss::current_queue_size));
expect(result.isMember(jss::expected_ledger_size));
}
}
{
Env env(*this);
auto fee = env.rpc("fee");
if(expect(fee.isMember(jss::result) &&
RPC::contains_error(fee[jss::result])))
{
auto const& result = fee[jss::result];
expect(result.isMember(jss::error) &&
result[jss::error] ==
RPC::get_error_info(rpcNOT_ENABLED).token);
}
}
}
void run()
{
testQueue();
@@ -1546,6 +1583,7 @@ public:
testBlockers();
testInFlightBalance();
testConsequences();
testRPC();
}
};

View File

@@ -18,8 +18,9 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/ledger/OpenLedger.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/TxQ.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/rpc/Context.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/Feature.h>
@@ -29,13 +30,19 @@ namespace ripple
Json::Value doFee(RPC::Context& context)
{
// Bail if fee escalation is not enabled.
if (!context.app.getLedgerMaster().getValidatedRules().
enabled(featureFeeEscalation, context.app.config().features))
auto const view = context.app.openLedger().current();
if (!view || !view->rules().enabled(
featureFeeEscalation, context.app.config().features))
{
RPC::inject_error(rpcNOT_ENABLED, context.params);
return context.params;
}
return context.app.getTxQ().doRPC(context.app);
auto result = context.app.getTxQ().doRPC(context.app);
if (result.type() == Json::objectValue)
return result;
assert(false);
RPC::inject_error(rpcINTERNAL, context.params);
return context.params;
}
} // ripple