@@ -34,6 +34,8 @@ using namespace stellar::txtest;
3434namespace
3535{
3636int const NUM_ACCOUNTS = 40 ;
37+ // Config::TX_FLOOD_TARGET_LEADERS's default.
38+ uint32_t const TARGET_LEADERS = 2 ;
3739
3840Config
3941acceleratedConfig (int configNum)
@@ -108,8 +110,7 @@ expectedTargets(Application::pointer const& app)
108110 std::max<uint32_t >(1 , herder.getSCP ().getLeaderRound (slot));
109111 auto & driver = herder.getHerderSCPDriver ();
110112 std::vector<NodeID> res;
111- for (uint32_t r = round; r < round + HerderImpl::TX_FLOOD_TARGET_ROUNDS ;
112- ++r)
113+ for (uint32_t r = round; r < round + TARGET_LEADERS ; ++r)
113114 {
114115 auto leader = driver.getRoundLeader (slot, r);
115116 REQUIRE (leader);
@@ -188,7 +189,7 @@ TEST_CASE("transactions go to the round leaders only",
188189 auto targets = herderOf (app).computeTxFloodTargets ();
189190 REQUIRE (targets);
190191 REQUIRE (*targets == expectedTargets (app));
191- REQUIRE (targets->size () == HerderImpl:: TX_FLOOD_TARGET_ROUNDS );
192+ REQUIRE (targets->size () == TARGET_LEADERS );
192193 }
193194
194195 // Submit payments at every node over several ledgers, each from its own
@@ -255,12 +256,96 @@ TEST_CASE("transactions go to the round leaders only",
255256 REQUIRE (after.mDirectRecv > 0 );
256257 REQUIRE (after.mDirectSent <=
257258 static_cast <int64_t >(submitted) *
258- HerderImpl:: TX_FLOOD_TARGET_ROUNDS * (ledgers + 1 ));
259+ TARGET_LEADERS * (ledgers + 1 ));
259260 // Far fewer than a flood, which delivers every transaction to the three
260261 // other nodes.
261262 REQUIRE (after.mDirectSent < 3 * static_cast <int64_t >(submitted) * 2 );
262263}
263264
265+ TEST_CASE (" transactions go to every validator when no leader count is set" ,
266+ " [herder][tx-flood-targets][simulation]" )
267+ {
268+ // TX_FLOOD_TARGET_LEADERS = 0: every validator is a target. Still no
269+ // adverts and no demands, and every transaction goes to each of the
270+ // three other nodes exactly once.
271+ auto simulation = Topologies::core (
272+ 4 , 0.75 , sha256 (getTestConfig ().NETWORK_PASSPHRASE ), [](int i) {
273+ auto cfg = acceleratedConfig (i);
274+ cfg.TX_FLOOD_TARGET_LEADERS = 0 ;
275+ return cfg;
276+ });
277+ simulation->startAllNodes ();
278+ auto nodes = simulation->getNodes ();
279+ simulation->crankUntil (
280+ [&]() {
281+ if (!allClosed (nodes, 4 ))
282+ {
283+ return false ;
284+ }
285+ for (auto const & app : nodes)
286+ {
287+ if (identifiedPeers (app) != 3 ||
288+ !herderOf (app).getTxFloodTargetsForTesting ())
289+ {
290+ return false ;
291+ }
292+ }
293+ return true ;
294+ },
295+ std::chrono::seconds (120 ), false );
296+ for (auto const & app : nodes)
297+ {
298+ auto targets = herderOf (app).computeTxFloodTargets ();
299+ REQUIRE (targets);
300+ REQUIRE (targets->size () == 4 );
301+ REQUIRE (std::is_sorted (targets->begin (), targets->end ()));
302+ // The same list whatever the slot, so it was sent once.
303+ REQUIRE (herderOf (app).mTxFloodTargetHistoryForTesting .size () == 1 );
304+ }
305+
306+ auto const appliedBefore = appliedTxs (nodes[0 ]);
307+ int submitted = 0 ;
308+ for (int batch = 0 ; batch < 5 ; ++batch)
309+ {
310+ for (size_t n = 0 ; n < nodes.size (); ++n)
311+ {
312+ auto source = getGenesisAccount (*nodes[n], submitted);
313+ auto dest = getGenesisAccount (*nodes[n], NUM_ACCOUNTS - 1 );
314+ auto tx = source.tx ({payment (dest.getPublicKey (), 1000 )});
315+ REQUIRE (nodes[n]->getHerder ().recvTransaction (tx, false ) ==
316+ TxSubmitStatus::TX_STATUS_PENDING );
317+ ++submitted;
318+ }
319+ auto const next =
320+ nodes[0 ]->getLedgerManager ().getLastClosedLedgerNum () + 1 ;
321+ simulation->crankUntil ([&]() { return allClosed (nodes, next); },
322+ std::chrono::seconds (60 ), false );
323+ }
324+ simulation->crankUntil (
325+ [&]() {
326+ for (auto const & app : nodes)
327+ {
328+ if (appliedTxs (app) - appliedBefore < submitted)
329+ {
330+ return false ;
331+ }
332+ }
333+ return true ;
334+ },
335+ std::chrono::seconds (120 ), false );
336+ auto const counts = countTxFlood (nodes);
337+ INFO (counts.toString ());
338+ REQUIRE (counts.mAdvertised == 0 );
339+ REQUIRE (counts.mDemanded == 0 );
340+ REQUIRE (counts.mLocalFlooded == 0 );
341+ REQUIRE (counts.mDirectSent == 3 * static_cast <int64_t >(submitted));
342+ REQUIRE (counts.mDirectRecv == counts.mDirectSent );
343+ for (auto const & app : nodes)
344+ {
345+ REQUIRE (appliedTxs (app) - appliedBefore == submitted);
346+ }
347+ }
348+
264349TEST_CASE (" transactions are included while a leader is down" ,
265350 " [herder][tx-flood-targets][simulation]" )
266351{
0 commit comments