20#include <test/jtx/Env.h>
21#include <xrpld/overlay/detail/OverlayImpl.h>
22#include <xrpld/overlay/detail/PeerImp.h>
23#include <xrpld/peerfinder/detail/SlotImp.h>
24#include <xrpl/basics/make_SSLContext.h>
25#include <xrpl/beast/unit_test.h>
51 auto test = [&](
bool enable,
57 str <<
"[reduce_relay]\n"
58 <<
"tx_enable=" <<
static_cast<int>(enable) <<
"\n"
59 <<
"tx_metrics=" <<
static_cast<int>(metrics) <<
"\n"
60 <<
"tx_min_peers=" << min <<
"\n"
61 <<
"tx_relay_percentage=" << pct <<
"\n";
85 test(
true,
true, 20, 25);
86 test(
false,
false, 20, 25);
87 test(
false,
false, 20, 0,
false);
88 test(
false,
false, 20, 101,
false);
89 test(
false,
false, 9, 10,
false);
90 test(
false,
false, 10, 9,
false);
114 std::move(stream_ptr),
167 boost::beast::http::request<boost::beast::http::dynamic_body> request;
169 ? (
void)request.insert(
173 auto stream_ptr = std::make_unique<stream_type>(
174 socket_type(std::forward<boost::asio::io_service&>(
182 auto consumer = overlay.resourceManager().newInboundEndpoint(remote);
183 auto slot = overlay.peerFinder().new_inbound_slot(local, remote);
184 auto const peer = std::make_shared<PeerTest>(
191 std::move(stream_ptr),
195 overlay.add_active(peer);
196 BEAST_EXPECT(overlay.findPeerByPublicKey(key) == peer);
197 peers.emplace_back(peer);
218 env.app().config().TX_REDUCE_RELAY_ENABLE = txRREnabled;
219 env.app().config().TX_REDUCE_RELAY_MIN_PEERS = minPeers;
220 env.app().config().TX_RELAY_PERCENTAGE = relayPercentage;
224 for (
int i = 0; i < nPeers; i++)
225 addPeer(env, peers, nDisabled);
227 auto const jtx = env.jt(
noop(env.master));
228 if (BEAST_EXPECT(jtx.stx))
230 protocol::TMTransaction m;
233 m.set_rawtransaction(s.
data(), s.
size());
234 m.set_deferred(
false);
235 m.set_status(protocol::TransactionStatus::tsNEW);
236 env.app().overlay().relay(
uint256{0}, m, toSkip);
250 testRelay(
"feature disabled",
false, 10, 0, 10, 25, 10, 0);
252 testRelay(
"feature disabled & skip",
false, 10, 0, 10, 25, 5, 0, skip);
254 testRelay(
"relay all 1",
true, 10, 0, 20, 25, 10, 0);
256 testRelay(
"relay all 2",
true, 20, 15, 10, 25, 20, 0);
259 testRelay(
"relay & queue",
true, 60, 0, 20, 25, 30, 30);
263 testRelay(
"skip",
true, 60, 0, 20, 25, 25, 30, skip);
266 testRelay(
"disabled",
true, 70, 10, 20, 25, 40, 30);
270 testRelay(
"disabled & skip",
true, 70, 10, 20, 25, 35, 30, skip);
274 skip = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
275 testRelay(
"disabled & skip, no queue",
true, 15, 5, 10, 25, 5, 0, skip);
279 skip = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
280 testRelay(
"disabled & skip, no relay",
true, 20, 2, 10, 25, 0, 6, skip);
284BEAST_DEFINE_TESTSUITE(tx_reduce_relay, ripple_data,
ripple);
A version-independent IP address and port combination.
log_os< char > log
Logging output stream.
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
virtual Overlay & overlay()=0
virtual boost::asio::io_service & getIOService()=0
std::size_t TX_REDUCE_RELAY_MIN_PEERS
bool TX_REDUCE_RELAY_ENABLE
bool TX_REDUCE_RELAY_METRICS
std::size_t TX_RELAY_PERCENTAGE
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
std::shared_ptr< PeerFinder::Slot > const & slot()
An endpoint that consumes resources.
std::size_t size() const noexcept
void const * data() const noexcept
A transaction testing environment.
static std::uint16_t sendTx_
void send(std::shared_ptr< Message > const &) override
static std::uint16_t queueTx_
void addTxQueue(const uint256 &hash) override
Aggregate transaction's hash.
PeerTest(Application &app, std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type &&request, PublicKey const &publicKey, ProtocolVersion protocol, Resource::Consumer consumer, std::unique_ptr< tx_reduce_relay_test::stream_type > &&stream_ptr, OverlayImpl &overlay)
void testRelay(std::string const &test, bool txRREnabled, std::uint16_t nPeers, std::uint16_t nDisabled, std::uint16_t minPeers, std::uint16_t relayPercentage, std::uint16_t expectRelay, std::uint16_t expectQueue, std::set< Peer::id_t > const &toSkip={})
void doTest(const std::string &msg, bool log, std::function< void(bool)> f)
ProtocolVersion protocolVersion_
void testConfig(bool log)
void addPeer(jtx::Env &env, std::vector< std::shared_ptr< PeerTest > > &peers, std::uint16_t &nDisabled)
boost::beast::tcp_stream middle_type
boost::beast::ssl_stream< middle_type > stream_type
void run() override
Runs the suite.
boost::beast::multi_buffer read_buf_
boost::asio::ip::tcp::socket socket_type
Json::Value noop(Account const &account)
The null transaction.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string makeFeaturesRequestHeader(bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled)
Make request header X-Protocol-Ctl value with supported features.
std::shared_ptr< boost::asio::ssl::context > make_SSLContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.