21#include <test/jtx/Env.h>
23#include <xrpld/overlay/detail/OverlayImpl.h>
24#include <xrpld/overlay/detail/PeerImp.h>
25#include <xrpld/peerfinder/detail/SlotImp.h>
27#include <xrpl/basics/make_SSLContext.h>
28#include <xrpl/beast/unit_test.h>
54 auto test = [&](
bool enable,
60 str <<
"[reduce_relay]\n"
61 <<
"tx_enable=" <<
static_cast<int>(enable) <<
"\n"
62 <<
"tx_metrics=" <<
static_cast<int>(metrics) <<
"\n"
63 <<
"tx_min_peers=" << min <<
"\n"
64 <<
"tx_relay_percentage=" << pct <<
"\n";
88 test(
true,
true, 20, 25);
89 test(
false,
false, 20, 25);
90 test(
false,
false, 20, 0,
false);
91 test(
false,
false, 20, 101,
false);
92 test(
false,
false, 9, 10,
false);
93 test(
false,
false, 10, 9,
false);
117 std::move(stream_ptr),
170 boost::beast::http::request<boost::beast::http::dynamic_body> request;
172 ? (
void)request.insert(
176 auto stream_ptr = std::make_unique<stream_type>(
177 socket_type(std::forward<boost::asio::io_service&>(
185 auto consumer = overlay.resourceManager().newInboundEndpoint(remote);
186 auto slot = overlay.peerFinder().new_inbound_slot(local, remote);
187 auto const peer = std::make_shared<PeerTest>(
194 std::move(stream_ptr),
198 overlay.add_active(peer);
199 BEAST_EXPECT(overlay.findPeerByPublicKey(key) == peer);
200 peers.emplace_back(peer);
221 env.app().config().TX_REDUCE_RELAY_ENABLE = txRREnabled;
222 env.app().config().TX_REDUCE_RELAY_MIN_PEERS = minPeers;
223 env.app().config().TX_RELAY_PERCENTAGE = relayPercentage;
227 for (
int i = 0; i < nPeers; i++)
228 addPeer(env, peers, nDisabled);
230 auto const jtx = env.jt(
noop(env.master));
231 if (BEAST_EXPECT(jtx.stx))
233 protocol::TMTransaction m;
236 m.set_rawtransaction(s.
data(), s.
size());
237 m.set_deferred(
false);
238 m.set_status(protocol::TransactionStatus::tsNEW);
239 env.app().overlay().relay(
uint256{0}, m, toSkip);
253 testRelay(
"feature disabled",
false, 10, 0, 10, 25, 10, 0);
255 testRelay(
"feature disabled & skip",
false, 10, 0, 10, 25, 5, 0, skip);
257 testRelay(
"relay all 1",
true, 10, 0, 20, 25, 10, 0);
259 testRelay(
"relay all 2",
true, 20, 15, 10, 25, 20, 0);
262 testRelay(
"relay & queue",
true, 60, 0, 20, 25, 30, 30);
266 testRelay(
"skip",
true, 60, 0, 20, 25, 25, 30, skip);
269 testRelay(
"disabled",
true, 70, 10, 20, 25, 40, 30);
273 testRelay(
"disabled & skip",
true, 70, 10, 20, 25, 35, 30, skip);
277 skip = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
278 testRelay(
"disabled & skip, no queue",
true, 15, 5, 10, 25, 5, 0, skip);
282 skip = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
283 testRelay(
"disabled & skip, no relay",
true, 20, 2, 10, 25, 0, 6, skip);
287BEAST_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(uint256 const &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={})
ProtocolVersion protocolVersion_
void testConfig(bool log)
void addPeer(jtx::Env &env, std::vector< std::shared_ptr< PeerTest > > &peers, std::uint16_t &nDisabled)
void doTest(std::string const &msg, bool log, std::function< void(bool)> f)
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
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.