xrpld
Loading...
Searching...
No Matches
Transactor.cpp
1#include <xrpl/tx/Transactor.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/core/NetworkIDService.h>
10#include <xrpl/core/ServiceRegistry.h>
11#include <xrpl/json/to_string.h> // IWYU pragma: keep
12#include <xrpl/ledger/ApplyView.h>
13#include <xrpl/ledger/ReadView.h>
14#include <xrpl/ledger/helpers/AccountRootHelpers.h>
15#include <xrpl/ledger/helpers/CredentialHelpers.h>
16#include <xrpl/ledger/helpers/DelegateHelpers.h>
17#include <xrpl/ledger/helpers/NFTokenHelpers.h>
18#include <xrpl/ledger/helpers/OfferHelpers.h>
19#include <xrpl/ledger/helpers/ProposalHelpers.h>
20#include <xrpl/ledger/helpers/RippleStateHelpers.h>
21#include <xrpl/ledger/helpers/SponsorHelpers.h>
22#include <xrpl/protocol/AccountID.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/Indexes.h>
25#include <xrpl/protocol/LedgerFormats.h>
26#include <xrpl/protocol/Permissions.h>
27#include <xrpl/protocol/Protocol.h>
28#include <xrpl/protocol/PublicKey.h>
29#include <xrpl/protocol/Rules.h>
30#include <xrpl/protocol/SField.h>
31#include <xrpl/protocol/STAmount.h>
32#include <xrpl/protocol/STLedgerEntry.h>
33#include <xrpl/protocol/STTx.h>
34#include <xrpl/protocol/Serializer.h> // IWYU pragma: keep
35#include <xrpl/protocol/SystemParameters.h>
36#include <xrpl/protocol/TER.h>
37#include <xrpl/protocol/TxFlags.h>
38#include <xrpl/protocol/TxMeta.h>
39#include <xrpl/protocol/XRPAmount.h>
40#include <xrpl/server/LoadFeeTrack.h>
41#include <xrpl/tx/ApplyContext.h>
42#include <xrpl/tx/SignerEntries.h>
43#include <xrpl/tx/apply.h>
44#include <xrpl/tx/applySteps.h>
45#include <xrpl/tx/invariants/InvariantRunner.h>
46
47#include <algorithm>
48#include <cstddef>
49#include <cstdint>
50#include <functional>
51#include <map>
52#include <optional>
53#include <stdexcept>
54#include <tuple>
55#include <unordered_set>
56#include <utility>
57#include <vector>
58
59namespace xrpl {
60
66{
67 if (isPseudoTx(ctx.tx) && ctx.tx.isFlag(tfInnerBatchTxn))
68 {
69 JLOG(ctx.j.warn()) << "Pseudo transactions cannot contain the "
70 "tfInnerBatchTxn flag.";
71 return temINVALID_FLAG;
72 }
73
74 if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID))
75 {
76 uint32_t const nodeNID = ctx.registry.get().getNetworkIDService().getNetworkID();
77 std::optional<uint32_t> txNID = ctx.tx[~sfNetworkID];
78
79 if (nodeNID <= 1024)
80 {
81 // legacy networks have ids less than 1024, these networks cannot
82 // specify NetworkID in txn
83 if (txNID)
85 }
86 else
87 {
88 // new networks both require the field to be present and require it
89 // to match
90 if (!txNID)
92
93 if (*txNID != nodeNID)
94 return telWRONG_NETWORK;
95 }
96 }
97
98 auto const txID = ctx.tx.getTransactionID();
99
100 if (txID == beast::kZero)
101 {
102 JLOG(ctx.j.warn()) << "applyTransaction: transaction id may not be zero";
103 return temINVALID;
104 }
105
106 if ((ctx.tx.getFlags() & flagMask) != 0u)
107 {
108 JLOG(ctx.j.debug()) << ctx.tx.peekAtField(sfTransactionType).getFullText()
109 << ": invalid flags.";
110 return temINVALID_FLAG;
111 }
112
113 return tesSUCCESS;
114}
115
116namespace detail {
117
123NotTEC
125{
126 if (auto const spk = sigObject.getFieldVL(sfSigningPubKey);
127 !spk.empty() && !publicKeyType(makeSlice(spk)))
128 {
129 JLOG(j.debug()) << "preflightCheckSigningKey: invalid signing key";
130 return temBAD_SIGNATURE;
131 }
132 return tesSUCCESS;
133}
134
137{
138 if ((flags & TapDryRun) != 0u) // simulation
139 {
140 std::optional<Slice> const signature = sigObject[~sfTxnSignature];
141 if (signature && !signature->empty())
142 {
143 // NOTE: This code should never be hit because it's checked in the
144 // `simulate` RPC
145 return temINVALID; // LCOV_EXCL_LINE
146 }
147
148 if (!sigObject.isFieldPresent(sfSigners))
149 {
150 // no signers, no signature - a valid simulation
151 return tesSUCCESS;
152 }
153
154 for (auto const& signer : sigObject.getFieldArray(sfSigners))
155 {
156 if (signer.isFieldPresent(sfTxnSignature) && !signer[sfTxnSignature].empty())
157 {
158 // NOTE: This code should never be hit because it's
159 // checked in the `simulate` RPC
160 return temINVALID; // LCOV_EXCL_LINE
161 }
162 }
163
164 Slice const signingPubKey = sigObject[sfSigningPubKey];
165 if (!signingPubKey.empty())
166 {
167 // trying to single-sign _and_ multi-sign a transaction
168 return temINVALID;
169 }
170 return tesSUCCESS;
171 }
172 return {};
173}
174
175} // namespace detail
176
177static NotTEC
179{
180 bool const hasSponsor = ctx.tx.isFieldPresent(sfSponsor);
181 bool const hasSponsorFlags = ctx.tx.isFieldPresent(sfSponsorFlags);
182 bool const hasSponsorSig = ctx.tx.isFieldPresent(sfSponsorSignature);
183
184 if ((hasSponsor || hasSponsorFlags || hasSponsorSig) && !ctx.rules.enabled(featureSponsor))
185 return temDISABLED;
186
187 if (hasSponsor != hasSponsorFlags)
188 {
189 JLOG(ctx.j.debug()) << "preflight1: sponsor and sponsor flags mismatch";
190 return temINVALID_FLAG;
191 }
192 if (hasSponsorSig && (!hasSponsor || !hasSponsorFlags))
193 {
194 JLOG(ctx.j.debug()) << "preflight1: sponsor signature without sponsor definition";
195 return temMALFORMED;
196 }
197
198 if (hasSponsorFlags)
199 {
200 auto const sponsorFlags = ctx.tx.getFieldU32(sfSponsorFlags);
201 if (((sponsorFlags & spfSponsorFlagMask) != 0u) || sponsorFlags == 0)
202 {
203 JLOG(ctx.j.debug()) << "preflight1: invalid sponsor flags";
204 return temINVALID_FLAG;
205 }
206
207 // Reserve sponsorship is only permitted for an explicit allow-list of
208 // transaction types, for v1. All other tx types reject spfSponsorReserve here.
209 if (isReserveSponsored(ctx.tx))
210 {
212 {
213 JLOG(ctx.j.debug())
214 << "preflight1: spfSponsorReserve not allowed for this transaction type";
215 return temINVALID_FLAG;
216 }
217 }
218 }
219
220 if (hasSponsor && ctx.tx.getAccountID(sfSponsor) == ctx.tx.getAccountID(sfAccount))
221 {
222 JLOG(ctx.j.debug()) << "preflight1: Sponsor account cannot be the same as the account";
223 return temMALFORMED;
224 }
225
226 return tesSUCCESS;
227}
228
232NotTEC
234{
235 if (ctx.tx.isFieldPresent(sfDelegate))
236 {
237 if (!ctx.rules.enabled(featurePermissionDelegationV1_1))
238 return temDISABLED;
239
240 if (ctx.tx[sfDelegate] == ctx.tx[sfAccount])
241 return temBAD_SIGNER;
242
243 auto const& perm = Permission::getInstance();
244 auto const txType = ctx.tx.getTxnType();
245
246 // If the transaction is not delegable and does not have granular permissions, fail earlier
247 // with temINVALID. This is to prevent transactions that are not delegable at all from
248 // being processed further in the invokeCheckPermission function.
249 if (!perm.isDelegable(Permission::txToPermissionType(txType), ctx.rules) &&
250 !perm.hasGranularPermissions(txType))
251 return temINVALID;
252 }
253
254 if (auto const ret = preflight0(ctx, flagMask))
255 return ret;
256
257 auto const id = ctx.tx.getAccountID(sfAccount);
258 if (id == beast::kZero)
259 {
260 JLOG(ctx.j.warn()) << "preflight1: bad account id";
261 return temBAD_SRC_ACCOUNT;
262 }
263
264 // No point in going any further if the transaction fee is malformed.
265 auto const fee = ctx.tx.getFieldAmount(sfFee);
266 if (!fee.native() || fee.negative() || !isLegalAmount(fee.xrp()))
267 {
268 JLOG(ctx.j.debug()) << "preflight1: invalid fee";
269 return temBAD_FEE;
270 }
271
272 if (auto const ret = detail::preflightCheckSigningKey(ctx.tx, ctx.j))
273 return ret;
274
275 // An AccountTxnID field constrains transaction ordering more than the
276 // Sequence field. Tickets, on the other hand, reduce ordering
277 // constraints. Because Tickets and AccountTxnID work against one
278 // another the combination is unsupported and treated as malformed.
279 //
280 // We return temINVALID for such transactions.
281 if (ctx.tx.getSeqProxy().isTicket() && ctx.tx.isFieldPresent(sfAccountTxnID))
282 return temINVALID;
283
284 if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatchV1_1))
285 return temINVALID_FLAG;
286
287 // Reject if the inner batch flag and parentBatchId are inconsistent.
288 // A standalone tx with tfInnerBatchTxn but no parentBatchId is an
289 // attack attempt. A tx with parentBatchId but without tfInnerBatchTxn
290 // is a programming error.
291 if (ctx.tx.isFlag(tfInnerBatchTxn) != ctx.parentBatchId.has_value())
293
294 if (auto const ter = preflight1Sponsor(ctx); !isTesSuccess(ter))
295 return ter;
296
297 return tesSUCCESS;
298}
299
303NotTEC
305{
306 if (auto const ret = detail::preflightCheckSimulateKeys(ctx.flags, ctx.tx, ctx.j))
307 {
308 // Skips following checks if the transaction is being simulated,
309 // regardless of success or failure
310 return *ret;
311 }
312
313 // Skip the signature check on batch inner transactions. preflight1 already
314 // enforces both conditions; re-checking them as defense in depth guarantees
315 // we never return success (and so skip signature validation) for an inner
316 // transaction unless the amendment is enabled and it really sits inside a
317 // batch.
318 if (ctx.tx.isFlag(tfInnerBatchTxn))
319 {
320 if (!ctx.rules.enabled(featureBatchV1_1))
321 return temINVALID_FLAG;
322 if (!ctx.parentBatchId.has_value())
324 return tesSUCCESS;
325 }
326 // Do not add any checks after this point that are relevant for
327 // batch inner transactions. They will be skipped.
328
329 auto const sigValid = checkValidity(ctx.registry.get().getHashRouter(), ctx.tx, ctx.rules);
330 if (sigValid.first == Validity::SigBad)
331 {
332 JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second;
333 return temINVALID;
334 }
335
336 // Do not add any checks after this point that are relevant for
337 // batch inner transactions. They will be skipped.
338
339 return tesSUCCESS;
340}
341
342NotTEC
344{
345 if (ctx.rules.enabled(fixCleanup3_2_0) && hasInvalidAmount(ctx.tx, ctx.j))
346 return temBAD_AMOUNT;
347
348 return tesSUCCESS;
349}
350
351//------------------------------------------------------------------------------
352
354 : ctx_(ctx)
355 , sink_(ctx.journal, toShortString(ctx.tx.getTransactionID()) + " ")
356 , j_(sink_)
357 , accountID_(ctx.tx.getAccountID(sfAccount))
358{
359}
360
361bool
363{
364 if (!slice)
365 return true;
366 return !slice->empty() && slice->length() <= maxLength;
367}
368
374
375NotTEC
380
381NotTEC
383 ReadView const& view,
384 STTx const& tx,
385 std::unordered_set<GranularPermissionType>& heldGranularPermissions)
386{
387 auto const delegate = tx[~sfDelegate];
388 if (!delegate)
389 return tesSUCCESS;
390
391 auto const sle = view.read(keylet::delegate(tx[sfAccount], *delegate));
392 if (!sle)
394
395 if (isTesSuccess(checkTxPermission(sle, tx)))
396 return tesSUCCESS;
397
398 if (!Permission::getInstance().hasGranularPermissions(tx.getTxnType()))
400
401 heldGranularPermissions = getGranularPermission(sle, tx.getTxnType());
402 if (heldGranularPermissions.empty())
404
405 if (!Permission::getInstance().checkGranularSandbox(tx, heldGranularPermissions))
407
408 return tesSUCCESS;
409}
410
411NotTEC
413{
414 if (!tx.isFieldPresent(sfSponsor))
415 return tesSUCCESS;
416
417 // Reserve sponsorship with permissioned delegation is disallowed.
418 if (tx.isFieldPresent(sfDelegate) && isReserveSponsored(tx))
419 return temINVALID;
420
421 if (!view.exists(keylet::account(tx.getAccountID(sfSponsor))))
422 return terNO_ACCOUNT;
423
424 // Skip Sponsorship existence checks if the sponsor has signed the transaction - this
425 // transaction is valid regardless of the Sponsorship object.
426 // The use of the Sponsorship object is properly handled in
427 // getFeePayer/checkReserve/increaseOwnerCount/decreaseOwnerCount.
428 if (tx.isFieldPresent(sfSponsorSignature))
429 return tesSUCCESS;
430
431 // If the transaction contains sfDelegate, the Sponsorship object should be
432 // between the sponsor and the delegate.
433 auto const sponsorshipSle =
434 view.read(keylet::sponsorship(tx.getAccountID(sfSponsor), tx.getInitiator()));
435
436 // sponsorship object missing for pre-funded (no co-signing) tx
437 if (!sponsorshipSle)
438 return terNO_PERMISSION;
439
440 if (isFeeSponsored(tx) && sponsorshipSle->isFlag(lsfSponsorshipRequireSignForFee))
441 return terNO_PERMISSION;
442
443 if (isReserveSponsored(tx) && sponsorshipSle->isFlag(lsfSponsorshipRequireSignForReserve))
444 return terNO_PERMISSION;
445
446 return tesSUCCESS;
447}
448
451{
452 // Returns the fee in fee units.
453
454 // The computation has two parts:
455 // * The base fee, which is the same for most transactions.
456 // * The additional cost of each multisignature on the transaction.
457 // * The additional cost of each multisignature on the sponsor.
458 XRPAmount const baseFee = view.fees().base;
459
460 // Each signer adds one more baseFee to the minimum required fee
461 // for the transaction.
462 std::size_t const signerCount =
463 tx.isFieldPresent(sfSigners) ? tx.getFieldArray(sfSigners).size() : 0;
464
465 std::size_t sponsorSignerCount = 0;
466 if (tx.isFieldPresent(sfSponsorSignature))
467 {
468 auto const sponsorObj = tx.getFieldObject(sfSponsorSignature);
469 if (sponsorObj.isFieldPresent(sfSigners))
470 sponsorSignerCount += sponsorObj.getFieldArray(sfSigners).size();
471 }
472
473 return baseFee + ((signerCount + sponsorSignerCount) * baseFee);
474}
475
478 ReadView const& view,
479 STTx const& tx,
480 std::uint32_t extraBaseFeeMultiplier)
481{
482 return calculateBaseFee(view, tx) + view.fees().base * extraBaseFeeMultiplier;
483}
484
485// Returns the fee in fee units, not scaled for load.
488{
489 // Assumption: One reserve increment is typically much greater than one base
490 // fee.
491 // This check is in an assert so that it will come to the attention of
492 // developers if that assumption is not correct. If the owner reserve is not
493 // significantly larger than the base fee (or even worse, smaller), we will
494 // need to rethink charging an owner reserve as a transaction fee.
495 // TODO: This function is static, and I don't want to add more parameters.
496 // When it is finally refactored to be in a context that has access to the
497 // Application, include "app().getOverlay().networkID() > 2 ||" in the
498 // condition.
499 XRPL_ASSERT(
500 view.fees().increment > view.fees().base * 100,
501 "xrpl::Transactor::calculateOwnerReserveFee : Owner reserve is "
502 "reasonable");
503 return view.fees().increment;
504}
505
508 ServiceRegistry& registry,
509 XRPAmount baseFee,
510 Fees const& fees,
511 ApplyFlags flags)
512{
513 return scaleFeeLoad(baseFee, registry.getFeeTrack(), fees, (flags & TapUnlimited) != 0u);
514}
515
516TER
518{
519 if (!ctx.tx[sfFee].native())
520 return temBAD_FEE;
521
522 auto const feePaid = ctx.tx[sfFee].xrp();
523
524 if ((ctx.flags & TapBatch) != 0u)
525 {
526 if (feePaid == beast::kZero)
527 return tesSUCCESS;
528
529 JLOG(ctx.j.trace()) << "Batch: Fee must be zero.";
530 return temBAD_FEE; // LCOV_EXCL_LINE
531 }
532
533 if (!isLegalAmount(feePaid) || feePaid < beast::kZero)
534 return temBAD_FEE;
535
536 // Only check fee is sufficient when the ledger is open.
537 if (ctx.view.open())
538 {
539 auto const feeDue = minimumFee(ctx.registry, baseFee, ctx.view.fees(), ctx.flags);
540
541 if (feePaid < feeDue)
542 {
543 JLOG(ctx.j.trace()) << "Insufficient fee paid: " << to_string(feePaid) << "/"
544 << to_string(feeDue);
545 return telINSUF_FEE_P;
546 }
547 }
548
549 if (feePaid == beast::kZero)
550 return tesSUCCESS;
551
552 auto const feePayer = getFeePayer(ctx.view, ctx.tx);
553 auto const payerSle = ctx.view.read(feePayer.keylet);
554
555 if (!payerSle)
556 {
557 if (feePayer.type == FeePayerType::SponsorPreFunded)
558 {
559 // Sanity check: already checked in checkSponsor
560 return tefINTERNAL; // LCOV_EXCL_LINE
561 }
562
563 return terNO_ACCOUNT;
564 }
565
566 XRPAmount maxSpendable = beast::kZero;
567
568 if (feePayer.type == FeePayerType::SponsorPreFunded)
569 {
570 if (payerSle->getType() != ltSPONSORSHIP)
571 return tefINTERNAL; // LCOV_EXCL_LINE
572
573 if (payerSle->isFieldPresent(feePayer.balanceField))
574 maxSpendable = payerSle->getFieldAmount(feePayer.balanceField).xrp();
575
576 if (payerSle->isFieldPresent(sfMaxFee))
577 {
578 auto const cap = payerSle->getFieldAmount(sfMaxFee).xrp();
579 maxSpendable = std::min(maxSpendable, cap);
580 }
581 }
582 else
583 {
584 if (payerSle->getType() != ltACCOUNT_ROOT)
585 return tefINTERNAL; // LCOV_EXCL_LINE
586
587 if (feePayer.type == FeePayerType::SponsorCoSigned)
588 {
589 auto const sponsorReserve = accountReserve(ctx.view, payerSle, ctx.j);
590 maxSpendable = payerSle->getFieldAmount(sfBalance).xrp() - sponsorReserve;
591 }
592 else
593 {
594 maxSpendable = payerSle->getFieldAmount(feePayer.balanceField).xrp();
595 }
596 }
597
598 // NOTE: Because preclaim evaluates against a static readview, it
599 // does not reflect fee deductions from other transactions paid by
600 // the same account within the current ledger.
601 // As a result, if an account's balance is over-committed across multiple
602 // transactions, this check may pass optimistically.
603 // The fee shortfall will be handled by the Transactor::reset mechanism,
604 // which caps the fee to the remaining actual balance.
605 if (maxSpendable < feePaid)
606 {
607 JLOG(ctx.j.trace()) << "Insufficient balance:" << " balance=" << to_string(maxSpendable)
608 << " paid=" << to_string(feePaid);
609
610 if ((maxSpendable > beast::kZero) && !ctx.view.open())
611 {
612 // Closed ledger, non-zero balance, less than fee
613 return tecINSUFF_FEE;
614 }
615
616 return terINSUF_FEE_B;
617 }
618
619 return tesSUCCESS;
620}
621
622TER
624{
625 auto const feePaid = ctx_.tx[sfFee].xrp();
626
627 auto const feePayer = getFeePayer(view(), ctx_.tx);
628 auto const sle = view().peek(feePayer.keylet);
629
630 JLOG(j_.trace()) << "Fee payer: " + to_string(feePayer.id);
631
632 if (!sle)
633 return tefINTERNAL; // LCOV_EXCL_LINE
634
635 if (feePaid == beast::kZero)
636 return tesSUCCESS;
637
638 XRPAmount balance = beast::kZero;
639 if (sle->isFieldPresent(feePayer.balanceField))
640 {
641 balance = sle->getFieldAmount(feePayer.balanceField).xrp();
642 }
643 else if (feePayer.balanceField != sfFeeAmount)
644 {
645 return tefINTERNAL; // LCOV_EXCL_LINE
646 }
647
648 // A co-signed sponsor pays the fee out of its own account balance, but must
649 // never be charged into its account reserve, and a pre-funded sponsorship's
650 // fee is capped by sfMaxFee. Mirror the spendable amount computed in
651 // checkFee() so both limits are enforced on the apply path too.
652 XRPAmount spendable = balance;
653 if (feePayer.type == FeePayerType::SponsorCoSigned)
654 {
655 auto const sponsorReserve = accountReserve(view(), sle, j_);
656 // max(balance - reserve, 0) with overflow handling
657 spendable = balance > sponsorReserve ? balance - sponsorReserve : beast::kZero;
658 }
659 else if (feePayer.type == FeePayerType::SponsorPreFunded && sle->isFieldPresent(sfMaxFee))
660 {
661 auto const cap = sle->getFieldAmount(sfMaxFee).xrp();
662 spendable = std::min(spendable, cap);
663 }
664
665 // Only sponsor fee-payers reject here on insufficient funds. For an
666 // ordinary account, the fee falls through and is capped by reset(), which
667 // caps to the account's balance. That capping is wrong for sponsors: a
668 // co-signed sponsor would be charged into its own reserve, and a prefunded
669 // sponsorship's fee amount should be rejected rather than partially spent.
670 if (feePaid > spendable &&
671 (feePayer.type == FeePayerType::SponsorPreFunded ||
672 feePayer.type == FeePayerType::SponsorCoSigned))
673 {
674 if ((spendable > beast::kZero) && !view().open())
675 return tecINSUFF_FEE;
676
677 return terINSUF_FEE_B;
678 }
679
680 auto const feeAmountAfter = balance - feePaid;
681
682 if (feeAmountAfter == beast::kZero && feePayer.balanceField == sfFeeAmount)
683 {
684 // Because ltSponsorship.sfFeeAmount is soeOptional
685 sle->makeFieldAbsent(feePayer.balanceField);
686 }
687 else
688 {
689 sle->setFieldAmount(feePayer.balanceField, feeAmountAfter);
690 }
691
692 view().update(sle);
693
694 // VFALCO Should we call view().rawDestroyXRP() here as well?
695 return tesSUCCESS;
696}
697
698NotTEC
700{
701 auto const id = tx.getAccountID(sfAccount);
702
703 auto const sle = view.read(keylet::account(id));
704
705 if (!sle)
706 {
707 JLOG(j.trace()) << "applyTransaction: delay: source account does not exist "
708 << toBase58(id);
709 return terNO_ACCOUNT;
710 }
711
712 SeqProxy const tSeqProx = tx.getSeqProxy();
713 SeqProxy const aSeq = SeqProxy::rawSequence((*sle)[sfSequence]);
714
715 if (tSeqProx.isSeq())
716 {
717 if (tx.isFieldPresent(sfTicketSequence))
718 {
719 JLOG(j.trace()) << "applyTransaction: has both a TicketSequence "
720 "and a non-zero Sequence number";
721 return temSEQ_AND_TICKET;
722 }
723 if (tSeqProx != aSeq)
724 {
725 if (aSeq < tSeqProx)
726 {
727 JLOG(j.trace()) << "applyTransaction: has future sequence number "
728 << "a_seq=" << aSeq << " t_seq=" << tSeqProx;
729 return terPRE_SEQ;
730 }
731 // It's an already-used sequence number.
732 JLOG(j.trace()) << "applyTransaction: has past sequence number "
733 << "a_seq=" << aSeq << " t_seq=" << tSeqProx;
734 return tefPAST_SEQ;
735 }
736 }
737 else if (tSeqProx.isTicket())
738 {
739 // Bypass the type comparison. Apples and oranges.
740 if (aSeq.value() <= tSeqProx.value())
741 {
742 // If the Ticket number is greater than or equal to the
743 // account sequence there's the possibility that the
744 // transaction to create the Ticket has not hit the ledger
745 // yet. Allow a retry.
746 JLOG(j.trace()) << "applyTransaction: has future ticket id "
747 << "a_seq=" << aSeq << " t_seq=" << tSeqProx;
748 return terPRE_TICKET;
749 }
750
751 // Transaction can never succeed if the Ticket is not in the ledger.
752 if (!view.exists(keylet::ticket(id, tSeqProx)))
753 {
754 JLOG(j.trace()) << "applyTransaction: ticket already used or never created "
755 << "a_seq=" << aSeq << " t_seq=" << tSeqProx;
756 return tefNO_TICKET;
757 }
758
759 // While a TransactionProposal keyed to this Ticket exists, the
760 // Ticket is reserved: only the proposal's own proposed transaction
761 // may consume it, so unrelated activity cannot invalidate the
762 // proposal while signatures are being collected (On-Chain Cosigner spec §4.2.1).
763 // Cancelling the proposal frees the Ticket, so this is a retry, not
764 // a final failure. No proposal can exist before the Cosign amendment,
765 // so the gate only makes that dependency explicit.
766 if (view.rules().enabled(featureCosign) && !proposal::canConsumeTicket(view, tx))
767 {
768 JLOG(j.trace()) << "applyTransaction: ticket " << tSeqProx << " is reserved";
769 return terTICKET_RESERVED;
770 }
771 }
772
773 return tesSUCCESS;
774}
775
776NotTEC
778{
779 auto const id = ctx.tx.getAccountID(sfAccount);
780
781 auto const sle = ctx.view.read(keylet::account(id));
782
783 if (!sle)
784 {
785 JLOG(ctx.j.trace()) << "applyTransaction: delay: source account does not exist "
786 << toBase58(id);
787 return terNO_ACCOUNT;
788 }
789
790 if (ctx.tx.isFieldPresent(sfAccountTxnID) &&
791 (sle->getFieldH256(sfAccountTxnID) != ctx.tx.getFieldH256(sfAccountTxnID)))
792 return tefWRONG_PRIOR;
793
794 if (ctx.tx.isFieldPresent(sfLastLedgerSequence) &&
795 (ctx.view.seq() > ctx.tx.getFieldU32(sfLastLedgerSequence)))
796 return tefMAX_LEDGER;
797
798 if (ctx.view.txExists(ctx.tx.getTransactionID()))
799 return tefALREADY;
800
801 return tesSUCCESS;
802}
803
804TER
806{
807 XRPL_ASSERT(sleAccount, "xrpl::Transactor::consumeSeqProxy : non-null account");
808 SeqProxy const seqProxy = ctx_.tx.getSeqProxy();
809 if (seqProxy.isSeq())
810 {
811 // Note that if this transaction is a TicketCreate, then
812 // the transaction will modify the account root sfSequence
813 // yet again.
814 sleAccount->setFieldU32(sfSequence, seqProxy.value() + 1);
815 return tesSUCCESS;
816 }
817 auto const keylet = keylet::ticket(accountID_, seqProxy);
818 return ticketDelete(view(), accountID_, keylet.key, j_);
819}
820
821// Remove a single Ticket from the ledger.
822TER
825 AccountID const& account,
826 UInt256 const& ticketIndex,
828{
829 // Delete the Ticket, adjust the account root ticket count, and
830 // reduce the owner count.
831 SLE::pointer const sleTicket = view.peek(keylet::ticket(ticketIndex));
832 if (!sleTicket)
833 {
834 // LCOV_EXCL_START
835 JLOG(j.fatal()) << "Ticket disappeared from ledger.";
836 return tefBAD_LEDGER;
837 // LCOV_EXCL_STOP
838 }
839
840 std::uint64_t const page{(*sleTicket)[sfOwnerNode]};
841 if (!view.dirRemove(keylet::ownerDir(account), page, ticketIndex, true))
842 {
843 // LCOV_EXCL_START
844 JLOG(j.fatal()) << "Unable to delete Ticket from owner.";
845 return tefBAD_LEDGER;
846 // LCOV_EXCL_STOP
847 }
848
849 // Update the account root's TicketCount. If the ticket count drops to
850 // zero remove the (optional) field.
851 auto const sleAccount = view.peek(keylet::account(account));
852 if (!sleAccount)
853 {
854 // LCOV_EXCL_START
855 JLOG(j.fatal()) << "Could not find Ticket owner account root.";
856 return tefBAD_LEDGER;
857 // LCOV_EXCL_STOP
858 }
859
860 if (auto ticketCount = (*sleAccount)[~sfTicketCount])
861 {
862 if (*ticketCount == 1)
863 {
864 sleAccount->makeFieldAbsent(sfTicketCount);
865 }
866 else
867 {
868 ticketCount = *ticketCount - 1;
869 }
870 }
871 else
872 {
873 // LCOV_EXCL_START
874 JLOG(j.fatal()) << "TicketCount field missing from account root.";
875 return tefBAD_LEDGER;
876 // LCOV_EXCL_STOP
877 }
878
879 // Update the Ticket owner's reserve.
880 decreaseOwnerCountForObject(view, sleAccount, sleTicket, 1, j);
881
882 std::uint32_t const ticketSeq{(*sleTicket)[sfTicketSequence]};
883
884 // Remove Ticket from ledger.
885 view.erase(sleTicket);
886
887 // Once the Ticket is gone, a TransactionProposal keyed to it can never
888 // execute: its proposed transaction would fail with tefNO_TICKET. Clean
889 // up the stale proposal and release its Owner's reserve (On-Chain Cosigner spec §4.5).
890 // The reservation check in checkSeqProxy means this is reached only by
891 // the proposal's own proposed transaction executing (or failing with a
892 // claimed-fee tec), or by AccountDelete sweeping the target account's
893 // Tickets. No proposal can exist before the Cosign amendment, so the gate
894 // only makes that dependency explicit.
895 if (view.rules().enabled(featureCosign))
896 {
897 if (auto const sleProposal = view.peek(keylet::txProposal(account, ticketSeq)))
898 {
899 if (TER const ter = proposal::deleteProposal(view, sleProposal, j); !isTesSuccess(ter))
900 return ter; // LCOV_EXCL_LINE
901 }
902 }
903
904 return tesSUCCESS;
905}
906
907// check stuff before you bother to lock the ledger
908void
910{
911 XRPL_ASSERT(accountID_ != beast::kZero, "xrpl::Transactor::preCompute : nonzero account");
912}
913
914TER
916{
917 preCompute();
918
919 // If the transactor requires a valid account and the transaction doesn't
920 // list one, preflight will have already a flagged a failure.
921 auto const sle = view().peek(keylet::account(accountID_));
922
923 // sle must exist except for transactions
924 // that allow zero account.
925 XRPL_ASSERT(
926 sle != nullptr || accountID_ == beast::kZero,
927 "xrpl::Transactor::apply : non-null SLE or zero account");
928
929 if (sle)
930 {
931 preFeeBalance_ = STAmount{(*sle)[sfBalance]}.xrp();
932
933 TER result = consumeSeqProxy(sle);
934 if (!isTesSuccess(result))
935 return result;
936
937 result = payFee();
938 if (!isTesSuccess(result))
939 return result;
940
941 if (sle->isFieldPresent(sfAccountTxnID))
942 sle->setFieldH256(sfAccountTxnID, ctx_.tx.getTransactionID());
943
944 view().update(sle);
945 }
946
947 return doApply();
948}
949
950NotTEC
952 ReadView const& view,
953 ApplyFlags flags,
954 std::optional<UInt256 const> const& parentBatchId,
955 AccountID const& idAccount,
956 STObject const& sigObject,
957 beast::Journal const j,
958 bool permitUncreatedAccount)
959{
960 {
961 auto const sle = view.read(keylet::account(idAccount));
962
963 if ((view.rules().enabled(featureLendingProtocol) ||
964 view.rules().enabled(featureBatchV1_1) || view.rules().enabled(fixCleanup3_3_0)) &&
965 isPseudoAccount(sle))
966 {
967 // Pseudo-accounts can't sign transactions. This check is gated on a
968 // few different amendments so that it takes effect as soon as any of
969 // them is activated.
970 return tefBAD_AUTH;
971 }
972 }
973
974 auto const pkSigner = sigObject.getFieldVL(sfSigningPubKey);
975 // Ignore signature check on batch inner transactions
976 if (parentBatchId && view.rules().enabled(featureBatchV1_1))
977 {
978 // Defensive Check: These values are also checked in Batch::preflight
979 if (sigObject.isFieldPresent(sfTxnSignature) || !pkSigner.empty() ||
980 sigObject.isFieldPresent(sfSigners))
981 {
982 return temINVALID_FLAG; // LCOV_EXCL_LINE
983 }
984 return tesSUCCESS;
985 }
986
987 if (((flags & TapDryRun) != 0u) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners))
988 {
989 // simulate: skip signature validation when neither SigningPubKey nor
990 // Signers are provided
991 return tesSUCCESS;
992 }
993
994 if (sigObject.isFieldPresent(sfSponsorSignature))
995 {
996 // Co-signed sponsorship
997
998 // Sanity check: already checked in preflight1
999 if (!sigObject.isFieldPresent(sfSponsor))
1000 return tefINTERNAL; // LCOV_EXCL_LINE
1001
1002 auto const sponsorID = sigObject.getAccountID(sfSponsor);
1003 auto const sponsorSignature = sigObject.getFieldObject(sfSponsorSignature);
1004 if (auto const ret = checkSign(view, flags, std::nullopt, sponsorID, sponsorSignature, j);
1005 !isTesSuccess(ret))
1006 return ret;
1007 }
1008
1009 // If the pk is empty and not simulate or simulate and signers,
1010 // then we must be multi-signing.
1011 if (sigObject.isFieldPresent(sfSigners))
1012 {
1013 return checkMultiSign(view, flags, idAccount, sigObject, j);
1014 }
1015
1016 // Check Single Sign
1017 XRPL_ASSERT(!pkSigner.empty(), "xrpl::Transactor::checkSign : non-empty signer");
1018
1019 if (!publicKeyType(makeSlice(pkSigner)))
1020 {
1021 JLOG(j.trace()) << "checkSign: signing public key type is unknown";
1022 return tefBAD_AUTH; // FIXME: should be better error!
1023 }
1024
1025 // Look up the account.
1026 auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner)));
1027 auto const sleAccount = view.read(keylet::account(idAccount));
1028 if (!sleAccount)
1029 {
1030 // An account that does not exist yet can only be authorized by its own
1031 // master key, and only where an un-created signer is permitted (a batch
1032 // whose earlier inner creates the account). Otherwise it cannot sign.
1033 if (!permitUncreatedAccount)
1034 return terNO_ACCOUNT;
1035 if (idAccount != idSigner)
1036 return tefBAD_AUTH;
1037 return tesSUCCESS;
1038 }
1039
1040 return checkSingleSign(view, idSigner, idAccount, sleAccount, j);
1041}
1042
1043NotTEC
1045{
1046 auto const idAccount = ctx.tx.isFieldPresent(sfDelegate) ? ctx.tx.getAccountID(sfDelegate)
1047 : ctx.tx.getAccountID(sfAccount);
1048 return checkSign(ctx.view, ctx.flags, ctx.parentBatchId, idAccount, ctx.tx, ctx.j);
1049}
1050
1051NotTEC
1053 ReadView const& view,
1054 AccountID const& idSigner,
1055 AccountID const& idAccount,
1056 SLE::const_pointer sleAccount,
1057 beast::Journal const j)
1058{
1059 bool const isMasterDisabled = sleAccount->isFlag(lsfDisableMaster);
1060
1061 // Signed with regular key.
1062 if ((*sleAccount)[~sfRegularKey] == idSigner)
1063 {
1064 return tesSUCCESS;
1065 }
1066
1067 // Signed with enabled master key.
1068 if (!isMasterDisabled && idAccount == idSigner)
1069 {
1070 return tesSUCCESS;
1071 }
1072
1073 // Signed with disabled master key.
1074 if (isMasterDisabled && idAccount == idSigner)
1075 {
1076 return tefMASTER_DISABLED;
1077 }
1078
1079 // Signed with any other key.
1080 return tefBAD_AUTH;
1081}
1082
1083NotTEC
1085 ReadView const& view,
1086 ApplyFlags flags,
1087 AccountID const& id,
1088 STObject const& sigObject,
1089 beast::Journal const j)
1090{
1091 // Get id's SignerList and Quorum.
1092 STLedgerEntry::const_pointer const sleAccountSigners = view.read(keylet::signerList(id));
1093 // If the signer list doesn't exist the account is not multi-signing.
1094 if (!sleAccountSigners)
1095 {
1096 JLOG(j.trace()) << "applyTransaction: Invalid: Not a multi-signing account.";
1097 return tefNOT_MULTI_SIGNING;
1098 }
1099
1100 // We have plans to support multiple SignerLists in the future. The
1101 // presence and defaulted value of the SignerListID field will enable that.
1102 XRPL_ASSERT(
1103 sleAccountSigners->isFieldPresent(sfSignerListID),
1104 "xrpl::Transactor::checkMultiSign : has signer list ID");
1105 XRPL_ASSERT(
1106 sleAccountSigners->getFieldU32(sfSignerListID) == 0,
1107 "xrpl::Transactor::checkMultiSign : signer list ID is 0");
1108
1109 auto accountSigners = SignerEntries::deserialize(*sleAccountSigners, j, "ledger");
1110 if (!accountSigners)
1111 return accountSigners.error();
1112
1113 // Get the array of transaction signers.
1114 STArray const& txSigners(sigObject.getFieldArray(sfSigners));
1115
1116 // Walk the accountSigners performing a variety of checks and see if
1117 // the quorum is met.
1118
1119 // Both the multiSigners and accountSigners are sorted by account. So
1120 // matching multi-signers to account signers should be a simple
1121 // linear walk. *All* signers must be valid or the transaction fails.
1122 std::uint32_t weightSum = 0;
1123 auto iter = accountSigners->begin();
1124 for (auto const& txSigner : txSigners)
1125 {
1126 AccountID const txSignerAcctID = txSigner.getAccountID(sfAccount);
1127
1128 // Attempt to match the SignerEntry with a Signer;
1129 while (iter->account < txSignerAcctID)
1130 {
1131 if (++iter == accountSigners->end())
1132 {
1133 JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account.";
1134 return tefBAD_SIGNATURE;
1135 }
1136 }
1137 if (iter->account != txSignerAcctID)
1138 {
1139 // The SigningAccount is not in the SignerEntries.
1140 JLOG(j.trace()) << "applyTransaction: Invalid SigningAccount.Account.";
1141 return tefBAD_SIGNATURE;
1142 }
1143
1144 // We found the SigningAccount in the list of valid signers. Now we
1145 // need to compute the accountID that is associated with the signer's
1146 // public key.
1147 auto const spk = txSigner.getFieldVL(sfSigningPubKey);
1148
1149 // spk being non-empty in non-simulate is checked in
1150 // STTx::checkMultiSign
1151 if (!spk.empty() && !publicKeyType(makeSlice(spk)))
1152 {
1153 JLOG(j.trace()) << "checkMultiSign: signing public key type is unknown";
1154 return tefBAD_SIGNATURE;
1155 }
1156
1157 XRPL_ASSERT(
1158 (flags & TapDryRun) || !spk.empty(),
1159 "xrpl::Transactor::checkMultiSign : non-empty signer or "
1160 "simulation");
1161 AccountID const signingAcctIDFromPubKey =
1162 spk.empty() ? txSignerAcctID : calcAccountID(PublicKey(makeSlice(spk)));
1163
1164 // Verify that the signingAcctID and the signingAcctIDFromPubKey
1165 // belong together. Here are the rules:
1166 //
1167 // 1. "Phantom account": an account that is not in the ledger
1168 // A. If signingAcctID == signingAcctIDFromPubKey and the
1169 // signingAcctID is not in the ledger then we have a phantom
1170 // account.
1171 // B. Phantom accounts are always allowed as multi-signers.
1172 //
1173 // 2. "Master Key"
1174 // A. signingAcctID == signingAcctIDFromPubKey, and signingAcctID
1175 // is in the ledger.
1176 // B. If the signingAcctID in the ledger does not have the
1177 // asfDisableMaster flag set, then the signature is allowed.
1178 //
1179 // 3. "Regular Key"
1180 // A. signingAcctID != signingAcctIDFromPubKey, and signingAcctID
1181 // is in the ledger.
1182 // B. If signingAcctIDFromPubKey == signingAcctID.RegularKey (from
1183 // ledger) then the signature is allowed.
1184 //
1185 // No other signatures are allowed. (January 2015)
1186
1187 // In any of these cases we need to know whether the account is in
1188 // the ledger. Determine that now.
1189 auto const sleTxSignerRoot = view.read(keylet::account(txSignerAcctID));
1190
1191 if (signingAcctIDFromPubKey == txSignerAcctID)
1192 {
1193 // Either Phantom or Master. Phantoms automatically pass.
1194 if (sleTxSignerRoot)
1195 {
1196 // Master Key. Account may not have asfDisableMaster set.
1197 std::uint32_t const signerAccountFlags = sleTxSignerRoot->getFieldU32(sfFlags);
1198
1199 if ((signerAccountFlags & lsfDisableMaster) != 0u)
1200 {
1201 JLOG(j.trace()) << "applyTransaction: Signer:Account lsfDisableMaster.";
1202 return tefMASTER_DISABLED;
1203 }
1204 }
1205 }
1206 else
1207 {
1208 // May be a Regular Key. Let's find out.
1209 // Public key must hash to the account's regular key.
1210 if (!sleTxSignerRoot)
1211 {
1212 JLOG(j.trace()) << "applyTransaction: Non-phantom signer "
1213 "lacks account root.";
1214 return tefBAD_SIGNATURE;
1215 }
1216
1217 if (!sleTxSignerRoot->isFieldPresent(sfRegularKey))
1218 {
1219 JLOG(j.trace()) << "applyTransaction: Account lacks RegularKey.";
1220 return tefBAD_SIGNATURE;
1221 }
1222 if (signingAcctIDFromPubKey != sleTxSignerRoot->getAccountID(sfRegularKey))
1223 {
1224 JLOG(j.trace()) << "applyTransaction: Account doesn't match RegularKey.";
1225 return tefBAD_SIGNATURE;
1226 }
1227 }
1228 // The signer is legitimate. Add their weight toward the quorum.
1229 weightSum += iter->weight;
1230 }
1231
1232 // Cannot perform transaction if quorum is not met.
1233 if (weightSum < sleAccountSigners->getFieldU32(sfSignerQuorum))
1234 {
1235 JLOG(j.trace()) << "applyTransaction: Signers failed to meet quorum.";
1236 return tefBAD_QUORUM;
1237 }
1238
1239 // Met the quorum. Continue.
1240 return tesSUCCESS;
1241}
1242
1243//------------------------------------------------------------------------------
1244
1245static void
1247{
1248 int removed = 0;
1249
1250 for (auto const& index : offers)
1251 {
1252 if (auto const sleOffer = view.peek(keylet::offer(index)))
1253 {
1254 // offer is unfunded
1255 offerDelete(view, sleOffer, viewJ);
1256 if (++removed == kUnfundedOfferRemoveLimit)
1257 return;
1258 }
1259 }
1260}
1261
1262static void
1264 ApplyView& view,
1265 std::vector<UInt256> const& offers,
1266 beast::Journal viewJ)
1267{
1268 std::size_t removed = 0;
1269
1270 for (auto const& index : offers)
1271 {
1272 if (auto const offer = view.peek(keylet::nftokenOffer(index)))
1273 {
1274 nft::deleteTokenOffer(view, offer);
1275 if (++removed == kExpiredOfferRemoveLimit)
1276 return;
1277 }
1278 }
1279}
1280
1281static void
1283{
1284 for (auto const& index : creds)
1285 {
1286 if (auto const sle = view.peek(keylet::credential(index)))
1287 {
1288 if (auto const ter = credentials::deleteSLE(view, sle, viewJ); !isTesSuccess(ter))
1289 {
1290 JLOG(viewJ.error())
1291 << "removeExpiredCredentials: failed to delete expired credential. Err: "
1292 << transToken(ter);
1293 }
1294 }
1295 }
1296}
1297
1298static void
1300 ApplyView& view,
1301 std::vector<UInt256> const& trustLines,
1302 beast::Journal viewJ)
1303{
1304 if (trustLines.size() > kMaxDeletableAmmTrustLines)
1305 {
1306 JLOG(viewJ.error()) << "removeDeletedTrustLines: deleted trustlines exceed max "
1307 << trustLines.size();
1308 return;
1309 }
1310
1311 for (auto const& index : trustLines)
1312 {
1313 if (auto const sleState = view.peek({ltRIPPLE_STATE, index});
1314 !isTesSuccess(deleteAMMTrustLine(view, sleState, std::nullopt, viewJ)))
1315 {
1316 JLOG(viewJ.error()) << "removeDeletedTrustLines: failed to delete AMM trustline";
1317 }
1318 }
1319}
1320
1329{
1330 ctx_.discard();
1331
1332 auto const txnAcct = view().peek(keylet::account(ctx_.tx.getAccountID(sfAccount)));
1333
1334 // The account should never be missing from the ledger. But if it
1335 // is missing then we can't very well charge it a fee, can we?
1336 if (!txnAcct)
1337 return {tefINTERNAL, beast::kZero};
1338
1339 auto const feePayer = getFeePayer(view(), ctx_.tx);
1340 auto const payerSle = view().peek(feePayer.keylet);
1341
1342 if (!payerSle)
1343 return {tefINTERNAL, beast::kZero}; // LCOV_EXCL_LINE
1344
1345 XRPAmount balance = beast::kZero;
1346 if (payerSle->isFieldPresent(feePayer.balanceField))
1347 {
1348 balance = payerSle->getFieldAmount(feePayer.balanceField).xrp();
1349 }
1350 else if (feePayer.balanceField != sfFeeAmount)
1351 {
1352 return {tefINTERNAL, beast::kZero}; // LCOV_EXCL_LINE
1353 }
1354
1355 if (feePayer.type == FeePayerType::SponsorPreFunded && payerSle->isFieldPresent(sfMaxFee))
1356 {
1357 auto const cap = payerSle->getFieldAmount(sfMaxFee).xrp();
1358 fee = std::min(fee, cap);
1359 }
1360
1361 // A co-signed sponsor must never be charged into its own account reserve,
1362 // so the fee is capped to the balance above the reserve rather than to the
1363 // full balance.
1364 XRPAmount spendable = balance;
1365 if (feePayer.type == FeePayerType::SponsorCoSigned)
1366 {
1367 auto const sponsorReserve = accountReserve(view(), payerSle, j_);
1368 // max(balance - reserve, 0) with overflow handling
1369 spendable = balance > sponsorReserve ? balance - sponsorReserve : beast::kZero;
1370 }
1371
1372 // balance should have already been checked in checkFee / preFlight.
1373 XRPL_ASSERT(
1374 (fee == beast::kZero || balance != beast::kZero) && (!view().open() || balance >= fee),
1375 "xrpl::Transactor::reset : valid balance");
1376
1377 // We retry/reject the transaction if the account balance is zero or
1378 // we're applying against an open ledger and the balance is less than
1379 // the fee
1380 if (fee > spendable)
1381 fee = spendable;
1382
1383 // Since we reset the context, we need to charge the fee and update
1384 // the account's sequence number (or consume the Ticket) again.
1385 //
1386 // If for some reason we are unable to consume the ticket or sequence
1387 // then the ledger is corrupted. Rather than make things worse we
1388 // reject the transaction.
1389 auto const feeAmountAfter = balance - fee;
1390 if (feeAmountAfter == beast::kZero && feePayer.balanceField == sfFeeAmount)
1391 {
1392 // Because ltSponsorship.sfFeeAmount is soeOptional
1393 payerSle->makeFieldAbsent(feePayer.balanceField);
1394 }
1395 else
1396 {
1397 payerSle->setFieldAmount(feePayer.balanceField, feeAmountAfter);
1398 }
1399
1400 TER const ter{consumeSeqProxy(txnAcct)};
1401 XRPL_ASSERT(isTesSuccess(ter), "xrpl::Transactor::reset : result is tesSUCCESS");
1402
1403 if (isTesSuccess(ter))
1404 {
1405 view().update(txnAcct);
1406 if (payerSle != txnAcct)
1407 view().update(payerSle);
1408 }
1409
1410 return {ter, fee};
1411}
1412
1415{
1416 if (tx.isFieldPresent(sfSponsor) && isFeeSponsored(tx))
1417 {
1418 auto const sponsorID = tx.getAccountID(sfSponsor);
1419 auto const sponseeID = tx.getInitiator();
1420 auto const sponsorshipKeylet = keylet::sponsorship(sponsorID, sponseeID);
1421
1422 // if pre-funded sponsorship exists, prefer it
1423 if (view.exists(sponsorshipKeylet))
1424 {
1425 // pre funded
1426 return FeePayer{
1427 .id = sponsorID,
1428 .keylet = sponsorshipKeylet,
1429 .balanceField = sfFeeAmount,
1431 };
1432 }
1433
1434 // Checked in Transactor::checkSponsor
1435 XRPL_ASSERT(
1436 tx.isFieldPresent(sfSponsorSignature),
1437 "xrpl::getFeePayer has sponsor signature without a sponsorship object");
1438
1439 // co-signed
1440 return FeePayer{
1441 .id = sponsorID,
1442 .keylet = keylet::account(sponsorID),
1443 .balanceField = sfBalance,
1445 };
1446 }
1447
1448 AccountID const payerID = tx.getInitiator();
1449 auto const payerAccountKeylet = keylet::account(payerID);
1450 auto const payerType =
1452
1453 return FeePayer{
1454 .id = payerID,
1455 .keylet = payerAccountKeylet,
1456 .balanceField = sfBalance,
1457 .type = payerType,
1458 };
1459}
1460
1461// The sole purpose of this function is to provide a convenient, named
1462// location to set a breakpoint, to be used when replaying transactions.
1463void
1465{
1466 JLOG(j_.debug()) << "Transaction trapped: " << txHash;
1467}
1468
1471{
1472 JLOG(j_.trace()) << "reapplying because of " << transToken(result);
1473
1474 // FIXME: This mechanism for doing work while returning a `tec` is
1475 // awkward and very limiting. A more general purpose approach
1476 // should be used, making it possible to do more useful work
1477 // when transactions fail with a `tec` code.
1478
1479 auto const typesForResult = [](TER const ter) {
1481 if ((ter == tecOVERSIZE) || (ter == tecKILLED))
1482 {
1483 types.insert(ltOFFER);
1484 }
1485 else if (ter == tecINCOMPLETE)
1486 {
1487 types.insert(ltRIPPLE_STATE);
1488 }
1489 else if (ter == tecEXPIRED)
1490 {
1491 types.insert(ltNFTOKEN_OFFER);
1492 types.insert(ltCREDENTIAL);
1493 }
1494 return types;
1495 };
1496
1497 // Build a list of ledger entry types to collect, based on the
1498 // result code. Only deleted objects of these types will be
1499 // re-applied after the context is reset.
1500 auto const typesToCollect = typesForResult(result);
1501
1503 if (!typesToCollect.empty())
1504 {
1505 ctx_.visit(
1506 [&typesToCollect, &deletedObjects](
1507 UInt256 const& index, bool isDelete, SLE::ConstRef before, SLE::ConstRef after) {
1508 if (isDelete)
1509 {
1510 XRPL_ASSERT(
1511 before && after,
1512 "xrpl::Transactor::processPersistentChanges : non-null "
1513 "SLE inputs");
1514 if (before && after)
1515 {
1516 auto const type = before->getType();
1517 if (typesToCollect.contains(type))
1518 {
1519 // For offers, only collect unfunded removals
1520 // (where TakerPays is unchanged)
1521 if (type == ltOFFER &&
1522 before->getFieldAmount(sfTakerPays) !=
1523 after->getFieldAmount(sfTakerPays))
1524 return;
1525
1526 deletedObjects[type].push_back(index);
1527 }
1528 }
1529 }
1530 });
1531 }
1532
1533 // Reset the context, potentially adjusting the fee.
1534 {
1535 auto const resetResult = reset(fee);
1536 if (!isTesSuccess(resetResult.first))
1537 result = resetResult.first;
1538
1539 fee = resetResult.second;
1540 }
1541
1542 // Re-apply the collected deletions, but only if the reset succeeded
1543 // and the post-reset result still allows the same deletion type.
1544 auto const typesToApply = typesForResult(result);
1545 if (isTecClaim(result) && !typesToApply.empty())
1546 {
1547 auto const viewJ = ctx_.registry.get().getJournal("View");
1548 for (auto const& [type, ids] : deletedObjects)
1549 {
1550 if (ids.empty() || !typesToApply.contains(type))
1551 continue;
1552
1553 switch (type)
1554 {
1555 case ltOFFER:
1556 removeUnfundedOffers(view(), ids, viewJ);
1557 break;
1558 case ltNFTOKEN_OFFER:
1559 removeExpiredNFTokenOffers(view(), ids, viewJ);
1560 break;
1561 case ltRIPPLE_STATE:
1562 removeDeletedTrustLines(view(), ids, viewJ);
1563 break;
1564 case ltCREDENTIAL:
1565 removeExpiredCredentials(view(), ids, viewJ);
1566 break;
1567 // LCOV_EXCL_START
1568 default:
1569 UNREACHABLE(
1570 "xrpl::Transactor::processPersistentChanges() : "
1571 "unexpected type");
1572 break;
1573 // LCOV_EXCL_STOP
1574 }
1575 }
1576 }
1577
1578 return {result, fee, isTecClaim(result)};
1579}
1580
1581[[nodiscard]] TER
1583{
1584 if (scope == InvariantScope::Full)
1585 return xrpl::checkInvariants(ctx_, result, fee, *this);
1586
1587 return xrpl::checkInvariants(ctx_, result, fee);
1588}
1589
1590//------------------------------------------------------------------------------
1593{
1594 JLOG(j_.trace()) << "apply: " << ctx_.tx.getTransactionID();
1595
1596 // These global updates really should have been for every Transaction
1597 // step: preflight, preclaim, and doApply. And even calculateBaseFee. See
1598 // with_txn_type().
1599 //
1600 // raii classes for the current ledger rules.
1601 CurrentTransactionRulesGuard const currentTransactionRulesGuard(view().rules());
1602
1603#ifdef DEBUG
1604 {
1605 Serializer ser;
1606 ctx_.tx.add(ser);
1607 SerialIter sit(ser.slice());
1608 STTx const s2(sit);
1609
1610 if (!s2.isEquivalent(ctx_.tx))
1611 {
1612 // LCOV_EXCL_START
1613 JLOG(j_.fatal()) << "Transaction serdes mismatch";
1614 JLOG(j_.fatal()) << ctx_.tx.getJson(JsonOptions::Values::None);
1615 JLOG(j_.fatal()) << s2.getJson(JsonOptions::Values::None);
1616 UNREACHABLE("xrpl::Transactor::operator() : transaction serdes mismatch");
1617 // LCOV_EXCL_STOP
1618 }
1619 }
1620#endif
1621
1622 if (auto const& trap = ctx_.registry.get().getTrapTxID();
1623 trap && *trap == ctx_.tx.getTransactionID())
1624 {
1625 trapTransaction(*trap);
1626 }
1627
1628 auto result = ctx_.preclaimResult;
1629 if (isTesSuccess(result))
1630 result = apply();
1631
1632 // No transaction can return temUNKNOWN from apply,
1633 // and it can't be passed in from a preclaim.
1634 XRPL_ASSERT(result != temUNKNOWN, "xrpl::Transactor::operator() : result is not temUNKNOWN");
1635
1636 if (auto const stream = j_.trace())
1637 stream << "preclaim result: " << transToken(result);
1638
1639 auto fee = ctx_.tx.getFieldAmount(sfFee).xrp();
1640 bool const canApply = std::invoke([&result, &fee, this] {
1641 bool canApplyTmp = isTesSuccess(result);
1642
1643 if (ctx_.size() > kOversizeMetaDataCap)
1644 result = tecOVERSIZE;
1645
1646 if (isTecClaim(result) && ((view().flags() & TapFailHard) != 0u))
1647 {
1648 // If the TapFailHard flag is set, a tec result
1649 // must not do anything
1650 ctx_.discard();
1651 canApplyTmp = false;
1652 }
1653 else if (
1654 (result == tecOVERSIZE) || (result == tecKILLED) || (result == tecINCOMPLETE) ||
1655 (result == tecEXPIRED) || isTecClaimHardFail(result, view().flags()))
1656 {
1657 // This is and must remain the only place where `canApplyTmp` can change from false to
1658 // true. Changing from true to false is no problem.
1659 std::tie(result, fee, canApplyTmp) = processPersistentChanges(result, fee);
1660 }
1661 return canApplyTmp;
1662 });
1663
1664 auto const logger = [this](
1665 TER result,
1666 bool canApply,
1667 std::optional<TxMeta>&& metadata = std::nullopt) -> ApplyResult {
1668 JLOG(j_.trace()) << (canApply ? "applied " : "not applied ") << transToken(result);
1669 return {result, canApply, std::move(metadata)};
1670 };
1671
1672 if (!canApply)
1673 return logger(result, canApply);
1674
1675 // First invariant pass: both protocol and transaction-specific
1676 // checks run against the transaction's tentative outcome. If it
1677 // does not return tecINVARIANT_FAILED, we can proceed to apply the
1678 // tx.
1679 result = checkInvariants(result, fee, InvariantScope::Full);
1680 if (result == tecINVARIANT_FAILED)
1681 {
1682 // Fee-claim reset: roll the transaction's effects back so that
1683 // only the fee deduction remains. This is the reset referenced
1684 // by InvariantScope::ProtocolOnly.
1685 auto const resetResult = reset(fee);
1686 if (!isTesSuccess(resetResult.first))
1687 result = resetResult.first;
1688
1689 fee = resetResult.second;
1690
1691 // Re-check invariants against the post-reset (fee-claim only)
1692 // state. The transaction's effects are gone, so the
1693 // transaction-specific invariants no longer apply and only the
1694 // protocol invariants are re-run. A failure here escalates to
1695 // tefINVARIANT_FAILED and excludes the tx from the ledger.
1696 if (isTesSuccess(result) || isTecClaim(result))
1697 result = checkInvariants(result, fee, InvariantScope::ProtocolOnly);
1698 }
1699
1700 // We ran through the invariant checker, which can, in some cases,
1701 // return a tef error code. Don't apply the transaction in that case.
1702 if (!isTecClaim(result) && !isTesSuccess(result))
1703 return logger(result, false);
1704
1705 std::optional<TxMeta> metadata;
1706
1707 // Transaction succeeded fully or (retries are not allowed and the
1708 // transaction could claim a fee)
1709
1710 // The transactor and invariant checkers guarantee that this will
1711 // *never* trigger but if it, somehow, happens, don't allow a tx
1712 // that charges a negative fee.
1713 if (fee < beast::kZero)
1714 Throw<std::logic_error>("fee charged is negative!");
1715
1716 // Charge whatever fee they specified. The fee has already been
1717 // deducted from the balance of the account that issued the
1718 // transaction. We just need to account for it in the ledger
1719 // header.
1720 if (!view().open() && fee != beast::kZero)
1721 ctx_.destroyXRP(fee);
1722
1723 // Once we call apply, we will no longer be able to look at view()
1724 metadata = ctx_.apply(result);
1725
1726 if ((ctx_.flags() & TapDryRun) != 0u)
1727 return logger(result, false, std::move(metadata));
1728
1729 return logger(result, canApply, std::move(metadata));
1730}
1731
1732} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream fatal() const
Definition Journal.h:368
Stream error() const
Definition Journal.h:362
Stream debug() const
Definition Journal.h:344
Stream trace() const
Severity stream access functions.
Definition Journal.h:338
Stream warn() const
Definition Journal.h:356
State information when applying a tx.
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:141
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::Ref sle)=0
Indicate changes to a peeked SLE.
RAII class to set and restore the current transaction rules.
Definition Rules.h:113
static uint32_t txToPermissionType(TxType type)
static Permission const & getInstance()
A public key.
Definition PublicKey.h:53
A view into a ledger.
Definition ReadView.h:41
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
virtual bool open() const =0
Returns true if this reflects an open ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:115
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:182
size_type size() const
Definition STArray.h:248
virtual std::string getFullText() const
Definition STBase.cpp:60
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry const > const_pointer
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:649
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:351
UInt256 getFieldH256(SField const &field) const
Definition STObject.cpp:631
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:601
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:688
bool isFlag(std::uint32_t) const
Definition STObject.cpp:511
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:464
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:409
STObject getFieldObject(SField const &field) const
Definition STObject.cpp:678
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:643
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:657
std::uint32_t getFlags() const
Definition STObject.cpp:517
SeqProxy getSeqProxy() const
Definition STTx.cpp:198
TxType getTxnType() const
Definition STTx.h:250
UInt256 getTransactionID() const
Definition STTx.h:262
json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:351
AccountID getInitiator() const
The account responsible for the authorization: the delegate when sfDelegate is present,...
Definition STTx.cpp:659
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
constexpr bool isTicket() const
Definition SeqProxy.h:92
constexpr std::uint32_t value() const
Definition SeqProxy.h:80
constexpr bool isSeq() const
Definition SeqProxy.h:86
Slice slice() const noexcept
Definition Serializer.h:141
Service registry for dependency injection.
virtual LoadFeeTrack & getFeeTrack()=0
static std::expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
An immutable linear range of bytes.
Definition Slice.h:28
bool empty() const noexcept
Return true if the byte range is empty.
Definition Slice.h:58
static NotTEC preflight1(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the account and fee fields.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
TER consumeSeqProxy(SLE::pointer const &sleAccount)
static NotTEC checkPermission(ReadView const &view, STTx const &tx, std::unordered_set< GranularPermissionType > &heldGranularPermissions)
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
beast::WrappedSink sink_
Definition Transactor.h:163
static XRPAmount minimumFee(ServiceRegistry &registry, XRPAmount baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
static NotTEC checkSign(PreclaimContext const &ctx)
static NotTEC checkSponsor(ReadView const &view, STTx const &tx)
static XRPAmount calculateOwnerReserveFee(ReadView const &view, STTx const &tx)
ApplyResult operator()()
Process the transaction.
TER checkInvariants(TER result, XRPAmount fee, InvariantScope scope)
Check all invariants for the current transaction.
void trapTransaction(UInt256) const
static NotTEC preflightSigValidated(PreflightContext const &ctx)
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
beast::Journal const j_
Definition Transactor.h:164
virtual TER doApply()=0
InvariantScope
Which invariant layers to check.
Definition Transactor.h:217
static FeePayer getFeePayer(ReadView const &view, STTx const &tx)
static NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
static NotTEC checkSingleSign(ReadView const &view, AccountID const &idSigner, AccountID const &idAccount, SLE::const_pointer sleAccount, beast::Journal const j)
ApplyView & view()
Definition Transactor.h:184
Transactor(Transactor const &)=delete
static NotTEC preflightUniversal(PreflightContext const &ctx)
Universal validations.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
AccountID const accountID_
Definition Transactor.h:166
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
XRPAmount preFeeBalance_
Definition Transactor.h:167
static NotTEC checkMultiSign(ReadView const &view, ApplyFlags flags, AccountID const &id, STObject const &sigObject, beast::Journal const j)
static bool validDataLength(std::optional< Slice > const &slice, std::size_t maxLength)
virtual void preCompute()
ApplyContext & ctx_
Definition Transactor.h:162
std::pair< TER, XRPAmount > reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
static TER ticketDelete(ApplyView &view, AccountID const &account, UInt256 const &ticketIndex, beast::Journal j)
This method removes one Ticket ledger-object from the ledger.
std::tuple< TER, XRPAmount, bool > processPersistentChanges(TER result, XRPAmount fee)
T empty(T... args)
T insert(T... args)
T invoke(T... args)
T min(T... args)
constexpr Zero kZero
Definition Zero.h:30
TER deleteSLE(ApplyView &view, SLE::Ref sleCredential, beast::Journal j)
std::optional< NotTEC > preflightCheckSimulateKeys(ApplyFlags flags, STObject const &sigObject, beast::Journal j)
Checks the special signing key state needed for simulation.
NotTEC preflightCheckSigningKey(STObject const &sigObject, beast::Journal j)
Checks the validity of the transactor signing key.
Keylet computation functions.
Definition Indexes.h:39
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:465
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition Indexes.cpp:310
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:360
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:415
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Definition Indexes.cpp:378
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Definition Indexes.cpp:344
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Definition Indexes.cpp:523
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
Definition Indexes.cpp:366
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:559
bool deleteTokenOffer(ApplyView &view, SLE::Ref offer)
Deletes the given token offer.
bool canConsumeTicket(ReadView const &view, STTx const &tx)
Whether tx may consume its Ticket.
TER deleteProposal(ApplyView &view, SLE::pointer const &sleProposal, beast::Journal j)
Delete a TransactionProposal ledger entry.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static void removeDeletedTrustLines(ApplyView &view, std::vector< UInt256 > const &trustLines, beast::Journal viewJ)
@ telWRONG_NETWORK
Definition TER.h:51
@ telNETWORK_ID_MAKES_TX_NON_CANONICAL
Definition TER.h:53
@ telINSUF_FEE_P
Definition TER.h:43
@ telREQUIRES_NETWORK_ID
Definition TER.h:52
@ terPRE_SEQ
Definition TER.h:223
@ terTICKET_RESERVED
Definition TER.h:235
@ terNO_PERMISSION
Definition TER.h:234
@ terINSUF_FEE_B
Definition TER.h:218
@ terNO_DELEGATE_PERMISSION
Definition TER.h:232
@ terNO_ACCOUNT
Definition TER.h:219
@ terPRE_TICKET
Definition TER.h:228
constexpr FlagValue tfInnerBatchTxn
Definition TxFlags.h:44
TER offerDelete(ApplyView &view, SLE::Ref sle, beast::Journal j)
Delete an offer.
bool isLegalAmount(XRPAmount const &amount)
Returns true if the amount does not exceed the initial XRP in existence.
std::unordered_set< GranularPermissionType > getGranularPermission(SLE::ConstRef delegate, TxType const &type)
Load the granular permissions granted to the delegate account for the specified transaction type.
@ SigBad
Signature is bad.
Definition apply.h:28
TER deleteAMMTrustLine(ApplyView &view, SLE::pointer sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
static void removeExpiredNFTokenOffers(ApplyView &view, std::vector< UInt256 > const &offers, beast::Journal viewJ)
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
Definition applySteps.h:42
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
Definition apply.cpp:62
@ tefBAD_QUORUM
Definition TER.h:174
@ tefMAX_LEDGER
Definition TER.h:172
@ tefMASTER_DISABLED
Definition TER.h:171
@ tefALREADY
Definition TER.h:161
@ tefBAD_LEDGER
Definition TER.h:164
@ tefWRONG_PRIOR
Definition TER.h:170
@ tefNO_TICKET
Definition TER.h:179
@ tefBAD_SIGNATURE
Definition TER.h:173
@ tefINTERNAL
Definition TER.h:167
@ tefBAD_AUTH
Definition TER.h:163
@ tefPAST_SEQ
Definition TER.h:169
@ tefNOT_MULTI_SIGNING
Definition TER.h:175
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
NotTEC checkTxPermission(SLE::ConstRef delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
static void removeExpiredCredentials(ApplyView &view, std::vector< UInt256 > const &creds, beast::Journal viewJ)
constexpr std::uint16_t kMaxDeletableAmmTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:436
std::string transToken(TER code)
Definition TER.cpp:259
bool isReserveSponsored(STTx const &tx)
Whether the transaction's reserve is sponsored (sfSponsor present + spfSponsorReserve set).
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
constexpr std::size_t kExpiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Definition Protocol.h:48
TER checkInvariants(ApplyContext &ctx, TER result, XRPAmount fee, std::optional< std::reference_wrapper< TxInvariantCheck > > txCheck)
Run all protocol invariant checks plus the transaction-specific check in a single pass over the modif...
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition SociDB.cpp:91
bool isReserveSponsorAllowed(TxType txType)
Whether the given transaction type may use reserve sponsorship (v1).
std::string toShortString(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:665
BaseUInt< 256 > UInt256
Definition base_uint.h:581
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:617
static void removeUnfundedOffers(ApplyView &view, std::vector< UInt256 > const &offers, beast::Journal viewJ)
void decreaseOwnerCountForObject(ApplyView &view, SLE::Ref accountSle, SLE::Ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:668
bool isFeeSponsored(STTx const &tx)
Whether the transaction's fee is sponsored (sfSponsor present + spfSponsorFee set).
static NotTEC preflight1Sponsor(PreflightContext const &ctx)
AccountID calcAccountID(PublicKey const &pk)
bool hasInvalidAmount(STBase const &field, beast::Journal j)
ApplyFlags
Definition ApplyView.h:27
@ TapDryRun
Definition ApplyView.h:46
@ TapUnlimited
Definition ApplyView.h:39
@ TapFailHard
Definition ApplyView.h:32
@ TapBatch
Definition ApplyView.h:42
bool isPseudoAccount(SLE::const_pointer sleAcct)
Returns true if and only if sleAcct is a pseudo-account of any kind (i.e.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
constexpr FlagValue spfSponsorFlagMask
Definition TxFlags.h:469
@ temBAD_FEE
Definition TER.h:80
@ temINVALID
Definition TER.h:98
@ temINVALID_FLAG
Definition TER.h:99
@ temBAD_SRC_ACCOUNT
Definition TER.h:94
@ temMALFORMED
Definition TER.h:75
@ temSEQ_AND_TICKET
Definition TER.h:114
@ temDISABLED
Definition TER.h:102
@ temUNKNOWN
Definition TER.h:112
@ temBAD_AMOUNT
Definition TER.h:77
@ temBAD_SIGNATURE
Definition TER.h:93
@ temINVALID_INNER_BATCH
Definition TER.h:131
@ temBAD_SIGNER
Definition TER.h:103
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
TERSubset< CanCvtToTER > TER
Definition TER.h:657
XRPAmount accountReserve(ReadView const &view, SLE::ConstRef sle, beast::Journal j, Adjustment adj={})
Returns the account reserve, in drops.
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid and flags.
@ tecINSUFF_FEE
Definition TER.h:313
@ tecINCOMPLETE
Definition TER.h:346
@ tecINVARIANT_FAILED
Definition TER.h:324
@ tecEXPIRED
Definition TER.h:325
@ tecKILLED
Definition TER.h:327
@ tecOVERSIZE
Definition TER.h:322
bool isTecClaim(TER x) noexcept
Definition TER.h:693
constexpr std::size_t kUnfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
Definition Protocol.h:43
constexpr std::size_t kOversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
Definition Protocol.h:53
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:889
constexpr FlagValue tfUniversalMask
Definition TxFlags.h:46
@ tesSUCCESS
Definition TER.h:253
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T size(T... args)
Reflects the fee settings for a particular ledger.
LedgerEntryType type
Definition Keylet.h:22
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
ReadView const & view
Definition Transactor.h:95
std::reference_wrapper< ServiceRegistry > registry
Definition Transactor.h:94
std::optional< UInt256 const > const parentBatchId
Definition Transactor.h:99
beast::Journal const j
Definition Transactor.h:100
State information when preflighting a tx.
Definition Transactor.h:39
beast::Journal const j
Definition Transactor.h:46
std::optional< UInt256 const > parentBatchId
Definition Transactor.h:45
std::reference_wrapper< ServiceRegistry > registry
Definition Transactor.h:41
T tie(T... args)