xrpld
Loading...
Searching...
No Matches
TxQ_test.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/Env_ss.h>
4#include <test/jtx/TestHelpers.h>
5#include <test/jtx/WSClient.h>
6#include <test/jtx/amount.h>
7#include <test/jtx/balance.h>
8#include <test/jtx/delegate.h>
9#include <test/jtx/envconfig.h>
10#include <test/jtx/fee.h>
11#include <test/jtx/flags.h>
12#include <test/jtx/jtx_json.h>
13#include <test/jtx/last_ledger_sequence.h>
14#include <test/jtx/multisign.h>
15#include <test/jtx/noop.h>
16#include <test/jtx/offer.h>
17#include <test/jtx/owners.h>
18#include <test/jtx/pay.h>
19#include <test/jtx/regkey.h>
20#include <test/jtx/require.h>
21#include <test/jtx/sendmax.h>
22#include <test/jtx/seq.h>
23#include <test/jtx/sig.h>
24#include <test/jtx/sponsor.h>
25#include <test/jtx/tags.h>
26#include <test/jtx/ter.h>
27#include <test/jtx/ticket.h>
28#include <test/jtx/trust.h>
29
30#include <xrpld/app/main/Application.h>
31#include <xrpld/app/misc/TxQ.h>
32
33#include <xrpl/beast/unit_test/suite.h>
34#include <xrpl/beast/utility/Journal.h>
35#include <xrpl/config/Constants.h>
36#include <xrpl/json/json_value.h>
37#include <xrpl/json/to_string.h>
38#include <xrpl/ledger/ApplyView.h>
39#include <xrpl/ledger/View.h>
40#include <xrpl/protocol/AccountID.h>
41#include <xrpl/protocol/ErrorCodes.h>
42#include <xrpl/protocol/Feature.h>
43#include <xrpl/protocol/SField.h>
44#include <xrpl/protocol/TER.h>
45#include <xrpl/protocol/TxFlags.h>
46#include <xrpl/protocol/Units.h>
47#include <xrpl/protocol/jss.h>
48#include <xrpl/server/LoadFeeTrack.h>
49#include <xrpl/tx/apply.h>
50#include <xrpl/tx/applySteps.h>
51
52#include <algorithm>
53#include <chrono>
54#include <cstddef>
55#include <cstdint>
56#include <map>
57#include <optional>
58#include <stdexcept>
59#include <string>
60#include <utility>
61
62namespace xrpl::test {
63
65{
68
69 static void
70 fillQueue(jtx::Env& env, jtx::Account const& account)
71 {
72 auto const metrics = env.app().getTxQ().getMetrics(*env.current());
73 for (int i = metrics.txInLedger; i <= metrics.txPerLedger; ++i)
74 env(noop(account));
75 }
76
77 static auto
79 {
80 using namespace jtx;
81
82 auto const& view = *env.current();
83 auto const base = [&view] {
84 auto base = view.fees().base;
85 if (!base)
86 base += 1;
87 return base;
88 }();
89
90 // Don't care about the overflow flag
91 auto const& metrics = env.app().getTxQ().getMetrics(view);
92 return toDrops(metrics.openLedgerFeeLevel, base) + 1;
93 }
94
95 // Get a fee level of a transaction made by an account
96 // This fee level is used to ensure we can place transaction into TxQ
97 static auto
99 {
100 using namespace jtx;
101
102 auto const& txq = env.app().getTxQ();
103 auto const& txs = txq.getAccountTxs(account.id());
104
105 return txs.begin()->feeLevel.fee();
106 }
107
108 // Calculating expected median fee level based on known fee levels of median
109 // transaction levels.
110 static auto
111 calcMedFeeLevel(FeeLevel64 const feeLevel1, FeeLevel64 const feeLevel2)
112 {
113 FeeLevel64 const expectedMedFeeLevel = (feeLevel1 + feeLevel2 + FeeLevel64{1}) / 2;
114
115 return std::max(expectedMedFeeLevel, kMinEscalationFeeLevel).fee();
116 }
117
118 static auto
120 {
121 return calcMedFeeLevel(feeLevel, feeLevel);
122 }
123
126 jtx::Env& env,
127 std::size_t expectedPerLedger,
128 std::size_t ledgersInQueue,
129 std::uint32_t base,
131 std::uint32_t increment)
132 {
133 // Run past the flag ledger so that a Fee change vote occurs and
134 // lowers the reserve fee. (It also activates all supported
135 // amendments.) This will allow creating accounts with lower
136 // reserves and balances.
137 for (auto i = env.current()->seq(); i <= 257; ++i)
138 env.close();
139 // The ledger after the flag ledger creates all the
140 // fee (1) and amendment (numUpVotedAmendments())
141 // pseudotransactions. The queue treats the fees on these
142 // transactions as though they are ordinary transactions.
143 auto const flagPerLedger = 1 + xrpl::detail::numUpVotedAmendments();
144 auto const flagMaxQueue = ledgersInQueue * flagPerLedger;
145 checkMetrics(*this, env, 0, flagMaxQueue, 0, flagPerLedger);
146
147 // Pad a couple of txs with normal fees so the median comes
148 // back down to normal
149 env(noop(env.master));
150 env(noop(env.master));
151
152 // Close the ledger with a delay, which causes all the TxQ
153 // metrics to reset to defaults, EXCEPT the maxQueue size.
154 using namespace std::chrono_literals;
155 env.close(env.now() + 5s, 10000ms);
156 checkMetrics(*this, env, 0, flagMaxQueue, 0, expectedPerLedger);
157 auto const fees = env.current()->fees();
158 BEAST_EXPECT(fees.base == XRPAmount{base});
159 BEAST_EXPECT(fees.reserve == XRPAmount{reserve});
160 BEAST_EXPECT(fees.increment == XRPAmount{increment});
161
162 return flagMaxQueue;
163 }
164
165public:
166 void
168 {
169 using namespace jtx;
170 using namespace std::chrono;
171 testcase("queue sequence");
172
174
175 auto const alice = Account("alice");
176 auto const bob = Account("bob");
177 auto const charlie = Account("charlie");
178 auto const daria = Account("daria");
179 auto const elmo = Account("elmo");
180 auto const fred = Account("fred");
181 auto const gwen = Account("gwen");
182 auto const hank = Account("hank");
183 auto const iris = Account("iris");
184
185 auto const queued = Ter(terQUEUED);
186 auto const baseFee = env.current()->fees().base.drops();
187
188 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
189
190 // Create several accounts while the fee is cheap so they all apply.
191 env.fund(XRP(50000), noripple(alice, bob, charlie, daria));
192 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
193
194 // Alice - price starts exploding: held
195 env(noop(alice), queued);
196 checkMetrics(*this, env, 1, std::nullopt, 4, 3);
197
198 // Bob with really high fee - applies
199 env(noop(bob), Fee(openLedgerCost(env)));
200 checkMetrics(*this, env, 1, std::nullopt, 5, 3);
201
202 // Daria with low fee: hold
203 env(noop(daria), Fee(baseFee * 100), queued);
204 checkMetrics(*this, env, 2, std::nullopt, 5, 3);
205
206 env.close();
207 // Verify that the held transactions got applied
208 checkMetrics(*this, env, 0, 10, 2, 5);
209
211
212 // Make some more accounts. We'll need them later to abuse the queue.
213 env.fund(XRP(50000), noripple(elmo, fred, gwen, hank));
214 checkMetrics(*this, env, 0, 10, 6, 5);
215
216 // Now get a bunch of transactions held.
217 env(noop(alice), Fee(baseFee * 1.2), queued);
218 checkMetrics(*this, env, 1, 10, 6, 5);
219
220 env(noop(bob), Fee(baseFee), queued); // won't clear the queue
221 env(noop(charlie), Fee(baseFee * 2), queued);
222 env(noop(daria), Fee(baseFee * 1.5), queued);
223 env(noop(elmo), Fee(baseFee * 1.1), queued);
224 env(noop(fred), Fee(baseFee * 1.9), queued);
225 env(noop(gwen), Fee(baseFee * 1.6), queued);
226 env(noop(hank), Fee(baseFee * 1.8), queued);
227 checkMetrics(*this, env, 8, 10, 6, 5);
228
229 env.close();
230 // Verify that the held transactions got applied
231 checkMetrics(*this, env, 1, 12, 7, 6);
232
233 // Bob's transaction is still stuck in the queue.
234
236
237 // Hank sends another txn
238 env(noop(hank), Fee(baseFee), queued);
239 // But he's not going to leave it in the queue
240 checkMetrics(*this, env, 2, 12, 7, 6);
241
242 // Hank sees his txn got held and bumps the fee,
243 // but doesn't even bump it enough to requeue
244 env(noop(hank), Fee(baseFee * 1.1), Ter(telCAN_NOT_QUEUE_FEE));
245 checkMetrics(*this, env, 2, 12, 7, 6);
246
247 // Hank sees his txn got held and bumps the fee,
248 // enough to requeue, but doesn't bump it enough to
249 // apply to the ledger
250 env(noop(hank), Fee(baseFee * 600), queued);
251 // But he's not going to leave it in the queue
252 checkMetrics(*this, env, 2, 12, 7, 6);
253
254 // Hank sees his txn got held and bumps the fee,
255 // high enough to get into the open ledger, because
256 // he doesn't want to wait.
257 env(noop(hank), Fee(openLedgerCost(env)));
258 checkMetrics(*this, env, 1, 12, 8, 6);
259
260 // Hank then sends another, less important txn
261 // (In addition to the metrics, this will verify that
262 // the original txn got removed.)
263 env(noop(hank), Fee(baseFee * 2), queued);
264 checkMetrics(*this, env, 2, 12, 8, 6);
265
266 env.close();
267
268 // Verify that bob and hank's txns were applied
269 checkMetrics(*this, env, 0, 16, 2, 8);
270
271 // Close again with a simulated time leap to
272 // reset the escalation limit down to minimum
273 env.close(env.now() + 5s, 10000ms);
274 checkMetrics(*this, env, 0, 16, 0, 3);
275 // Then close once more without the time leap
276 // to reset the queue maxsize down to minimum
277 env.close();
278 checkMetrics(*this, env, 0, 6, 0, 3);
279
281
282 static constexpr auto kLargeFeeMultiplier = 700;
283 auto const largeFee = baseFee * kLargeFeeMultiplier;
284
285 // Stuff the ledger and queue so we can verify that
286 // stuff gets kicked out.
287 env(noop(hank), Fee(largeFee));
288 env(noop(gwen), Fee(largeFee));
289 env(noop(fred), Fee(largeFee));
290 env(noop(elmo), Fee(largeFee));
291 checkMetrics(*this, env, 0, 6, 4, 3);
292
293 // Use explicit fees so we can control which txn
294 // will get dropped
295 // This one gets into the queue, but gets dropped when the
296 // higher fee one is added later.
297 env(noop(daria), Fee(baseFee * 1.5), queued);
298 // These stay in the queue.
299 env(noop(elmo), Fee(baseFee * 1.6), queued);
300 env(noop(fred), Fee(baseFee * 1.7), queued);
301 env(noop(gwen), Fee(baseFee * 1.8), queued);
302 env(noop(hank), Fee(baseFee * 1.9), queued);
303 env(noop(alice), Fee(baseFee * 2.0), queued);
304
305 // Queue is full now.
306 checkMetrics(*this, env, 6, 6, 4, 3, txFeeLevelByAccount(env, daria) + 1);
307 // Try to add another transaction with the default (low) fee,
308 // it should fail because the queue is full.
309 env(noop(charlie), Ter(telCAN_NOT_QUEUE_FULL));
310
311 // Add another transaction, with a higher fee,
312 // Not high enough to get into the ledger, but high
313 // enough to get into the queue (and kick somebody out)
314 env(noop(charlie), Fee(baseFee * 10), queued);
315
316 // Queue is still full, of course, but the min fee has gone up
317 checkMetrics(*this, env, 6, 6, 4, 3, txFeeLevelByAccount(env, elmo) + 1);
318
319 // Close out the ledger, the transactions are accepted, the
320 // queue is cleared, then the localTxs are retried. At this
321 // point, daria's transaction that was dropped from the queue
322 // is put back in. Neat.
323 env.close();
324 // clang-format off
325 checkMetrics(*this, env, 2, 8, 5, 4, kBaseFeeLevel.fee(), calcMedFeeLevel(FeeLevel64{kBaseFeeLevel.fee() * kLargeFeeMultiplier}));
326 // clang-format on
327
328 env.close();
329 checkMetrics(*this, env, 0, 10, 2, 5);
330
332
333 // Attempt to put a transaction in the queue for an account
334 // that is not yet funded.
335 env.memoize(iris);
336
337 env(noop(alice));
338 env(noop(bob));
339 env(noop(charlie));
340 env(noop(daria));
341 env(pay(alice, iris, XRP(1000)), queued);
342 env(noop(iris), Seq(1), Fee(baseFee * 2), Ter(terNO_ACCOUNT));
343 checkMetrics(*this, env, 1, 10, 6, 5);
344
345 env.close();
346 checkMetrics(*this, env, 0, 12, 1, 6);
347
348 env.require(Balance(iris, XRP(1000)));
349 BEAST_EXPECT(env.seq(iris) == 11);
350
352 // Cleanup:
353
354 // Create a few more transactions, so that
355 // we can be sure that there's one in the queue when the
356 // test ends and the TxQ is destructed.
357
358 auto metrics = env.app().getTxQ().getMetrics(*env.current());
359 BEAST_EXPECT(metrics.txCount == 0);
360
361 // Stuff the ledger.
362 for (int i = metrics.txInLedger; i <= metrics.txPerLedger; ++i)
363 {
364 env(noop(env.master));
365 }
366
367 // Queue one straightforward transaction
368 env(noop(env.master), Fee(baseFee * 2), queued);
369 ++metrics.txCount;
370
372 *this,
373 env,
374 metrics.txCount,
375 metrics.txQMaxSize,
376 metrics.txPerLedger + 1,
377 metrics.txPerLedger);
378 }
379
380 void
382 {
383 using namespace jtx;
384 testcase("queue ticket");
385
387
388 auto const alice = Account("alice");
389
390 auto const queued = Ter(terQUEUED);
391 auto const baseFee = env.current()->fees().base.drops();
392
393 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
394
395 // Fund alice and then fill the ledger.
396 env.fund(XRP(50000), noripple(alice));
397 env(noop(alice));
398 env(noop(alice));
399 env(noop(alice));
400 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
401
403
404 // Alice requests tickets, but that transaction is queued. So
405 // Alice can't queue ticketed transactions yet.
406 std::uint32_t const tkt1{env.seq(alice) + 1};
407 env(ticket::create(alice, 250), Seq(tkt1 - 1), queued);
408
409 env(noop(alice), ticket::Use(tkt1 - 2), Ter(tefNO_TICKET));
410 env(noop(alice), ticket::Use(tkt1 - 1), Ter(terPRE_TICKET));
411 env.require(Owners(alice, 0), Tickets(alice, 0));
412 checkMetrics(*this, env, 1, std::nullopt, 4, 3);
413
414 env.close();
415 env.require(Owners(alice, 250), Tickets(alice, 250));
416 checkMetrics(*this, env, 0, 8, 1, 4);
417 BEAST_EXPECT(env.seq(alice) == tkt1 + 250);
418
420
421 // Unlike queued sequence-based transactions, ticket-based
422 // transactions _do_ move out of the queue largest fee first,
423 // even within one account, since they can be applied in any order.
424 // Demonstrate that.
425
426 // Fill the ledger so we can start queuing things.
427 env(noop(alice), ticket::Use(tkt1 + 1), Fee(baseFee * 1.1));
428 env(noop(alice), ticket::Use(tkt1 + 2), Fee(baseFee * 1.2));
429 env(noop(alice), ticket::Use(tkt1 + 3), Fee(baseFee * 1.3));
430 env(noop(alice), ticket::Use(tkt1 + 4), Fee(baseFee * 1.4));
431 env(noop(alice), ticket::Use(tkt1 + 5), Fee(baseFee * 1.5), queued);
432 auto const expectedMinFeeLevel = txFeeLevelByAccount(env, alice) + 1;
433 env(noop(alice), ticket::Use(tkt1 + 6), Fee(baseFee * 1.6), queued);
434 env(noop(alice), ticket::Use(tkt1 + 7), Fee(baseFee * 1.7), queued);
435 env(noop(alice), ticket::Use(tkt1 + 8), Fee(baseFee * 1.8), queued);
436 env(noop(alice), ticket::Use(tkt1 + 9), Fee(baseFee * 1.9), queued);
437 env(noop(alice), ticket::Use(tkt1 + 10), Fee(baseFee * 2.0), queued);
438 env(noop(alice), ticket::Use(tkt1 + 11), Fee(baseFee * 2.1), queued);
439 env(noop(alice), ticket::Use(tkt1 + 12), Fee(baseFee * 2.2), queued);
440 env(noop(alice), ticket::Use(tkt1 + 13), Fee(baseFee * 2.3), Ter(telCAN_NOT_QUEUE_FULL));
441 checkMetrics(*this, env, 8, 8, 5, 4, expectedMinFeeLevel);
442
443 // Check which of the queued transactions got into the ledger by
444 // attempting to replace them.
445 // o Get tefNO_TICKET if the ticket has already been used.
446 // o Get telCAN_NOT_QUEUE_FEE if the transaction is still in the queue.
447 env.close();
448 env.require(Owners(alice, 240), Tickets(alice, 240));
449
450 // These 4 went straight to the ledger:
451 env(noop(alice), ticket::Use(tkt1 + 1), Ter(tefNO_TICKET));
452 env(noop(alice), ticket::Use(tkt1 + 2), Ter(tefNO_TICKET));
453 env(noop(alice), ticket::Use(tkt1 + 3), Ter(tefNO_TICKET));
454 env(noop(alice), ticket::Use(tkt1 + 4), Ter(tefNO_TICKET));
455
456 // These two are still in the TxQ:
457 env(noop(alice), ticket::Use(tkt1 + 5), Ter(telCAN_NOT_QUEUE_FEE));
458 env(noop(alice), ticket::Use(tkt1 + 6), Ter(telCAN_NOT_QUEUE_FEE));
459
460 // These six were moved from the queue into the open ledger
461 // since those with the highest fees go first.
462 env(noop(alice), ticket::Use(tkt1 + 7), Ter(tefNO_TICKET));
463 env(noop(alice), ticket::Use(tkt1 + 8), Ter(tefNO_TICKET));
464 env(noop(alice), ticket::Use(tkt1 + 9), Ter(tefNO_TICKET));
465 env(noop(alice), ticket::Use(tkt1 + 10), Ter(tefNO_TICKET));
466 env(noop(alice), ticket::Use(tkt1 + 11), Ter(tefNO_TICKET));
467 env(noop(alice), ticket::Use(tkt1 + 12), Ter(tefNO_TICKET));
468
469 // This last one was moved from the local transactions into
470 // the queue.
471 env(noop(alice), ticket::Use(tkt1 + 13), Ter(telCAN_NOT_QUEUE_FEE));
472
473 checkMetrics(*this, env, 3, 10, 6, 5);
474
476
477 // Do some experiments with putting sequence-based transactions
478 // into the queue while there are ticket-based transactions
479 // already in the queue.
480
481 // Alice still has three ticket-based transactions in the queue.
482 // The fee is escalated so unless we pay a sufficient fee
483 // transactions will go straight to the queue.
484 std::uint32_t const nextSeq{env.seq(alice)};
485 env(noop(alice), Seq(nextSeq + 1), Ter(terPRE_SEQ));
486 env(noop(alice), Seq(nextSeq - 1), Ter(tefPAST_SEQ));
487 env(noop(alice), Seq(nextSeq + 0), queued);
488
489 // Now that nextSeq is in the queue, we should be able to queue
490 // nextSeq + 1.
491 env(noop(alice), Seq(nextSeq + 1), queued);
492
493 // Fill the queue with sequence-based transactions. When the
494 // ledger closes we should find the three ticket-based
495 // transactions gone from the queue (because they had the
496 // highest fee). Then the earliest of the sequence-based
497 // transactions should also be gone from the queue.
498 env(noop(alice), Seq(nextSeq + 2), queued);
499 env(noop(alice), Seq(nextSeq + 3), queued);
500 env(noop(alice), Seq(nextSeq + 4), queued);
501 env(noop(alice), Seq(nextSeq + 5), queued);
502 env(noop(alice), Seq(nextSeq + 6), queued);
503 env(noop(alice), Seq(nextSeq + 7), Ter(telCAN_NOT_QUEUE_FULL));
504 checkMetrics(*this, env, 10, 10, 6, 5, 257);
505
506 // Check which of the queued transactions got into the ledger by
507 // attempting to replace them.
508 // o Get tefNo_TICKET if the ticket has already been used.
509 // o Get tefPAST_SEQ if the sequence moved out of the queue.
510 // o Get telCAN_NOT_QUEUE_FEE if the transaction is still in
511 // the queue.
512 env.close();
513 env.require(Owners(alice, 237), Tickets(alice, 237));
514
515 // The four ticket-based transactions went out first, since
516 // they paid the highest fee.
517 env(noop(alice), ticket::Use(tkt1 + 4), Ter(tefNO_TICKET));
518 env(noop(alice), ticket::Use(tkt1 + 5), Ter(tefNO_TICKET));
519 env(noop(alice), ticket::Use(tkt1 + 12), Ter(tefNO_TICKET));
520 env(noop(alice), ticket::Use(tkt1 + 13), Ter(tefNO_TICKET));
521
522 // Three of the sequence-based transactions also moved out of
523 // the queue.
524 env(noop(alice), Seq(nextSeq + 1), Ter(tefPAST_SEQ));
525 env(noop(alice), Seq(nextSeq + 2), Ter(tefPAST_SEQ));
526 env(noop(alice), Seq(nextSeq + 3), Ter(tefPAST_SEQ));
527 env(noop(alice), Seq(nextSeq + 4), Ter(telCAN_NOT_QUEUE_FEE));
528 env(noop(alice), Seq(nextSeq + 5), Ter(telCAN_NOT_QUEUE_FEE));
529 env(noop(alice), Seq(nextSeq + 6), Ter(telCAN_NOT_QUEUE_FEE));
530 env(noop(alice), Seq(nextSeq + 7), Ter(telCAN_NOT_QUEUE_FEE));
531
532 checkMetrics(*this, env, 4, 12, 7, 6);
533 BEAST_EXPECT(env.seq(alice) == nextSeq + 4);
534
536
537 // We haven't yet shown that ticket-based transactions can be added
538 // to the queue in any order. We should do that...
539 std::uint32_t const tkt250 = tkt1 + 249;
540 env(noop(alice), ticket::Use(tkt250 - 0), Fee(baseFee * 3.0), queued);
541 env(noop(alice), ticket::Use(tkt1 + 14), Fee(baseFee * 2.9), queued);
542 env(noop(alice), ticket::Use(tkt250 - 1), Fee(baseFee * 2.8), queued);
543 env(noop(alice), ticket::Use(tkt1 + 15), Fee(baseFee * 2.7), queued);
544 env(noop(alice), ticket::Use(tkt250 - 2), Fee(baseFee * 2.6), queued);
545 env(noop(alice), ticket::Use(tkt1 + 16), Fee(baseFee * 2.5), queued);
546 env(noop(alice), ticket::Use(tkt250 - 3), Fee(baseFee * 2.4), Ter(telCAN_NOT_QUEUE_FULL));
547 env(noop(alice), ticket::Use(tkt1 + 17), Fee(baseFee * 2.3), Ter(telCAN_NOT_QUEUE_FULL));
548 env(noop(alice), ticket::Use(tkt250 - 4), Fee(baseFee * 2.2), Ter(telCAN_NOT_QUEUE_FULL));
549 env(noop(alice), ticket::Use(tkt1 + 18), Fee(baseFee * 2.1), Ter(telCAN_NOT_QUEUE_FULL));
550
551 checkMetrics(*this, env, 10, 12, 7, 6);
552
553 env.close();
554 env.require(Owners(alice, 231), Tickets(alice, 231));
555
556 // These three ticket-based transactions escaped the queue.
557 env(noop(alice), ticket::Use(tkt1 + 14), Ter(tefNO_TICKET));
558 env(noop(alice), ticket::Use(tkt1 + 15), Ter(tefNO_TICKET));
559 env(noop(alice), ticket::Use(tkt1 + 16), Ter(tefNO_TICKET));
560
561 // But these four ticket-based transactions are in the queue
562 // now; they moved into the TxQ from local transactions.
563 env(noop(alice), ticket::Use(tkt250 - 3), Ter(telCAN_NOT_QUEUE_FEE));
564 env(noop(alice), ticket::Use(tkt1 + 17), Ter(telCAN_NOT_QUEUE_FEE));
565 env(noop(alice), ticket::Use(tkt250 - 4), Ter(telCAN_NOT_QUEUE_FEE));
566 env(noop(alice), ticket::Use(tkt1 + 18), Ter(telCAN_NOT_QUEUE_FEE));
567
568 // These three ticket-based transactions also escaped the queue.
569 env(noop(alice), ticket::Use(tkt250 - 2), Ter(tefNO_TICKET));
570 env(noop(alice), ticket::Use(tkt250 - 1), Ter(tefNO_TICKET));
571 env(noop(alice), ticket::Use(tkt250 - 0), Ter(tefNO_TICKET));
572
573 // These sequence-based transactions escaped the queue.
574 env(noop(alice), Seq(nextSeq + 4), Ter(tefPAST_SEQ));
575 env(noop(alice), Seq(nextSeq + 5), Ter(tefPAST_SEQ));
576
577 // But these sequence-based transactions are still stuck in the queue.
578 env(noop(alice), Seq(nextSeq + 6), Ter(telCAN_NOT_QUEUE_FEE));
579 env(noop(alice), Seq(nextSeq + 7), Ter(telCAN_NOT_QUEUE_FEE));
580
581 BEAST_EXPECT(env.seq(alice) == nextSeq + 6);
582 checkMetrics(*this, env, 6, 14, 8, 7);
583
585
586 // Since we still have two ticket-based transactions in the queue
587 // let's try replacing them.
588
589 // The lowest fee ticket is baseFee * 2.1, trying to replace it
590 env(noop(alice),
591 ticket::Use(tkt1 + 18),
592 Fee((baseFee * 2.1 * 1.25) - 1),
594 env(noop(alice), ticket::Use(tkt1 + 18), Fee((baseFee * 2.1 * 1.25) + 1), queued);
595
596 // New lowest fee ticket is baseFee * 2.2
597 env(noop(alice),
598 ticket::Use(tkt250 - 4),
599 Fee((baseFee * 2.2 * 1.25) - 1),
601 env(noop(alice), ticket::Use(tkt250 - 4), Fee((baseFee * 2.2 * 1.25) + 1), queued);
602
603 env.close();
604 env.require(Owners(alice, 227), Tickets(alice, 227));
605
606 // Verify that all remaining transactions made it out of the TxQ.
607 env(noop(alice), ticket::Use(tkt1 + 18), Ter(tefNO_TICKET));
608 env(noop(alice), ticket::Use(tkt250 - 4), Ter(tefNO_TICKET));
609 env(noop(alice), Seq(nextSeq + 4), Ter(tefPAST_SEQ));
610 env(noop(alice), Seq(nextSeq + 5), Ter(tefPAST_SEQ));
611 env(noop(alice), Seq(nextSeq + 6), Ter(tefPAST_SEQ));
612 env(noop(alice), Seq(nextSeq + 7), Ter(tefPAST_SEQ));
613
614 BEAST_EXPECT(env.seq(alice) == nextSeq + 8);
615 checkMetrics(*this, env, 0, 16, 6, 8);
616 }
617
618 void
620 {
621 using namespace jtx;
622 testcase("queue tec");
623
625
626 auto const alice = Account("alice");
627 auto const gw = Account("gw");
628 auto const usd = gw["USD"];
629
630 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
631
632 // Create accounts
633 env.fund(XRP(50000), noripple(alice, gw));
634 checkMetrics(*this, env, 0, std::nullopt, 2, 2);
635 env.close();
636 checkMetrics(*this, env, 0, 4, 0, 2);
637
638 // Alice creates an unfunded offer while the ledger is not full
639 env(offer(alice, XRP(1000), usd(1000)), Ter(tecUNFUNDED_OFFER));
640 checkMetrics(*this, env, 0, 4, 1, 2);
641
642 fillQueue(env, alice);
643 checkMetrics(*this, env, 0, 4, 3, 2);
644
645 // Alice creates an unfunded offer that goes in the queue
646 env(offer(alice, XRP(1000), usd(1000)), Ter(terQUEUED));
647 checkMetrics(*this, env, 1, 4, 3, 2);
648
649 // The offer comes out of the queue
650 env.close();
651 checkMetrics(*this, env, 0, 6, 1, 3);
652 }
653
654 void
656 {
657 using namespace jtx;
658 using namespace std::chrono;
659 testcase("local tx retry");
660
662
663 auto const alice = Account("alice");
664 auto const bob = Account("bob");
665 auto const charlie = Account("charlie");
666
667 auto const queued = Ter(terQUEUED);
668 auto const baseFee = env.current()->fees().base.drops();
669
670 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
671
672 // Create several accounts while the fee is cheap so they all apply.
673 env.fund(XRP(50000), noripple(alice, bob, charlie));
674 checkMetrics(*this, env, 0, std::nullopt, 3, 2);
675
676 // Future transaction for Alice - fails
677 env(noop(alice), Fee(openLedgerCost(env)), Seq(env.seq(alice) + 1), Ter(terPRE_SEQ));
678 checkMetrics(*this, env, 0, std::nullopt, 3, 2);
679
680 // Current transaction for Alice: held
681 env(noop(alice), queued);
682 checkMetrics(*this, env, 1, std::nullopt, 3, 2);
683
684 // Alice - sequence is too far ahead, so won't queue.
685 env(noop(alice), Seq(env.seq(alice) + 2), Ter(telCAN_NOT_QUEUE));
686 checkMetrics(*this, env, 1, std::nullopt, 3, 2);
687
688 // Bob with really high fee - applies
689 env(noop(bob), Fee(openLedgerCost(env)));
690 checkMetrics(*this, env, 1, std::nullopt, 4, 2);
691
692 // Daria with low fee: hold
693 env(noop(charlie), Fee(baseFee * 100), queued);
694 checkMetrics(*this, env, 2, std::nullopt, 4, 2);
695
696 // Alice with normal fee: hold
697 env(noop(alice), Seq(env.seq(alice) + 1), queued);
698 checkMetrics(*this, env, 3, std::nullopt, 4, 2);
699
700 env.close();
701 // Verify that the held transactions got applied
702 // Alice's bad transaction applied from the
703 // Local Txs.
704 checkMetrics(*this, env, 0, 8, 4, 4);
705 }
706
707 void
709 {
710 using namespace jtx;
711 using namespace std::chrono;
712 testcase("last ledger sequence");
713
715
716 auto const alice = Account("alice");
717 auto const bob = Account("bob");
718 auto const charlie = Account("charlie");
719 auto const daria = Account("daria");
720 auto const edgar = Account("edgar");
721 auto const felicia = Account("felicia");
722
723 auto const queued = Ter(terQUEUED);
724 auto const baseFee = env.current()->fees().base.drops();
725
726 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
727
728 // Fund across several ledgers so the TxQ metrics stay restricted.
729 env.fund(XRP(1000), noripple(alice, bob));
730 env.close(env.now() + 5s, 10000ms);
731 env.fund(XRP(1000), noripple(charlie, daria));
732 env.close(env.now() + 5s, 10000ms);
733 env.fund(XRP(1000), noripple(edgar, felicia));
734 env.close(env.now() + 5s, 10000ms);
735
736 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
737 env(noop(bob));
738 env(noop(charlie));
739 env(noop(daria));
740 checkMetrics(*this, env, 0, std::nullopt, 3, 2);
741
742 BEAST_EXPECT(env.current()->header().seq == 6);
743 // Fail to queue an item with a low LastLedgerSeq
744 env(noop(alice), LastLedgerSeq(7), Ter(telCAN_NOT_QUEUE));
745 // Queue an item with a sufficient LastLedgerSeq.
746 env(noop(alice), LastLedgerSeq(8), queued);
747
748 static constexpr auto kLargeFeeMultiplier = 700;
749 auto const largeFee = baseFee * kLargeFeeMultiplier;
750
751 // Queue items with higher fees to force the previous
752 // txn to wait.
753 env(noop(bob), Fee(largeFee), queued);
754 env(noop(charlie), Fee(largeFee), queued);
755 env(noop(daria), Fee(largeFee), queued);
756 env(noop(edgar), Fee(largeFee), queued);
757 checkMetrics(*this, env, 5, std::nullopt, 3, 2);
758 {
759 auto const& txQ = env.app().getTxQ();
760 auto aliceStat = txQ.getAccountTxs(alice.id());
761 BEAST_EXPECT(aliceStat.size() == 1);
762 BEAST_EXPECT(aliceStat.begin()->feeLevel == kBaseFeeLevel);
763 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
764 BEAST_EXPECT(aliceStat.begin()->lastValid && *aliceStat.begin()->lastValid == 8);
765 BEAST_EXPECT(!aliceStat.begin()->consequences.isBlocker());
766
767 auto bobStat = txQ.getAccountTxs(bob.id());
768 BEAST_EXPECT(bobStat.size() == 1);
769 BEAST_EXPECT(
770 bobStat.begin()->feeLevel == FeeLevel64{kBaseFeeLevel.fee() * kLargeFeeMultiplier});
771 BEAST_EXPECT(!bobStat.begin()->lastValid);
772 BEAST_EXPECT(!bobStat.begin()->consequences.isBlocker());
773
774 auto const noStat = txQ.getAccountTxs(Account::kMaster.id());
775 BEAST_EXPECT(noStat.empty());
776 }
777
778 env.close();
779 checkMetrics(*this, env, 1, 6, 4, 3);
780
781 // Keep alice's transaction waiting.
782 env(noop(bob), Fee(largeFee), queued);
783 env(noop(charlie), Fee(largeFee), queued);
784 env(noop(daria), Fee(largeFee), queued);
785 env(noop(edgar), Fee(largeFee), queued);
786 env(noop(felicia), Fee(largeFee - 1), queued);
787 checkMetrics(*this, env, 6, 6, 4, 3, 257);
788
789 env.close();
790 // alice's transaction is still hanging around
791 // clang-format off
792 checkMetrics(*this, env, 1, 8, 5, 4, kBaseFeeLevel.fee(), kBaseFeeLevel.fee() * kLargeFeeMultiplier);
793 // clang-format on
794 BEAST_EXPECT(env.seq(alice) == 3);
795
796 static constexpr auto kAnotherLargeFeeMultiplier = 800;
797 auto const anotherLargeFee = baseFee * kAnotherLargeFeeMultiplier;
798 // Keep alice's transaction waiting.
799 // clang-format off
800 env(noop(bob), Fee(anotherLargeFee), queued);
801 env(noop(charlie), Fee(anotherLargeFee), queued);
802 env(noop(daria), Fee(anotherLargeFee), queued);
803 env(noop(daria), Fee(anotherLargeFee), Seq(env.seq(daria) + 1), queued);
804 env(noop(edgar), Fee(anotherLargeFee), queued);
805 env(noop(felicia), Fee(anotherLargeFee - 1), queued);
806 env(noop(felicia), Fee(anotherLargeFee - 1), Seq(env.seq(felicia) + 1), queued);
807 checkMetrics(*this, env, 8, 8, 5, 4, kBaseFeeLevel.fee() + 1, kBaseFeeLevel.fee() * kLargeFeeMultiplier);
808 // clang-format on
809
810 env.close();
811 // alice's transaction expired without getting
812 // into the ledger, so her transaction is gone,
813 // though one of felicia's is still in the queue.
814 // clang-format off
815 checkMetrics(*this, env, 1, 10, 6, 5, kBaseFeeLevel.fee(), kBaseFeeLevel.fee() * kLargeFeeMultiplier);
816 // clang-format on
817 BEAST_EXPECT(env.seq(alice) == 3);
818 BEAST_EXPECT(env.seq(felicia) == 7);
819
820 env.close();
821 // And now the queue is empty
822 // clang-format off
823 checkMetrics(*this, env, 0, 12, 1, 6, kBaseFeeLevel.fee(), kBaseFeeLevel.fee() * kAnotherLargeFeeMultiplier);
824 // clang-format on
825 BEAST_EXPECT(env.seq(alice) == 3);
826 BEAST_EXPECT(env.seq(felicia) == 8);
827 }
828
829 void
831 {
832 using namespace jtx;
833 using namespace std::chrono;
834 testcase("zero transaction fee");
835
837
838 auto const alice = Account("alice");
839 auto const bob = Account("bob");
840 auto const carol = Account("carol");
841
842 auto const queued = Ter(terQUEUED);
843 auto const baseFee = env.current()->fees().base.drops();
844
845 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
846
847 // Fund across several ledgers so the TxQ metrics stay restricted.
848 env.fund(XRP(1000), noripple(alice, bob));
849 env.close(env.now() + 5s, 10000ms);
850 env.fund(XRP(1000), noripple(carol));
851 env.close(env.now() + 5s, 10000ms);
852
853 // Fill the ledger
854 env(noop(alice));
855 env(noop(alice));
856 env(noop(alice));
857 checkMetrics(*this, env, 0, std::nullopt, 3, 2);
858
859 env(noop(bob), queued);
860 checkMetrics(*this, env, 1, std::nullopt, 3, 2);
861
862 // Since Alice's queue is empty this blocker can go into her queue.
863 env(regkey(alice, bob), Fee(0), queued);
864 checkMetrics(*this, env, 2, std::nullopt, 3, 2);
865
866 // Close out this ledger so we can get a maxsize
867 env.close();
868 checkMetrics(*this, env, 0, 6, 2, 3);
869
870 fillQueue(env, alice);
871 checkMetrics(*this, env, 0, 6, 4, 3);
872
873 static constexpr auto kAliceFeeMultiplier = 3;
874 auto feeAlice = baseFee * kAliceFeeMultiplier;
875 auto seqAlice = env.seq(alice);
876 for (int i = 0; i < 4; ++i)
877 {
878 env(noop(alice), Fee(feeAlice), Seq(seqAlice), queued);
879 feeAlice = (feeAlice + 1) * 125 / 100;
880 ++seqAlice;
881 }
882 checkMetrics(*this, env, 4, 6, 4, 3);
883
884 // Bob adds a zero fee blocker to his queue.
885 auto const seqBob = env.seq(bob);
886 env(regkey(bob, alice), Fee(0), queued);
887 checkMetrics(*this, env, 5, 6, 4, 3);
888
889 // Carol fills the queue.
890 auto feeCarol = feeAlice;
891 auto seqCarol = env.seq(carol);
892 for (int i = 0; i < 4; ++i)
893 {
894 env(noop(carol), Fee(feeCarol), Seq(seqCarol), queued);
895 feeCarol = (feeCarol + 1) * 125 / 100;
896 ++seqCarol;
897 }
898 // clang-format off
899 checkMetrics(*this, env, 6, 6, 4, 3, (kBaseFeeLevel.fee() * kAliceFeeMultiplier) + 1);
900 // clang-format on
901
902 // Carol submits high enough to beat Bob's average fee which kicks
903 // out Bob's queued transaction. However Bob's transaction stays
904 // in the localTx queue, so it will return to the TxQ next time
905 // around.
906 env(noop(carol), Fee(feeCarol), Seq(seqCarol), Ter(terQUEUED));
907
908 env.close();
909 // Some of Alice's transactions stay in the queue. Bob's
910 // transaction returns to the TxQ.
911 checkMetrics(*this, env, 5, 8, 5, 4);
912 BEAST_EXPECT(env.seq(alice) == seqAlice - 4);
913 BEAST_EXPECT(env.seq(bob) == seqBob);
914 BEAST_EXPECT(env.seq(carol) == seqCarol + 1);
915
916 env.close();
917 // The remaining queued transactions flush through to the ledger.
918 checkMetrics(*this, env, 0, 10, 5, 5);
919 BEAST_EXPECT(env.seq(alice) == seqAlice);
920 BEAST_EXPECT(env.seq(bob) == seqBob + 1);
921 BEAST_EXPECT(env.seq(carol) == seqCarol + 1);
922
923 env.close();
924 checkMetrics(*this, env, 0, 10, 0, 5);
925 BEAST_EXPECT(env.seq(alice) == seqAlice);
926 BEAST_EXPECT(env.seq(bob) == seqBob + 1);
927 BEAST_EXPECT(env.seq(carol) == seqCarol + 1);
928 }
929
930 void
932 {
933 using namespace jtx;
934
935 Env env(*this, makeConfig());
936 testcase("fail in preclaim");
937
938 auto const alice = Account("alice");
939 auto const bob = Account("bob");
940
941 env.fund(XRP(1000), noripple(alice));
942
943 // These types of checks are tested elsewhere, but
944 // this verifies that TxQ handles the failures as
945 // expected.
946
947 // Fail in preflight
948 env(pay(alice, bob, XRP(-1000)), Ter(temBAD_AMOUNT));
949
950 // Fail in preflight
951 env(pay(alice, alice, XRP(100)), Ter(temREDUNDANT));
952
953 // Fail in preclaim
954 env(noop(alice), Fee(XRP(100000)), Ter(terINSUF_FEE_B));
955 }
956
957 void
959 {
960 using namespace jtx;
961 testcase("queued tx fails");
962
964
965 auto const alice = Account("alice");
966 auto const bob = Account("bob");
967
968 auto const queued = Ter(terQUEUED);
969
970 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
971
972 env.fund(XRP(1000), noripple(alice, bob));
973
974 checkMetrics(*this, env, 0, std::nullopt, 2, 2);
975
976 // Fill the ledger
977 env(noop(alice));
978 checkMetrics(*this, env, 0, std::nullopt, 3, 2);
979
980 // Put a transaction in the queue
981 env(noop(alice), queued);
982 checkMetrics(*this, env, 1, std::nullopt, 3, 2);
983
984 // Now cheat, and bypass the queue.
985 {
986 auto const& jt = env.jt(noop(alice));
987 BEAST_EXPECT(jt.stx);
988
989 Env::ParsedResult parsed;
990
991 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
992 auto const result = xrpl::apply(env.app(), view, *jt.stx, TapNone, env.journal);
993 parsed.ter = result.ter;
994 return result.applied;
995 });
996 env.postconditions(jt, parsed);
997 }
998 checkMetrics(*this, env, 1, std::nullopt, 4, 2);
999
1000 env.close();
1001 // Alice's queued transaction failed in TxQ::accept
1002 // with tefPAST_SEQ
1003 checkMetrics(*this, env, 0, 8, 0, 4);
1004 }
1005
1006 void
1008 {
1009 using namespace jtx;
1010 testcase("multi tx per account");
1011
1012 Env env(
1013 *this,
1014 makeConfig(
1016 {{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
1017
1018 auto const alice = Account("alice");
1019 auto const bob = Account("bob");
1020 auto const charlie = Account("charlie");
1021 auto const daria = Account("daria");
1022
1023 auto const queued = Ter(terQUEUED);
1024
1025 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
1026
1027 // ledgers in queue is 2 because of makeConfig
1028 initFee(env, 3, 2, 10, 200, 50);
1029 // Close an empty ledger to shrink queue from the flag-ledger
1030 // size to 2*3=6, independent of amendment count.
1031 env.close();
1032 static constexpr std::size_t kInitQueueMax = 6;
1033 checkMetrics(*this, env, 0, kInitQueueMax, 0, 3);
1034
1035 // Create several accounts while the fee is cheap so they all apply.
1036 env.fund(drops(2000), noripple(alice));
1037 env.fund(XRP(500000), noripple(bob, charlie, daria));
1038 checkMetrics(*this, env, 0, kInitQueueMax, 4, 3);
1039
1040 // Alice - price starts exploding: held
1041 env(noop(alice), Fee(11), queued);
1042 checkMetrics(*this, env, 1, kInitQueueMax, 4, 3);
1043
1044 auto aliceSeq = env.seq(alice);
1045 auto bobSeq = env.seq(bob);
1046 auto charlieSeq = env.seq(charlie);
1047
1048 // Alice - try to queue a second transaction, but leave a gap
1049 env(noop(alice), Seq(aliceSeq + 2), Fee(100), Ter(telCAN_NOT_QUEUE));
1050 checkMetrics(*this, env, 1, kInitQueueMax, 4, 3);
1051
1052 // Alice - queue a second transaction. Yay!
1053 env(noop(alice), Seq(aliceSeq + 1), Fee(13), queued);
1054 checkMetrics(*this, env, 2, kInitQueueMax, 4, 3);
1055
1056 // Alice - queue a third transaction. Yay.
1057 env(noop(alice), Seq(aliceSeq + 2), Fee(17), queued);
1058 checkMetrics(*this, env, 3, kInitQueueMax, 4, 3);
1059
1060 // Bob - queue a transaction
1061 env(noop(bob), queued);
1062 checkMetrics(*this, env, 4, kInitQueueMax, 4, 3);
1063
1064 // Bob - queue a second transaction
1065 env(noop(bob), Seq(bobSeq + 1), Fee(50), queued);
1066 checkMetrics(*this, env, 5, kInitQueueMax, 4, 3);
1067
1068 // Charlie - queue a transaction, with a higher fee
1069 // than default
1070 env(noop(charlie), Fee(15), queued);
1071 checkMetrics(*this, env, 6, kInitQueueMax, 4, 3, 257);
1072
1073 BEAST_EXPECT(env.seq(alice) == aliceSeq);
1074 BEAST_EXPECT(env.seq(bob) == bobSeq);
1075 BEAST_EXPECT(env.seq(charlie) == charlieSeq);
1076
1077 env.close();
1078 // Verify that all of but one of the queued transactions
1079 // got applied.
1080 checkMetrics(*this, env, 1, 8, 5, 4);
1081
1082 // Verify that the stuck transaction is Bob's second.
1083 // Even though it had a higher fee than Alice's and
1084 // Charlie's, it didn't get attempted until the fee escalated.
1085 BEAST_EXPECT(env.seq(alice) == aliceSeq + 3);
1086 BEAST_EXPECT(env.seq(bob) == bobSeq + 1);
1087 BEAST_EXPECT(env.seq(charlie) == charlieSeq + 1);
1088
1089 // Alice - fill up the queue
1090 std::int64_t aliceFee = 27;
1091 aliceSeq = env.seq(alice);
1092 auto const lastLedgerSeq = env.current()->header().seq + 2;
1093 for (auto i = 0; i < 7; i++)
1094 {
1095 env(noop(alice),
1096 Seq(aliceSeq),
1097 Json(jss::LastLedgerSequence, lastLedgerSeq + i),
1098 Fee(--aliceFee),
1099 queued);
1100 ++aliceSeq;
1101 }
1102 checkMetrics(*this, env, 8, 8, 5, 4, 513);
1103 {
1104 auto const& txQ = env.app().getTxQ();
1105 auto const aliceStat = txQ.getAccountTxs(alice.id());
1106 aliceFee = 27;
1107 auto const& baseFee = env.current()->fees().base;
1108 auto seq = env.seq(alice);
1109 BEAST_EXPECT(aliceStat.size() == 7);
1110 for (auto const& tx : aliceStat)
1111 {
1112 BEAST_EXPECT(tx.seqProxy.isSeq() && tx.seqProxy.value() == seq);
1113 BEAST_EXPECT(tx.feeLevel == toFeeLevel(XRPAmount(--aliceFee), baseFee));
1114 BEAST_EXPECT(tx.lastValid);
1115 BEAST_EXPECT(
1116 (tx.consequences.fee() == drops(aliceFee) &&
1117 tx.consequences.potentialSpend() == drops(0) &&
1118 !tx.consequences.isBlocker()) ||
1119 tx.seqProxy.value() == env.seq(alice) + 6);
1120 ++seq;
1121 }
1122 }
1123
1124 // Alice attempts to add another item to the queue,
1125 // but you can't force your own earlier txn off the
1126 // queue.
1127 env(noop(alice),
1128 Seq(aliceSeq),
1129 Json(jss::LastLedgerSequence, lastLedgerSeq + 7),
1130 Fee(aliceFee),
1132 checkMetrics(*this, env, 8, 8, 5, 4, 513);
1133
1134 // Charlie - try to add another item to the queue,
1135 // which fails because fee is lower than Alice's
1136 // queued average.
1137 env(noop(charlie), Fee(19), Ter(telCAN_NOT_QUEUE_FULL));
1138 checkMetrics(*this, env, 8, 8, 5, 4, 513);
1139
1140 // Charlie - add another item to the queue, which
1141 // causes Alice's last txn to drop
1142 env(noop(charlie), Fee(30), queued);
1143 checkMetrics(*this, env, 8, 8, 5, 4, 538);
1144
1145 // Alice - now attempt to add one more to the queue,
1146 // which fails because the last tx was dropped, so
1147 // there is no complete chain.
1148 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), Ter(telCAN_NOT_QUEUE));
1149 checkMetrics(*this, env, 8, 8, 5, 4, 538);
1150
1151 // Alice wants this tx more than the dropped tx,
1152 // so resubmits with higher fee, but the queue
1153 // is full, and her account is the cheapest.
1154 env(noop(alice), Seq(aliceSeq - 1), Fee(aliceFee), Ter(telCAN_NOT_QUEUE_FULL));
1155 checkMetrics(*this, env, 8, 8, 5, 4, 538);
1156
1157 // Try to replace a middle item in the queue
1158 // without enough fee.
1159 aliceSeq = env.seq(alice) + 2;
1160 aliceFee = 29;
1161 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), Ter(telCAN_NOT_QUEUE_FEE));
1162 checkMetrics(*this, env, 8, 8, 5, 4, 538);
1163
1164 // Replace a middle item from the queue successfully
1165 ++aliceFee;
1166 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), queued);
1167 checkMetrics(*this, env, 8, 8, 5, 4, 538);
1168
1169 env.close();
1170 // Alice's transactions processed, along with
1171 // Charlie's, and the lost one is replayed and
1172 // added back to the queue.
1173 checkMetrics(*this, env, 4, 10, 6, 5);
1174
1175 aliceSeq = env.seq(alice) + 1;
1176
1177 // Try to replace that item with a transaction that will
1178 // bankrupt Alice. Fails, because an account can't have
1179 // more than the minimum reserve in flight before the
1180 // last queued transaction
1181 aliceFee = env.le(alice)->getFieldAmount(sfBalance).xrp().drops() - 62;
1182 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), Ter(telCAN_NOT_QUEUE_BALANCE));
1183 checkMetrics(*this, env, 4, 10, 6, 5);
1184
1185 // Try to spend more than Alice can afford with all the other txs.
1186 aliceSeq += 2;
1187 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), Ter(terINSUF_FEE_B));
1188 checkMetrics(*this, env, 4, 10, 6, 5);
1189
1190 // Replace the last queued item with a transaction that will
1191 // bankrupt Alice
1192 --aliceFee;
1193 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), queued);
1194 checkMetrics(*this, env, 4, 10, 6, 5);
1195
1196 // Alice - Attempt to queue a last transaction, but it
1197 // fails because the fee in flight is too high, before
1198 // the fee is checked against the balance
1199 aliceFee /= 5;
1200 ++aliceSeq;
1201 env(noop(alice), Seq(aliceSeq), Fee(aliceFee), Ter(telCAN_NOT_QUEUE_BALANCE));
1202 checkMetrics(*this, env, 4, 10, 6, 5);
1203
1204 env.close();
1205 // All of Alice's transactions applied.
1206 checkMetrics(*this, env, 0, 12, 4, 6);
1207
1208 env.close();
1209 checkMetrics(*this, env, 0, 12, 0, 6);
1210
1211 // Alice is broke
1212 env.require(Balance(alice, XRP(0)));
1213 env(noop(alice), Ter(terINSUF_FEE_B));
1214
1215 // Bob tries to queue up more than the single
1216 // account limit (10) txs.
1217 fillQueue(env, bob);
1218 bobSeq = env.seq(bob);
1219 checkMetrics(*this, env, 0, 12, 7, 6);
1220 for (int i = 0; i < 10; ++i)
1221 env(noop(bob), Seq(bobSeq + i), queued);
1222 checkMetrics(*this, env, 10, 12, 7, 6);
1223 // Bob hit the single account limit
1224 env(noop(bob), Seq(bobSeq + 10), Ter(telCAN_NOT_QUEUE_FULL));
1225 checkMetrics(*this, env, 10, 12, 7, 6);
1226 // Bob can replace one of the earlier txs regardless
1227 // of the limit
1228 env(noop(bob), Seq(bobSeq + 5), Fee(20), queued);
1229 checkMetrics(*this, env, 10, 12, 7, 6);
1230
1231 // Try to replace a middle item in the queue
1232 // with enough fee to bankrupt bob and make the
1233 // later transactions unable to pay their fees
1234 std::int64_t bobFee = env.le(bob)->getFieldAmount(sfBalance).xrp().drops() - ((9 * 10) - 1);
1235 env(noop(bob), Seq(bobSeq + 5), Fee(bobFee), Ter(telCAN_NOT_QUEUE_BALANCE));
1236 checkMetrics(*this, env, 10, 12, 7, 6);
1237
1238 // Attempt to replace a middle item in the queue with enough fee
1239 // to bankrupt bob, and also to use fee averaging to clear out the
1240 // first six transactions.
1241 //
1242 // The attempt fails because the sum of bob's fees now exceeds the
1243 // (artificially lowered to 200 drops) account reserve.
1244 bobFee = env.le(bob)->getFieldAmount(sfBalance).xrp().drops() - (9 * 10);
1245 env(noop(bob), Seq(bobSeq + 5), Fee(bobFee), Ter(telCAN_NOT_QUEUE_BALANCE));
1246 checkMetrics(*this, env, 10, 12, 7, 6);
1247
1248 // Close the ledger and verify that the queued transactions succeed
1249 // and bob has the right ending balance.
1250 env.close();
1251 checkMetrics(*this, env, 3, 14, 8, 7);
1252 env.close();
1253 checkMetrics(*this, env, 0, 16, 3, 8);
1254 env.require(Balance(bob, drops(499'999'999'750)));
1255 }
1256
1257 void
1259 {
1260 using namespace jtx;
1261 using namespace std::chrono;
1262 testcase("tie breaking");
1263
1265 cfg->fees.referenceFee = 10;
1266 Env env(*this, std::move(cfg));
1267
1268 auto const alice = Account("alice");
1269 auto const bob = Account("bob");
1270 auto const charlie = Account("charlie");
1271 auto const daria = Account("daria");
1272 auto const elmo = Account("elmo");
1273 auto const fred = Account("fred");
1274 auto const gwen = Account("gwen");
1275 auto const hank = Account("hank");
1276
1277 auto const queued = Ter(terQUEUED);
1278
1279 BEAST_EXPECT(env.current()->fees().base == 10);
1280
1281 checkMetrics(*this, env, 0, std::nullopt, 0, 4);
1282
1283 // Create several accounts while the fee is cheap so they all apply.
1284 env.fund(XRP(50000), noripple(alice, bob, charlie, daria));
1285 checkMetrics(*this, env, 0, std::nullopt, 4, 4);
1286
1287 env.close();
1288 checkMetrics(*this, env, 0, 8, 0, 4);
1289
1290 env.fund(XRP(50000), noripple(elmo, fred, gwen, hank));
1291 checkMetrics(*this, env, 0, 8, 4, 4);
1292
1293 env.close();
1294 checkMetrics(*this, env, 0, 8, 0, 4);
1295
1297
1298 // Stuff the ledger and queue so we can verify that
1299 // stuff gets kicked out.
1300 env(noop(gwen));
1301 env(noop(hank));
1302 env(noop(gwen));
1303 env(noop(fred));
1304 env(noop(elmo));
1305 checkMetrics(*this, env, 0, 8, 5, 4);
1306
1307 auto aliceSeq = env.seq(alice);
1308 auto bobSeq = env.seq(bob);
1309 auto charlieSeq = env.seq(charlie);
1310 auto dariaSeq = env.seq(daria);
1311 auto elmoSeq = env.seq(elmo);
1312 auto fredSeq = env.seq(fred);
1313 auto gwenSeq = env.seq(gwen);
1314 auto hankSeq = env.seq(hank);
1315
1316 // This time, use identical fees.
1317
1318 // All of these get into the queue, but one gets dropped when the
1319 // higher fee one is added later. Which one depends on ordering.
1320 env(noop(alice), Fee(15), queued);
1321 env(noop(bob), Fee(15), queued);
1322 env(noop(charlie), Fee(15), queued);
1323 env(noop(daria), Fee(15), queued);
1324 env(noop(elmo), Fee(15), queued);
1325 env(noop(fred), Fee(15), queued);
1326 env(noop(gwen), Fee(15), queued);
1327 env(noop(hank), Fee(15), queued);
1328
1329 // Queue is full now. Minimum fee now reflects the
1330 // lowest fee in the queue.
1331 auto minFeeLevel = txFeeLevelByAccount(env, alice);
1332 checkMetrics(*this, env, 8, 8, 5, 4, minFeeLevel + 1);
1333
1334 // Try to add another transaction with the default (low) fee,
1335 // it should fail because it can't replace the one already
1336 // there.
1337 env(noop(charlie), Ter(telCAN_NOT_QUEUE_FEE));
1338
1339 // Add another transaction, with a higher fee,
1340 // Not high enough to get into the ledger, but high
1341 // enough to get into the queue (and kick somebody out)
1342 env(noop(charlie), Fee(100), Seq(charlieSeq + 1), queued);
1343
1344 // Queue is still full.
1345 checkMetrics(*this, env, 8, 8, 5, 4, minFeeLevel + 1);
1346
1347 // Six txs are processed out of the queue into the ledger,
1348 // leaving two txs. The dropped tx is retried from localTxs, and
1349 // put back into the queue.
1350 env.close();
1351 checkMetrics(*this, env, 3, 10, 6, 5);
1352
1353 // This next test should remain unchanged regardless of
1354 // transaction ordering
1355 BEAST_EXPECT(
1356 aliceSeq + bobSeq + charlieSeq + dariaSeq + elmoSeq + fredSeq + gwenSeq + hankSeq + 6 ==
1357 env.seq(alice) + env.seq(bob) + env.seq(charlie) + env.seq(daria) + env.seq(elmo) +
1358 env.seq(fred) + env.seq(gwen) + env.seq(hank));
1359 // These tests may change if TxQ ordering is changed
1360 using namespace std::string_literals;
1361 BEAST_EXPECTS(
1362 aliceSeq == env.seq(alice),
1363 "alice: "s + std::to_string(aliceSeq) + ", " + std::to_string(env.seq(alice)));
1364 BEAST_EXPECTS(
1365 bobSeq + 1 == env.seq(bob),
1366 "bob: "s + std::to_string(bobSeq) + ", " + std::to_string(env.seq(bob)));
1367 BEAST_EXPECTS(
1368 charlieSeq + 2 == env.seq(charlie),
1369 "charlie: "s + std::to_string(charlieSeq) + ", " + std::to_string(env.seq(charlie)));
1370 BEAST_EXPECTS(
1371 dariaSeq == env.seq(daria),
1372 "daria: "s + std::to_string(dariaSeq) + ", " + std::to_string(env.seq(daria)));
1373 BEAST_EXPECTS(
1374 elmoSeq + 1 == env.seq(elmo),
1375 "elmo: "s + std::to_string(elmoSeq) + ", " + std::to_string(env.seq(elmo)));
1376 BEAST_EXPECTS(
1377 fredSeq == env.seq(fred),
1378 "fred: "s + std::to_string(fredSeq) + ", " + std::to_string(env.seq(fred)));
1379 BEAST_EXPECTS(
1380 gwenSeq + 1 == env.seq(gwen),
1381 "gwen: "s + std::to_string(gwenSeq) + ", " + std::to_string(env.seq(gwen)));
1382 BEAST_EXPECTS(
1383 hankSeq + 1 == env.seq(hank),
1384 "hank: "s + std::to_string(hankSeq) + ", " + std::to_string(env.seq(hank)));
1385
1386 // Which sequences get incremented may change if TxQ ordering is
1387 // changed
1388 //++aliceSeq;
1389 ++bobSeq;
1390 ++(++charlieSeq);
1391 // ++dariaSeq;
1392 ++elmoSeq;
1393 // ++fredSeq;
1394 ++gwenSeq;
1395 ++hankSeq;
1396
1397 auto const getTxsQueued = [&] {
1398 auto const txs = env.app().getTxQ().getTxs();
1400 for (auto const& tx : txs)
1401 {
1402 ++result[tx.txn->at(sfAccount)];
1403 }
1404 return result;
1405 };
1406 auto qTxCount1 = getTxsQueued();
1407 BEAST_EXPECT(qTxCount1.size() <= 3);
1408
1409 // Fill up the queue again
1410 env(noop(alice), Seq(aliceSeq + qTxCount1[alice.id()]++), Fee(15), queued);
1411 env(noop(bob), Seq(bobSeq + qTxCount1[bob.id()]++), Fee(15), queued);
1412 env(noop(charlie), Seq(charlieSeq + qTxCount1[charlie.id()]++), Fee(15), queued);
1413 env(noop(daria), Seq(dariaSeq + qTxCount1[daria.id()]++), Fee(15), queued);
1414 env(noop(elmo), Seq(elmoSeq + qTxCount1[elmo.id()]++), Fee(15), queued);
1415 env(noop(fred), Seq(fredSeq + qTxCount1[fred.id()]++), Fee(15), queued);
1416 env(noop(gwen), Seq(gwenSeq + qTxCount1[gwen.id()]++), Fee(15), queued);
1417
1418 minFeeLevel = txFeeLevelByAccount(env, gwen) + 1;
1419 checkMetrics(*this, env, 10, 10, 6, 5, minFeeLevel);
1420
1421 // Add another transaction, with a higher fee,
1422 // Not high enough to get into the ledger, but high
1423 // enough to get into the queue (and kick somebody out)
1424 env(noop(alice), Fee(100), Seq(aliceSeq + qTxCount1[alice.id()]++), queued);
1425
1426 checkMetrics(*this, env, 10, 10, 6, 5, minFeeLevel);
1427
1428 // Seven txs are processed out of the queue, leaving 3. One
1429 // dropped tx is retried from localTxs, and put back into the
1430 // queue.
1431 env.close();
1432 checkMetrics(*this, env, 4, 12, 7, 6);
1433
1434 // Refresh the queue counts
1435 auto qTxCount2 = getTxsQueued();
1436 BEAST_EXPECT(qTxCount2.size() <= 4);
1437
1438 // This next test should remain unchanged regardless of
1439 // transaction ordering
1440 BEAST_EXPECT(
1441 aliceSeq + bobSeq + charlieSeq + dariaSeq + elmoSeq + fredSeq + gwenSeq + hankSeq + 7 ==
1442 env.seq(alice) + env.seq(bob) + env.seq(charlie) + env.seq(daria) + env.seq(elmo) +
1443 env.seq(fred) + env.seq(gwen) + env.seq(hank));
1444 // These tests may change if TxQ ordering is changed
1445 BEAST_EXPECTS(
1446 aliceSeq + qTxCount1[alice.id()] - qTxCount2[alice.id()] == env.seq(alice),
1447 "alice: "s + std::to_string(aliceSeq) + ", " + std::to_string(env.seq(alice)));
1448 BEAST_EXPECTS(
1449 bobSeq + qTxCount1[bob.id()] - qTxCount2[bob.id()] == env.seq(bob),
1450 "bob: "s + std::to_string(bobSeq) + ", " + std::to_string(env.seq(bob)));
1451 BEAST_EXPECTS(
1452 charlieSeq + qTxCount1[charlie.id()] - qTxCount2[charlie.id()] == env.seq(charlie),
1453 "charlie: "s + std::to_string(charlieSeq) + ", " + std::to_string(env.seq(charlie)));
1454 BEAST_EXPECTS(
1455 dariaSeq + qTxCount1[daria.id()] - qTxCount2[daria.id()] == env.seq(daria),
1456 "daria: "s + std::to_string(dariaSeq) + ", " + std::to_string(env.seq(daria)));
1457 BEAST_EXPECTS(
1458 elmoSeq + qTxCount1[elmo.id()] - qTxCount2[elmo.id()] == env.seq(elmo),
1459 "elmo: "s + std::to_string(elmoSeq) + ", " + std::to_string(env.seq(elmo)));
1460 BEAST_EXPECTS(
1461 fredSeq + qTxCount1[fred.id()] - qTxCount2[fred.id()] == env.seq(fred),
1462 "fred: "s + std::to_string(fredSeq) + ", " + std::to_string(env.seq(fred)));
1463 BEAST_EXPECTS(
1464 gwenSeq + qTxCount1[gwen.id()] - qTxCount2[gwen.id()] == env.seq(gwen),
1465 "gwen: "s + std::to_string(gwenSeq) + ", " + std::to_string(env.seq(gwen)));
1466 BEAST_EXPECTS(
1467 hankSeq + qTxCount1[hank.id()] - qTxCount2[hank.id()] == env.seq(hank),
1468 "hank: "s + std::to_string(hankSeq) + ", " + std::to_string(env.seq(hank)));
1469 }
1470
1471 void
1473 {
1474 using namespace jtx;
1475 testcase("acct tx id");
1476
1478
1479 auto const alice = Account("alice");
1480
1481 checkMetrics(*this, env, 0, std::nullopt, 0, 1);
1482
1483 env.fund(XRP(50000), noripple(alice));
1484 checkMetrics(*this, env, 0, std::nullopt, 1, 1);
1485
1486 env(fset(alice, asfAccountTxnID));
1487 checkMetrics(*this, env, 0, std::nullopt, 2, 1);
1488
1489 // Immediately after the fset, the sfAccountTxnID field
1490 // is still uninitialized, so preflight succeeds here,
1491 // and this txn fails because it can't be stored in the queue.
1492 env(noop(alice), Json(R"({"AccountTxnID": "0"})"), Ter(telCAN_NOT_QUEUE));
1493
1494 checkMetrics(*this, env, 0, std::nullopt, 2, 1);
1495 env.close();
1496 // The failed transaction is retried from LocalTx
1497 // and succeeds.
1498 checkMetrics(*this, env, 0, 4, 1, 2);
1499
1500 env(noop(alice));
1501 checkMetrics(*this, env, 0, 4, 2, 2);
1502
1503 env(noop(alice), Json(R"({"AccountTxnID": "0"})"), Ter(tefWRONG_PRIOR));
1504 }
1505
1506 void
1508 {
1509 using namespace jtx;
1510 using namespace std::string_literals;
1511 testcase("maximum tx");
1512
1513 {
1514 Env env(
1515 *this,
1516 makeConfig({
1521 }));
1522 auto const baseFee = env.current()->fees().base.drops();
1523
1524 auto const alice = Account("alice");
1525
1526 checkMetrics(*this, env, 0, std::nullopt, 0, 2);
1527
1528 env.fund(XRP(50000), noripple(alice));
1529 checkMetrics(*this, env, 0, std::nullopt, 1, 2);
1530
1531 FeeLevel64 medFeeLevel;
1532 for (int i = 0; i < 10; ++i)
1533 {
1534 auto const cost = openLedgerCost(env);
1535 // We know there's going to be 11 transactions in ledger
1536 // Need to fetch 5th transaction cost here to be able to
1537 // calculate median fee level.
1538 if (i == 4)
1539 {
1540 double const feeMultiplier = static_cast<double>(cost.drops()) / baseFee;
1541 medFeeLevel =
1542 FeeLevel64{static_cast<uint64_t>(feeMultiplier * kBaseFeeLevel.fee())};
1543 }
1544
1545 env(noop(alice), Fee(cost));
1546 }
1547
1548 checkMetrics(*this, env, 0, std::nullopt, 11, 2);
1549
1550 env.close();
1551 // If not for the maximum, the per ledger would be 11.
1552 // clang-format off
1553 checkMetrics(*this, env, 0, 10, 0, 5, kBaseFeeLevel.fee(), calcMedFeeLevel(medFeeLevel));
1554 // clang-format on
1555 }
1556
1557 try
1558 {
1559 Env const env(
1560 *this,
1561 makeConfig({
1566 }));
1567 // should throw
1568 fail();
1569 }
1570 catch (std::runtime_error const& e)
1571 {
1572 BEAST_EXPECT(
1573 e.what() ==
1574 "The minimum number of low-fee transactions allowed "
1575 "per ledger (minimum_txn_in_ledger) exceeds "
1576 "the maximum number of low-fee transactions allowed per "
1577 "ledger (maximum_txn_in_ledger)."s);
1578 }
1579 try
1580 {
1581 Env const env(
1582 *this,
1583 makeConfig({
1588 }));
1589 // should throw
1590 fail();
1591 }
1592 catch (std::runtime_error const& e)
1593 {
1594 BEAST_EXPECT(
1595 e.what() ==
1596 "The minimum number of low-fee transactions allowed "
1597 "per ledger (minimum_txn_in_ledger) exceeds "
1598 "the maximum number of low-fee transactions allowed per "
1599 "ledger (maximum_txn_in_ledger)."s);
1600 }
1601 try
1602 {
1603 Env const env(
1604 *this,
1605 makeConfig({
1610 }));
1611 // should throw
1612 fail();
1613 }
1614 catch (std::runtime_error const& e)
1615 {
1616 BEAST_EXPECT(
1617 e.what() ==
1618 "The minimum number of low-fee transactions allowed "
1619 "per ledger (minimum_txn_in_ledger_standalone) exceeds "
1620 "the maximum number of low-fee transactions allowed per "
1621 "ledger (maximum_txn_in_ledger)."s);
1622 }
1623 }
1624
1625 void
1627 {
1628 using namespace jtx;
1629 testcase("unexpected balance change");
1630
1631 Env env(
1632 *this,
1633 makeConfig(
1635 {{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
1636
1637 auto const alice = Account("alice");
1638 auto const bob = Account("bob");
1639
1640 auto const queued = Ter(terQUEUED);
1641
1642 // ledgers in queue is 2 because of makeConfig
1643 auto const initQueueMax = initFee(env, 3, 2, 10, 200, 50);
1644
1645 checkMetrics(*this, env, 0, initQueueMax, 0, 3);
1646
1647 env.fund(drops(5000), noripple(alice));
1648 env.fund(XRP(50000), noripple(bob));
1649 checkMetrics(*this, env, 0, initQueueMax, 2, 3);
1650 auto const usd = bob["USD"];
1651
1652 env(offer(alice, usd(5000), drops(5000)), Require(Owners(alice, 1)));
1653 checkMetrics(*this, env, 0, initQueueMax, 3, 3);
1654
1655 env.close();
1656 checkMetrics(*this, env, 0, 6, 0, 3);
1657
1658 // Fill up the ledger
1659 fillQueue(env, alice);
1660 checkMetrics(*this, env, 0, 6, 4, 3);
1661
1662 // Queue up a couple of transactions, plus one
1663 // more expensive one.
1664 auto aliceSeq = env.seq(alice);
1665 env(noop(alice), Seq(aliceSeq++), queued);
1666 env(noop(alice), Seq(aliceSeq++), queued);
1667 env(noop(alice), Seq(aliceSeq++), queued);
1668 env(noop(alice), Fee(drops(1000)), Seq(aliceSeq), queued);
1669 checkMetrics(*this, env, 4, 6, 4, 3);
1670
1671 // This offer should take Alice's offer
1672 // up to Alice's reserve.
1673 env(offer(bob, drops(5000), usd(5000)),
1674 Fee(openLedgerCost(env)),
1675 Require(Balance(alice, drops(250)), Owners(alice, 1), Lines(alice, 1)));
1676 checkMetrics(*this, env, 4, 6, 5, 3);
1677
1678 // Try adding a new transaction.
1679 // Too many fees in flight.
1680 env(noop(alice), Fee(drops(200)), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BALANCE));
1681 checkMetrics(*this, env, 4, 6, 5, 3);
1682
1683 // Close the ledger. All of Alice's transactions
1684 // take a fee, except the last one.
1685 env.close();
1686 checkMetrics(*this, env, 1, 10, 3, 5);
1687 env.require(Balance(alice, drops(250 - 30)));
1688
1689 // Still can't add a new transaction for Alice,
1690 // no matter the fee.
1691 env(noop(alice), Fee(drops(200)), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BALANCE));
1692 checkMetrics(*this, env, 1, 10, 3, 5);
1693
1694 /* At this point, Alice's transaction is indefinitely
1695 stuck in the queue. Eventually it will either
1696 expire, get forced off the end by more valuable
1697 transactions, get replaced by Alice, or Alice
1698 will get more XRP, and it'll process.
1699 */
1700
1701 for (int i = 0; i < 9; ++i)
1702 {
1703 env.close();
1704 checkMetrics(*this, env, 1, 10, 0, 5);
1705 }
1706
1707 // And Alice's transaction expires (via the retry limit,
1708 // not LastLedgerSequence).
1709 env.close();
1710 checkMetrics(*this, env, 0, 10, 0, 5);
1711 }
1712
1713 void
1715 {
1716 using namespace jtx;
1717 testcase("blockers sequence");
1718
1719 auto const alice = Account("alice");
1720 auto bob = Account("bob");
1721 auto charlie = Account("charlie");
1722 auto daria = Account("daria");
1723
1724 auto const queued = Ter(terQUEUED);
1725
1727 auto const baseFee = env.current()->fees().base.drops();
1728
1729 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
1730
1731 env.fund(XRP(50000), noripple(alice, bob));
1732 env.memoize(charlie);
1733 checkMetrics(*this, env, 0, std::nullopt, 2, 3);
1734 {
1735 // Cannot put a blocker in an account's queue if that queue
1736 // already holds two or more (non-blocker) entries.
1737
1738 // Fill up the open ledger
1739 env(noop(alice));
1740 // Set a regular key just to clear the password spent flag
1741 env(regkey(alice, charlie));
1742 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
1743
1744 // Put two "normal" txs in the queue
1745 auto const aliceSeq = env.seq(alice);
1746 env(noop(alice), Seq(aliceSeq + 0), queued);
1747 env(noop(alice), Seq(aliceSeq + 1), queued);
1748
1749 // Can't replace either queued transaction with a blocker
1750 env(fset(alice, asfAccountTxnID),
1751 Seq(aliceSeq + 0),
1752 Fee(baseFee * 2),
1754
1755 env(regkey(alice, bob),
1756 Seq(aliceSeq + 1),
1757 Fee(baseFee * 2),
1759
1760 // Can't append a blocker to the queue.
1761 env(signers(alice, 2, {{bob}, {charlie}, {daria}}),
1762 Seq(aliceSeq + 2),
1763 Fee(baseFee * 2),
1765
1766 // Other accounts are not affected
1767 env(noop(bob), queued);
1768 checkMetrics(*this, env, 3, std::nullopt, 4, 3);
1769
1770 // Drain the queue.
1771 env.close();
1772 checkMetrics(*this, env, 0, 8, 4, 4);
1773 }
1774 {
1775 // Replace a lone non-blocking tx with a blocker.
1776
1777 // Fill up the open ledger and put just one entry in the TxQ.
1778 env(noop(alice));
1779
1780 auto const aliceSeq = env.seq(alice);
1781 env(noop(alice), Seq(aliceSeq + 0), queued);
1782
1783 // Since there's only one entry in the queue we can replace
1784 // that entry with a blocker.
1785 env(regkey(alice, bob), Seq(aliceSeq + 0), Fee(baseFee * 2), queued);
1786
1787 // Now that there's a blocker in the queue we can't append to
1788 // the queue.
1789 env(noop(alice), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1790
1791 // Other accounts are unaffected.
1792 env(noop(bob), queued);
1793
1794 // We can replace the blocker with a different blocker.
1795 env(signers(alice, 2, {{bob}, {charlie}, {daria}}),
1796 Seq(aliceSeq + 0),
1797 Fee(baseFee * 2.6),
1798 queued);
1799
1800 // Prove that the queue is still blocked.
1801 env(noop(alice), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1802
1803 // We can replace the blocker with a non-blocker. Then we can
1804 // successfully append to the queue.
1805 env(noop(alice), Seq(aliceSeq + 0), Fee(baseFee * 3.3), queued);
1806 env(noop(alice), Seq(aliceSeq + 1), queued);
1807
1808 // Drain the queue.
1809 env.close();
1810 checkMetrics(*this, env, 0, 10, 3, 5);
1811 }
1812 {
1813 // Put a blocker in an empty queue.
1814
1815 // Fill up the open ledger and put a blocker as Alice's first
1816 // entry in the (empty) TxQ.
1817 env(noop(alice));
1818 env(noop(alice));
1819 env(noop(alice));
1820
1821 auto const aliceSeq = env.seq(alice);
1822 env(fset(alice, asfAccountTxnID), Seq(aliceSeq + 0), queued);
1823
1824 // Since there's a blocker in the queue we can't append to
1825 // the queue.
1826 env(noop(alice), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1827
1828 // Other accounts are unaffected.
1829 env(noop(bob), queued);
1830
1831 // We can replace the blocker with a non-blocker. Then we can
1832 // successfully append to the queue.
1833 env(noop(alice), Seq(aliceSeq + 0), Fee(baseFee * 2), queued);
1834 env(noop(alice), Seq(aliceSeq + 1), queued);
1835
1836 // Drain the queue.
1837 env.close();
1838 checkMetrics(*this, env, 0, 12, 3, 6);
1839 }
1840 }
1841
1842 void
1844 {
1845 using namespace jtx;
1846 testcase("blockers ticket");
1847
1848 auto const alice = Account("alice");
1849 auto bob = Account("bob");
1850 auto charlie = Account("charlie");
1851 auto daria = Account("daria");
1852
1853 auto const queued = Ter(terQUEUED);
1854
1856 auto const baseFee = env.current()->fees().base.drops();
1857
1858 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
1859
1860 env.fund(XRP(50000), noripple(alice, bob));
1861 env.memoize(charlie);
1862
1863 checkMetrics(*this, env, 0, std::nullopt, 2, 3);
1864
1865 std::uint32_t tkt{env.seq(alice) + 1};
1866 {
1867 // Cannot put a blocker in an account's queue if that queue
1868 // already holds two or more (non-blocker) entries.
1869
1870 // Fill up the open ledger
1871 env(ticket::create(alice, 250), Seq(tkt - 1));
1872 // Set a regular key just to clear the password spent flag
1873 env(regkey(alice, charlie));
1874 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
1875
1876 // Put two "normal" txs in the queue
1877 auto const aliceSeq = env.seq(alice);
1878 env(noop(alice), ticket::Use(tkt + 2), queued);
1879 env(noop(alice), ticket::Use(tkt + 1), queued);
1880
1881 // Can't replace either queued transaction with a blocker
1882 env(fset(alice, asfAccountTxnID),
1883 ticket::Use(tkt + 1),
1884 Fee(baseFee * 2),
1886
1887 env(regkey(alice, bob),
1888 ticket::Use(tkt + 2),
1889 Fee(baseFee * 2),
1891
1892 // Can't append a blocker to the queue.
1893 env(signers(alice, 2, {{bob}, {charlie}, {daria}}),
1894 Fee(baseFee * 2),
1896
1897 env(signers(alice, 2, {{bob}, {charlie}, {daria}}),
1898 ticket::Use(tkt + 0),
1899 Fee(baseFee * 2),
1901
1902 // Other accounts are not affected
1903 env(noop(bob), queued);
1904 checkMetrics(*this, env, 3, std::nullopt, 4, 3);
1905
1906 // Drain the queue and local transactions.
1907 env.close();
1908 checkMetrics(*this, env, 0, 8, 5, 4);
1909
1910 // Show that the local transactions have flushed through as well.
1911 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1912 env(noop(alice), ticket::Use(tkt + 0), Ter(tefNO_TICKET));
1913 env(noop(alice), ticket::Use(tkt + 1), Ter(tefNO_TICKET));
1914 env(noop(alice), ticket::Use(tkt + 2), Ter(tefNO_TICKET));
1915 tkt += 3;
1916 }
1917 {
1918 // Replace a lone non-blocking tx with a blocker.
1919
1920 // Put just one entry in the TxQ.
1921 auto const aliceSeq = env.seq(alice);
1922 env(noop(alice), ticket::Use(tkt + 0), queued);
1923
1924 // Since there's an entry in the queue we cannot append a
1925 // blocker to the account's queue.
1926 env(regkey(alice, bob), Fee(baseFee * 2), Ter(telCAN_NOT_QUEUE_BLOCKS));
1927 env(regkey(alice, bob),
1928 ticket::Use(tkt + 1),
1929 Fee(baseFee * 2),
1931
1932 // However we can _replace_ that lone entry with a blocker.
1933 env(regkey(alice, bob), ticket::Use(tkt + 0), Fee(baseFee * 2), queued);
1934
1935 // Now that there's a blocker in the queue we can't append to
1936 // the queue.
1937 env(noop(alice), Ter(telCAN_NOT_QUEUE_BLOCKED));
1938 env(noop(alice), ticket::Use(tkt + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1939
1940 // Other accounts are unaffected.
1941 env(noop(bob), queued);
1942
1943 // We can replace the blocker with a different blocker.
1944 env(signers(alice, 2, {{bob}, {charlie}, {daria}}),
1945 ticket::Use(tkt + 0),
1946 Fee(baseFee * 2.6),
1947 queued);
1948
1949 // Prove that the queue is still blocked.
1950 env(noop(alice), Ter(telCAN_NOT_QUEUE_BLOCKED));
1951 env(noop(alice), ticket::Use(tkt + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1952
1953 // We can replace the blocker with a non-blocker. Then we can
1954 // successfully append to the queue.
1955 env(noop(alice), ticket::Use(tkt + 0), Fee(baseFee * 3.3), queued);
1956 env(noop(alice), ticket::Use(tkt + 1), queued);
1957 env(noop(alice), Seq(aliceSeq), queued);
1958
1959 // Drain the queue.
1960 env.close();
1961 checkMetrics(*this, env, 0, 10, 4, 5);
1962
1963 // Show that the local transactions have flushed through as well.
1964 BEAST_EXPECT(env.seq(alice) == aliceSeq + 1);
1965 env(noop(alice), ticket::Use(tkt + 0), Ter(tefNO_TICKET));
1966 env(noop(alice), ticket::Use(tkt + 1), Ter(tefNO_TICKET));
1967 tkt += 2;
1968 }
1969 {
1970 // Put a blocker in an empty queue.
1971
1972 // Fill up the open ledger and put a blocker as Alice's first
1973 // entry in the (empty) TxQ.
1974 env(noop(alice));
1975 env(noop(alice));
1976
1977 env(fset(alice, asfAccountTxnID), ticket::Use(tkt + 2), queued);
1978
1979 // Since there's a blocker in the queue we can't append to
1980 // the queue.
1981 env(noop(alice), ticket::Use(tkt + 1), Ter(telCAN_NOT_QUEUE_BLOCKED));
1982
1983 // Other accounts are unaffected.
1984 env(noop(bob), queued);
1985
1986 // We can replace the blocker with a non-blocker. Then we can
1987 // successfully append to the queue.
1988 env(noop(alice), ticket::Use(tkt + 2), Fee(baseFee * 2), queued);
1989 env(noop(alice), ticket::Use(tkt + 1), queued);
1990
1991 // Drain the queue.
1992 env.close();
1993 checkMetrics(*this, env, 0, 12, 3, 6);
1994 }
1995 }
1996
1997 void
1999 {
2000 using namespace jtx;
2001 testcase("In-flight balance checks");
2002
2003 Env env(
2004 *this,
2005 makeConfig(
2007 {{Keys::kAccountReserve, "200"}, {Keys::kOwnerReserve, "50"}}));
2008
2009 auto const alice = Account("alice");
2010 auto const charlie = Account("charlie");
2011 auto const gw = Account("gw");
2012
2013 auto const queued = Ter(terQUEUED);
2014
2015 // Set the fee reserves _really_ low so transactions with fees
2016 // in the ballpark of the reserves can be queued. With default
2017 // reserves, a couple hundred transactions would have to be
2018 // queued before the open ledger fee approached the reserve,
2019 // which would unnecessarily slow down this test.
2020 // ledgers in queue is 2 because of makeConfig
2021 auto const initQueueMax = initFee(env, 3, 2, 10, 200, 50);
2022
2023 auto limit = 3;
2024
2025 checkMetrics(*this, env, 0, initQueueMax, 0, limit);
2026
2027 env.fund(XRP(50000), noripple(alice, charlie), gw);
2028 checkMetrics(*this, env, 0, initQueueMax, limit + 1, limit);
2029
2030 auto const usd = gw["USD"];
2031 auto const bux = gw["BUX"];
2032
2034 // Offer with high XRP out and low fee doesn't block
2035 auto aliceSeq = env.seq(alice);
2036 auto aliceBal = env.balance(alice);
2037
2038 env.require(Balance(alice, XRP(50000)), Owners(alice, 0));
2039
2040 // If this offer crosses, all of alice's
2041 // XRP will be taken (except the reserve).
2042 env(offer(alice, bux(5000), XRP(50000)), queued);
2043 checkMetrics(*this, env, 1, initQueueMax, limit + 1, limit);
2044
2045 // But because the reserve is protected, another
2046 // transaction will be allowed to queue
2047 env(noop(alice), Seq(aliceSeq + 1), queued);
2048 checkMetrics(*this, env, 2, initQueueMax, limit + 1, limit);
2049
2050 env.close();
2051 ++limit;
2052 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2053
2054 // But once we close the ledger, we find alice
2055 // has plenty of XRP, because the offer didn't
2056 // cross (of course).
2057 env.require(Balance(alice, aliceBal - drops(20)), Owners(alice, 1));
2058 // cancel the offer
2059 env(offerCancel(alice, aliceSeq));
2060
2062 // Offer with high XRP out and high total fee blocks later txs
2063 fillQueue(env, alice);
2064 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2065 aliceSeq = env.seq(alice);
2066 aliceBal = env.balance(alice);
2067
2068 env.require(Owners(alice, 0));
2069
2070 // Alice creates an offer with a fee of half the reserve
2071 env(offer(alice, bux(5000), XRP(50000)), Fee(drops(100)), queued);
2072 checkMetrics(*this, env, 1, limit * 2, limit + 1, limit);
2073
2074 // Alice creates another offer with a fee
2075 // that brings the total to just shy of the reserve
2076 env(noop(alice), Fee(drops(99)), Seq(aliceSeq + 1), queued);
2077 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2078
2079 // So even a noop will look like alice
2080 // doesn't have the balance to pay the fee
2081 env(noop(alice), Fee(drops(51)), Seq(aliceSeq + 2), Ter(terINSUF_FEE_B));
2082 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2083
2084 env.close();
2085 ++limit;
2086 checkMetrics(*this, env, 0, limit * 2, 3, limit);
2087
2088 // But once we close the ledger, we find alice
2089 // has plenty of XRP, because the offer didn't
2090 // cross (of course).
2091 env.require(Balance(alice, aliceBal - drops(250)), Owners(alice, 1));
2092 // cancel the offer
2093 env(offerCancel(alice, aliceSeq));
2094
2096 // Offer with high XRP out and super high fee blocks later txs
2097 fillQueue(env, alice);
2098 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2099 aliceSeq = env.seq(alice);
2100 aliceBal = env.balance(alice);
2101
2102 env.require(Owners(alice, 0));
2103
2104 // Alice creates an offer with a fee larger than the reserve
2105 // This one can queue because it's the first in the queue for alice
2106 env(offer(alice, bux(5000), XRP(50000)), Fee(drops(300)), queued);
2107 checkMetrics(*this, env, 1, limit * 2, limit + 1, limit);
2108
2109 // So even a noop will look like alice
2110 // doesn't have the balance to pay the fee
2111 env(noop(alice), Fee(drops(51)), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BALANCE));
2112 checkMetrics(*this, env, 1, limit * 2, limit + 1, limit);
2113
2114 env.close();
2115 ++limit;
2116 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2117
2118 // But once we close the ledger, we find alice
2119 // has plenty of XRP, because the offer didn't
2120 // cross (of course).
2121 env.require(Balance(alice, aliceBal - drops(351)), Owners(alice, 1));
2122 // cancel the offer
2123 env(offerCancel(alice, aliceSeq));
2124
2126 // Offer with low XRP out allows later txs
2127 fillQueue(env, alice);
2128 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2129 aliceSeq = env.seq(alice);
2130 aliceBal = env.balance(alice);
2131
2132 // If this offer crosses, just a bit
2133 // of alice's XRP will be taken.
2134 env(offer(alice, bux(50), XRP(500)), queued);
2135
2136 // And later transactions are just fine
2137 env(noop(alice), Seq(aliceSeq + 1), queued);
2138 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2139
2140 env.close();
2141 ++limit;
2142 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2143
2144 // But once we close the ledger, we find alice
2145 // has plenty of XRP, because the offer didn't
2146 // cross (of course).
2147 env.require(Balance(alice, aliceBal - drops(20)), Owners(alice, 1));
2148 // cancel the offer
2149 env(offerCancel(alice, aliceSeq));
2150
2152 // Large XRP payment doesn't block later txs
2153 fillQueue(env, alice);
2154 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2155
2156 aliceSeq = env.seq(alice);
2157 aliceBal = env.balance(alice);
2158
2159 // If this payment succeeds, alice will
2160 // send her entire balance to charlie
2161 // (minus the reserve).
2162 env(pay(alice, charlie, XRP(50000)), queued);
2163
2164 // But because the reserve is protected, another
2165 // transaction will be allowed to queue
2166 env(noop(alice), Seq(aliceSeq + 1), queued);
2167 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2168
2169 env.close();
2170 ++limit;
2171 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2172
2173 // But once we close the ledger, we find alice
2174 // still has most of her balance, because the
2175 // payment was unfunded!
2176 env.require(Balance(alice, aliceBal - drops(20)), Owners(alice, 0));
2177
2179 // Small XRP payment allows later txs
2180 fillQueue(env, alice);
2181 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2182
2183 aliceSeq = env.seq(alice);
2184 aliceBal = env.balance(alice);
2185
2186 // If this payment succeeds, alice will
2187 // send just a bit of balance to charlie
2188 env(pay(alice, charlie, XRP(500)), queued);
2189
2190 // And later transactions are just fine
2191 env(noop(alice), Seq(aliceSeq + 1), queued);
2192 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2193
2194 env.close();
2195 ++limit;
2196 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2197
2198 // The payment succeeds
2199 env.require(Balance(alice, aliceBal - XRP(500) - drops(20)), Owners(alice, 0));
2200
2202 // Large IOU payment allows later txs
2203 auto const amount = usd(500000);
2204 env(trust(alice, usd(50000000)));
2205 env(trust(charlie, usd(50000000)));
2206 checkMetrics(*this, env, 0, limit * 2, 4, limit);
2207 // Close so we don't have to deal
2208 // with tx ordering in consensus.
2209 env.close();
2210
2211 env(pay(gw, alice, amount));
2212 checkMetrics(*this, env, 0, limit * 2, 1, limit);
2213 // Close so we don't have to deal
2214 // with tx ordering in consensus.
2215 env.close();
2216
2217 fillQueue(env, alice);
2218 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2219
2220 aliceSeq = env.seq(alice);
2221 aliceBal = env.balance(alice);
2222 auto const aliceUSD = env.balance(alice, usd);
2223
2224 // If this payment succeeds, alice will
2225 // send her entire USD balance to charlie.
2226 env(pay(alice, charlie, amount), queued);
2227
2228 // But that's fine, because it doesn't affect
2229 // alice's XRP balance (other than the fee, of course).
2230 env(noop(alice), Seq(aliceSeq + 1), queued);
2231 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2232
2233 env.close();
2234 ++limit;
2235 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2236
2237 // So once we close the ledger, alice has her
2238 // XRP balance, but her USD balance went to charlie.
2239 env.require(
2240 Balance(alice, aliceBal - drops(20)),
2241 Balance(alice, usd(0)),
2242 Balance(charlie, aliceUSD),
2243 Owners(alice, 1),
2244 Owners(charlie, 1));
2245
2247 // Large XRP to IOU payment doesn't block later txs.
2248
2249 env(offer(gw, XRP(500000), usd(50000)));
2250 // Close so we don't have to deal
2251 // with tx ordering in consensus.
2252 env.close();
2253
2254 fillQueue(env, charlie);
2255 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2256
2257 aliceSeq = env.seq(alice);
2258 aliceBal = env.balance(alice);
2259 auto charlieUSD = env.balance(charlie, usd);
2260
2261 // If this payment succeeds, and uses the
2262 // entire sendMax, alice will send her
2263 // entire XRP balance to charlie in the
2264 // form of USD.
2265 BEAST_EXPECT(XRP(60000) > aliceBal);
2266 env(pay(alice, charlie, usd(1000)), Sendmax(XRP(60000)), queued);
2267
2268 // But because the reserve is protected, another
2269 // transaction will be allowed to queue
2270 env(noop(alice), Seq(aliceSeq + 1), queued);
2271 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2272
2273 env.close();
2274 ++limit;
2275 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2276
2277 // So once we close the ledger, alice sent a payment
2278 // to charlie using only a portion of her XRP balance
2279 env.require(
2280 Balance(alice, aliceBal - XRP(10000) - drops(20)),
2281 Balance(alice, usd(0)),
2282 Balance(charlie, charlieUSD + usd(1000)),
2283 Owners(alice, 1),
2284 Owners(charlie, 1));
2285
2287 // Small XRP to IOU payment allows later txs.
2288
2289 fillQueue(env, charlie);
2290 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2291
2292 aliceSeq = env.seq(alice);
2293 aliceBal = env.balance(alice);
2294 charlieUSD = env.balance(charlie, usd);
2295
2296 // If this payment succeeds, and uses the
2297 // entire sendMax, alice will only send
2298 // a portion of her XRP balance to charlie
2299 // in the form of USD.
2300 BEAST_EXPECT(aliceBal > XRP(6001));
2301 env(pay(alice, charlie, usd(500)), Sendmax(XRP(6000)), queued);
2302
2303 // And later transactions are just fine
2304 env(noop(alice), Seq(aliceSeq + 1), queued);
2305 checkMetrics(*this, env, 2, limit * 2, limit + 1, limit);
2306
2307 env.close();
2308 ++limit;
2309 checkMetrics(*this, env, 0, limit * 2, 2, limit);
2310
2311 // So once we close the ledger, alice sent a payment
2312 // to charlie using only a portion of her XRP balance
2313 env.require(
2314 Balance(alice, aliceBal - XRP(5000) - drops(20)),
2315 Balance(alice, usd(0)),
2316 Balance(charlie, charlieUSD + usd(500)),
2317 Owners(alice, 1),
2318 Owners(charlie, 1));
2319
2321 // Edge case: what happens if the balance is below the reserve?
2322 env(noop(alice), Fee(env.balance(alice) - drops(30)));
2323 env.close();
2324
2325 fillQueue(env, charlie);
2326 checkMetrics(*this, env, 0, limit * 2, limit + 1, limit);
2327
2328 aliceSeq = env.seq(alice);
2329 aliceBal = env.balance(alice);
2330 BEAST_EXPECT(aliceBal == drops(30));
2331
2332 env(noop(alice), Fee(drops(25)), queued);
2333 env(noop(alice), Seq(aliceSeq + 1), Ter(terINSUF_FEE_B));
2334 BEAST_EXPECT(env.balance(alice) == drops(30));
2335
2336 checkMetrics(*this, env, 1, limit * 2, limit + 1, limit);
2337
2338 env.close();
2339 ++limit;
2340 checkMetrics(*this, env, 0, limit * 2, 1, limit);
2341 BEAST_EXPECT(env.balance(alice) == drops(5));
2342 }
2343
2344 void
2346 {
2347 using namespace jtx;
2348 testcase("disallow sponsored transaction from being queued");
2349
2351
2352 auto const sponsor = Account("sponsor");
2353 auto const sponsee = Account("sponsee");
2354 auto const filler = Account("filler");
2355
2356 env.fund(XRP(50000), noripple(sponsor, sponsee));
2357 env.close();
2358 env.fund(XRP(50000), noripple(filler));
2359 env.close();
2360
2361 fillQueue(env, filler);
2362 checkMetrics(*this, env, 0, 6, 4, 3);
2363
2364 // Sponsored transactions are not allowed to be queued.
2365 env(noop(sponsee),
2367 Sig(sfSponsorSignature, sponsor),
2369 checkMetrics(*this, env, 0, 6, 4, 3);
2370
2371 // Sponsored transactions may still apply directly if they pay the
2372 // open ledger fee. They just cannot be held in the queue.
2373 env(noop(sponsee),
2375 Sig(sfSponsorSignature, sponsor),
2376 Fee(openLedgerCost(env)),
2377 Ter(tesSUCCESS));
2378 checkMetrics(*this, env, 0, 6, 5, 3);
2379 }
2380
2381 void
2383 {
2384 using namespace jtx;
2385 testcase("disallow delegate transaction from being queued");
2386
2388
2389 auto const alice = Account("alice");
2390 auto const bob = Account("bob");
2391 auto const carol = Account("carol");
2392
2393 env.fund(XRP(50000), alice, bob);
2394 env.close();
2395 env.fund(XRP(50000), carol);
2396 env.close();
2397
2398 env(delegate::set(alice, bob, {"Payment"}));
2399 env.close();
2400
2401 fillQueue(env, alice);
2402 checkMetrics(*this, env, 0, 8, 5, 4);
2403
2404 // Delegated transactions are not allowed to be queued.
2405 env(pay(alice, carol, drops(1)), delegate::As(bob), Ter(telCAN_NOT_QUEUE));
2406 checkMetrics(*this, env, 0, 8, 5, 4);
2407
2408 // Delegated transactions may still apply directly if they pay the
2409 // open ledger fee. They just cannot be held in the queue.
2410 env(pay(alice, carol, drops(1)),
2411 delegate::As(bob),
2412 Fee(openLedgerCost(env)),
2413 Ter(tesSUCCESS));
2414 checkMetrics(*this, env, 0, 8, 6, 4);
2415 }
2416
2417 void
2419 {
2420 using namespace jtx;
2421 using namespace std::chrono;
2422 testcase("consequences");
2423
2424 Env env(*this);
2425 auto const alice = Account("alice");
2426 env.memoize(alice);
2427 env.memoize("bob");
2428 env.memoize("carol");
2429 {
2430 auto const jtx = env.jt(offerCancel(alice, 3), Seq(5), Fee(10));
2431 auto const pf =
2432 preflight(env.app(), env.current()->rules(), *jtx.stx, TapNone, env.journal);
2433 BEAST_EXPECT(isTesSuccess(pf.ter));
2434 BEAST_EXPECT(!pf.consequences.isBlocker());
2435 BEAST_EXPECT(pf.consequences.fee() == drops(10));
2436 BEAST_EXPECT(pf.consequences.potentialSpend() == XRP(0));
2437 }
2438
2439 {
2440 auto const usd = alice["USD"];
2441
2442 auto const jtx = env.jt(trust("carol", usd(50000000)), Seq(1), Fee(10));
2443 auto const pf =
2444 preflight(env.app(), env.current()->rules(), *jtx.stx, TapNone, env.journal);
2445 BEAST_EXPECT(isTesSuccess(pf.ter));
2446 BEAST_EXPECT(!pf.consequences.isBlocker());
2447 BEAST_EXPECT(pf.consequences.fee() == drops(10));
2448 BEAST_EXPECT(pf.consequences.potentialSpend() == XRP(0));
2449 }
2450
2451 {
2452 auto const jtx = env.jt(ticket::create(alice, 1), Seq(1), Fee(10));
2453 auto const pf =
2454 preflight(env.app(), env.current()->rules(), *jtx.stx, TapNone, env.journal);
2455 BEAST_EXPECT(isTesSuccess(pf.ter));
2456 BEAST_EXPECT(!pf.consequences.isBlocker());
2457 BEAST_EXPECT(pf.consequences.fee() == drops(10));
2458 BEAST_EXPECT(pf.consequences.potentialSpend() == XRP(0));
2459 }
2460 }
2461
2462 void
2464 {
2465 // It is possible for an account to be present in the queue but have
2466 // no queued transactions. This has been the source of at least one
2467 // bug where an insufficiently informed developer assumed that if an
2468 // account was present in the queue then it also had at least one
2469 // queued transaction.
2470 //
2471 // This test does touch testing to verify that, at least, that bug
2472 // is addressed.
2473 using namespace jtx;
2474 testcase("acct in queue but empty");
2475
2476 auto const alice = Account("alice");
2477 auto const bob = Account("bob");
2478 auto const charlie = Account("charlie");
2479
2480 auto const queued = Ter(terQUEUED);
2481
2483 auto const baseFee = env.current()->fees().base.drops();
2484
2485 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
2486
2487 // Fund accounts while the fee is cheap so they all apply.
2488 env.fund(XRP(50000), noripple(alice, bob, charlie));
2489 checkMetrics(*this, env, 0, std::nullopt, 3, 3);
2490
2491 // Alice - no fee change yet
2492 env(noop(alice));
2493 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
2494
2495 // Bob with really high fee - applies
2496 env(noop(bob), Fee(openLedgerCost(env)));
2497 checkMetrics(*this, env, 0, std::nullopt, 5, 3);
2498
2499 // Charlie with low fee: queued
2500 env(noop(charlie), Fee(baseFee * 100), queued);
2501 checkMetrics(*this, env, 1, std::nullopt, 5, 3);
2502
2503 env.close();
2504 // Verify that the queued transaction was applied
2505 checkMetrics(*this, env, 0, 10, 1, 5);
2506
2508
2509 // Stuff the ledger and queue so we can verify that
2510 // stuff gets kicked out.
2511 env(noop(bob), Fee(baseFee * 100));
2512 env(noop(bob), Fee(baseFee * 100));
2513 env(noop(bob), Fee(baseFee * 100));
2514 env(noop(bob), Fee(baseFee * 100));
2515 env(noop(bob), Fee(baseFee * 100));
2516 checkMetrics(*this, env, 0, 10, 6, 5);
2517
2518 // Use explicit fees so we can control which txn
2519 // will get dropped
2520 // This one gets into the queue, but gets dropped when the
2521 // higher fee one is added later.
2522 std::uint32_t const charlieSeq{env.seq(charlie)};
2523 env(noop(charlie), Fee(baseFee * 1.5), Seq(charlieSeq), queued);
2524 auto const expectedFeeLevel = txFeeLevelByAccount(env, charlie);
2525
2526 // These stay in the queue.
2527 std::uint32_t aliceSeq{env.seq(alice)};
2528 std::uint32_t bobSeq{env.seq(bob)};
2529
2530 env(noop(alice), Fee(baseFee * 1.6), Seq(aliceSeq++), queued);
2531 env(noop(bob), Fee(baseFee * 1.6), Seq(bobSeq++), queued);
2532 env(noop(alice), Fee(baseFee * 1.7), Seq(aliceSeq++), queued);
2533 env(noop(bob), Fee(baseFee * 1.7), Seq(bobSeq++), queued);
2534 env(noop(alice), Fee(baseFee * 1.8), Seq(aliceSeq++), queued);
2535 env(noop(bob), Fee(baseFee * 1.9), Seq(bobSeq++), queued);
2536 env(noop(alice), Fee(baseFee * 2), Seq(aliceSeq++), queued);
2537 env(noop(bob), Fee(baseFee * 2), Seq(bobSeq++), queued);
2538 env(noop(alice), Fee(baseFee * 2.1), Seq(aliceSeq++), queued);
2539
2540 // Queue is full now.
2541 checkMetrics(*this, env, 10, 10, 6, 5, expectedFeeLevel + 1);
2542
2543 // Try to add another transaction with the default (low) fee,
2544 // it should fail because the queue is full.
2545 env(noop(alice), Seq(aliceSeq++), Ter(telCAN_NOT_QUEUE_FULL));
2546
2547 // Add another transaction, with a higher fee,
2548 // not high enough to get into the ledger, but high
2549 // enough to get into the queue (and kick Charlie's out)
2550 env(noop(bob), Fee(baseFee * 2.2), Seq(bobSeq++), queued);
2551
2553
2554 // That was the setup for the actual test :-). Now make
2555 // sure we get the right results if we try to add a
2556 // transaction for Charlie (who's in the queue, but has no queued
2557 // transactions) with the wrong sequence numbers.
2558 //
2559 // Charlie is paying a high enough fee to go straight into the
2560 // ledger in order to get into the vicinity of an assert which
2561 // should no longer fire :-).
2562 env(noop(charlie), Fee(baseFee * 800), Seq(charlieSeq - 1), Ter(tefPAST_SEQ));
2563 env(noop(charlie), Fee(baseFee * 800), Seq(charlieSeq + 1), Ter(terPRE_SEQ));
2564 env(noop(charlie), Fee(baseFee * 800), Seq(charlieSeq), Ter(tesSUCCESS));
2565 }
2566
2567 void
2569 {
2570 using namespace jtx;
2571 testcase("rpc");
2572
2573 Env env(*this);
2574
2575 auto fee = env.rpc("fee");
2576
2577 if (BEAST_EXPECT(fee.isMember(jss::result)) &&
2578 BEAST_EXPECT(!rpc::containsError(fee[jss::result])))
2579 {
2580 auto const& result = fee[jss::result];
2581 BEAST_EXPECT(
2582 result.isMember(jss::ledger_current_index) &&
2583 result[jss::ledger_current_index] == 3);
2584 BEAST_EXPECT(result.isMember(jss::current_ledger_size));
2585 BEAST_EXPECT(result.isMember(jss::current_queue_size));
2586 BEAST_EXPECT(result.isMember(jss::expected_ledger_size));
2587 BEAST_EXPECT(!result.isMember(jss::max_queue_size));
2588 BEAST_EXPECT(result.isMember(jss::drops));
2589 auto const& drops = result[jss::drops];
2590 BEAST_EXPECT(drops.isMember(jss::base_fee));
2591 BEAST_EXPECT(drops.isMember(jss::median_fee));
2592 BEAST_EXPECT(drops.isMember(jss::minimum_fee));
2593 BEAST_EXPECT(drops.isMember(jss::open_ledger_fee));
2594 BEAST_EXPECT(result.isMember(jss::levels));
2595 auto const& levels = result[jss::levels];
2596 BEAST_EXPECT(levels.isMember(jss::median_level));
2597 BEAST_EXPECT(levels.isMember(jss::minimum_level));
2598 BEAST_EXPECT(levels.isMember(jss::open_ledger_level));
2599 BEAST_EXPECT(levels.isMember(jss::reference_level));
2600 }
2601
2602 env.close();
2603
2604 fee = env.rpc("fee");
2605
2606 if (BEAST_EXPECT(fee.isMember(jss::result)) &&
2607 BEAST_EXPECT(!rpc::containsError(fee[jss::result])))
2608 {
2609 auto const& result = fee[jss::result];
2610 BEAST_EXPECT(
2611 result.isMember(jss::ledger_current_index) &&
2612 result[jss::ledger_current_index] == 4);
2613 BEAST_EXPECT(result.isMember(jss::current_ledger_size));
2614 BEAST_EXPECT(result.isMember(jss::current_queue_size));
2615 BEAST_EXPECT(result.isMember(jss::expected_ledger_size));
2616 BEAST_EXPECT(result.isMember(jss::max_queue_size));
2617 auto const& drops = result[jss::drops];
2618 BEAST_EXPECT(drops.isMember(jss::base_fee));
2619 BEAST_EXPECT(drops.isMember(jss::median_fee));
2620 BEAST_EXPECT(drops.isMember(jss::minimum_fee));
2621 BEAST_EXPECT(drops.isMember(jss::open_ledger_fee));
2622 BEAST_EXPECT(result.isMember(jss::levels));
2623 auto const& levels = result[jss::levels];
2624 BEAST_EXPECT(levels.isMember(jss::median_level));
2625 BEAST_EXPECT(levels.isMember(jss::minimum_level));
2626 BEAST_EXPECT(levels.isMember(jss::open_ledger_level));
2627 BEAST_EXPECT(levels.isMember(jss::reference_level));
2628 }
2629 }
2630
2631 void
2633 {
2634 /* This test is based on a reported regression where a
2635 replacement candidate transaction found the tx it was trying
2636 to replace did not have `consequences` set
2637
2638 Hypothesis: The queue had '22 through '25. At some point(s),
2639 both the original '22 and '23 expired and were removed from
2640 the queue. A second '22 was submitted, and the multi-tx logic
2641 did not kick in, because it matched the account's sequence
2642 number (a_seq == t_seq). The third '22 was submitted and found
2643 the '22 in the queue did not have consequences.
2644 */
2645 using namespace jtx;
2646 testcase("expiration replacement");
2647
2648 Env env(
2649 *this,
2650 makeConfig({
2652 {Keys::kLedgersInQueue, "10"},
2654 }));
2655
2656 auto const baseFee = env.current()->fees().base.drops();
2657
2658 // Alice will recreate the scenario. Bob will block.
2659 auto const alice = Account("alice");
2660 auto const bob = Account("bob");
2661
2662 env.fund(XRP(500000), noripple(alice, bob));
2663 checkMetrics(*this, env, 0, std::nullopt, 2, 1);
2664
2665 auto const aliceSeq = env.seq(alice);
2666 BEAST_EXPECT(env.current()->header().seq == 3);
2667 env(noop(alice), Seq(aliceSeq), LastLedgerSeq(5), Ter(terQUEUED));
2668 env(noop(alice), Seq(aliceSeq + 1), LastLedgerSeq(5), Ter(terQUEUED));
2669 env(noop(alice), Seq(aliceSeq + 2), LastLedgerSeq(10), Ter(terQUEUED));
2670 env(noop(alice), Seq(aliceSeq + 3), LastLedgerSeq(11), Ter(terQUEUED));
2671 checkMetrics(*this, env, 4, std::nullopt, 2, 1);
2672 auto const bobSeq = env.seq(bob);
2673 // Ledger 4 gets 3,
2674 // Ledger 5 gets 4,
2675 // Ledger 6 gets 5.
2676 for (int i = 0; i < 3 + 4 + 5; ++i)
2677 {
2678 env(noop(bob), Seq(bobSeq + i), Fee(baseFee * 20), Ter(terQUEUED));
2679 }
2680 checkMetrics(*this, env, 4 + 3 + 4 + 5, std::nullopt, 2, 1);
2681 // Close ledger 3
2682 env.close();
2683 checkMetrics(*this, env, 4 + 4 + 5, 20, 3, 2);
2684 // Close ledger 4
2685 env.close();
2686 checkMetrics(*this, env, 4 + 5, 30, 4, 3);
2687 // Close ledger 5
2688 env.close();
2689 // Alice's first two txs expired.
2690 checkMetrics(*this, env, 2, 40, 5, 4);
2691
2692 // Because aliceSeq is missing, aliceSeq + 1 fails
2693 env(noop(alice), Seq(aliceSeq + 1), Ter(terPRE_SEQ));
2694
2695 // Cannot fill the gap with a blocker since Alice's queue is not empty.
2696 env(fset(alice, asfAccountTxnID), Seq(aliceSeq), Ter(telCAN_NOT_QUEUE_BLOCKS));
2697 checkMetrics(*this, env, 2, 40, 5, 4);
2698
2699 // However we can fill the gap with a non-blocker.
2700 env(noop(alice), Seq(aliceSeq), Fee(baseFee * 2), Ter(terQUEUED));
2701 checkMetrics(*this, env, 3, 40, 5, 4);
2702
2703 // Attempt to queue up a new aliceSeq + 1 tx that's a blocker.
2704 env(fset(alice, asfAccountTxnID), Seq(aliceSeq + 1), Ter(telCAN_NOT_QUEUE_BLOCKS));
2705 checkMetrics(*this, env, 3, 40, 5, 4);
2706
2707 // Queue up a non-blocker replacement for aliceSeq + 1.
2708 env(noop(alice), Seq(aliceSeq + 1), Fee(baseFee * 2), Ter(terQUEUED));
2709 checkMetrics(*this, env, 4, 40, 5, 4);
2710
2711 // Close ledger 6
2712 env.close();
2713 // We expect that all of alice's queued tx's got into
2714 // the open ledger.
2715 checkMetrics(*this, env, 0, 50, 4, 5);
2716 BEAST_EXPECT(env.seq(alice) == aliceSeq + 4);
2717 }
2718
2719 void
2721 {
2722 // This test focuses on which gaps in queued transactions are
2723 // allowed to be filled even when the account's queue is full.
2724
2725 // NOTE: This test is fragile and dependent on ordering of
2726 // transactions, which is affected by the closed/validated
2727 // ledger hash. This test may need to be edited if changes
2728 // are made that impact the ledger hash.
2729 // TODO: future-proof this test.
2730 using namespace jtx;
2731 testcase("full queue gap handling");
2732
2733 auto cfg = makeConfig({
2735 {Keys::kLedgersInQueue, "10"},
2737 });
2738 cfg->fees.referenceFee = 10;
2739 Env env(*this, std::move(cfg));
2740
2741 auto const baseFee = env.current()->fees().base.drops();
2742
2743 // Alice will have the gaps. Bob will keep the queue busy with
2744 // high fee transactions so alice's transactions can expire to leave
2745 // gaps.
2746 auto const alice = Account("alice");
2747 auto const bob = Account("bob");
2748
2749 env.fund(XRP(500000), noripple(alice, bob));
2750 checkMetrics(*this, env, 0, std::nullopt, 2, 1);
2751
2752 auto const aliceSeq = env.seq(alice);
2753 BEAST_EXPECT(env.current()->header().seq == 3);
2754
2755 // Start by procuring tickets for alice to use to keep her queue full
2756 // without affecting the sequence gap that will appear later.
2757 env(ticket::create(alice, 11), Seq(aliceSeq + 0), Fee((baseFee * 20) + 1), Ter(terQUEUED));
2758 env(noop(alice), Seq(aliceSeq + 11), LastLedgerSeq(11), Ter(terQUEUED));
2759 env(noop(alice), Seq(aliceSeq + 12), LastLedgerSeq(11), Ter(terQUEUED));
2760 env(noop(alice), Seq(aliceSeq + 13), LastLedgerSeq(11), Ter(terQUEUED));
2761 env(noop(alice), Seq(aliceSeq + 14), LastLedgerSeq(11), Ter(terQUEUED));
2762 env(noop(alice), Seq(aliceSeq + 15), LastLedgerSeq(11), Ter(terQUEUED));
2763 env(noop(alice), Seq(aliceSeq + 16), LastLedgerSeq(5), Ter(terQUEUED));
2764 env(noop(alice), Seq(aliceSeq + 17), LastLedgerSeq(5), Ter(terQUEUED));
2765 env(noop(alice), Seq(aliceSeq + 18), LastLedgerSeq(5), Ter(terQUEUED));
2766 env(noop(alice), Seq(aliceSeq + 19), LastLedgerSeq(11), Ter(terQUEUED));
2767 checkMetrics(*this, env, 10, std::nullopt, 2, 1);
2768
2769 auto const bobSeq = env.seq(bob);
2770 // Ledger 4 gets 2 from bob and 1 from alice,
2771 // Ledger 5 gets 4 from bob,
2772 // Ledger 6 gets 5 from bob.
2773 for (int i = 0; i < 2 + 4 + 5; ++i)
2774 {
2775 env(noop(bob), Seq(bobSeq + i), Fee(baseFee * 20), Ter(terQUEUED));
2776 }
2777 checkMetrics(*this, env, 10 + 2 + 4 + 5, std::nullopt, 2, 1);
2778 // Close ledger 3
2779 env.close();
2780 checkMetrics(*this, env, 9 + 4 + 5, 20, 3, 2);
2781 BEAST_EXPECT(env.seq(alice) == aliceSeq + 12);
2782
2783 // Close ledger 4
2784 env.close();
2785 checkMetrics(*this, env, 9 + 5, 30, 4, 3);
2786 BEAST_EXPECT(env.seq(alice) == aliceSeq + 12);
2787
2788 // Close ledger 5
2789 env.close();
2790 // Three of Alice's txs expired.
2791 checkMetrics(*this, env, 6, 40, 5, 4);
2792 BEAST_EXPECT(env.seq(alice) == aliceSeq + 12);
2793
2794 // Top off Alice's queue again using Tickets so the sequence gap is
2795 // unaffected.
2796 env(noop(alice), ticket::Use(aliceSeq + 1), Ter(terQUEUED));
2797 env(noop(alice), ticket::Use(aliceSeq + 2), Ter(terQUEUED));
2798 env(noop(alice), ticket::Use(aliceSeq + 3), Ter(terQUEUED));
2799 env(noop(alice), ticket::Use(aliceSeq + 4), Ter(terQUEUED));
2800 env(noop(alice), ticket::Use(aliceSeq + 5), Ter(terQUEUED));
2801 env(noop(alice), ticket::Use(aliceSeq + 6), Ter(telCAN_NOT_QUEUE_FULL));
2802 checkMetrics(*this, env, 11, 40, 5, 4);
2803
2804 // Even though alice's queue is full we can still slide in a couple
2805 // more transactions because she has a sequence gap. But we
2806 // can only install a transaction that fills the bottom of the gap.
2807 // Explore that...
2808
2809 // Verify that we can't queue a sequence-based transaction that
2810 // follows a gap.
2811 env(noop(alice), Seq(aliceSeq + 20), Ter(telCAN_NOT_QUEUE_FULL));
2812
2813 // Verify that the transaction in front of the gap is still present
2814 // by attempting to replace it without a sufficient fee.
2815 env(noop(alice), Seq(aliceSeq + 15), Ter(telCAN_NOT_QUEUE_FEE));
2816
2817 // We can't queue a transaction into the middle of the gap. It must
2818 // go at the front.
2819 env(noop(alice), Seq(aliceSeq + 18), Ter(telCAN_NOT_QUEUE_FULL));
2820 env(noop(alice), Seq(aliceSeq + 17), Ter(telCAN_NOT_QUEUE_FULL));
2821
2822 // Successfully put this transaction into the front of the gap.
2823 env(noop(alice), Seq(aliceSeq + 16), Ter(terQUEUED));
2824
2825 // Still can't put a sequence-based transaction at the end of the gap.
2826 env(noop(alice), Seq(aliceSeq + 18), Ter(telCAN_NOT_QUEUE_FULL));
2827
2828 // But we can still fill the gap from the front.
2829 env(noop(alice), Seq(aliceSeq + 17), Ter(terQUEUED));
2830
2831 // Finally we can fill in the entire gap.
2832 env(noop(alice), Seq(aliceSeq + 18), Ter(terQUEUED));
2833 checkMetrics(*this, env, 14, 40, 5, 4);
2834
2835 // Verify that nothing can be added now that the gap is filled.
2836 env(noop(alice), Seq(aliceSeq + 20), Ter(telCAN_NOT_QUEUE_FULL));
2837
2838 // Close ledger 6. That removes some of alice's transactions,
2839 // but alice adds some more transaction(s) so expectedCount
2840 // may not reduce to 8.
2841 env.close();
2842 checkMetrics(*this, env, 9, 50, 6, 5);
2843 BEAST_EXPECTS(
2844 env.seq(alice) == aliceSeq + 16,
2845 "alice: " + std::to_string(aliceSeq + 16) + ", " + std::to_string(env.seq(alice)));
2846
2847 // Close ledger 7. That should remove 3 more of alice's transactions.
2848 env.close();
2849 checkMetrics(*this, env, 2, 60, 7, 6);
2850 BEAST_EXPECTS(
2851 env.seq(alice) == aliceSeq + 19,
2852 "alice: " + std::to_string(aliceSeq + 19) + ", " + std::to_string(env.seq(alice)));
2853
2854 // Close one last ledger to see all of alice's transactions moved
2855 // into the ledger, including the tickets
2856 env.close();
2857 checkMetrics(*this, env, 0, 70, 2, 7);
2858 BEAST_EXPECTS(
2859 env.seq(alice) == aliceSeq + 21,
2860 "alice: " + std::to_string(aliceSeq + 21) + ", " + std::to_string(env.seq(alice)));
2861 }
2862
2863 void
2865 {
2866 testcase("Autofilled sequence should account for TxQ");
2867 using namespace jtx;
2869 auto const baseFee = env.current()->fees().base.drops();
2870 EnvSs envs(env);
2871 auto const& txQ = env.app().getTxQ();
2872
2873 auto const alice = Account("alice");
2874 auto const bob = Account("bob");
2875 env.fund(XRP(100000), alice, bob);
2876
2877 fillQueue(env, alice);
2878 checkMetrics(*this, env, 0, std::nullopt, 7, 6);
2879
2880 // Queue up several transactions for alice sign-and-submit
2881 auto const aliceSeq = env.seq(alice);
2882 auto const lastLedgerSeq = env.current()->header().seq + 2;
2883
2884 auto const submitParams = json::Value(json::ValueType::Object);
2885 for (int i = 0; i < 5; ++i)
2886 {
2887 if (i == 2)
2888 {
2889 envs(
2890 noop(alice),
2891 Fee(baseFee * 100),
2892 Seq(kNone),
2893 Json(jss::LastLedgerSequence, lastLedgerSeq),
2894 Ter(terQUEUED))(submitParams);
2895 }
2896 else
2897 {
2898 envs(noop(alice), Fee(baseFee * 100), Seq(kNone), Ter(terQUEUED))(submitParams);
2899 }
2900 }
2901 checkMetrics(*this, env, 5, std::nullopt, 7, 6);
2902 {
2903 auto const aliceStat = txQ.getAccountTxs(alice.id());
2904 SeqProxy seq = SeqProxy::rawSequence(aliceSeq);
2905 BEAST_EXPECT(aliceStat.size() == 5);
2906 for (auto const& tx : aliceStat)
2907 {
2908 BEAST_EXPECT(tx.seqProxy == seq);
2909 BEAST_EXPECT(tx.feeLevel == FeeLevel64{kBaseFeeLevel.fee() * 100});
2910 if (seq.value() == aliceSeq + 2)
2911 {
2912 BEAST_EXPECT(tx.lastValid && *tx.lastValid == lastLedgerSeq);
2913 }
2914 else
2915 {
2916 BEAST_EXPECT(!tx.lastValid);
2917 }
2918 seq.advanceBy(1);
2919 }
2920 }
2921 // Put some txs in the queue for bob.
2922 // Give them a higher fee so they'll beat alice's.
2923 for (int i = 0; i < 8; ++i)
2924 envs(noop(bob), Fee(baseFee * 200), Seq(kNone), Ter(terQUEUED))();
2925 checkMetrics(*this, env, 13, std::nullopt, 7, 6);
2926
2927 env.close();
2928 checkMetrics(*this, env, 5, 14, 8, 7);
2929 // Put some more txs in the queue for bob.
2930 // Give them a higher fee so they'll beat alice's.
2931 fillQueue(env, bob);
2932 for (int i = 0; i < 9; ++i)
2933 envs(noop(bob), Fee(baseFee * 200), Seq(kNone), Ter(terQUEUED))();
2934 checkMetrics(*this, env, 14, 14, 8, 7, 25601);
2935 env.close();
2936 // Put some more txs in the queue for bob.
2937 // Give them a higher fee so they'll beat alice's.
2938 fillQueue(env, bob);
2939 for (int i = 0; i < 10; ++i)
2940 envs(noop(bob), Fee(baseFee * 200), Seq(kNone), Ter(terQUEUED))();
2941 checkMetrics(*this, env, 15, 16, 9, 8);
2942 env.close();
2943 checkMetrics(*this, env, 4, 18, 10, 9);
2944 {
2945 // Bob has nothing left in the queue.
2946 auto const bobStat = txQ.getAccountTxs(bob.id());
2947 BEAST_EXPECT(bobStat.empty());
2948 }
2949 // Verify alice's tx got dropped as we BEAST_EXPECT, and that there's
2950 // a gap in her queued txs.
2951 {
2952 auto const aliceStat = txQ.getAccountTxs(alice.id());
2953 auto seq = aliceSeq;
2954 BEAST_EXPECT(aliceStat.size() == 4);
2955 for (auto const& tx : aliceStat)
2956 {
2957 // Skip over the missing one.
2958 if (seq == aliceSeq + 2)
2959 ++seq;
2960
2961 BEAST_EXPECT(tx.seqProxy.isSeq() && tx.seqProxy.value() == seq);
2962 BEAST_EXPECT(tx.feeLevel == FeeLevel64{kBaseFeeLevel.fee() * 100});
2963 BEAST_EXPECT(!tx.lastValid);
2964 ++seq;
2965 }
2966 }
2967 // Now, fill the gap.
2968 envs(noop(alice), Fee(baseFee * 100), Seq(kNone), Ter(terQUEUED))(submitParams);
2969 checkMetrics(*this, env, 5, 18, 10, 9);
2970 {
2971 auto const aliceStat = txQ.getAccountTxs(alice.id());
2972 auto seq = aliceSeq;
2973 BEAST_EXPECT(aliceStat.size() == 5);
2974 for (auto const& tx : aliceStat)
2975 {
2976 BEAST_EXPECT(tx.seqProxy.isSeq() && tx.seqProxy.value() == seq);
2977 BEAST_EXPECT(tx.feeLevel == FeeLevel64{kBaseFeeLevel * 100});
2978 BEAST_EXPECT(!tx.lastValid);
2979 ++seq;
2980 }
2981 }
2982
2983 env.close();
2984 checkMetrics(*this, env, 0, 20, 5, 10);
2985 {
2986 // Bob's data has been cleaned up.
2987 auto const bobStat = txQ.getAccountTxs(bob.id());
2988 BEAST_EXPECT(bobStat.empty());
2989 }
2990 {
2991 auto const aliceStat = txQ.getAccountTxs(alice.id());
2992 BEAST_EXPECT(aliceStat.empty());
2993 }
2994 }
2995
2996 void
2998 {
2999 using namespace jtx;
3000 testcase("account info");
3001
3003 auto const baseFee = env.current()->fees().base.drops();
3004 EnvSs envs(env);
3005
3006 Account const alice{"alice"};
3007 env.fund(XRP(1000000), alice);
3008 env.close();
3009
3010 json::Value withQueue;
3011 withQueue[jss::account] = alice.human();
3012 withQueue[jss::queue] = true;
3013
3014 json::Value withoutQueue;
3015 withoutQueue[jss::account] = alice.human();
3016
3017 json::Value prevLedgerWithQueue;
3018 prevLedgerWithQueue[jss::account] = alice.human();
3019 prevLedgerWithQueue[jss::queue] = true;
3020 prevLedgerWithQueue[jss::ledger_index] = 3;
3021 BEAST_EXPECT(env.current()->header().seq > 3);
3022
3023 {
3024 // account_info without the "queue" argument.
3025 auto const info = env.rpc("json", "account_info", to_string(withoutQueue));
3026 BEAST_EXPECT(
3027 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3028 BEAST_EXPECT(!info[jss::result].isMember(jss::queue_data));
3029 }
3030 {
3031 // account_info with the "queue" argument.
3032 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3033 BEAST_EXPECT(
3034 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3035 auto const& result = info[jss::result];
3036 BEAST_EXPECT(result.isMember(jss::queue_data));
3037 auto const& queueData = result[jss::queue_data];
3038 BEAST_EXPECT(queueData.isObject());
3039 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3040 BEAST_EXPECT(queueData[jss::txn_count] == 0);
3041 BEAST_EXPECT(!queueData.isMember(jss::lowest_sequence));
3042 BEAST_EXPECT(!queueData.isMember(jss::highest_sequence));
3043 BEAST_EXPECT(!queueData.isMember(jss::auth_change_queued));
3044 BEAST_EXPECT(!queueData.isMember(jss::max_spend_drops_total));
3045 BEAST_EXPECT(!queueData.isMember(jss::transactions));
3046 }
3047 checkMetrics(*this, env, 0, 6, 0, 3);
3048
3049 fillQueue(env, alice);
3050 checkMetrics(*this, env, 0, 6, 4, 3);
3051
3052 {
3053 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3054 BEAST_EXPECT(
3055 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3056 auto const& result = info[jss::result];
3057 BEAST_EXPECT(result.isMember(jss::queue_data));
3058 auto const& queueData = result[jss::queue_data];
3059 BEAST_EXPECT(queueData.isObject());
3060 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3061 BEAST_EXPECT(queueData[jss::txn_count] == 0);
3062 BEAST_EXPECT(!queueData.isMember(jss::lowest_sequence));
3063 BEAST_EXPECT(!queueData.isMember(jss::highest_sequence));
3064 BEAST_EXPECT(!queueData.isMember(jss::auth_change_queued));
3065 BEAST_EXPECT(!queueData.isMember(jss::max_spend_drops_total));
3066 BEAST_EXPECT(!queueData.isMember(jss::transactions));
3067 }
3068
3069 auto const submitParams = json::Value(json::ValueType::Object);
3070 envs(noop(alice), Fee(baseFee * 10), Seq(kNone), Ter(terQUEUED))(submitParams);
3071 envs(noop(alice), Fee(baseFee * 10), Seq(kNone), Ter(terQUEUED))(submitParams);
3072 envs(noop(alice), Fee(baseFee * 10), Seq(kNone), Ter(terQUEUED))(submitParams);
3073 envs(noop(alice), Fee(baseFee * 10), Seq(kNone), Ter(terQUEUED))(submitParams);
3074 checkMetrics(*this, env, 4, 6, 4, 3);
3075
3076 {
3077 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3078 BEAST_EXPECT(
3079 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3080 auto const& result = info[jss::result];
3081 auto const& data = result[jss::account_data];
3082 BEAST_EXPECT(result.isMember(jss::queue_data));
3083 auto const& queueData = result[jss::queue_data];
3084 BEAST_EXPECT(queueData.isObject());
3085 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3086 BEAST_EXPECT(queueData[jss::txn_count] == 4);
3087 BEAST_EXPECT(queueData.isMember(jss::lowest_sequence));
3088 BEAST_EXPECT(queueData[jss::lowest_sequence] == data[jss::Sequence]);
3089 BEAST_EXPECT(queueData.isMember(jss::highest_sequence));
3090 BEAST_EXPECT(
3091 queueData[jss::highest_sequence] ==
3092 data[jss::Sequence].asUInt() + queueData[jss::txn_count].asUInt() - 1);
3093 BEAST_EXPECT(queueData.isMember(jss::auth_change_queued));
3094 BEAST_EXPECT(queueData[jss::auth_change_queued] == false);
3095 BEAST_EXPECT(queueData.isMember(jss::max_spend_drops_total));
3096 BEAST_EXPECT(queueData[jss::max_spend_drops_total] == std::to_string(baseFee * 40));
3097 BEAST_EXPECT(queueData.isMember(jss::transactions));
3098 auto const& queued = queueData[jss::transactions];
3099 BEAST_EXPECT(queued.size() == queueData[jss::txn_count]);
3100 for (unsigned i = 0; i < queued.size(); ++i)
3101 {
3102 auto const& item = queued[i];
3103 BEAST_EXPECT(item[jss::seq] == data[jss::Sequence].asInt() + i);
3104 BEAST_EXPECT(item[jss::fee_level] == std::to_string(kBaseFeeLevel.fee() * 10));
3105 BEAST_EXPECT(!item.isMember(jss::LastLedgerSequence));
3106
3107 BEAST_EXPECT(item.isMember(jss::fee));
3108 BEAST_EXPECT(item[jss::fee] == std::to_string(baseFee * 10));
3109 BEAST_EXPECT(item.isMember(jss::max_spend_drops));
3110 BEAST_EXPECT(item[jss::max_spend_drops] == std::to_string(baseFee * 10));
3111 BEAST_EXPECT(item.isMember(jss::auth_change));
3112 BEAST_EXPECT(item[jss::auth_change].asBool() == false);
3113 }
3114 }
3115
3116 // Drain the queue so we can queue up a blocker.
3117 env.close();
3118 checkMetrics(*this, env, 0, 8, 4, 4);
3119
3120 // Fill the ledger and then queue up a blocker.
3121 envs(noop(alice), Seq(kNone))(submitParams);
3122
3123 envs(
3124 fset(alice, asfAccountTxnID),
3125 Fee(baseFee * 10),
3126 Seq(kNone),
3127 Json(jss::LastLedgerSequence, 10),
3128 Ter(terQUEUED))(submitParams);
3129 checkMetrics(*this, env, 1, 8, 5, 4);
3130
3131 {
3132 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3133 BEAST_EXPECT(
3134 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3135 auto const& result = info[jss::result];
3136 auto const& data = result[jss::account_data];
3137 BEAST_EXPECT(result.isMember(jss::queue_data));
3138 auto const& queueData = result[jss::queue_data];
3139 BEAST_EXPECT(queueData.isObject());
3140 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3141 BEAST_EXPECT(queueData[jss::txn_count] == 1);
3142 BEAST_EXPECT(queueData.isMember(jss::lowest_sequence));
3143 BEAST_EXPECT(queueData[jss::lowest_sequence] == data[jss::Sequence]);
3144 BEAST_EXPECT(queueData.isMember(jss::highest_sequence));
3145 BEAST_EXPECT(
3146 queueData[jss::highest_sequence] ==
3147 data[jss::Sequence].asUInt() + queueData[jss::txn_count].asUInt() - 1);
3148 BEAST_EXPECT(queueData.isMember(jss::auth_change_queued));
3149 BEAST_EXPECT(queueData[jss::auth_change_queued] == true);
3150 BEAST_EXPECT(queueData.isMember(jss::max_spend_drops_total));
3151 BEAST_EXPECT(queueData[jss::max_spend_drops_total] == std::to_string(baseFee * 10));
3152 BEAST_EXPECT(queueData.isMember(jss::transactions));
3153 auto const& queued = queueData[jss::transactions];
3154 BEAST_EXPECT(queued.size() == queueData[jss::txn_count]);
3155 for (unsigned i = 0; i < queued.size(); ++i)
3156 {
3157 auto const& item = queued[i];
3158 BEAST_EXPECT(item[jss::seq] == data[jss::Sequence].asInt() + i);
3159 BEAST_EXPECT(item[jss::fee_level] == std::to_string(kBaseFeeLevel.fee() * 10));
3160 BEAST_EXPECT(item.isMember(jss::fee));
3161 BEAST_EXPECT(item[jss::fee] == std::to_string(baseFee * 10));
3162 BEAST_EXPECT(item.isMember(jss::max_spend_drops));
3163 BEAST_EXPECT(item[jss::max_spend_drops] == std::to_string(baseFee * 10));
3164 BEAST_EXPECT(item.isMember(jss::auth_change));
3165
3166 if (i == queued.size() - 1)
3167 {
3168 BEAST_EXPECT(item[jss::auth_change].asBool() == true);
3169 BEAST_EXPECT(item.isMember(jss::LastLedgerSequence));
3170 BEAST_EXPECT(item[jss::LastLedgerSequence] == 10);
3171 }
3172 else
3173 {
3174 BEAST_EXPECT(item[jss::auth_change].asBool() == false);
3175 BEAST_EXPECT(!item.isMember(jss::LastLedgerSequence));
3176 }
3177 }
3178 }
3179
3180 envs(noop(alice), Fee(baseFee * 10), Seq(kNone), Ter(telCAN_NOT_QUEUE_BLOCKED))(
3181 submitParams);
3182 checkMetrics(*this, env, 1, 8, 5, 4);
3183
3184 {
3185 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3186 BEAST_EXPECT(
3187 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3188 auto const& result = info[jss::result];
3189 auto const& data = result[jss::account_data];
3190 BEAST_EXPECT(result.isMember(jss::queue_data));
3191 auto const& queueData = result[jss::queue_data];
3192 BEAST_EXPECT(queueData.isObject());
3193 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3194 BEAST_EXPECT(queueData[jss::txn_count] == 1);
3195 BEAST_EXPECT(queueData.isMember(jss::lowest_sequence));
3196 BEAST_EXPECT(queueData[jss::lowest_sequence] == data[jss::Sequence]);
3197 BEAST_EXPECT(queueData.isMember(jss::highest_sequence));
3198 BEAST_EXPECT(
3199 queueData[jss::highest_sequence] ==
3200 data[jss::Sequence].asUInt() + queueData[jss::txn_count].asUInt() - 1);
3201 BEAST_EXPECT(queueData.isMember(jss::auth_change_queued));
3202 BEAST_EXPECT(queueData[jss::auth_change_queued].asBool());
3203 BEAST_EXPECT(queueData.isMember(jss::max_spend_drops_total));
3204 BEAST_EXPECT(queueData[jss::max_spend_drops_total] == std::to_string(baseFee * 10));
3205 BEAST_EXPECT(queueData.isMember(jss::transactions));
3206 auto const& queued = queueData[jss::transactions];
3207 BEAST_EXPECT(queued.size() == queueData[jss::txn_count]);
3208 for (unsigned i = 0; i < queued.size(); ++i)
3209 {
3210 auto const& item = queued[i];
3211 BEAST_EXPECT(item[jss::seq] == data[jss::Sequence].asInt() + i);
3212 BEAST_EXPECT(item[jss::fee_level] == std::to_string(kBaseFeeLevel.fee() * 10));
3213
3214 if (i == queued.size() - 1)
3215 {
3216 BEAST_EXPECT(item.isMember(jss::fee));
3217 BEAST_EXPECT(item[jss::fee] == std::to_string(baseFee * 10));
3218 BEAST_EXPECT(item.isMember(jss::max_spend_drops));
3219 BEAST_EXPECT(item[jss::max_spend_drops] == std::to_string(baseFee * 10));
3220 BEAST_EXPECT(item.isMember(jss::auth_change));
3221 BEAST_EXPECT(item[jss::auth_change].asBool());
3222 BEAST_EXPECT(item.isMember(jss::LastLedgerSequence));
3223 BEAST_EXPECT(item[jss::LastLedgerSequence] == 10);
3224 }
3225 else
3226 {
3227 BEAST_EXPECT(item.isMember(jss::fee));
3228 BEAST_EXPECT(item[jss::fee] == std::to_string(baseFee * 10));
3229 BEAST_EXPECT(item.isMember(jss::max_spend_drops));
3230 BEAST_EXPECT(item[jss::max_spend_drops] == std::to_string(baseFee * 10));
3231 BEAST_EXPECT(item.isMember(jss::auth_change));
3232 BEAST_EXPECT(!item[jss::auth_change].asBool());
3233 BEAST_EXPECT(!item.isMember(jss::LastLedgerSequence));
3234 }
3235 }
3236 }
3237
3238 {
3239 auto const info = env.rpc("json", "account_info", to_string(prevLedgerWithQueue));
3240 BEAST_EXPECT(info[jss::result][jss::error] == "invalidParams");
3241 BEAST_EXPECT(info[jss::result][jss::error_code] == RpcInvalidParams);
3242 BEAST_EXPECT(info[jss::result][jss::error_message] == "Invalid parameters.");
3243 }
3244
3245 env.close();
3246 checkMetrics(*this, env, 0, 10, 2, 5);
3247 env.close();
3248 checkMetrics(*this, env, 0, 10, 0, 5);
3249
3250 {
3251 auto const info = env.rpc("json", "account_info", to_string(withQueue));
3252 BEAST_EXPECT(
3253 info.isMember(jss::result) && info[jss::result].isMember(jss::account_data));
3254 auto const& result = info[jss::result];
3255 BEAST_EXPECT(result.isMember(jss::queue_data));
3256 auto const& queueData = result[jss::queue_data];
3257 BEAST_EXPECT(queueData.isObject());
3258 BEAST_EXPECT(queueData.isMember(jss::txn_count));
3259 BEAST_EXPECT(queueData[jss::txn_count] == 0);
3260 BEAST_EXPECT(!queueData.isMember(jss::lowest_sequence));
3261 BEAST_EXPECT(!queueData.isMember(jss::highest_sequence));
3262 BEAST_EXPECT(!queueData.isMember(jss::auth_change_queued));
3263 BEAST_EXPECT(!queueData.isMember(jss::max_spend_drops_total));
3264 BEAST_EXPECT(!queueData.isMember(jss::transactions));
3265 }
3266 }
3267
3268 void
3270 {
3271 using namespace jtx;
3272 testcase("server info");
3273
3275 auto const baseFee = env.current()->fees().base.drops();
3276 EnvSs envs(env);
3277
3278 Account const alice{"alice"};
3279 env.fund(XRP(1000000), alice);
3280 env.close();
3281
3282 {
3283 auto const serverInfo = env.rpc("server_info");
3284 BEAST_EXPECT(
3285 serverInfo.isMember(jss::result) && serverInfo[jss::result].isMember(jss::info));
3286 auto const& info = serverInfo[jss::result][jss::info];
3287 BEAST_EXPECT(info.isMember(jss::load_factor) && info[jss::load_factor] == 1);
3288 BEAST_EXPECT(!info.isMember(jss::load_factor_server));
3289 BEAST_EXPECT(!info.isMember(jss::load_factor_local));
3290 BEAST_EXPECT(!info.isMember(jss::load_factor_net));
3291 BEAST_EXPECT(!info.isMember(jss::load_factor_fee_escalation));
3292 }
3293 {
3294 auto const serverState = env.rpc("server_state");
3295 auto const& state = serverState[jss::result][jss::state];
3296 BEAST_EXPECT(state.isMember(jss::load_factor) && state[jss::load_factor] == 256);
3297 BEAST_EXPECT(state.isMember(jss::load_base) && state[jss::load_base] == 256);
3298 BEAST_EXPECT(
3299 state.isMember(jss::load_factor_server) && state[jss::load_factor_server] == 256);
3300 BEAST_EXPECT(
3301 state.isMember(jss::load_factor_fee_escalation) &&
3302 state[jss::load_factor_fee_escalation] == 256);
3303 BEAST_EXPECT(
3304 state.isMember(jss::load_factor_fee_queue) &&
3305 state[jss::load_factor_fee_queue] == 256);
3306 BEAST_EXPECT(
3307 state.isMember(jss::load_factor_fee_reference) &&
3308 state[jss::load_factor_fee_reference] == 256);
3309 }
3310
3311 checkMetrics(*this, env, 0, 6, 0, 3);
3312
3313 fillQueue(env, alice);
3314 checkMetrics(*this, env, 0, 6, 4, 3);
3315
3316 auto aliceSeq = env.seq(alice);
3317 auto const submitParams = json::Value(json::ValueType::Object);
3318 for (auto i = 0; i < 4; ++i)
3319 envs(noop(alice), Fee(baseFee * 10), Seq(aliceSeq + i), Ter(terQUEUED))(submitParams);
3320 checkMetrics(*this, env, 4, 6, 4, 3);
3321
3322 {
3323 auto const serverInfo = env.rpc("server_info");
3324 BEAST_EXPECT(
3325 serverInfo.isMember(jss::result) && serverInfo[jss::result].isMember(jss::info));
3326 auto const& info = serverInfo[jss::result][jss::info];
3327 // Avoid double rounding issues by comparing to a range.
3328 BEAST_EXPECT(
3329 info.isMember(jss::load_factor) && info[jss::load_factor] > 888.88 &&
3330 info[jss::load_factor] < 888.89);
3331 BEAST_EXPECT(
3332 info.isMember(jss::load_factor_server) && info[jss::load_factor_server] == 1);
3333 BEAST_EXPECT(!info.isMember(jss::load_factor_local));
3334 BEAST_EXPECT(!info.isMember(jss::load_factor_net));
3335 BEAST_EXPECT(
3336 info.isMember(jss::load_factor_fee_escalation) &&
3337 info[jss::load_factor_fee_escalation] > 888.88 &&
3338 info[jss::load_factor_fee_escalation] < 888.89);
3339 }
3340 {
3341 auto const serverState = env.rpc("server_state");
3342 auto const& state = serverState[jss::result][jss::state];
3343 BEAST_EXPECT(state.isMember(jss::load_factor) && state[jss::load_factor] == 227555);
3344 BEAST_EXPECT(state.isMember(jss::load_base) && state[jss::load_base] == 256);
3345 BEAST_EXPECT(
3346 state.isMember(jss::load_factor_server) && state[jss::load_factor_server] == 256);
3347 BEAST_EXPECT(
3348 state.isMember(jss::load_factor_fee_escalation) &&
3349 state[jss::load_factor_fee_escalation] == 227555);
3350 BEAST_EXPECT(
3351 state.isMember(jss::load_factor_fee_queue) &&
3352 state[jss::load_factor_fee_queue] == 256);
3353 BEAST_EXPECT(
3354 state.isMember(jss::load_factor_fee_reference) &&
3355 state[jss::load_factor_fee_reference] == 256);
3356 }
3357
3358 env.app().getFeeTrack().setRemoteFee(256000);
3359
3360 {
3361 auto const serverInfo = env.rpc("server_info");
3362 BEAST_EXPECT(
3363 serverInfo.isMember(jss::result) && serverInfo[jss::result].isMember(jss::info));
3364 auto const& info = serverInfo[jss::result][jss::info];
3365 // Avoid double rounding issues by comparing to a range.
3366 BEAST_EXPECT(info.isMember(jss::load_factor) && info[jss::load_factor] == 1000);
3367 BEAST_EXPECT(!info.isMember(jss::load_factor_server));
3368 BEAST_EXPECT(!info.isMember(jss::load_factor_local));
3369 BEAST_EXPECT(info.isMember(jss::load_factor_net) && info[jss::load_factor_net] == 1000);
3370 BEAST_EXPECT(
3371 info.isMember(jss::load_factor_fee_escalation) &&
3372 info[jss::load_factor_fee_escalation] > 888.88 &&
3373 info[jss::load_factor_fee_escalation] < 888.89);
3374 }
3375 {
3376 auto const serverState = env.rpc("server_state");
3377 auto const& state = serverState[jss::result][jss::state];
3378 BEAST_EXPECT(state.isMember(jss::load_factor) && state[jss::load_factor] == 256000);
3379 BEAST_EXPECT(state.isMember(jss::load_base) && state[jss::load_base] == 256);
3380 BEAST_EXPECT(
3381 state.isMember(jss::load_factor_server) &&
3382 state[jss::load_factor_server] == 256000);
3383 BEAST_EXPECT(
3384 state.isMember(jss::load_factor_fee_escalation) &&
3385 state[jss::load_factor_fee_escalation] == 227555);
3386 BEAST_EXPECT(
3387 state.isMember(jss::load_factor_fee_queue) &&
3388 state[jss::load_factor_fee_queue] == 256);
3389 BEAST_EXPECT(
3390 state.isMember(jss::load_factor_fee_reference) &&
3391 state[jss::load_factor_fee_reference] == 256);
3392 }
3393
3394 env.app().getFeeTrack().setRemoteFee(256);
3395
3396 // Increase the server load
3397 for (int i = 0; i < 5; ++i)
3398 env.app().getFeeTrack().raiseLocalFee();
3399 BEAST_EXPECT(env.app().getFeeTrack().getLoadFactor() == 625);
3400
3401 {
3402 auto const serverInfo = env.rpc("server_info");
3403 BEAST_EXPECT(
3404 serverInfo.isMember(jss::result) && serverInfo[jss::result].isMember(jss::info));
3405 auto const& info = serverInfo[jss::result][jss::info];
3406 // Avoid double rounding issues by comparing to a range.
3407 BEAST_EXPECT(
3408 info.isMember(jss::load_factor) && info[jss::load_factor] > 888.88 &&
3409 info[jss::load_factor] < 888.89);
3410 // There can be a race between LoadManager lowering the fee,
3411 // and the call to server_info, so check a wide range.
3412 // The important thing is that it's not 1.
3413 BEAST_EXPECT(
3414 info.isMember(jss::load_factor_server) && info[jss::load_factor_server] > 1.245 &&
3415 info[jss::load_factor_server] < 2.4415);
3416 BEAST_EXPECT(
3417 info.isMember(jss::load_factor_local) && info[jss::load_factor_local] > 1.245 &&
3418 info[jss::load_factor_local] < 2.4415);
3419 BEAST_EXPECT(!info.isMember(jss::load_factor_net));
3420 BEAST_EXPECT(
3421 info.isMember(jss::load_factor_fee_escalation) &&
3422 info[jss::load_factor_fee_escalation] > 888.88 &&
3423 info[jss::load_factor_fee_escalation] < 888.89);
3424 }
3425 {
3426 auto const serverState = env.rpc("server_state");
3427 auto const& state = serverState[jss::result][jss::state];
3428 BEAST_EXPECT(state.isMember(jss::load_factor) && state[jss::load_factor] == 227555);
3429 BEAST_EXPECT(state.isMember(jss::load_base) && state[jss::load_base] == 256);
3430 // There can be a race between LoadManager lowering the fee,
3431 // and the call to server_info, so check a wide range.
3432 // The important thing is that it's not 256.
3433 BEAST_EXPECT(
3434 state.isMember(jss::load_factor_server) && state[jss::load_factor_server] >= 320 &&
3435 state[jss::load_factor_server] <= 625);
3436 BEAST_EXPECT(
3437 state.isMember(jss::load_factor_fee_escalation) &&
3438 state[jss::load_factor_fee_escalation] == 227555);
3439 BEAST_EXPECT(
3440 state.isMember(jss::load_factor_fee_queue) &&
3441 state[jss::load_factor_fee_queue] == 256);
3442 BEAST_EXPECT(
3443 state.isMember(jss::load_factor_fee_reference) &&
3444 state[jss::load_factor_fee_reference] == 256);
3445 }
3446
3447 env.close();
3448
3449 {
3450 auto const serverInfo = env.rpc("server_info");
3451 BEAST_EXPECT(
3452 serverInfo.isMember(jss::result) && serverInfo[jss::result].isMember(jss::info));
3453 auto const& info = serverInfo[jss::result][jss::info];
3454 // Avoid double rounding issues by comparing to a range.
3455
3456 // There can be a race between LoadManager lowering the fee,
3457 // and the call to server_info, so check a wide range.
3458 // The important thing is that it's not 1.
3459 BEAST_EXPECT(
3460 info.isMember(jss::load_factor) && info[jss::load_factor] > 1.245 &&
3461 info[jss::load_factor] < 2.4415);
3462 BEAST_EXPECT(!info.isMember(jss::load_factor_server));
3463 BEAST_EXPECT(
3464 info.isMember(jss::load_factor_local) && info[jss::load_factor_local] > 1.245 &&
3465 info[jss::load_factor_local] < 2.4415);
3466 BEAST_EXPECT(!info.isMember(jss::load_factor_net));
3467 BEAST_EXPECT(!info.isMember(jss::load_factor_fee_escalation));
3468 }
3469 {
3470 auto const serverState = env.rpc("server_state");
3471 auto const& state = serverState[jss::result][jss::state];
3472 BEAST_EXPECT(
3473 state.isMember(jss::load_factor) && state[jss::load_factor] >= 320 &&
3474 state[jss::load_factor] <= 625);
3475 BEAST_EXPECT(state.isMember(jss::load_base) && state[jss::load_base] == 256);
3476 // There can be a race between LoadManager lowering the fee,
3477 // and the call to server_info, so check a wide range.
3478 // The important thing is that it's not 256.
3479 BEAST_EXPECT(
3480 state.isMember(jss::load_factor_server) && state[jss::load_factor_server] >= 320 &&
3481 state[jss::load_factor_server] <= 625);
3482 BEAST_EXPECT(
3483 state.isMember(jss::load_factor_fee_escalation) &&
3484 state[jss::load_factor_fee_escalation] == 256);
3485 BEAST_EXPECT(
3486 state.isMember(jss::load_factor_fee_queue) &&
3487 state[jss::load_factor_fee_queue] == 256);
3488 BEAST_EXPECT(
3489 state.isMember(jss::load_factor_fee_reference) &&
3490 state[jss::load_factor_fee_reference] == 256);
3491 }
3492 }
3493
3494 void
3496 {
3497 using namespace jtx;
3498 testcase("server subscribe");
3499
3501 auto const baseFee = env.current()->fees().base.drops();
3502
3503 json::Value stream;
3504 stream[jss::streams] = json::ValueType::Array;
3505 stream[jss::streams].append("server");
3506 auto wsc = makeWSClient(env.app().config());
3507 {
3508 auto jv = wsc->invoke("subscribe", stream);
3509 BEAST_EXPECT(jv[jss::status] == "success");
3510 }
3511
3512 // NOLINTNEXTLINE(misc-const-correctness)
3513 Account a{"a"}, b{"b"}, c{"c"}, d{"d"}, e{"e"}, f{"f"}, g{"g"}, h{"h"}, i{"i"};
3514
3515 // Fund the first few accounts at non escalated fee
3516 env.fund(XRP(50000), noripple(a, b, c, d));
3517 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
3518
3519 // First transaction establishes the messaging
3520 using namespace std::chrono_literals;
3521 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3522 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3523 jv[jss::load_factor] == 256 && jv.isMember(jss::load_base) &&
3524 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3525 jv[jss::load_factor_server] == 256 &&
3526 jv.isMember(jss::load_factor_fee_escalation) &&
3527 jv[jss::load_factor_fee_escalation] == 256 &&
3528 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3529 jv.isMember(jss::load_factor_fee_reference) &&
3530 jv[jss::load_factor_fee_reference] == 256;
3531 }));
3532 // Last transaction escalates the fee
3533 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3534 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3535 jv[jss::load_factor] == 227555 && jv.isMember(jss::load_base) &&
3536 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3537 jv[jss::load_factor_server] == 256 &&
3538 jv.isMember(jss::load_factor_fee_escalation) &&
3539 jv[jss::load_factor_fee_escalation] == 227555 &&
3540 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3541 jv.isMember(jss::load_factor_fee_reference) &&
3542 jv[jss::load_factor_fee_reference] == 256;
3543 }));
3544
3545 env.close();
3546
3547 // Closing ledger should publish a status update
3548 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3549 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3550 jv[jss::load_factor] == 256 && jv.isMember(jss::load_base) &&
3551 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3552 jv[jss::load_factor_server] == 256 &&
3553 jv.isMember(jss::load_factor_fee_escalation) &&
3554 jv[jss::load_factor_fee_escalation] == 256 &&
3555 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3556 jv.isMember(jss::load_factor_fee_reference) &&
3557 jv[jss::load_factor_fee_reference] == 256;
3558 }));
3559
3560 checkMetrics(*this, env, 0, 8, 0, 4);
3561
3562 // Fund then next few accounts at non escalated fee
3563 env.fund(XRP(50000), noripple(e, f, g, h, i));
3564
3565 // Extra transactions with low fee are queued
3566 auto const queued = Ter(terQUEUED);
3567 env(noop(a), Fee(baseFee), queued);
3568 env(noop(b), Fee(baseFee), queued);
3569 env(noop(c), Fee(baseFee), queued);
3570 env(noop(d), Fee(baseFee), queued);
3571 env(noop(e), Fee(baseFee), queued);
3572 env(noop(f), Fee(baseFee), queued);
3573 env(noop(g), Fee(baseFee), queued);
3574 checkMetrics(*this, env, 7, 8, 5, 4);
3575
3576 // Last transaction escalates the fee
3577 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3578 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3579 jv[jss::load_factor] == 200000 && jv.isMember(jss::load_base) &&
3580 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3581 jv[jss::load_factor_server] == 256 &&
3582 jv.isMember(jss::load_factor_fee_escalation) &&
3583 jv[jss::load_factor_fee_escalation] == 200000 &&
3584 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3585 jv.isMember(jss::load_factor_fee_reference) &&
3586 jv[jss::load_factor_fee_reference] == 256;
3587 }));
3588
3589 env.close();
3590 // Ledger close publishes with escalated fees for queued transactions
3591 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3592 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3593 jv[jss::load_factor] == 184320 && jv.isMember(jss::load_base) &&
3594 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3595 jv[jss::load_factor_server] == 256 &&
3596 jv.isMember(jss::load_factor_fee_escalation) &&
3597 jv[jss::load_factor_fee_escalation] == 184320 &&
3598 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3599 jv.isMember(jss::load_factor_fee_reference) &&
3600 jv[jss::load_factor_fee_reference] == 256;
3601 }));
3602
3603 env.close();
3604 // ledger close clears queue so fee is back to normal
3605 BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) {
3606 return jv[jss::type] == "serverStatus" && jv.isMember(jss::load_factor) &&
3607 jv[jss::load_factor] == 256 && jv.isMember(jss::load_base) &&
3608 jv[jss::load_base] == 256 && jv.isMember(jss::load_factor_server) &&
3609 jv[jss::load_factor_server] == 256 &&
3610 jv.isMember(jss::load_factor_fee_escalation) &&
3611 jv[jss::load_factor_fee_escalation] == 256 &&
3612 jv.isMember(jss::load_factor_fee_queue) && jv[jss::load_factor_fee_queue] == 256 &&
3613 jv.isMember(jss::load_factor_fee_reference) &&
3614 jv[jss::load_factor_fee_reference] == 256;
3615 }));
3616 // Drain any extra serverStatus messages that may arrive
3617 // asynchronously from the ledger close processing. The drain
3618 // is bounded so the test cannot hang if serverStatus keeps
3619 // arriving (e.g. LoadManager raising/lowering fees).
3620 auto const drainDeadline = std::chrono::steady_clock::now() + 5s;
3621 while (std::chrono::steady_clock::now() < drainDeadline)
3622 {
3623 if (!wsc->findMsg(1s, [&](auto const& jv) { return jv[jss::type] == "serverStatus"; }))
3624 {
3625 break;
3626 }
3627 }
3628
3629 auto jv = wsc->invoke("unsubscribe", stream);
3630 BEAST_EXPECT(jv[jss::status] == "success");
3631 }
3632
3633 void
3635 {
3636 using namespace jtx;
3637 testcase("clear queued acct txs");
3638
3640 auto const baseFee = env.current()->fees().base.drops();
3641 auto const alice = Account("alice");
3642 auto const bob = Account("bob");
3643
3644 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
3645 env.fund(XRP(50000000), alice, bob);
3646
3647 fillQueue(env, alice);
3648
3649 auto const calcTotalFee = [&](std::int64_t alreadyPaid,
3650 std::optional<std::size_t> numToClear =
3651 std::nullopt) -> std::uint64_t {
3652 auto totalFactor = 0;
3653 auto const metrics = env.app().getTxQ().getMetrics(*env.current());
3654 if (!numToClear)
3655 numToClear.emplace(metrics.txCount + 1);
3656 for (int i = 0; i < *numToClear; ++i)
3657 {
3658 auto const inLedger = metrics.txInLedger + i;
3659 totalFactor += inLedger * inLedger;
3660 }
3661
3662 auto const den = (metrics.txPerLedger * metrics.txPerLedger);
3663 FeeLevel64 const feeLevel =
3664 (metrics.medFeeLevel * totalFactor + FeeLevel64{den - 1}) / den;
3665
3666 auto result = toDrops(feeLevel, env.current()->fees().base).drops();
3667
3668 // Subtract the fees already paid
3669 result -= alreadyPaid;
3670 // round up
3671 ++result;
3672 return result;
3673 };
3674
3675 testcase("straightforward positive case");
3676 {
3677 // Queue up some transactions at a too-low fee.
3678 auto aliceSeq = env.seq(alice);
3679 std::uint64_t totalPaid = 0;
3680 for (int i = 0; i < 2; ++i)
3681 {
3682 env(noop(alice), Fee(baseFee * 10), Seq(aliceSeq++), Ter(terQUEUED));
3683 totalPaid += baseFee * 10;
3684 }
3685
3686 // Queue up a transaction paying the open ledger fee
3687 // This will be the first tx to call the operative function,
3688 // but it won't succeed.
3689 totalPaid += openLedgerCost(env).drops();
3690 env(noop(alice), Fee(openLedgerCost(env)), Seq(aliceSeq++), Ter(terQUEUED));
3691
3692 checkMetrics(*this, env, 3, std::nullopt, 4, 3);
3693
3694 // Figure out how much it would cost to cover all the
3695 // queued txs + itself
3696 std::uint64_t totalFee = calcTotalFee(totalPaid);
3697 --totalFee;
3698
3699 // Submit a transaction with that fee. It will get queued
3700 // because the fee level calculation rounds down. This is
3701 // the edge case test.
3702 env(noop(alice), Fee(totalFee), Seq(aliceSeq++), Ter(terQUEUED));
3703
3704 checkMetrics(*this, env, 4, std::nullopt, 4, 3);
3705
3706 // Now repeat the process including the new tx
3707 // and avoiding the rounding error
3708 totalPaid += totalFee;
3709 totalFee = calcTotalFee(totalPaid);
3710
3711 // Submit a transaction with that fee. It will succeed.
3712 env(noop(alice), Fee(totalFee), Seq(aliceSeq++));
3713
3714 checkMetrics(*this, env, 0, std::nullopt, 9, 3);
3715 }
3716
3717 testcase("replace last tx with enough to clear queue");
3718 {
3719 // Queue up some transactions at a too-low fee.
3720 auto aliceSeq = env.seq(alice);
3721 uint64_t totalPaid = 0;
3722 for (int i = 0; i < 2; ++i)
3723 {
3724 env(noop(alice), Fee(baseFee * 10), Seq(aliceSeq++), Ter(terQUEUED));
3725 totalPaid += baseFee * 10;
3726 }
3727
3728 // Queue up a transaction paying the open ledger fee
3729 // This will be the first tx to call the operative function,
3730 // but it won't succeed.
3731 env(noop(alice), Fee(openLedgerCost(env)), Seq(aliceSeq++), Ter(terQUEUED));
3732
3733 checkMetrics(*this, env, 3, std::nullopt, 9, 3);
3734
3735 // Figure out how much it would cost to cover all the
3736 // queued txs + itself
3737 auto const metrics = env.app().getTxQ().getMetrics(*env.current());
3738 std::uint64_t const totalFee = calcTotalFee(totalPaid, metrics.txCount);
3739 // Replacing the last tx with the large fee succeeds.
3740 --aliceSeq;
3741 env(noop(alice), Fee(totalFee), Seq(aliceSeq++));
3742
3743 // The queue is clear
3744 checkMetrics(*this, env, 0, std::nullopt, 12, 3);
3745
3746 env.close();
3747 checkMetrics(*this, env, 0, 24, 0, 12);
3748 }
3749
3750 testcase("replace middle tx with enough to clear queue");
3751 {
3752 fillQueue(env, alice);
3753 // Queue up some transactions at a too-low fee.
3754 auto aliceSeq = env.seq(alice);
3755 for (int i = 0; i < 5; ++i)
3756 {
3757 env(noop(alice), Fee(baseFee * 10), Seq(aliceSeq++), Ter(terQUEUED));
3758 }
3759
3760 checkMetrics(*this, env, 5, 24, 13, 12);
3761
3762 // Figure out how much it would cost to cover 3 txns
3763 uint64_t const totalFee = calcTotalFee(baseFee * 10 * 2, 3);
3764 // Replacing the last tx with the large fee succeeds.
3765 aliceSeq -= 3;
3766 env(noop(alice), Fee(totalFee), Seq(aliceSeq++));
3767
3768 checkMetrics(*this, env, 2, 24, 16, 12);
3769 auto const aliceQueue = env.app().getTxQ().getAccountTxs(alice.id());
3770 BEAST_EXPECT(aliceQueue.size() == 2);
3771 SeqProxy seq = SeqProxy::rawSequence(aliceSeq);
3772 for (auto const& tx : aliceQueue)
3773 {
3774 BEAST_EXPECT(tx.seqProxy == seq);
3775 BEAST_EXPECT(tx.feeLevel == FeeLevel64{kBaseFeeLevel.fee() * 10});
3776 seq.advanceBy(1);
3777 }
3778
3779 // Close the ledger to clear the queue
3780 env.close();
3781 checkMetrics(*this, env, 0, 32, 2, 16);
3782 }
3783
3784 testcase("clear queue failure (load)");
3785 {
3786 fillQueue(env, alice);
3787 // Queue up some transactions at a too-low fee.
3788 auto aliceSeq = env.seq(alice);
3789 uint64_t totalPaid = 0;
3790 for (int i = 0; i < 2; ++i)
3791 {
3792 env(noop(alice), Fee(baseFee * 20), Seq(aliceSeq++), Ter(terQUEUED));
3793 totalPaid += baseFee * 20;
3794 }
3795 for (int i = 0; i < 2; ++i)
3796 {
3797 env(noop(alice), Fee(baseFee * 2.2), Seq(aliceSeq++), Ter(terQUEUED));
3798 totalPaid += baseFee * 2.2;
3799 }
3800
3801 checkMetrics(*this, env, 4, 32, 17, 16);
3802
3803 // Figure out how much it would cost to cover all the txns
3804 // + 1
3805 std::uint64_t const totalFee = calcTotalFee(totalPaid);
3806 // This fee should be enough, but oh no! Server load went up!
3807 auto& feeTrack = env.app().getFeeTrack();
3808 auto const origFee = feeTrack.getRemoteFee();
3809 feeTrack.setRemoteFee(origFee * 5);
3810 // Instead the tx gets queued, and all of the queued
3811 // txs stay in the queue.
3812 env(noop(alice), Fee(totalFee), Seq(aliceSeq++), Ter(terQUEUED));
3813
3814 // The original last transaction is still in the queue
3815 checkMetrics(*this, env, 5, 32, 17, 16);
3816
3817 // With high load, some of the txs stay in the queue
3818 env.close();
3819 checkMetrics(*this, env, 3, 34, 2, 17);
3820
3821 // Load drops back down
3822 feeTrack.setRemoteFee(origFee);
3823
3824 // Because of the earlier failure, alice can not clear the queue,
3825 // no matter how high the fee
3826 fillQueue(env, bob);
3827 checkMetrics(*this, env, 3, 34, 18, 17);
3828
3829 env(noop(alice), Fee(XRP(1)), Seq(aliceSeq++), Ter(terQUEUED));
3830 checkMetrics(*this, env, 4, 34, 18, 17);
3831
3832 // With normal load, those txs get into the ledger
3833 env.close();
3834 checkMetrics(*this, env, 0, 36, 4, 18);
3835 }
3836 }
3837
3838 void
3840 {
3841 using namespace jtx;
3842 using namespace std::chrono_literals;
3843 testcase("scaling");
3844
3845 {
3846 Env env(
3847 *this,
3848 makeConfig({
3854 }));
3855 auto const alice = Account("alice");
3856
3857 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
3858 env.fund(XRP(50000000), alice);
3859
3860 fillQueue(env, alice);
3861 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
3862 auto seqAlice = env.seq(alice);
3863 auto txCount = 140;
3864 for (int i = 0; i < txCount; ++i)
3865 env(noop(alice), Seq(seqAlice++), Ter(terQUEUED));
3866 checkMetrics(*this, env, txCount, std::nullopt, 4, 3);
3867
3868 // Close a few ledgers successfully, so the limit grows
3869
3870 env.close();
3871 // 4 + 25% = 5
3872 txCount -= 6;
3873 checkMetrics(*this, env, txCount, 10, 6, 5, 257);
3874
3875 env.close();
3876 // 6 + 25% = 7
3877 txCount -= 8;
3878 checkMetrics(*this, env, txCount, 14, 8, 7, 257);
3879
3880 env.close();
3881 // 8 + 25% = 10
3882 txCount -= 11;
3883 checkMetrics(*this, env, txCount, 20, 11, 10, 257);
3884
3885 env.close();
3886 // 11 + 25% = 13
3887 txCount -= 14;
3888 checkMetrics(*this, env, txCount, 26, 14, 13, 257);
3889
3890 env.close();
3891 // 14 + 25% = 17
3892 txCount -= 18;
3893 checkMetrics(*this, env, txCount, 34, 18, 17, 257);
3894
3895 env.close();
3896 // 18 + 25% = 22
3897 txCount -= 23;
3898 checkMetrics(*this, env, txCount, 44, 23, 22, 257);
3899
3900 env.close();
3901 // 23 + 25% = 28
3902 txCount -= 29;
3903 checkMetrics(*this, env, txCount, 56, 29, 28);
3904
3905 // From 3 expected to 28 in 7 "fast" ledgers.
3906
3907 // Close the ledger with a delay.
3908 env.close(env.now() + 5s, 10000ms);
3909 txCount -= 15;
3910 checkMetrics(*this, env, txCount, 56, 15, 14);
3911
3912 // Close the ledger with a delay.
3913 env.close(env.now() + 5s, 10000ms);
3914 txCount -= 8;
3915 checkMetrics(*this, env, txCount, 56, 8, 7);
3916
3917 // Close the ledger with a delay.
3918 env.close(env.now() + 5s, 10000ms);
3919 txCount -= 4;
3920 checkMetrics(*this, env, txCount, 56, 4, 3);
3921
3922 // From 28 expected back down to 3 in 3 "slow" ledgers.
3923
3924 // Confirm the minimum sticks
3925 env.close(env.now() + 5s, 10000ms);
3926 txCount -= 4;
3927 checkMetrics(*this, env, txCount, 56, 4, 3);
3928
3929 BEAST_EXPECT(!txCount);
3930 }
3931
3932 {
3933 Env env(
3934 *this,
3935 makeConfig({
3941 }));
3942 auto const alice = Account("alice");
3943
3944 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
3945 env.fund(XRP(50000000), alice);
3946
3947 fillQueue(env, alice);
3948 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
3949 auto seqAlice = env.seq(alice);
3950 auto txCount = 43;
3951 for (int i = 0; i < txCount; ++i)
3952 env(noop(alice), Seq(seqAlice++), Ter(terQUEUED));
3953 checkMetrics(*this, env, txCount, std::nullopt, 4, 3);
3954
3955 // Close a few ledgers successfully, so the limit grows
3956
3957 env.close();
3958 // 4 + 150% = 10
3959 txCount -= 11;
3960 checkMetrics(*this, env, txCount, 20, 11, 10, 257);
3961
3962 env.close();
3963 // 11 + 150% = 27
3964 txCount -= 28;
3965 checkMetrics(*this, env, txCount, 54, 28, 27);
3966
3967 // From 3 expected to 28 in 7 "fast" ledgers.
3968
3969 // Close the ledger with a delay.
3970 env.close(env.now() + 5s, 10000ms);
3971 txCount -= 4;
3972 checkMetrics(*this, env, txCount, 54, 4, 3);
3973
3974 // From 28 expected back down to 3 in 3 "slow" ledgers.
3975
3976 BEAST_EXPECT(!txCount);
3977 }
3978 }
3979
3980 void
3982 {
3983 // Test the situation where a transaction with an account and
3984 // sequence that's in the queue also appears in the ledger.
3985 //
3986 // Normally this situation can only happen on a network
3987 // when a transaction gets validated by most of the network,
3988 // but one or more nodes have that transaction (or a different
3989 // transaction with the same sequence) queued. And, yes, this
3990 // situation has been observed (rarely) in the wild.
3991 testcase("Sequence in queue and open ledger");
3992 using namespace jtx;
3993
3995
3996 auto const alice = Account("alice");
3997
3998 auto const queued = Ter(terQUEUED);
3999
4000 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
4001
4002 // Create account
4003 env.fund(XRP(50000), noripple(alice));
4004 checkMetrics(*this, env, 0, std::nullopt, 1, 3);
4005
4006 fillQueue(env, alice);
4007 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
4008
4009 // Queue a transaction
4010 auto const aliceSeq = env.seq(alice);
4011 env(noop(alice), queued);
4012 checkMetrics(*this, env, 1, std::nullopt, 4, 3);
4013
4014 // Now, apply a (different) transaction directly
4015 // to the open ledger, bypassing the queue
4016 // (This requires calling directly into the open ledger,
4017 // which won't work if unit tests are separated to only
4018 // be callable via RPC.)
4019 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
4020 auto const tx = env.jt(noop(alice), Seq(aliceSeq), Fee(openLedgerCost(env)));
4021 auto const result = xrpl::apply(env.app(), view, *tx.stx, TapUnlimited, j);
4022 BEAST_EXPECT(isTesSuccess(result.ter) && result.applied);
4023 return result.applied;
4024 });
4025 // the queued transaction is still there
4026 checkMetrics(*this, env, 1, std::nullopt, 5, 3);
4027
4028 // The next transaction should be able to go into the open
4029 // ledger, even though aliceSeq is queued. In earlier incarnations
4030 // of the TxQ this would cause an assert.
4031 env(noop(alice), Seq(aliceSeq + 1), Fee(openLedgerCost(env)));
4032 checkMetrics(*this, env, 1, std::nullopt, 6, 3);
4033 // Now queue a couple more transactions to make sure
4034 // they succeed despite aliceSeq being queued
4035 env(noop(alice), Seq(aliceSeq + 2), queued);
4036 env(noop(alice), Seq(aliceSeq + 3), queued);
4037 checkMetrics(*this, env, 3, std::nullopt, 6, 3);
4038
4039 // Now close the ledger. One of the queued transactions
4040 // (aliceSeq) should be dropped.
4041 env.close();
4042 checkMetrics(*this, env, 0, 12, 2, 6);
4043 }
4044
4045 void
4047 {
4048 // Test the situation where a transaction with an account and
4049 // ticket that's in the queue also appears in the ledger.
4050 //
4051 // Although this situation has not (yet) been observed in the wild,
4052 // it is a direct analogy to the previous sequence based test. So
4053 // there is no reason to not expect to see it in the wild.
4054 testcase("Ticket in queue and open ledger");
4055 using namespace jtx;
4056
4058
4059 auto alice = Account("alice");
4060
4061 auto const queued = Ter(terQUEUED);
4062
4063 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
4064
4065 // Create account
4066 env.fund(XRP(50000), noripple(alice));
4067 checkMetrics(*this, env, 0, std::nullopt, 1, 3);
4068
4069 // Create tickets
4070 std::uint32_t const tktSeq0{env.seq(alice) + 1};
4071 env(ticket::create(alice, 4));
4072
4073 // Fill the queue so the next transaction will be queued.
4074 fillQueue(env, alice);
4075 checkMetrics(*this, env, 0, std::nullopt, 4, 3);
4076
4077 // Queue a transaction with a ticket. Leave an unused ticket
4078 // on either side.
4079 env(noop(alice), ticket::Use(tktSeq0 + 1), queued);
4080 checkMetrics(*this, env, 1, std::nullopt, 4, 3);
4081
4082 // Now, apply a (different) transaction directly
4083 // to the open ledger, bypassing the queue
4084 // (This requires calling directly into the open ledger,
4085 // which won't work if unit tests are separated to only
4086 // be callable via RPC.)
4087 env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
4088 auto const tx = env.jt(noop(alice), ticket::Use(tktSeq0 + 1), Fee(openLedgerCost(env)));
4089 auto const result = xrpl::apply(env.app(), view, *tx.stx, TapUnlimited, j);
4090 BEAST_EXPECT(isTesSuccess(result.ter) && result.applied);
4091 return result.applied;
4092 });
4093 // the queued transaction is still there
4094 checkMetrics(*this, env, 1, std::nullopt, 5, 3);
4095
4096 // The next (sequence-based) transaction should be able to go into
4097 // the open ledger, even though tktSeq0 is queued. Note that this
4098 // sequence-based transaction goes in front of the queued
4099 // transaction, so the queued transaction is left in the queue.
4100 env(noop(alice), Fee(openLedgerCost(env)));
4101 checkMetrics(*this, env, 1, std::nullopt, 6, 3);
4102
4103 // We should be able to do the same thing with a ticket that goes
4104 // if front of the queued transaction. This one too will leave
4105 // the queued transaction in place.
4106 env(noop(alice), ticket::Use(tktSeq0 + 0), Fee(openLedgerCost(env)));
4107 checkMetrics(*this, env, 1, std::nullopt, 7, 3);
4108
4109 // We have one ticketed transaction in the queue. We should able
4110 // to add another to the queue.
4111 env(noop(alice), ticket::Use(tktSeq0 + 2), queued);
4112 checkMetrics(*this, env, 2, std::nullopt, 7, 3);
4113
4114 // Here we try to force the queued transactions into the ledger by
4115 // adding one more queued (ticketed) transaction that pays enough
4116 // so fee averaging kicks in. It doesn't work. It only succeeds in
4117 // forcing just the one ticketed transaction into the ledger.
4118 //
4119 // The fee averaging functionality makes sense for sequence-based
4120 // transactions because if there are several sequence-based
4121 // transactions queued, the transactions in front must go into the
4122 // ledger before the later ones can go in.
4123 //
4124 // Fee averaging does not make sense with tickets. Every ticketed
4125 // transaction is equally capable of going into the ledger independent
4126 // of all other ticket- or sequence-based transactions.
4127 env(noop(alice), ticket::Use(tktSeq0 + 3), Fee(XRP(10)));
4128 checkMetrics(*this, env, 2, std::nullopt, 8, 3);
4129
4130 // Now close the ledger. One of the queued transactions
4131 // (the one with tktSeq0 + 1) should be dropped.
4132 env.close();
4133 checkMetrics(*this, env, 0, 16, 1, 8);
4134 }
4135
4136 void
4138 {
4139 // The TxQ caches preflight results. But there are situations where
4140 // that cache must become invalidated, like if amendments change.
4141 //
4142 // This test puts transactions into the TxQ and then enables an
4143 // amendment. We won't really see much interesting here in the unit
4144 // test, but the code that checks for cache invalidation should be
4145 // exercised. You can see that in improved code coverage,
4146 testcase("Re-execute preflight");
4147 using namespace jtx;
4148
4149 Account const alice("alice");
4150 Account const bob("bob");
4151 Account const carol("carol");
4152 Account const daria("daria");
4153 Account const ellie("ellie");
4154 Account const fiona("fiona");
4155
4156 static constexpr int kLedgersInQueue = 30;
4157 auto cfg = makeConfig(
4158 {
4160 {Keys::kLedgersInQueue, std::to_string(kLedgersInQueue)},
4162 },
4163 {{Keys::kAccountReserve, "1000"}, {Keys::kOwnerReserve, "50"}});
4164
4165 auto& votingSection = cfg->section(Sections::kVoting);
4166 votingSection.set(
4167 Keys::kAccountReserve, std::to_string(cfg->fees.referenceFee.drops() * 100));
4168
4169 votingSection.set(Keys::kReferenceFee, std::to_string(cfg->fees.referenceFee.drops()));
4170
4171 Env env(*this, std::move(cfg));
4172
4173 env.fund(XRP(10000), alice);
4174 env.close();
4175 env.fund(XRP(10000), bob);
4176 env.close();
4177 env.fund(XRP(10000), carol);
4178 env.close();
4179 env.fund(XRP(10000), daria);
4180 env.close();
4181 env.fund(XRP(10000), ellie);
4182 env.close();
4183 env.fund(XRP(10000), fiona);
4184 env.close();
4185
4186 auto const metrics = env.app().getTxQ().getMetrics(*env.current());
4187 checkMetrics(*this, env, 0, kLedgersInQueue * metrics.txPerLedger, 0, 2);
4188
4189 // Close ledgers until the amendments show up.
4190 int i = 0;
4191 for (i = 0; i <= 257; ++i)
4192 {
4193 env.close();
4194 if (!getMajorityAmendments(*env.closed()).empty())
4195 break;
4196 }
4197 auto expectedPerLedger = xrpl::detail::numUpVotedAmendments() + 1;
4198 checkMetrics(*this, env, 0, kLedgersInQueue * expectedPerLedger, 0, expectedPerLedger);
4199
4200 // Now wait 2 weeks modulo 256 ledgers for the amendments to be
4201 // enabled. Speed the process by closing ledgers every 80 minutes,
4202 // which should get us to just past 2 weeks after 256 ledgers.
4203 using namespace std::chrono_literals;
4204 auto const closeDuration = 80min;
4205 for (i = 0; i <= 255; ++i)
4206 {
4207 env.close(closeDuration);
4208 }
4209
4210 auto const baseFee = env.current()->fees().base.drops();
4211 // We're very close to the flag ledger. Fill the ledger.
4212 fillQueue(env, alice);
4214 *this,
4215 env,
4216 0,
4217 kLedgersInQueue * expectedPerLedger,
4218 expectedPerLedger + 1,
4219 expectedPerLedger);
4220
4221 // Fill everyone's queues.
4222 auto seqAlice = env.seq(alice);
4223 auto seqBob = env.seq(bob);
4224 auto seqCarol = env.seq(carol);
4225 auto seqDaria = env.seq(daria);
4226 auto seqEllie = env.seq(ellie);
4227 auto seqFiona = env.seq(fiona);
4228
4229 // Use fees to guarantee order
4230 int txFee{static_cast<int>(baseFee * 9)};
4231 auto const prepareFee = [&](uint64_t multiplier) {
4232 return Fee(txFee - (multiplier * baseFee / 10));
4233 };
4234
4235 uint64_t multiplier = 0;
4236 for (int i = 0; i < 10; ++i)
4237 {
4238 env(noop(alice), Seq(seqAlice++), prepareFee(++multiplier), Ter(terQUEUED));
4239 env(noop(bob), Seq(seqBob++), prepareFee(++multiplier), Ter(terQUEUED));
4240 env(noop(carol), Seq(seqCarol++), prepareFee(++multiplier), Ter(terQUEUED));
4241 env(noop(daria), Seq(seqDaria++), prepareFee(++multiplier), Ter(terQUEUED));
4242 env(noop(ellie), Seq(seqEllie++), prepareFee(++multiplier), Ter(terQUEUED));
4243 env(noop(fiona), Seq(seqFiona++), prepareFee(++multiplier), Ter(terQUEUED));
4244 }
4245 std::size_t expectedInQueue = multiplier;
4247 *this,
4248 env,
4249 expectedInQueue,
4250 kLedgersInQueue * expectedPerLedger,
4251 expectedPerLedger + 1,
4252 expectedPerLedger);
4253
4254 // The next close should cause the in-ledger amendments to change.
4255 // Alice's queued transactions have a cached PreflightResult
4256 // that resulted from running against the Rules in the previous
4257 // ledger. Since the amendments change in this newest ledger
4258 // The TxQ must re-run preflight using the new rules.
4259 //
4260 // These particular amendments don't impact any of the queued
4261 // transactions, so we won't see any change in the transaction
4262 // outcomes. But code coverage is affected.
4263 do
4264 {
4265 env.close(closeDuration);
4266 auto expectedInLedger = expectedInQueue;
4267 expectedInQueue =
4268 (expectedInQueue > expectedPerLedger + 2 ? expectedInQueue - (expectedPerLedger + 2)
4269 : 0);
4270 expectedInLedger -= expectedInQueue;
4271 ++expectedPerLedger;
4273 *this,
4274 env,
4275 expectedInQueue,
4276 kLedgersInQueue * expectedPerLedger,
4277 expectedInLedger,
4278 expectedPerLedger);
4279 {
4280 auto const expectedPerAccount = expectedInQueue / 6;
4281 auto const expectedRemainder = expectedInQueue % 6;
4282 BEAST_EXPECT(env.seq(alice) == seqAlice - expectedPerAccount);
4283 BEAST_EXPECT(
4284 env.seq(bob) == seqBob - expectedPerAccount - (expectedRemainder > 4 ? 1 : 0));
4285 BEAST_EXPECT(
4286 env.seq(carol) ==
4287 seqCarol - expectedPerAccount - (expectedRemainder > 3 ? 1 : 0));
4288 BEAST_EXPECT(
4289 env.seq(daria) ==
4290 seqDaria - expectedPerAccount - (expectedRemainder > 2 ? 1 : 0));
4291 BEAST_EXPECT(
4292 env.seq(ellie) ==
4293 seqEllie - expectedPerAccount - (expectedRemainder > 1 ? 1 : 0));
4294 BEAST_EXPECT(
4295 env.seq(fiona) ==
4296 seqFiona - expectedPerAccount - (expectedRemainder > 0 ? 1 : 0));
4297 }
4298 } while (expectedInQueue > 0);
4299 }
4300
4301 void
4303 {
4304 // If...
4305 // o The queue is close to full,
4306 // o An account has multiple txs queued, and
4307 // o That same account has a transaction fail
4308 // Then drop the last transaction for the account if possible.
4309 //
4310 // Verify that happens.
4311 testcase("Queue full drop penalty");
4312 using namespace jtx;
4313
4314 // Because we're looking at a phenomenon that occurs when the TxQ
4315 // is at 95% capacity or greater, we need to have lots of entries
4316 // in the queue. You can't even see 95% capacity unless there are
4317 // 20 entries in the queue.
4318 Account const alice("alice");
4319 Account const bob("bob");
4320 Account const carol("carol");
4321 Account const daria("daria");
4322 Account const ellie("ellie");
4323 Account const fiona("fiona");
4324
4325 auto cfg = makeConfig({
4327 {Keys::kLedgersInQueue, "5"},
4330 });
4331
4332 Env env(*this, std::move(cfg));
4333 auto const baseFee = env.current()->fees().base.drops();
4334
4335 // We'll be using fees to control which entries leave the queue in
4336 // which order. There's no "lowFee" -- that's the default fee from
4337 // the unit test.
4338 int const medFee = baseFee * 10;
4339 int const hiFee = baseFee * 100;
4340
4341 // The noripple is to reduce the number of transactions required to
4342 // fund the accounts. There is no rippling in this test.
4343 env.fund(XRP(10000), noripple(alice, bob, carol, daria, ellie, fiona));
4344 env.close();
4345
4346 // Get bob some tickets.
4347 std::uint32_t const bobTicketSeq = env.seq(bob) + 1;
4348 env(ticket::create(bob, 10));
4349 env.close();
4350
4351 // Get the dropPenalty flag set on alice and bob by having one
4352 // of their transactions expire out of the queue. To start out
4353 // alice fills the ledger.
4354 fillQueue(env, alice);
4355 checkMetrics(*this, env, 0, 50, 7, 6);
4356
4357 // Now put a few transactions into alice's queue, including one that
4358 // will expire out soon.
4359 auto seqAlice = env.seq(alice);
4360 auto const seqSaveAlice = seqAlice;
4361 int feeDrops = baseFee * 4;
4362 env(noop(alice), Seq(seqAlice++), Fee(--feeDrops), LastLedgerSeq(7), Ter(terQUEUED));
4363 env(noop(alice), Seq(seqAlice++), Fee(--feeDrops), Ter(terQUEUED));
4364 env(noop(alice), Seq(seqAlice++), Fee(--feeDrops), Ter(terQUEUED));
4365 BEAST_EXPECT(env.seq(alice) == seqSaveAlice);
4366
4367 // Similarly for bob, but bob uses tickets in his transactions.
4368 // The drop penalty works a little differently with tickets.
4369 env(noop(bob), ticket::Use(bobTicketSeq + 0), LastLedgerSeq(7), Ter(terQUEUED));
4370 env(noop(bob), ticket::Use(bobTicketSeq + 1), Fee(--feeDrops), Ter(terQUEUED));
4371 env(noop(bob), ticket::Use(bobTicketSeq + 2), Fee(--feeDrops), Ter(terQUEUED));
4372
4373 // Fill the queue with higher fee transactions so alice's and
4374 // bob's transactions are stuck in the queue.
4375 auto seqCarol = env.seq(carol);
4376 auto seqDaria = env.seq(daria);
4377 auto seqEllie = env.seq(ellie);
4378 auto seqFiona = env.seq(fiona);
4379 feeDrops = medFee;
4380 for (int i = 0; i < 7; ++i)
4381 {
4382 env(noop(carol), Seq(seqCarol++), Fee(--feeDrops), Ter(terQUEUED));
4383 env(noop(daria), Seq(seqDaria++), Fee(--feeDrops), Ter(terQUEUED));
4384 env(noop(ellie), Seq(seqEllie++), Fee(--feeDrops), Ter(terQUEUED));
4385 env(noop(fiona), Seq(seqFiona++), Fee(--feeDrops), Ter(terQUEUED));
4386 }
4387
4388 checkMetrics(*this, env, 34, 50, 7, 6);
4389 env.close();
4390 checkMetrics(*this, env, 26, 50, 8, 7);
4391
4392 // Re-fill the queue so alice and bob stay stuck.
4393 feeDrops = medFee;
4394 for (int i = 0; i < 3; ++i)
4395 {
4396 env(noop(carol), Seq(seqCarol++), Fee(--feeDrops), Ter(terQUEUED));
4397 env(noop(daria), Seq(seqDaria++), Fee(--feeDrops), Ter(terQUEUED));
4398 env(noop(ellie), Seq(seqEllie++), Fee(--feeDrops), Ter(terQUEUED));
4399 env(noop(fiona), Seq(seqFiona++), Fee(--feeDrops), Ter(terQUEUED));
4400 }
4401 checkMetrics(*this, env, 38, 50, 8, 7);
4402 env.close();
4403 checkMetrics(*this, env, 29, 50, 9, 8);
4404
4405 // One more time...
4406 feeDrops = medFee;
4407 for (int i = 0; i < 3; ++i)
4408 {
4409 env(noop(carol), Seq(seqCarol++), Fee(--feeDrops), Ter(terQUEUED));
4410 env(noop(daria), Seq(seqDaria++), Fee(--feeDrops), Ter(terQUEUED));
4411 env(noop(ellie), Seq(seqEllie++), Fee(--feeDrops), Ter(terQUEUED));
4412 env(noop(fiona), Seq(seqFiona++), Fee(--feeDrops), Ter(terQUEUED));
4413 }
4414 checkMetrics(*this, env, 41, 50, 9, 8);
4415 env.close();
4416 checkMetrics(*this, env, 29, 50, 10, 9);
4417
4418 // Finally the stage is set. alice's and bob's transactions expired
4419 // out of the queue which caused the dropPenalty flag to be set on
4420 // their accounts.
4421 //
4422 // This also means that alice has a sequence gap in her transactions,
4423 // and thus can't queue any more.
4424 env(noop(alice), Seq(seqAlice), Fee(hiFee), Ter(telCAN_NOT_QUEUE));
4425
4426 // Once again, fill the queue almost to the brim.
4427 feeDrops = medFee;
4428 for (int i = 0; i < 4; ++i)
4429 {
4430 env(noop(carol), Seq(seqCarol++), Fee(--feeDrops), Ter(terQUEUED));
4431 env(noop(daria), Seq(seqDaria++), Fee(--feeDrops), Ter(terQUEUED));
4432 env(noop(ellie), Seq(seqEllie++), Fee(--feeDrops), Ter(terQUEUED));
4433 env(noop(fiona), Seq(seqFiona++), Fee(--feeDrops), Ter(terQUEUED));
4434 }
4435 env(noop(carol), Seq(seqCarol++), Fee(--feeDrops), Ter(terQUEUED));
4436 env(noop(daria), Seq(seqDaria++), Fee(--feeDrops), Ter(terQUEUED));
4437 env(noop(ellie), Seq(seqEllie++), Fee(--feeDrops), Ter(terQUEUED));
4438 checkMetrics(*this, env, 48, 50, 10, 9);
4439
4440 // Now induce a fee jump which should cause all the transactions
4441 // in the queue to fail with telINSUF_FEE_P.
4442 //
4443 // *NOTE* raiseLocalFee() is tricky to use since the local fee is
4444 // asynchronously lowered by LoadManager. Here we're just
4445 // pushing the local fee up really high and then hoping that we
4446 // outrace LoadManager undoing our work.
4447 for (int i = 0; i < 30; ++i)
4448 {
4449 env.app().getFeeTrack().raiseLocalFee();
4450 }
4451
4452 // Now close the ledger, which will attempt to process alice's
4453 // and bob's queued transactions.
4454 // o The _last_ transaction should be dropped from alice's queue.
4455 // o The first failing transaction should be dropped from bob's queue.
4456 env.close();
4457 checkMetrics(*this, env, 46, 50, 0, 10);
4458
4459 // Run the local fee back down.
4460 while (env.app().getFeeTrack().lowerLocalFee())
4461 ;
4462
4463 // bob fills the ledger so it's easier to probe the TxQ.
4464 fillQueue(env, bob);
4465 checkMetrics(*this, env, 46, 50, 11, 10);
4466
4467 // Before the close() alice had two transactions in her queue.
4468 // We now expect her to have one. Here's the state of alice's queue.
4469 //
4470 // 0. The transaction that used to be first in her queue expired
4471 // out two env.close() calls back. That left a gap in alice's
4472 // queue which has not been filled yet.
4473 //
4474 // 1. The first transaction in the queue failed to apply because
4475 // of the sequence gap. But it is retained in the queue.
4476 //
4477 // 2. The last (second) transaction in alice's queue was removed
4478 // as "punishment"...
4479 // a) For already having a transaction expire out of her queue, and
4480 // b) For just now having a queued transaction fail on apply()
4481 // because of the sequence gap.
4482 //
4483 // Verify that kNone of alice's queued transactions actually applied to
4484 // her account.
4485 BEAST_EXPECT(env.seq(alice) == seqSaveAlice);
4486 seqAlice = seqSaveAlice;
4487
4488 // Verify that there's a gap at the front of alice's queue by
4489 // queuing another low fee transaction into that spot.
4490 env(noop(alice), Seq(seqAlice++), Fee(baseFee * 1.1), Ter(terQUEUED));
4491
4492 // Verify that the first entry in alice's queue is still there
4493 // by trying to replace it and having that fail.
4494 env(noop(alice), Seq(seqAlice++), Ter(telCAN_NOT_QUEUE_FEE));
4495
4496 // Verify that the last transaction in alice's queue was removed by
4497 // appending to her queue with a very low fee.
4498 env(noop(alice), Seq(seqAlice++), Ter(terQUEUED));
4499
4500 // Before the close() bob had two transactions in his queue.
4501 // We now expect him to have one. Here's the state of bob's queue.
4502 //
4503 // 0. The transaction that used to be first in his queue expired out
4504 // two env.close() calls back. That is how the dropPenalty flag
4505 // got set on bob's queue.
4506 //
4507 // 1. Since bob's remaining transactions all have the same fee, the
4508 // TxQ attempted to apply bob's second transaction to the ledger,
4509 // but the fee was too low. So the TxQ threw that transaction
4510 // (not bob's last transaction) out of the queue.
4511 //
4512 // 2. The last of bob's transactions remains in the TxQ.
4513
4514 // Verify that bob's first transaction was removed from the queue
4515 // by queueing another low fee transaction into that spot.
4516 env(noop(bob), ticket::Use(bobTicketSeq + 0), Fee(baseFee * 1.2), Ter(terQUEUED));
4517
4518 // The following two TXs should consist of
4519 // - 1 tx that is queued
4520 // - 1 tx that cannot be queued.
4521 // There seems to be a bit of a race condition based on the raiseLocalFee above
4522 // that can produce a different result on Debian bookworm.
4523 // Ultimately we are wanting to check if exactly one of bob's txs is dropped penalized.
4524 auto const ter =
4525 env(noop(bob), ticket::Use(bobTicketSeq + 1), Fee(baseFee * 1.1), Ter(std::ignore))
4526 .ter();
4527 if (ter == terQUEUED)
4528 {
4529 env(noop(bob), ticket::Use(bobTicketSeq + 2), Ter(telCAN_NOT_QUEUE_FEE));
4530 }
4531 else
4532 {
4533 BEAST_EXPECT(ter == telCAN_NOT_QUEUE_FEE);
4534 env(noop(bob), ticket::Use(bobTicketSeq + 2), Fee(baseFee * 1.1), Ter(terQUEUED));
4535 }
4536 }
4537
4538 void
4540 {
4541 testcase("Cancel queued offers");
4542 using namespace jtx;
4543
4544 Account const alice("alice");
4545 auto const gw = Account("gw");
4546 auto const usd = gw["USD"];
4547
4548 auto cfg = makeConfig({
4550 {Keys::kLedgersInQueue, "5"},
4553 });
4554
4555 Env env(*this, std::move(cfg));
4556
4557 // The noripple is to reduce the number of transactions required to
4558 // fund the accounts. There is no rippling in this test.
4559 env.fund(XRP(100000), noripple(alice));
4560 env.close();
4561
4562 {
4563 // ------- Sequence-based transactions -------
4564 fillQueue(env, alice);
4565
4566 // Alice creates a couple offers
4567 auto const aliceSeq = env.seq(alice);
4568 env(offer(alice, usd(1000), XRP(1000)), Ter(terQUEUED));
4569
4570 env(offer(alice, usd(1000), XRP(1001)), Seq(aliceSeq + 1), Ter(terQUEUED));
4571
4572 // Alice creates transactions that cancel the first set of
4573 // offers, one through another offer, and one cancel
4574 env(offer(alice, usd(1000), XRP(1002)),
4575 Seq(aliceSeq + 2),
4576 Json(jss::OfferSequence, aliceSeq),
4577 Ter(terQUEUED));
4578
4579 env(offerCancel(alice, aliceSeq + 1), Seq(aliceSeq + 3), Ter(terQUEUED));
4580
4581 env.close();
4582
4583 checkMetrics(*this, env, 0, 50, 4, 6);
4584 }
4585
4586 {
4587 // ------- Ticket-based transactions -------
4588
4589 // Alice creates some tickets
4590 auto const aliceTkt = env.seq(alice);
4591 env(ticket::create(alice, 6));
4592 env.close();
4593
4594 fillQueue(env, alice);
4595
4596 // Alice creates a couple offers using tickets, consuming the
4597 // tickets in reverse order
4598 auto const aliceSeq = env.seq(alice);
4599 env(offer(alice, usd(1000), XRP(1000)), ticket::Use(aliceTkt + 4), Ter(terQUEUED));
4600
4601 env(offer(alice, usd(1000), XRP(1001)), ticket::Use(aliceTkt + 3), Ter(terQUEUED));
4602
4603 // Alice creates a couple more transactions that cancel the first
4604 // set of offers, also in reverse order. This allows Alice to submit
4605 // a tx with a lower ticket value than the offer it's cancelling.
4606 // These transactions succeed because Ticket ordering is arbitrary
4607 // and it's up to the user to ensure they don't step on their own
4608 // feet.
4609 env(offer(alice, usd(1000), XRP(1002)),
4610 ticket::Use(aliceTkt + 2),
4611 Json(jss::OfferSequence, aliceTkt + 4),
4612 Ter(terQUEUED));
4613
4614 env(offerCancel(alice, aliceTkt + 3), ticket::Use(aliceTkt + 1), Ter(terQUEUED));
4615
4616 // Create a couple more offers using sequences
4617 env(offer(alice, usd(1000), XRP(1000)), Ter(terQUEUED));
4618
4619 env(offer(alice, usd(1000), XRP(1001)), Seq(aliceSeq + 1), Ter(terQUEUED));
4620
4621 // And try to cancel those using tickets
4622 env(offer(alice, usd(1000), XRP(1002)),
4623 ticket::Use(aliceTkt + 5),
4624 Json(jss::OfferSequence, aliceSeq),
4625 Ter(terQUEUED));
4626
4627 env(offerCancel(alice, aliceSeq + 1), ticket::Use(aliceTkt + 6), Ter(terQUEUED));
4628
4629 env.close();
4630
4631 // The ticket transactions that didn't succeed or get queued succeed
4632 // this time because the tickets got consumed when the offers came
4633 // out of the queue
4634 checkMetrics(*this, env, 0, 50, 8, 7);
4635 }
4636 }
4637
4638 void
4640 {
4641 testcase("Zero reference fee");
4642 using namespace jtx;
4643
4644 Account const alice("alice");
4645 auto const queued = Ter(terQUEUED);
4646
4647 Env env(
4648 *this,
4649 makeConfig(
4651 {
4652 {Keys::kReferenceFee, "0"},
4653 {Keys::kAccountReserve, "0"},
4654 {Keys::kOwnerReserve, "0"},
4655 }));
4656
4657 checkMetrics(*this, env, 0, std::nullopt, 0, 3);
4658
4659 // ledgers in queue is 2 because of makeConfig
4660 auto const initQueueMax = initFee(env, 3, 2, 0, 0, 0);
4661
4662 BEAST_EXPECT(env.current()->fees().base == 0);
4663
4664 {
4665 auto const fee = env.rpc("fee");
4666
4667 if (BEAST_EXPECT(fee.isMember(jss::result)) &&
4668 BEAST_EXPECT(!rpc::containsError(fee[jss::result])))
4669 {
4670 auto const& result = fee[jss::result];
4671
4672 BEAST_EXPECT(result.isMember(jss::levels));
4673 auto const& levels = result[jss::levels];
4674 BEAST_EXPECT(
4675 levels.isMember(jss::median_level) && levels[jss::median_level] == "128000");
4676 BEAST_EXPECT(
4677 levels.isMember(jss::minimum_level) && levels[jss::minimum_level] == "256");
4678 BEAST_EXPECT(
4679 levels.isMember(jss::open_ledger_level) &&
4680 levels[jss::open_ledger_level] == "256");
4681 BEAST_EXPECT(
4682 levels.isMember(jss::reference_level) && levels[jss::reference_level] == "256");
4683
4684 auto const& drops = result[jss::drops];
4685 BEAST_EXPECT(drops.isMember(jss::base_fee) && drops[jss::base_fee] == "0");
4686 BEAST_EXPECT(drops.isMember(jss::median_fee) && drops[jss::median_fee] == "0");
4687 BEAST_EXPECT(drops.isMember(jss::minimum_fee) && drops[jss::minimum_fee] == "0");
4688 BEAST_EXPECT(
4689 drops.isMember(jss::open_ledger_fee) && drops[jss::open_ledger_fee] == "0");
4690 }
4691 }
4692
4693 checkMetrics(*this, env, 0, initQueueMax, 0, 3);
4694
4695 // The noripple is to reduce the number of transactions required to
4696 // fund the accounts. There is no rippling in this test.
4697 env.fund(XRP(100000), noripple(alice));
4698
4699 checkMetrics(*this, env, 0, initQueueMax, 1, 3);
4700
4701 env.close();
4702
4703 checkMetrics(*this, env, 0, 6, 0, 3);
4704
4705 fillQueue(env, alice);
4706
4707 checkMetrics(*this, env, 0, 6, 4, 3);
4708
4709 env(noop(alice), Fee(openLedgerCost(env)));
4710
4711 checkMetrics(*this, env, 0, 6, 5, 3);
4712
4713 auto aliceSeq = env.seq(alice);
4714 env(noop(alice), queued);
4715
4716 checkMetrics(*this, env, 1, 6, 5, 3);
4717
4718 env(noop(alice), Seq(aliceSeq + 1), Fee(10), queued);
4719
4720 checkMetrics(*this, env, 2, 6, 5, 3);
4721
4722 {
4723 auto const fee = env.rpc("fee");
4724
4725 if (BEAST_EXPECT(fee.isMember(jss::result)) &&
4726 BEAST_EXPECT(!rpc::containsError(fee[jss::result])))
4727 {
4728 auto const& result = fee[jss::result];
4729
4730 BEAST_EXPECT(result.isMember(jss::levels));
4731 auto const& levels = result[jss::levels];
4732 BEAST_EXPECT(
4733 levels.isMember(jss::median_level) && levels[jss::median_level] == "128000");
4734 BEAST_EXPECT(
4735 levels.isMember(jss::minimum_level) && levels[jss::minimum_level] == "256");
4736 BEAST_EXPECT(
4737 levels.isMember(jss::open_ledger_level) &&
4738 levels[jss::open_ledger_level] == "355555");
4739 BEAST_EXPECT(
4740 levels.isMember(jss::reference_level) && levels[jss::reference_level] == "256");
4741
4742 auto const& drops = result[jss::drops];
4743 BEAST_EXPECT(drops.isMember(jss::base_fee) && drops[jss::base_fee] == "0");
4744 BEAST_EXPECT(drops.isMember(jss::median_fee) && drops[jss::median_fee] == "0");
4745 BEAST_EXPECT(drops.isMember(jss::minimum_fee) && drops[jss::minimum_fee] == "0");
4746 BEAST_EXPECT(
4747 drops.isMember(jss::open_ledger_fee) && drops[jss::open_ledger_fee] == "1389");
4748 }
4749 }
4750
4751 env.close();
4752
4753 checkMetrics(*this, env, 0, 10, 2, 5);
4754 }
4755
4756 void
4779
4780 void
4800};
4801
4803{
4804 void
4805 run() override
4806 {
4807 runMetaInfo();
4808 }
4809};
4810
4811BEAST_DEFINE_TESTSUITE_PRIO(TxQPosNegFlows, app, xrpl, 1);
4812BEAST_DEFINE_TESTSUITE_PRIO(TxQMetaInfo, app, xrpl, 1);
4813
4814} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:44
A testsuite class.
Definition suite.h:52
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition suite.h:554
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:155
Represents a JSON value.
Definition json_value.h:121
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
SeqProxy & advanceBy(std::uint32_t amount)
Definition SeqProxy.h:102
constexpr std::uint32_t value() const
Definition SeqProxy.h:80
virtual TxQ & getTxQ()=0
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
Definition TxQ.cpp:2070
std::vector< TxDetails > getAccountTxs(AccountID const &account) const
Returns information about the transactions currently in the queue for the account.
Definition TxQ.cpp:2120
std::vector< TxDetails > getTxs() const
Returns information about all transactions currently in the queue.
Definition TxQ.cpp:2140
static constexpr FeeLevel64 kBaseLevel
Fee level for single-signed reference transaction.
Definition TxQ.h:64
constexpr value_type drops() const
Returns the number of drops.
Definition XRPAmount.h:163
static Account const kMaster
The master account that holds all XRP in genesis.
void run() override
Runs the suite.
static constexpr FeeLevel64 kBaseFeeLevel
Definition TxQ_test.cpp:66
static auto calcMedFeeLevel(FeeLevel64 const feeLevel1, FeeLevel64 const feeLevel2)
Definition TxQ_test.cpp:111
void run() override
Runs the suite.
static auto calcMedFeeLevel(FeeLevel64 const feeLevel)
Definition TxQ_test.cpp:119
static auto openLedgerCost(jtx::Env &env)
Definition TxQ_test.cpp:78
static void fillQueue(jtx::Env &env, jtx::Account const &account)
Definition TxQ_test.cpp:70
static constexpr FeeLevel64 kMinEscalationFeeLevel
Definition TxQ_test.cpp:67
static auto txFeeLevelByAccount(jtx::Env &env, jtx::Account const &account)
Definition TxQ_test.cpp:98
std::size_t initFee(jtx::Env &env, std::size_t expectedPerLedger, std::size_t ledgersInQueue, std::uint32_t base, std::uint32_t reserve, std::uint32_t increment)
Definition TxQ_test.cpp:125
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
A balance matches.
Definition balance.h:24
A transaction testing environment wrapper.
Definition Env_ss.h:19
A transaction testing environment.
Definition Env.h:161
Application & app()
Definition Env.h:300
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
Definition Env.cpp:133
std::shared_ptr< ReadView const > closed()
Returns the last closed ledger.
Definition Env.cpp:127
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Definition Env.cpp:323
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition Env.cpp:302
Account const & master
Definition Env.h:165
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1058
JTx jt(JsonValue &&jv, FN const &... fN)
Create a JTx from parameters.
Definition Env.h:723
void memoize(Account const &account)
Associate AccountID with account.
Definition Env.cpp:174
beast::Journal const journal
Definition Env.h:204
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:377
NetClock::time_point now()
Returns the current network time.
Definition Env.h:326
Set the fee on a JTx.
Definition fee.h:20
Inject raw JSON.
Definition jtx_json.h:16
Match the number of items in the account's owner directory.
Definition owners.h:55
Check a set of conditions.
Definition require.h:49
Sets the SendMax on a JTx.
Definition sendmax.h:16
Set the regular signature on a JTx.
Definition sig.h:19
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:18
Set a ticket sequence on a JTx.
Definition ticket.h:36
T data(T... args)
T empty(T... args)
T max(T... args)
T min(T... args)
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
std::size_t numUpVotedAmendments()
Amendments that this server will vote for by default.
bool containsError(json::Value const &json)
Returns true if the json contains an rpc error specification.
json::Value set(jtx::Account const &account, jtx::Account const &authorize, std::vector< std::string > const &permissions)
Definition delegate.cpp:17
json::Value create(Account const &account, std::uint32_t count)
Create one of more tickets.
Definition ticket.cpp:16
static NoneT const kNone
Definition tags.h:9
json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
Definition pay.cpp:14
json::Value regkey(Account const &account, DisabledT)
Disable the regular key.
Definition regkey.cpp:13
json::Value offerCancel(Account const &account, std::uint32_t offerSeq)
Cancel an offer.
Definition offer.cpp:31
XrpT const XRP
Converts to XRP Issue or STAmount.
Definition amount.cpp:92
json::Value noop(Account const &account)
The null transaction.
Definition noop.h:14
XRPAmount txFee(Env const &env, std::uint16_t n)
std::unique_ptr< Config > makeConfig(std::map< std::string, std::string > extraTxQ={}, std::map< std::string, std::string > extraVoting={})
void checkMetrics(Suite &test, jtx::Env &env, std::size_t expectedCount, std::optional< std::size_t > expectedMaxCount, std::size_t expectedInLedger, std::size_t expectedPerLedger, std::uint64_t expectedMinFeeLevel=kBaseFeeLevel.fee(), std::uint64_t expectedMedFeeLevel=kMinEscalationFeeLevel.fee(), std::source_location const location=std::source_location::current())
OwnerCount< ltRIPPLE_STATE > Lines
Match the number of trust lines in the account's owner directory.
Definition owners.h:132
std::array< Account, 1+sizeof...(Args)> noripple(Account const &account, Args const &... args)
Designate accounts as no-ripple in Env::fund.
Definition Env.h:86
json::Value offer(Account const &account, STAmount const &takerPays, STAmount const &takerGets, std::uint32_t flags)
Create an offer.
Definition offer.cpp:14
json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:18
PrettyAmount drops(Integer i)
Returns an XRP PrettyAmount, which is trivially convertible to STAmount.
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Definition multisign.cpp:31
OwnerCount< ltTICKET > Tickets
Match the number of tickets on the account.
Definition ticket.h:54
json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition flags.cpp:15
constexpr XRPAmount
Convert XRP to drops (integral types).
Definition TxTest.h:53
static XRPAmount reserve(jtx::Env const &env, std::uint32_t count)
BEAST_DEFINE_TESTSUITE_PRIO(AccountDelete, app, xrpl, 2)
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
Definition WSClient.cpp:373
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr FlagValue spfSponsorFee
Definition TxFlags.h:467
@ telCAN_NOT_QUEUE_FULL
Definition TER.h:50
@ telCAN_NOT_QUEUE_FEE
Definition TER.h:49
@ telCAN_NOT_QUEUE_BLOCKED
Definition TER.h:48
@ telCAN_NOT_QUEUE
Definition TER.h:45
@ telCAN_NOT_QUEUE_BALANCE
Definition TER.h:46
@ telCAN_NOT_QUEUE_BLOCKS
Definition TER.h:47
@ terPRE_SEQ
Definition TER.h:223
@ terINSUF_FEE_B
Definition TER.h:218
@ terNO_ACCOUNT
Definition TER.h:219
@ terPRE_TICKET
Definition TER.h:228
@ terQUEUED
Definition TER.h:227
@ RpcInvalidParams
Definition ErrorCodes.h:67
PreflightResult preflight(ServiceRegistry &registry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
ApplyResult apply(ServiceRegistry &registry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition apply.cpp:181
@ tefWRONG_PRIOR
Definition TER.h:170
@ tefNO_TICKET
Definition TER.h:179
@ tefPAST_SEQ
Definition TER.h:169
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
Definition TxQ.h:1011
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
FeeLevel< std::uint64_t > FeeLevel64
Definition Units.h:443
FeeLevel64 toFeeLevel(XRPAmount const &drops, XRPAmount const &baseFee)
Definition TxQ.h:1017
@ TapUnlimited
Definition ApplyView.h:39
@ TapNone
Definition ApplyView.h:28
@ temBAD_AMOUNT
Definition TER.h:77
@ temREDUNDANT
Definition TER.h:100
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
@ tecUNFUNDED_OFFER
Definition TER.h:295
MajorityAmendmentsT getMajorityAmendments(ReadView const &view)
Definition View.cpp:318
@ tesSUCCESS
Definition TER.h:253
static constexpr auto kMaximumTxnInLedger
Definition Constants.h:128
static constexpr auto kSlowConsensusDecreasePercent
Definition Constants.h:163
static constexpr auto kAccountReserve
Definition Constants.h:84
static constexpr auto kReferenceFee
Definition Constants.h:153
static constexpr auto kMaximumTxnPerAccount
Definition Constants.h:129
static constexpr auto kTargetTxnInLedger
Definition Constants.h:171
static constexpr auto kMinimumQueueSize
Definition Constants.h:135
static constexpr auto kMinimumTxnInLedger
Definition Constants.h:136
static constexpr auto kNormalConsensusIncreasePercent
Definition Constants.h:138
static constexpr auto kLedgersInQueue
Definition Constants.h:120
static constexpr auto kMinimumTxnInLedgerStandalone
Definition Constants.h:137
static constexpr auto kOwnerReserve
Definition Constants.h:144
static constexpr auto kVoting
Definition Constants.h:78
Used by parseResult() and postConditions().
Definition Env.h:171
std::optional< TER > ter
Definition Env.h:172
Set the sequence number on a JTx.
Definition seq.h:16
T to_string(T... args)
T what(T... args)