mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 21:45:52 +00:00
Check amendment block status and update w/ ledgers:
Check and modify amendment blocked status with each new ledger (provided by @wilsonianb). Honor blocked status in certain RPC commands and when deciding whether to propose/validate. Fixes: RIPD-1479 Fixes: RIPD-1447 Release Notes ------------- This resolves an issue whereby an amendment blocked server would still serve some RPC requests that are unreliable in blocked state and would continue to publish validations.
This commit is contained in:
@@ -4943,6 +4943,10 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\test\rpc\AmendmentBlocked_test.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\test\rpc\Book_test.cpp">
|
<ClCompile Include="..\..\src\test\rpc\Book_test.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -5658,6 +5658,9 @@
|
|||||||
<ClCompile Include="..\..\src\test\rpc\AccountSet_test.cpp">
|
<ClCompile Include="..\..\src\test\rpc\AccountSet_test.cpp">
|
||||||
<Filter>test\rpc</Filter>
|
<Filter>test\rpc</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\test\rpc\AmendmentBlocked_test.cpp">
|
||||||
|
<Filter>test\rpc</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\test\rpc\Book_test.cpp">
|
<ClCompile Include="..\..\src\test\rpc\Book_test.cpp">
|
||||||
<Filter>test\rpc</Filter>
|
<Filter>test\rpc</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -934,9 +934,12 @@ RCLConsensus::peerProposal(
|
|||||||
bool
|
bool
|
||||||
RCLConsensus::Adaptor::preStartRound(RCLCxLedger const & prevLgr)
|
RCLConsensus::Adaptor::preStartRound(RCLCxLedger const & prevLgr)
|
||||||
{
|
{
|
||||||
// We have a key, and we have some idea what the ledger is
|
// We have a key, we have some idea what the ledger is, and we are not
|
||||||
|
// amendment blocked
|
||||||
validating_ =
|
validating_ =
|
||||||
!app_.getOPs().isNeedNetworkLedger() && (valPublic_.size() != 0);
|
!app_.getOPs().isNeedNetworkLedger() &&
|
||||||
|
(valPublic_.size() != 0) &&
|
||||||
|
!app_.getOPs().isAmendmentBlocked();
|
||||||
|
|
||||||
if (validating_)
|
if (validating_)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -227,6 +227,13 @@ LedgerMaster::setValidLedger(
|
|||||||
app_.getSHAMapStore().onLedgerClosed (getValidatedLedger());
|
app_.getSHAMapStore().onLedgerClosed (getValidatedLedger());
|
||||||
mLedgerHistory.validatedLedger (l);
|
mLedgerHistory.validatedLedger (l);
|
||||||
app_.getAmendmentTable().doValidatedLedger (l);
|
app_.getAmendmentTable().doValidatedLedger (l);
|
||||||
|
if (!app_.getOPs().isAmendmentBlocked() &&
|
||||||
|
app_.getAmendmentTable().hasUnsupportedEnabled ())
|
||||||
|
{
|
||||||
|
JLOG (m_journal.error()) <<
|
||||||
|
"One or more unsupported amendments activated: server blocked.";
|
||||||
|
app_.getOPs().setAmendmentBlocked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ public:
|
|||||||
virtual bool isEnabled (uint256 const& amendment) = 0;
|
virtual bool isEnabled (uint256 const& amendment) = 0;
|
||||||
virtual bool isSupported (uint256 const& amendment) = 0;
|
virtual bool isSupported (uint256 const& amendment) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief returns true if one or more amendments on the network
|
||||||
|
* have been enabled that this server does not support
|
||||||
|
*
|
||||||
|
* @return true if an unsupported feature is enabled on the network
|
||||||
|
*/
|
||||||
|
virtual bool hasUnsupportedEnabled () = 0;
|
||||||
|
|
||||||
virtual Json::Value getJson (int) = 0;
|
virtual Json::Value getJson (int) = 0;
|
||||||
|
|
||||||
/** Returns a Json::objectValue. */
|
/** Returns a Json::objectValue. */
|
||||||
|
|||||||
@@ -157,6 +157,9 @@ protected:
|
|||||||
// we haven't participated in one yet.
|
// we haven't participated in one yet.
|
||||||
std::unique_ptr <AmendmentSet> lastVote_;
|
std::unique_ptr <AmendmentSet> lastVote_;
|
||||||
|
|
||||||
|
// True if an unsupported amendment is enabled
|
||||||
|
bool unsupportedEnabled_;
|
||||||
|
|
||||||
beast::Journal j_;
|
beast::Journal j_;
|
||||||
|
|
||||||
// Finds or creates state
|
// Finds or creates state
|
||||||
@@ -187,6 +190,8 @@ public:
|
|||||||
bool isEnabled (uint256 const& amendment) override;
|
bool isEnabled (uint256 const& amendment) override;
|
||||||
bool isSupported (uint256 const& amendment) override;
|
bool isSupported (uint256 const& amendment) override;
|
||||||
|
|
||||||
|
bool hasUnsupportedEnabled () override;
|
||||||
|
|
||||||
Json::Value getJson (int) override;
|
Json::Value getJson (int) override;
|
||||||
Json::Value getJson (uint256 const&) override;
|
Json::Value getJson (uint256 const&) override;
|
||||||
|
|
||||||
@@ -222,6 +227,7 @@ AmendmentTableImpl::AmendmentTableImpl (
|
|||||||
: lastUpdateSeq_ (0)
|
: lastUpdateSeq_ (0)
|
||||||
, majorityTime_ (majorityTime)
|
, majorityTime_ (majorityTime)
|
||||||
, majorityFraction_ (majorityFraction)
|
, majorityFraction_ (majorityFraction)
|
||||||
|
, unsupportedEnabled_ (false)
|
||||||
, j_ (journal)
|
, j_ (journal)
|
||||||
{
|
{
|
||||||
assert (majorityFraction_ != 0);
|
assert (majorityFraction_ != 0);
|
||||||
@@ -340,6 +346,14 @@ AmendmentTableImpl::enable (uint256 const& amendment)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
s->enabled = true;
|
s->enabled = true;
|
||||||
|
|
||||||
|
if (! s->supported)
|
||||||
|
{
|
||||||
|
JLOG (j_.error()) <<
|
||||||
|
"Unsupported amendment " << amendment << " activated.";
|
||||||
|
unsupportedEnabled_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,6 +386,13 @@ AmendmentTableImpl::isSupported (uint256 const& amendment)
|
|||||||
return s && s->supported;
|
return s && s->supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
AmendmentTableImpl::hasUnsupportedEnabled ()
|
||||||
|
{
|
||||||
|
std::lock_guard <std::mutex> sl (mutex_);
|
||||||
|
return unsupportedEnabled_;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector <uint256>
|
std::vector <uint256>
|
||||||
AmendmentTableImpl::doValidation (
|
AmendmentTableImpl::doValidation (
|
||||||
std::set<uint256> const& enabled)
|
std::set<uint256> const& enabled)
|
||||||
@@ -523,10 +544,8 @@ AmendmentTableImpl::doValidatedLedger (
|
|||||||
LedgerIndex ledgerSeq,
|
LedgerIndex ledgerSeq,
|
||||||
std::set<uint256> const& enabled)
|
std::set<uint256> const& enabled)
|
||||||
{
|
{
|
||||||
std::lock_guard <std::mutex> sl (mutex_);
|
for (auto& e : enabled)
|
||||||
|
enable(e);
|
||||||
for (auto& e : amendmentMap_)
|
|
||||||
e.second.enabled = (enabled.count (e.first) != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ enum error_code_i
|
|||||||
rpcHIGH_FEE,
|
rpcHIGH_FEE,
|
||||||
rpcNOT_ENABLED,
|
rpcNOT_ENABLED,
|
||||||
rpcNOT_READY,
|
rpcNOT_READY,
|
||||||
|
rpcAMENDMENT_BLOCKED,
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
rpcNO_CLOSED,
|
rpcNO_CLOSED,
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
add (rpcACT_EXISTS, "actExists", "Account already exists.");
|
add (rpcACT_EXISTS, "actExists", "Account already exists.");
|
||||||
add (rpcACT_MALFORMED, "actMalformed", "Account malformed.");
|
add (rpcACT_MALFORMED, "actMalformed", "Account malformed.");
|
||||||
add (rpcACT_NOT_FOUND, "actNotFound", "Account not found.");
|
add (rpcACT_NOT_FOUND, "actNotFound", "Account not found.");
|
||||||
|
add (rpcAMENDMENT_BLOCKED, "amendmentBlocked", "Amendment blocked, need upgrade.");
|
||||||
add (rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range.");
|
add (rpcATX_DEPRECATED, "deprecated", "Use the new API or specify a ledger range.");
|
||||||
add (rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string.");
|
add (rpcBAD_BLOB, "badBlob", "Blob must be a non-empty hex string.");
|
||||||
add (rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid.");
|
add (rpcBAD_FEATURE, "badFeature", "Feature unknown or invalid.");
|
||||||
|
|||||||
@@ -157,6 +157,13 @@ error_code_i fillHandler (Context& context,
|
|||||||
return rpcNO_NETWORK;
|
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() &&
|
if (!context.app.config().standalone() &&
|
||||||
handler->condition_ & NEEDS_CURRENT_LEDGER)
|
handler->condition_ & NEEDS_CURRENT_LEDGER)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -745,6 +745,20 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testHasUnsupported ()
|
||||||
|
{
|
||||||
|
testcase ("hasUnsupportedEnabled");
|
||||||
|
|
||||||
|
auto table = makeTable(1);
|
||||||
|
BEAST_EXPECT(! table->hasUnsupportedEnabled());
|
||||||
|
|
||||||
|
std::set <uint256> enabled;
|
||||||
|
std::for_each(m_set4.begin(), m_set4.end(),
|
||||||
|
[&enabled](auto const &s){ enabled.insert(amendmentId(s)); });
|
||||||
|
table->doValidatedLedger(1, enabled);
|
||||||
|
BEAST_EXPECT(table->hasUnsupportedEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
void run ()
|
void run ()
|
||||||
{
|
{
|
||||||
testConstruct();
|
testConstruct();
|
||||||
@@ -757,6 +771,7 @@ public:
|
|||||||
testDetectMajority ();
|
testDetectMajority ();
|
||||||
testLostMajority ();
|
testLostMajority ();
|
||||||
testSupportedAmendments ();
|
testSupportedAmendments ();
|
||||||
|
testHasUnsupported ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
169
src/test/rpc/AmendmentBlocked_test.cpp
Normal file
169
src/test/rpc/AmendmentBlocked_test.cpp
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of rippled: https://github.com/ripple/rippled
|
||||||
|
Copyright (c) 2017 Ripple Labs Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#include <test/jtx.h>
|
||||||
|
#include <ripple/protocol/JsonFields.h>
|
||||||
|
#include <ripple/app/misc/NetworkOPs.h>
|
||||||
|
#include <test/jtx/WSClient.h>
|
||||||
|
|
||||||
|
namespace ripple {
|
||||||
|
|
||||||
|
class AmendmentBlocked_test : public beast::unit_test::suite
|
||||||
|
{
|
||||||
|
void testBlockedMethods()
|
||||||
|
{
|
||||||
|
using namespace test::jtx;
|
||||||
|
Env env {*this};
|
||||||
|
auto const gw = Account {"gateway"};
|
||||||
|
auto const USD = gw["USD"];
|
||||||
|
auto const alice = Account {"alice"};
|
||||||
|
auto const bob = Account {"bob"};
|
||||||
|
env.fund (XRP(10000), alice, bob, gw);
|
||||||
|
env.trust (USD(600), alice);
|
||||||
|
env.trust (USD(700), bob);
|
||||||
|
env(pay (gw, alice, USD(70)));
|
||||||
|
env(pay (gw, bob, USD(50)));
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
auto wsc = test::makeWSClient(env.app().config());
|
||||||
|
|
||||||
|
auto current = env.current ();
|
||||||
|
// ledger_accept
|
||||||
|
auto jr = env.rpc ("ledger_accept") [jss::result];
|
||||||
|
BEAST_EXPECT (jr[jss::ledger_current_index] == current->seq ()+1);
|
||||||
|
|
||||||
|
// ledger_current
|
||||||
|
jr = env.rpc ("ledger_current") [jss::result];
|
||||||
|
BEAST_EXPECT (jr[jss::ledger_current_index] == current->seq ()+1);
|
||||||
|
|
||||||
|
// owner_info
|
||||||
|
jr = env.rpc ("owner_info", alice.human()) [jss::result];
|
||||||
|
BEAST_EXPECT (jr.isMember (jss::accepted) && jr.isMember (jss::current));
|
||||||
|
|
||||||
|
// path_find
|
||||||
|
Json::Value pf_req;
|
||||||
|
pf_req[jss::subcommand] = "create";
|
||||||
|
pf_req[jss::source_account] = alice.human();
|
||||||
|
pf_req[jss::destination_account] = bob.human();
|
||||||
|
pf_req[jss::destination_amount] = bob["USD"](20).value ().getJson (0);
|
||||||
|
jr = wsc->invoke("path_find", pf_req) [jss::result];
|
||||||
|
BEAST_EXPECT (jr.isMember (jss::alternatives) &&
|
||||||
|
jr[jss::alternatives].isArray () &&
|
||||||
|
jr[jss::alternatives].size () == 1);
|
||||||
|
|
||||||
|
// submit
|
||||||
|
auto jt = env.jt (noop (alice));
|
||||||
|
Serializer s;
|
||||||
|
jt.stx->add (s);
|
||||||
|
jr = env.rpc ("submit", strHex (s.slice ())) [jss::result];
|
||||||
|
BEAST_EXPECT (jr.isMember (jss::engine_result) &&
|
||||||
|
jr[jss::engine_result] == "tesSUCCESS");
|
||||||
|
|
||||||
|
// submit_multisigned
|
||||||
|
env(signers(bob, 1, {{alice, 1}}), sig (bob));
|
||||||
|
Account const ali {"ali", KeyType::secp256k1};
|
||||||
|
env(regkey (alice, ali));
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
Json::Value set_tx;
|
||||||
|
set_tx[jss::Account] = bob.human();
|
||||||
|
set_tx[jss::TransactionType] = "AccountSet";
|
||||||
|
set_tx[jss::Fee] =
|
||||||
|
static_cast<uint32_t>(8 * env.current()->fees().base);
|
||||||
|
set_tx[jss::Sequence] = env.seq(bob);
|
||||||
|
set_tx[jss::SigningPubKey] = "";
|
||||||
|
|
||||||
|
Json::Value sign_for;
|
||||||
|
sign_for[jss::tx_json] = set_tx;
|
||||||
|
sign_for[jss::account] = alice.human();
|
||||||
|
sign_for[jss::secret] = ali.name();
|
||||||
|
jr = env.rpc("json", "sign_for", to_string(sign_for)) [jss::result];
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "success");
|
||||||
|
|
||||||
|
Json::Value ms_req;
|
||||||
|
ms_req[jss::tx_json] = jr[jss::tx_json];
|
||||||
|
jr = env.rpc("json", "submit_multisigned", to_string(ms_req))
|
||||||
|
[jss::result];
|
||||||
|
BEAST_EXPECT (jr.isMember (jss::engine_result) &&
|
||||||
|
jr[jss::engine_result] == "tesSUCCESS");
|
||||||
|
|
||||||
|
// make the network amendment blocked...now all the same
|
||||||
|
// requests should fail
|
||||||
|
|
||||||
|
env.app ().getOPs ().setAmendmentBlocked ();
|
||||||
|
|
||||||
|
// ledger_accept
|
||||||
|
jr = env.rpc ("ledger_accept") [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "error");
|
||||||
|
|
||||||
|
// ledger_current
|
||||||
|
jr = env.rpc ("ledger_current") [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "error");
|
||||||
|
|
||||||
|
// owner_info
|
||||||
|
jr = env.rpc ("owner_info", alice.human()) [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "error");
|
||||||
|
|
||||||
|
// path_find
|
||||||
|
jr = wsc->invoke("path_find", pf_req) [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "error");
|
||||||
|
|
||||||
|
// submit
|
||||||
|
jr = env.rpc("submit", strHex(s.slice())) [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "error");
|
||||||
|
|
||||||
|
// submit_multisigned
|
||||||
|
set_tx[jss::Sequence] = env.seq(bob);
|
||||||
|
sign_for[jss::tx_json] = set_tx;
|
||||||
|
jr = env.rpc("json", "sign_for", to_string(sign_for)) [jss::result];
|
||||||
|
BEAST_EXPECT(jr[jss::status] == "success");
|
||||||
|
ms_req[jss::tx_json] = jr[jss::tx_json];
|
||||||
|
jr = env.rpc("json", "submit_multisigned", to_string(ms_req))
|
||||||
|
[jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
jr.isMember (jss::error) &&
|
||||||
|
jr[jss::error] == "amendmentBlocked");
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
testBlockedMethods();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BEAST_DEFINE_TESTSUITE(AmendmentBlocked,app,ripple);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
#include <test/jtx/WSClient.h>
|
#include <test/jtx/WSClient.h>
|
||||||
#include <test/jtx/JSONRPCClient.h>
|
#include <test/jtx/JSONRPCClient.h>
|
||||||
#include <ripple/core/DeadlineTimer.h>
|
#include <ripple/core/DeadlineTimer.h>
|
||||||
|
#include <ripple/app/misc/NetworkOPs.h>
|
||||||
|
#include <ripple/app/ledger/LedgerMaster.h>
|
||||||
#include <beast/http.hpp>
|
#include <beast/http.hpp>
|
||||||
#include <beast/test/yield_to.hpp>
|
#include <beast/test/yield_to.hpp>
|
||||||
#include <beast/websocket/detail/mask.hpp>
|
#include <beast/websocket/detail/mask.hpp>
|
||||||
@@ -87,7 +89,7 @@ class ServerStatus_test :
|
|||||||
|
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.insert("Host", host + ":" + to_string(port));
|
req.insert("Host", host + ":" + std::to_string(port));
|
||||||
req.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
req.method(beast::http::verb::get);
|
req.method(beast::http::verb::get);
|
||||||
req.insert("Upgrade", "websocket");
|
req.insert("Upgrade", "websocket");
|
||||||
@@ -111,7 +113,7 @@ class ServerStatus_test :
|
|||||||
|
|
||||||
req.target("/");
|
req.target("/");
|
||||||
req.version = 11;
|
req.version = 11;
|
||||||
req.insert("Host", host + ":" + to_string(port));
|
req.insert("Host", host + ":" + std::to_string(port));
|
||||||
req.insert("User-Agent", "test");
|
req.insert("User-Agent", "test");
|
||||||
if(body.empty())
|
if(body.empty())
|
||||||
{
|
{
|
||||||
@@ -131,7 +133,7 @@ class ServerStatus_test :
|
|||||||
void
|
void
|
||||||
doRequest(
|
doRequest(
|
||||||
boost::asio::yield_context& yield,
|
boost::asio::yield_context& yield,
|
||||||
beast::http::request<beast::http::string_body>& req,
|
beast::http::request<beast::http::string_body>&& req,
|
||||||
std::string const& host,
|
std::string const& host,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
bool secure,
|
bool secure,
|
||||||
@@ -146,7 +148,7 @@ class ServerStatus_test :
|
|||||||
|
|
||||||
auto it =
|
auto it =
|
||||||
r.async_resolve(
|
r.async_resolve(
|
||||||
ip::tcp::resolver::query{host, to_string(port)}, yield[ec]);
|
ip::tcp::resolver::query{host, std::to_string(port)}, yield[ec]);
|
||||||
if(ec)
|
if(ec)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -197,9 +199,14 @@ class ServerStatus_test :
|
|||||||
get<std::uint16_t>("port");
|
get<std::uint16_t>("port");
|
||||||
auto ip = env.app().config()["port_ws"].
|
auto ip = env.app().config()["port_ws"].
|
||||||
get<std::string>("ip");
|
get<std::string>("ip");
|
||||||
auto req = makeWSUpgrade(*ip, *port);
|
|
||||||
doRequest(
|
doRequest(
|
||||||
yield, req, *ip, *port, secure, resp, ec);
|
yield,
|
||||||
|
makeWSUpgrade(*ip, *port),
|
||||||
|
*ip,
|
||||||
|
*port,
|
||||||
|
secure,
|
||||||
|
resp,
|
||||||
|
ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,10 +223,9 @@ class ServerStatus_test :
|
|||||||
get<std::uint16_t>("port");
|
get<std::uint16_t>("port");
|
||||||
auto const ip = env.app().config()["port_rpc"].
|
auto const ip = env.app().config()["port_rpc"].
|
||||||
get<std::string>("ip");
|
get<std::string>("ip");
|
||||||
auto req = makeHTTPRequest(*ip, *port, body);
|
|
||||||
doRequest(
|
doRequest(
|
||||||
yield,
|
yield,
|
||||||
req,
|
makeHTTPRequest(*ip, *port, body),
|
||||||
*ip,
|
*ip,
|
||||||
*port,
|
*port,
|
||||||
secure,
|
secure,
|
||||||
@@ -368,7 +374,7 @@ class ServerStatus_test :
|
|||||||
|
|
||||||
auto it =
|
auto it =
|
||||||
r.async_resolve(
|
r.async_resolve(
|
||||||
ip::tcp::resolver::query{*ip, to_string(*port)}, yield[ec]);
|
ip::tcp::resolver::query{*ip, std::to_string(*port)}, yield[ec]);
|
||||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -510,6 +516,110 @@ class ServerStatus_test :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testAmendmentBlock(boost::asio::yield_context& yield)
|
||||||
|
{
|
||||||
|
testcase("Status request over WS and RPC with/without Amendment Block");
|
||||||
|
using namespace jtx;
|
||||||
|
using namespace boost::asio;
|
||||||
|
using namespace beast::http;
|
||||||
|
Env env {*this, validator( envconfig([](std::unique_ptr<Config> cfg)
|
||||||
|
{
|
||||||
|
cfg->section("port_rpc").set("protocol", "http,https");
|
||||||
|
return cfg;
|
||||||
|
}), "")};
|
||||||
|
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
// advance the ledger so that server status
|
||||||
|
// sees a published ledger -- without this, we get a status
|
||||||
|
// failure message about no published ledgers
|
||||||
|
env.app().getLedgerMaster().tryAdvance();
|
||||||
|
|
||||||
|
// make an RPC server info request and look for
|
||||||
|
// amendment_blocked status
|
||||||
|
auto si = env.rpc("server_info") [jss::result];
|
||||||
|
BEAST_EXPECT(! si[jss::info].isMember(jss::amendment_blocked));
|
||||||
|
BEAST_EXPECT(
|
||||||
|
env.app().getOPs().getConsensusInfo()["validating"] == true);
|
||||||
|
|
||||||
|
auto const port_ws = env.app().config()["port_ws"].
|
||||||
|
get<std::uint16_t>("port");
|
||||||
|
auto const ip_ws = env.app().config()["port_ws"].
|
||||||
|
get<std::string>("ip");
|
||||||
|
|
||||||
|
|
||||||
|
boost::system::error_code ec;
|
||||||
|
response<string_body> resp;
|
||||||
|
|
||||||
|
doRequest(
|
||||||
|
yield,
|
||||||
|
makeHTTPRequest(*ip_ws, *port_ws, ""),
|
||||||
|
*ip_ws,
|
||||||
|
*port_ws,
|
||||||
|
false,
|
||||||
|
resp,
|
||||||
|
ec);
|
||||||
|
|
||||||
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
|
return;
|
||||||
|
BEAST_EXPECT(resp.result() == beast::http::status::ok);
|
||||||
|
BEAST_EXPECT(
|
||||||
|
resp.body.find("connectivity is working.") != std::string::npos);
|
||||||
|
|
||||||
|
// mark the Network as Amendment Blocked, but still won't fail until
|
||||||
|
// ELB is enabled (next step)
|
||||||
|
env.app().getOPs().setAmendmentBlocked ();
|
||||||
|
env.app().getOPs().beginConsensus(env.closed()->info().hash);
|
||||||
|
|
||||||
|
// consensus now sees validation disabled
|
||||||
|
BEAST_EXPECT(
|
||||||
|
env.app().getOPs().getConsensusInfo()["validating"] == false);
|
||||||
|
|
||||||
|
// RPC request server_info again, now AB should be returned
|
||||||
|
si = env.rpc("server_info") [jss::result];
|
||||||
|
BEAST_EXPECT(
|
||||||
|
si[jss::info].isMember(jss::amendment_blocked) &&
|
||||||
|
si[jss::info][jss::amendment_blocked] == true);
|
||||||
|
|
||||||
|
// but status does not indicate because it still relies on ELB
|
||||||
|
// being enabled
|
||||||
|
doRequest(
|
||||||
|
yield,
|
||||||
|
makeHTTPRequest(*ip_ws, *port_ws, ""),
|
||||||
|
*ip_ws,
|
||||||
|
*port_ws,
|
||||||
|
false,
|
||||||
|
resp,
|
||||||
|
ec);
|
||||||
|
|
||||||
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
|
return;
|
||||||
|
BEAST_EXPECT(resp.result() == beast::http::status::ok);
|
||||||
|
BEAST_EXPECT(
|
||||||
|
resp.body.find("connectivity is working.") != std::string::npos);
|
||||||
|
|
||||||
|
env.app().config().ELB_SUPPORT = true;
|
||||||
|
|
||||||
|
doRequest(
|
||||||
|
yield,
|
||||||
|
makeHTTPRequest(*ip_ws, *port_ws, ""),
|
||||||
|
*ip_ws,
|
||||||
|
*port_ws,
|
||||||
|
false,
|
||||||
|
resp,
|
||||||
|
ec);
|
||||||
|
|
||||||
|
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||||
|
return;
|
||||||
|
BEAST_EXPECT(resp.result() == beast::http::status::internal_server_error);
|
||||||
|
BEAST_EXPECT(
|
||||||
|
resp.body.find("cannot accept clients:") != std::string::npos);
|
||||||
|
BEAST_EXPECT(
|
||||||
|
resp.body.find("Server version too old") != std::string::npos);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
run()
|
run()
|
||||||
@@ -527,6 +637,7 @@ public:
|
|||||||
//THIS HANGS - testCantConnect("wss", "ws", yield);
|
//THIS HANGS - testCantConnect("wss", "ws", yield);
|
||||||
testCantConnect("wss2", "ws2", yield);
|
testCantConnect("wss2", "ws2", yield);
|
||||||
testCantConnect("https", "http", yield);
|
testCantConnect("https", "http", yield);
|
||||||
|
testAmendmentBlock(yield);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto it : {"http", "ws", "ws2"})
|
for (auto it : {"http", "ws", "ws2"})
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <test/rpc/AccountObjects_test.cpp>
|
#include <test/rpc/AccountObjects_test.cpp>
|
||||||
#include <test/rpc/AccountOffers_test.cpp>
|
#include <test/rpc/AccountOffers_test.cpp>
|
||||||
#include <test/rpc/AccountSet_test.cpp>
|
#include <test/rpc/AccountSet_test.cpp>
|
||||||
|
#include <test/rpc/AmendmentBlocked_test.cpp>
|
||||||
#include <test/rpc/Book_test.cpp>
|
#include <test/rpc/Book_test.cpp>
|
||||||
#include <test/rpc/Feature_test.cpp>
|
#include <test/rpc/Feature_test.cpp>
|
||||||
#include <test/rpc/GatewayBalances_test.cpp>
|
#include <test/rpc/GatewayBalances_test.cpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user