rippled
Loading...
Searching...
No Matches
Transactor.cpp
1#include <xrpld/app/main/Application.h>
2#include <xrpld/app/misc/DelegateUtils.h>
3#include <xrpld/app/misc/LoadFeeTrack.h>
4#include <xrpld/app/tx/apply.h>
5#include <xrpld/app/tx/detail/NFTokenUtils.h>
6#include <xrpld/app/tx/detail/SignerEntries.h>
7#include <xrpld/app/tx/detail/Transactor.h>
8#include <xrpld/core/Config.h>
9
10#include <xrpl/basics/Log.h>
11#include <xrpl/basics/contract.h>
12#include <xrpl/json/to_string.h>
13#include <xrpl/ledger/CredentialHelpers.h>
14#include <xrpl/ledger/View.h>
15#include <xrpl/protocol/Feature.h>
16#include <xrpl/protocol/Indexes.h>
17#include <xrpl/protocol/Protocol.h>
18#include <xrpl/protocol/TxFlags.h>
19#include <xrpl/protocol/UintTypes.h>
20
21namespace xrpl {
22
26{
27 if (isPseudoTx(ctx.tx) && ctx.tx.isFlag(tfInnerBatchTxn))
28 {
29 JLOG(ctx.j.warn()) << "Pseudo transactions cannot contain the "
30 "tfInnerBatchTxn flag.";
31 return temINVALID_FLAG;
32 }
33
34 if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID))
35 {
36 uint32_t nodeNID = ctx.app.config().NETWORK_ID;
37 std::optional<uint32_t> txNID = ctx.tx[~sfNetworkID];
38
39 if (nodeNID <= 1024)
40 {
41 // legacy networks have ids less than 1024, these networks cannot
42 // specify NetworkID in txn
43 if (txNID)
45 }
46 else
47 {
48 // new networks both require the field to be present and require it
49 // to match
50 if (!txNID)
52
53 if (*txNID != nodeNID)
54 return telWRONG_NETWORK;
55 }
56 }
57
58 auto const txID = ctx.tx.getTransactionID();
59
60 if (txID == beast::zero)
61 {
62 JLOG(ctx.j.warn())
63 << "applyTransaction: transaction id may not be zero";
64 return temINVALID;
65 }
66
67 if (ctx.tx.getFlags() & flagMask)
68 {
69 JLOG(ctx.j.debug())
70 << ctx.tx.peekAtField(sfTransactionType).getFullText()
71 << ": invalid flags.";
72 return temINVALID_FLAG;
73 }
74
75 return tesSUCCESS;
76}
77
78namespace detail {
79
86{
87 if (auto const spk = sigObject.getFieldVL(sfSigningPubKey);
88 !spk.empty() && !publicKeyType(makeSlice(spk)))
89 {
90 JLOG(j.debug()) << "preflightCheckSigningKey: invalid signing key";
91 return temBAD_SIGNATURE;
92 }
93 return tesSUCCESS;
94}
95
98 ApplyFlags flags,
99 STObject const& sigObject,
101{
102 if (flags & tapDRY_RUN) // simulation
103 {
104 std::optional<Slice> const signature = sigObject[~sfTxnSignature];
105 if (signature && !signature->empty())
106 {
107 // NOTE: This code should never be hit because it's checked in the
108 // `simulate` RPC
109 return temINVALID; // LCOV_EXCL_LINE
110 }
111
112 if (!sigObject.isFieldPresent(sfSigners))
113 {
114 // no signers, no signature - a valid simulation
115 return tesSUCCESS;
116 }
117
118 for (auto const& signer : sigObject.getFieldArray(sfSigners))
119 {
120 if (signer.isFieldPresent(sfTxnSignature) &&
121 !signer[sfTxnSignature].empty())
122 {
123 // NOTE: This code should never be hit because it's
124 // checked in the `simulate` RPC
125 return temINVALID; // LCOV_EXCL_LINE
126 }
127 }
128
129 Slice const signingPubKey = sigObject[sfSigningPubKey];
130 if (!signingPubKey.empty())
131 {
132 // trying to single-sign _and_ multi-sign a transaction
133 return temINVALID;
134 }
135 return tesSUCCESS;
136 }
137 return {};
138}
139
140} // namespace detail
141
143NotTEC
145{
146 if (ctx.tx.isFieldPresent(sfDelegate))
147 {
148 if (!ctx.rules.enabled(featurePermissionDelegationV1_1))
149 return temDISABLED;
150
151 if (ctx.tx[sfDelegate] == ctx.tx[sfAccount])
152 return temBAD_SIGNER;
153 }
154
155 if (auto const ret = preflight0(ctx, flagMask))
156 return ret;
157
158 auto const id = ctx.tx.getAccountID(sfAccount);
159 if (id == beast::zero)
160 {
161 JLOG(ctx.j.warn()) << "preflight1: bad account id";
162 return temBAD_SRC_ACCOUNT;
163 }
164
165 // No point in going any further if the transaction fee is malformed.
166 auto const fee = ctx.tx.getFieldAmount(sfFee);
167 if (!fee.native() || fee.negative() || !isLegalAmount(fee.xrp()))
168 {
169 JLOG(ctx.j.debug()) << "preflight1: invalid fee";
170 return temBAD_FEE;
171 }
172
173 if (auto const ret = detail::preflightCheckSigningKey(ctx.tx, ctx.j))
174 return ret;
175
176 // An AccountTxnID field constrains transaction ordering more than the
177 // Sequence field. Tickets, on the other hand, reduce ordering
178 // constraints. Because Tickets and AccountTxnID work against one
179 // another the combination is unsupported and treated as malformed.
180 //
181 // We return temINVALID for such transactions.
182 if (ctx.tx.getSeqProxy().isTicket() &&
183 ctx.tx.isFieldPresent(sfAccountTxnID))
184 return temINVALID;
185
186 if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatch))
187 return temINVALID_FLAG;
188
189 XRPL_ASSERT(
190 ctx.tx.isFlag(tfInnerBatchTxn) == ctx.parentBatchId.has_value() ||
191 !ctx.rules.enabled(featureBatch),
192 "Inner batch transaction must have a parent batch ID.");
193
194 return tesSUCCESS;
195}
196
198NotTEC
200{
201 if (auto const ret =
203 // Skips following checks if the transaction is being simulated,
204 // regardless of success or failure
205 return *ret;
206
207 // Skip signature check on batch inner transactions
208 if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatch))
209 return tesSUCCESS;
210 // Do not add any checks after this point that are relevant for
211 // batch inner transactions. They will be skipped.
212
213 auto const sigValid = checkValidity(
214 ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config());
215 if (sigValid.first == Validity::SigBad)
216 { // LCOV_EXCL_START
217 JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second;
218 return temINVALID;
219 // LCOV_EXCL_STOP
220 }
221
222 // Do not add any checks after this point that are relevant for
223 // batch inner transactions. They will be skipped.
224
225 return tesSUCCESS;
226}
227
228//------------------------------------------------------------------------------
229
231 : ctx_(ctx)
232 , sink_(ctx.journal, to_short_string(ctx.tx.getTransactionID()) + " ")
233 , j_(sink_)
234 , account_(ctx.tx.getAccountID(sfAccount))
235{
236}
237
238bool
240 std::optional<Slice> const& slice,
241 std::size_t maxLength)
242{
243 if (!slice)
244 return true;
245 return !slice->empty() && slice->length() <= maxLength;
246}
247
253
254NotTEC
259
260NotTEC
262{
263 auto const delegate = tx[~sfDelegate];
264 if (!delegate)
265 return tesSUCCESS;
266
267 auto const delegateKey = keylet::delegate(tx[sfAccount], *delegate);
268 auto const sle = view.read(delegateKey);
269
270 if (!sle)
272
273 return checkTxPermission(sle, tx);
274}
275
278{
279 // Returns the fee in fee units.
280
281 // The computation has two parts:
282 // * The base fee, which is the same for most transactions.
283 // * The additional cost of each multisignature on the transaction.
284 XRPAmount const baseFee = view.fees().base;
285
286 // Each signer adds one more baseFee to the minimum required fee
287 // for the transaction.
288 std::size_t const signerCount =
289 tx.isFieldPresent(sfSigners) ? tx.getFieldArray(sfSigners).size() : 0;
290
291 return baseFee + (signerCount * baseFee);
292}
293
294// Returns the fee in fee units, not scaled for load.
297{
298 // Assumption: One reserve increment is typically much greater than one base
299 // fee.
300 // This check is in an assert so that it will come to the attention of
301 // developers if that assumption is not correct. If the owner reserve is not
302 // significantly larger than the base fee (or even worse, smaller), we will
303 // need to rethink charging an owner reserve as a transaction fee.
304 // TODO: This function is static, and I don't want to add more parameters.
305 // When it is finally refactored to be in a context that has access to the
306 // Application, include "app().overlay().networkID() > 2 ||" in the
307 // condition.
308 XRPL_ASSERT(
309 view.fees().increment > view.fees().base * 100,
310 "xrpl::Transactor::calculateOwnerReserveFee : Owner reserve is "
311 "reasonable");
312 return view.fees().increment;
313}
314
317 Application& app,
318 XRPAmount baseFee,
319 Fees const& fees,
320 ApplyFlags flags)
321{
322 return scaleFeeLoad(baseFee, app.getFeeTrack(), fees, flags & tapUNLIMITED);
323}
324
325TER
327{
328 if (!ctx.tx[sfFee].native())
329 return temBAD_FEE;
330
331 auto const feePaid = ctx.tx[sfFee].xrp();
332
333 if (ctx.flags & tapBATCH)
334 {
335 if (feePaid == beast::zero)
336 return tesSUCCESS;
337
338 JLOG(ctx.j.trace()) << "Batch: Fee must be zero.";
339 return temBAD_FEE; // LCOV_EXCL_LINE
340 }
341
342 if (!isLegalAmount(feePaid) || feePaid < beast::zero)
343 return temBAD_FEE;
344
345 // Only check fee is sufficient when the ledger is open.
346 if (ctx.view.open())
347 {
348 auto const feeDue =
349 minimumFee(ctx.app, baseFee, ctx.view.fees(), ctx.flags);
350
351 if (feePaid < feeDue)
352 {
353 JLOG(ctx.j.trace())
354 << "Insufficient fee paid: " << to_string(feePaid) << "/"
355 << to_string(feeDue);
356 return telINSUF_FEE_P;
357 }
358 }
359
360 if (feePaid == beast::zero)
361 return tesSUCCESS;
362
363 auto const id = ctx.tx.isFieldPresent(sfDelegate)
364 ? ctx.tx.getAccountID(sfDelegate)
365 : ctx.tx.getAccountID(sfAccount);
366 auto const sle = ctx.view.read(keylet::account(id));
367 if (!sle)
368 return terNO_ACCOUNT;
369
370 auto const balance = (*sle)[sfBalance].xrp();
371
372 if (balance < feePaid)
373 {
374 JLOG(ctx.j.trace())
375 << "Insufficient balance:" << " balance=" << to_string(balance)
376 << " paid=" << to_string(feePaid);
377
378 if ((balance > beast::zero) && !ctx.view.open())
379 {
380 // Closed ledger, non-zero balance, less than fee
381 return tecINSUFF_FEE;
382 }
383
384 return terINSUF_FEE_B;
385 }
386
387 return tesSUCCESS;
388}
389
390TER
392{
393 auto const feePaid = ctx_.tx[sfFee].xrp();
394
395 if (ctx_.tx.isFieldPresent(sfDelegate))
396 {
397 // Delegated transactions are paid by the delegated account.
398 auto const delegate = ctx_.tx.getAccountID(sfDelegate);
399 auto const delegatedSle = view().peek(keylet::account(delegate));
400 if (!delegatedSle)
401 return tefINTERNAL; // LCOV_EXCL_LINE
402
403 delegatedSle->setFieldAmount(
404 sfBalance, delegatedSle->getFieldAmount(sfBalance) - feePaid);
405 view().update(delegatedSle);
406 }
407 else
408 {
409 auto const sle = view().peek(keylet::account(account_));
410 if (!sle)
411 return tefINTERNAL; // LCOV_EXCL_LINE
412
413 // Deduct the fee, so it's not available during the transaction.
414 // Will only write the account back if the transaction succeeds.
415
416 mSourceBalance -= feePaid;
417 sle->setFieldAmount(sfBalance, mSourceBalance);
418
419 // VFALCO Should we call view().rawDestroyXRP() here as well?
420 }
421
422 return tesSUCCESS;
423}
424
425NotTEC
427 ReadView const& view,
428 STTx const& tx,
430{
431 auto const id = tx.getAccountID(sfAccount);
432
433 auto const sle = view.read(keylet::account(id));
434
435 if (!sle)
436 {
437 JLOG(j.trace())
438 << "applyTransaction: delay: source account does not exist "
439 << toBase58(id);
440 return terNO_ACCOUNT;
441 }
442
443 SeqProxy const t_seqProx = tx.getSeqProxy();
444 SeqProxy const a_seq = SeqProxy::sequence((*sle)[sfSequence]);
445
446 if (t_seqProx.isSeq())
447 {
448 if (tx.isFieldPresent(sfTicketSequence))
449 {
450 JLOG(j.trace()) << "applyTransaction: has both a TicketSequence "
451 "and a non-zero Sequence number";
452 return temSEQ_AND_TICKET;
453 }
454 if (t_seqProx != a_seq)
455 {
456 if (a_seq < t_seqProx)
457 {
458 JLOG(j.trace())
459 << "applyTransaction: has future sequence number "
460 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
461 return terPRE_SEQ;
462 }
463 // It's an already-used sequence number.
464 JLOG(j.trace()) << "applyTransaction: has past sequence number "
465 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
466 return tefPAST_SEQ;
467 }
468 }
469 else if (t_seqProx.isTicket())
470 {
471 // Bypass the type comparison. Apples and oranges.
472 if (a_seq.value() <= t_seqProx.value())
473 {
474 // If the Ticket number is greater than or equal to the
475 // account sequence there's the possibility that the
476 // transaction to create the Ticket has not hit the ledger
477 // yet. Allow a retry.
478 JLOG(j.trace()) << "applyTransaction: has future ticket id "
479 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
480 return terPRE_TICKET;
481 }
482
483 // Transaction can never succeed if the Ticket is not in the ledger.
484 if (!view.exists(keylet::ticket(id, t_seqProx)))
485 {
486 JLOG(j.trace())
487 << "applyTransaction: ticket already used or never created "
488 << "a_seq=" << a_seq << " t_seq=" << t_seqProx;
489 return tefNO_TICKET;
490 }
491 }
492
493 return tesSUCCESS;
494}
495
496NotTEC
498{
499 auto const id = ctx.tx.getAccountID(sfAccount);
500
501 auto const sle = ctx.view.read(keylet::account(id));
502
503 if (!sle)
504 {
505 JLOG(ctx.j.trace())
506 << "applyTransaction: delay: source account does not exist "
507 << toBase58(id);
508 return terNO_ACCOUNT;
509 }
510
511 if (ctx.tx.isFieldPresent(sfAccountTxnID) &&
512 (sle->getFieldH256(sfAccountTxnID) !=
513 ctx.tx.getFieldH256(sfAccountTxnID)))
514 return tefWRONG_PRIOR;
515
516 if (ctx.tx.isFieldPresent(sfLastLedgerSequence) &&
517 (ctx.view.seq() > ctx.tx.getFieldU32(sfLastLedgerSequence)))
518 return tefMAX_LEDGER;
519
520 if (ctx.view.txExists(ctx.tx.getTransactionID()))
521 return tefALREADY;
522
523 return tesSUCCESS;
524}
525
526TER
528{
529 XRPL_ASSERT(
530 sleAccount, "xrpl::Transactor::consumeSeqProxy : non-null account");
531 SeqProxy const seqProx = ctx_.tx.getSeqProxy();
532 if (seqProx.isSeq())
533 {
534 // Note that if this transaction is a TicketCreate, then
535 // the transaction will modify the account root sfSequence
536 // yet again.
537 sleAccount->setFieldU32(sfSequence, seqProx.value() + 1);
538 return tesSUCCESS;
539 }
540 return ticketDelete(
541 view(), account_, getTicketIndex(account_, seqProx), j_);
542}
543
544// Remove a single Ticket from the ledger.
545TER
547 ApplyView& view,
548 AccountID const& account,
549 uint256 const& ticketIndex,
551{
552 // Delete the Ticket, adjust the account root ticket count, and
553 // reduce the owner count.
554 SLE::pointer const sleTicket = view.peek(keylet::ticket(ticketIndex));
555 if (!sleTicket)
556 {
557 // LCOV_EXCL_START
558 JLOG(j.fatal()) << "Ticket disappeared from ledger.";
559 return tefBAD_LEDGER;
560 // LCOV_EXCL_STOP
561 }
562
563 std::uint64_t const page{(*sleTicket)[sfOwnerNode]};
564 if (!view.dirRemove(keylet::ownerDir(account), page, ticketIndex, true))
565 {
566 // LCOV_EXCL_START
567 JLOG(j.fatal()) << "Unable to delete Ticket from owner.";
568 return tefBAD_LEDGER;
569 // LCOV_EXCL_STOP
570 }
571
572 // Update the account root's TicketCount. If the ticket count drops to
573 // zero remove the (optional) field.
574 auto sleAccount = view.peek(keylet::account(account));
575 if (!sleAccount)
576 {
577 // LCOV_EXCL_START
578 JLOG(j.fatal()) << "Could not find Ticket owner account root.";
579 return tefBAD_LEDGER;
580 // LCOV_EXCL_STOP
581 }
582
583 if (auto ticketCount = (*sleAccount)[~sfTicketCount])
584 {
585 if (*ticketCount == 1)
586 sleAccount->makeFieldAbsent(sfTicketCount);
587 else
588 ticketCount = *ticketCount - 1;
589 }
590 else
591 {
592 // LCOV_EXCL_START
593 JLOG(j.fatal()) << "TicketCount field missing from account root.";
594 return tefBAD_LEDGER;
595 // LCOV_EXCL_STOP
596 }
597
598 // Update the Ticket owner's reserve.
599 adjustOwnerCount(view, sleAccount, -1, j);
600
601 // Remove Ticket from ledger.
602 view.erase(sleTicket);
603 return tesSUCCESS;
604}
605
606// check stuff before you bother to lock the ledger
607void
609{
610 XRPL_ASSERT(
611 account_ != beast::zero,
612 "xrpl::Transactor::preCompute : nonzero account");
613}
614
615TER
617{
618 preCompute();
619
620 // If the transactor requires a valid account and the transaction doesn't
621 // list one, preflight will have already a flagged a failure.
622 auto const sle = view().peek(keylet::account(account_));
623
624 // sle must exist except for transactions
625 // that allow zero account.
626 XRPL_ASSERT(
627 sle != nullptr || account_ == beast::zero,
628 "xrpl::Transactor::apply : non-null SLE or zero account");
629
630 if (sle)
631 {
632 mPriorBalance = STAmount{(*sle)[sfBalance]}.xrp();
634
635 TER result = consumeSeqProxy(sle);
636 if (result != tesSUCCESS)
637 return result;
638
639 result = payFee();
640 if (result != tesSUCCESS)
641 return result;
642
643 if (sle->isFieldPresent(sfAccountTxnID))
644 sle->setFieldH256(sfAccountTxnID, ctx_.tx.getTransactionID());
645
646 view().update(sle);
647 }
648
649 return doApply();
650}
651
652NotTEC
654 ReadView const& view,
655 ApplyFlags flags,
656 std::optional<uint256 const> const& parentBatchId,
657 AccountID const& idAccount,
658 STObject const& sigObject,
659 beast::Journal const j)
660{
661 {
662 auto const sle = view.read(keylet::account(idAccount));
663
664 if (view.rules().enabled(featureLendingProtocol) &&
665 isPseudoAccount(sle))
666 // Pseudo-accounts can't sign transactions. This check is gated on
667 // the Lending Protocol amendment because that's the project it was
668 // added under, and it doesn't justify another amendment
669 return tefBAD_AUTH;
670 }
671
672 auto const pkSigner = sigObject.getFieldVL(sfSigningPubKey);
673 // Ignore signature check on batch inner transactions
674 if (parentBatchId && view.rules().enabled(featureBatch))
675 {
676 // Defensive Check: These values are also checked in Batch::preflight
677 if (sigObject.isFieldPresent(sfTxnSignature) || !pkSigner.empty() ||
678 sigObject.isFieldPresent(sfSigners))
679 {
680 return temINVALID_FLAG; // LCOV_EXCL_LINE
681 }
682 return tesSUCCESS;
683 }
684
685 if ((flags & tapDRY_RUN) && pkSigner.empty() &&
686 !sigObject.isFieldPresent(sfSigners))
687 {
688 // simulate: skip signature validation when neither SigningPubKey nor
689 // Signers are provided
690 return tesSUCCESS;
691 }
692
693 // If the pk is empty and not simulate or simulate and signers,
694 // then we must be multi-signing.
695 if (sigObject.isFieldPresent(sfSigners))
696 {
697 return checkMultiSign(view, flags, idAccount, sigObject, j);
698 }
699
700 // Check Single Sign
701 XRPL_ASSERT(
702 !pkSigner.empty(), "xrpl::Transactor::checkSign : non-empty signer");
703
704 if (!publicKeyType(makeSlice(pkSigner)))
705 {
706 JLOG(j.trace()) << "checkSign: signing public key type is unknown";
707 return tefBAD_AUTH; // FIXME: should be better error!
708 }
709
710 // Look up the account.
711 auto const idSigner = pkSigner.empty()
712 ? idAccount
713 : calcAccountID(PublicKey(makeSlice(pkSigner)));
714 auto const sleAccount = view.read(keylet::account(idAccount));
715 if (!sleAccount)
716 return terNO_ACCOUNT;
717
718 return checkSingleSign(view, idSigner, idAccount, sleAccount, j);
719}
720
721NotTEC
723{
724 auto const idAccount = ctx.tx.isFieldPresent(sfDelegate)
725 ? ctx.tx.getAccountID(sfDelegate)
726 : ctx.tx.getAccountID(sfAccount);
727 return checkSign(
728 ctx.view, ctx.flags, ctx.parentBatchId, idAccount, ctx.tx, ctx.j);
729}
730
731NotTEC
733{
734 NotTEC ret = tesSUCCESS;
735 STArray const& signers{ctx.tx.getFieldArray(sfBatchSigners)};
736 for (auto const& signer : signers)
737 {
738 auto const idAccount = signer.getAccountID(sfAccount);
739
740 Blob const& pkSigner = signer.getFieldVL(sfSigningPubKey);
741 if (pkSigner.empty())
742 {
743 if (ret = checkMultiSign(
744 ctx.view, ctx.flags, idAccount, signer, ctx.j);
745 !isTesSuccess(ret))
746 return ret;
747 }
748 else
749 {
750 // LCOV_EXCL_START
751 if (!publicKeyType(makeSlice(pkSigner)))
752 return tefBAD_AUTH;
753 // LCOV_EXCL_STOP
754
755 auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner)));
756 auto const sleAccount = ctx.view.read(keylet::account(idAccount));
757
758 // A batch can include transactions from an un-created account ONLY
759 // when the account master key is the signer
760 if (!sleAccount)
761 {
762 if (idAccount != idSigner)
763 return tefBAD_AUTH;
764
765 return tesSUCCESS;
766 }
767
768 if (ret = checkSingleSign(
769 ctx.view, idSigner, idAccount, sleAccount, ctx.j);
770 !isTesSuccess(ret))
771 return ret;
772 }
773 }
774 return ret;
775}
776
777NotTEC
779 ReadView const& view,
780 AccountID const& idSigner,
781 AccountID const& idAccount,
783 beast::Journal const j)
784{
785 bool const isMasterDisabled = sleAccount->isFlag(lsfDisableMaster);
786
787 // Signed with regular key.
788 if ((*sleAccount)[~sfRegularKey] == idSigner)
789 {
790 return tesSUCCESS;
791 }
792
793 // Signed with enabled master key.
794 if (!isMasterDisabled && idAccount == idSigner)
795 {
796 return tesSUCCESS;
797 }
798
799 // Signed with disabled master key.
800 if (isMasterDisabled && idAccount == idSigner)
801 {
802 return tefMASTER_DISABLED;
803 }
804
805 // Signed with any other key.
806 return tefBAD_AUTH;
807}
808
809NotTEC
811 ReadView const& view,
812 ApplyFlags flags,
813 AccountID const& id,
814 STObject const& sigObject,
815 beast::Journal const j)
816{
817 // Get id's SignerList and Quorum.
818 std::shared_ptr<STLedgerEntry const> sleAccountSigners =
820 // If the signer list doesn't exist the account is not multi-signing.
821 if (!sleAccountSigners)
822 {
823 JLOG(j.trace())
824 << "applyTransaction: Invalid: Not a multi-signing account.";
826 }
827
828 // We have plans to support multiple SignerLists in the future. The
829 // presence and defaulted value of the SignerListID field will enable that.
830 XRPL_ASSERT(
831 sleAccountSigners->isFieldPresent(sfSignerListID),
832 "xrpl::Transactor::checkMultiSign : has signer list ID");
833 XRPL_ASSERT(
834 sleAccountSigners->getFieldU32(sfSignerListID) == 0,
835 "xrpl::Transactor::checkMultiSign : signer list ID is 0");
836
837 auto accountSigners =
838 SignerEntries::deserialize(*sleAccountSigners, j, "ledger");
839 if (!accountSigners)
840 return accountSigners.error();
841
842 // Get the array of transaction signers.
843 STArray const& txSigners(sigObject.getFieldArray(sfSigners));
844
845 // Walk the accountSigners performing a variety of checks and see if
846 // the quorum is met.
847
848 // Both the multiSigners and accountSigners are sorted by account. So
849 // matching multi-signers to account signers should be a simple
850 // linear walk. *All* signers must be valid or the transaction fails.
851 std::uint32_t weightSum = 0;
852 auto iter = accountSigners->begin();
853 for (auto const& txSigner : txSigners)
854 {
855 AccountID const txSignerAcctID = txSigner.getAccountID(sfAccount);
856
857 // Attempt to match the SignerEntry with a Signer;
858 while (iter->account < txSignerAcctID)
859 {
860 if (++iter == accountSigners->end())
861 {
862 JLOG(j.trace())
863 << "applyTransaction: Invalid SigningAccount.Account.";
864 return tefBAD_SIGNATURE;
865 }
866 }
867 if (iter->account != txSignerAcctID)
868 {
869 // The SigningAccount is not in the SignerEntries.
870 JLOG(j.trace())
871 << "applyTransaction: Invalid SigningAccount.Account.";
872 return tefBAD_SIGNATURE;
873 }
874
875 // We found the SigningAccount in the list of valid signers. Now we
876 // need to compute the accountID that is associated with the signer's
877 // public key.
878 auto const spk = txSigner.getFieldVL(sfSigningPubKey);
879
880 // spk being non-empty in non-simulate is checked in
881 // STTx::checkMultiSign
882 if (!spk.empty() && !publicKeyType(makeSlice(spk)))
883 {
884 JLOG(j.trace())
885 << "checkMultiSign: signing public key type is unknown";
886 return tefBAD_SIGNATURE;
887 }
888
889 XRPL_ASSERT(
890 (flags & tapDRY_RUN) || !spk.empty(),
891 "xrpl::Transactor::checkMultiSign : non-empty signer or "
892 "simulation");
893 AccountID const signingAcctIDFromPubKey = spk.empty()
894 ? txSignerAcctID
896
897 // Verify that the signingAcctID and the signingAcctIDFromPubKey
898 // belong together. Here are the rules:
899 //
900 // 1. "Phantom account": an account that is not in the ledger
901 // A. If signingAcctID == signingAcctIDFromPubKey and the
902 // signingAcctID is not in the ledger then we have a phantom
903 // account.
904 // B. Phantom accounts are always allowed as multi-signers.
905 //
906 // 2. "Master Key"
907 // A. signingAcctID == signingAcctIDFromPubKey, and signingAcctID
908 // is in the ledger.
909 // B. If the signingAcctID in the ledger does not have the
910 // asfDisableMaster flag set, then the signature is allowed.
911 //
912 // 3. "Regular Key"
913 // A. signingAcctID != signingAcctIDFromPubKey, and signingAcctID
914 // is in the ledger.
915 // B. If signingAcctIDFromPubKey == signingAcctID.RegularKey (from
916 // ledger) then the signature is allowed.
917 //
918 // No other signatures are allowed. (January 2015)
919
920 // In any of these cases we need to know whether the account is in
921 // the ledger. Determine that now.
922 auto const sleTxSignerRoot = view.read(keylet::account(txSignerAcctID));
923
924 if (signingAcctIDFromPubKey == txSignerAcctID)
925 {
926 // Either Phantom or Master. Phantoms automatically pass.
927 if (sleTxSignerRoot)
928 {
929 // Master Key. Account may not have asfDisableMaster set.
930 std::uint32_t const signerAccountFlags =
931 sleTxSignerRoot->getFieldU32(sfFlags);
932
933 if (signerAccountFlags & lsfDisableMaster)
934 {
935 JLOG(j.trace())
936 << "applyTransaction: Signer:Account lsfDisableMaster.";
937 return tefMASTER_DISABLED;
938 }
939 }
940 }
941 else
942 {
943 // May be a Regular Key. Let's find out.
944 // Public key must hash to the account's regular key.
945 if (!sleTxSignerRoot)
946 {
947 JLOG(j.trace()) << "applyTransaction: Non-phantom signer "
948 "lacks account root.";
949 return tefBAD_SIGNATURE;
950 }
951
952 if (!sleTxSignerRoot->isFieldPresent(sfRegularKey))
953 {
954 JLOG(j.trace())
955 << "applyTransaction: Account lacks RegularKey.";
956 return tefBAD_SIGNATURE;
957 }
958 if (signingAcctIDFromPubKey !=
959 sleTxSignerRoot->getAccountID(sfRegularKey))
960 {
961 JLOG(j.trace())
962 << "applyTransaction: Account doesn't match RegularKey.";
963 return tefBAD_SIGNATURE;
964 }
965 }
966 // The signer is legitimate. Add their weight toward the quorum.
967 weightSum += iter->weight;
968 }
969
970 // Cannot perform transaction if quorum is not met.
971 if (weightSum < sleAccountSigners->getFieldU32(sfSignerQuorum))
972 {
973 JLOG(j.trace()) << "applyTransaction: Signers failed to meet quorum.";
974 return tefBAD_QUORUM;
975 }
976
977 // Met the quorum. Continue.
978 return tesSUCCESS;
979}
980
981//------------------------------------------------------------------------------
982
983static void
985 ApplyView& view,
986 std::vector<uint256> const& offers,
987 beast::Journal viewJ)
988{
989 int removed = 0;
990
991 for (auto const& index : offers)
992 {
993 if (auto const sleOffer = view.peek(keylet::offer(index)))
994 {
995 // offer is unfunded
996 offerDelete(view, sleOffer, viewJ);
997 if (++removed == unfundedOfferRemoveLimit)
998 return;
999 }
1000 }
1001}
1002
1003static void
1005 ApplyView& view,
1006 std::vector<uint256> const& offers,
1007 beast::Journal viewJ)
1008{
1009 std::size_t removed = 0;
1010
1011 for (auto const& index : offers)
1012 {
1013 if (auto const offer = view.peek(keylet::nftoffer(index)))
1014 {
1015 nft::deleteTokenOffer(view, offer);
1016 if (++removed == expiredOfferRemoveLimit)
1017 return;
1018 }
1019 }
1020}
1021
1022static void
1024 ApplyView& view,
1025 std::vector<uint256> const& creds,
1026 beast::Journal viewJ)
1027{
1028 for (auto const& index : creds)
1029 {
1030 if (auto const sle = view.peek(keylet::credential(index)))
1031 credentials::deleteSLE(view, sle, viewJ);
1032 }
1033}
1034
1035static void
1037 ApplyView& view,
1038 std::vector<uint256> const& trustLines,
1039 beast::Journal viewJ)
1040{
1041 if (trustLines.size() > maxDeletableAMMTrustLines)
1042 {
1043 JLOG(viewJ.error())
1044 << "removeDeletedTrustLines: deleted trustlines exceed max "
1045 << trustLines.size();
1046 return;
1047 }
1048
1049 for (auto const& index : trustLines)
1050 {
1051 if (auto const sleState = view.peek({ltRIPPLE_STATE, index});
1052 deleteAMMTrustLine(view, sleState, std::nullopt, viewJ) !=
1053 tesSUCCESS)
1054 {
1055 JLOG(viewJ.error())
1056 << "removeDeletedTrustLines: failed to delete AMM trustline";
1057 }
1058 }
1059}
1060
1068{
1069 ctx_.discard();
1070
1071 auto const txnAcct =
1073
1074 // The account should never be missing from the ledger. But if it
1075 // is missing then we can't very well charge it a fee, can we?
1076 if (!txnAcct)
1077 return {tefINTERNAL, beast::zero};
1078
1079 auto const payerSle = ctx_.tx.isFieldPresent(sfDelegate)
1080 ? view().peek(keylet::account(ctx_.tx.getAccountID(sfDelegate)))
1081 : txnAcct;
1082 if (!payerSle)
1083 return {tefINTERNAL, beast::zero}; // LCOV_EXCL_LINE
1084
1085 auto const balance = payerSle->getFieldAmount(sfBalance).xrp();
1086
1087 // balance should have already been checked in checkFee / preFlight.
1088 XRPL_ASSERT(
1089 balance != beast::zero && (!view().open() || balance >= fee),
1090 "xrpl::Transactor::reset : valid balance");
1091
1092 // We retry/reject the transaction if the account balance is zero or
1093 // we're applying against an open ledger and the balance is less than
1094 // the fee
1095 if (fee > balance)
1096 fee = balance;
1097
1098 // Since we reset the context, we need to charge the fee and update
1099 // the account's sequence number (or consume the Ticket) again.
1100 //
1101 // If for some reason we are unable to consume the ticket or sequence
1102 // then the ledger is corrupted. Rather than make things worse we
1103 // reject the transaction.
1104 payerSle->setFieldAmount(sfBalance, balance - fee);
1105 TER const ter{consumeSeqProxy(txnAcct)};
1106 XRPL_ASSERT(
1107 isTesSuccess(ter), "xrpl::Transactor::reset : result is tesSUCCESS");
1108
1109 if (isTesSuccess(ter))
1110 {
1111 view().update(txnAcct);
1112 if (payerSle != txnAcct)
1113 view().update(payerSle);
1114 }
1115
1116 return {ter, fee};
1117}
1118
1119// The sole purpose of this function is to provide a convenient, named
1120// location to set a breakpoint, to be used when replaying transactions.
1121void
1123{
1124 JLOG(j_.debug()) << "Transaction trapped: " << txHash;
1125}
1126
1127//------------------------------------------------------------------------------
1130{
1131 JLOG(j_.trace()) << "apply: " << ctx_.tx.getTransactionID();
1132
1133 // raii classes for the current ledger rules.
1134 // fixUniversalNumber predate the rulesGuard and should be replaced.
1135 NumberSO stNumberSO{view().rules().enabled(fixUniversalNumber)};
1136 CurrentTransactionRulesGuard currentTransactionRulesGuard(view().rules());
1137
1138#ifdef DEBUG
1139 {
1140 Serializer ser;
1141 ctx_.tx.add(ser);
1142 SerialIter sit(ser.slice());
1143 STTx s2(sit);
1144
1145 if (!s2.isEquivalent(ctx_.tx))
1146 {
1147 // LCOV_EXCL_START
1148 JLOG(j_.fatal()) << "Transaction serdes mismatch";
1150 JLOG(j_.fatal()) << s2.getJson(JsonOptions::none);
1151 UNREACHABLE(
1152 "xrpl::Transactor::operator() : transaction serdes mismatch");
1153 // LCOV_EXCL_STOP
1154 }
1155 }
1156#endif
1157
1158 if (auto const& trap = ctx_.app.trapTxID();
1159 trap && *trap == ctx_.tx.getTransactionID())
1160 {
1161 trapTransaction(*trap);
1162 }
1163
1164 auto result = ctx_.preclaimResult;
1165 if (result == tesSUCCESS)
1166 result = apply();
1167
1168 // No transaction can return temUNKNOWN from apply,
1169 // and it can't be passed in from a preclaim.
1170 XRPL_ASSERT(
1171 result != temUNKNOWN,
1172 "xrpl::Transactor::operator() : result is not temUNKNOWN");
1173
1174 if (auto stream = j_.trace())
1175 stream << "preclaim result: " << transToken(result);
1176
1177 bool applied = isTesSuccess(result);
1178 auto fee = ctx_.tx.getFieldAmount(sfFee).xrp();
1179
1181 result = tecOVERSIZE;
1182
1183 if (isTecClaim(result) && (view().flags() & tapFAIL_HARD))
1184 {
1185 // If the tapFAIL_HARD flag is set, a tec result
1186 // must not do anything
1187 ctx_.discard();
1188 applied = false;
1189 }
1190 else if (
1191 (result == tecOVERSIZE) || (result == tecKILLED) ||
1192 (result == tecINCOMPLETE) || (result == tecEXPIRED) ||
1193 (isTecClaimHardFail(result, view().flags())))
1194 {
1195 JLOG(j_.trace()) << "reapplying because of " << transToken(result);
1196
1197 // FIXME: This mechanism for doing work while returning a `tec` is
1198 // awkward and very limiting. A more general purpose approach
1199 // should be used, making it possible to do more useful work
1200 // when transactions fail with a `tec` code.
1201 std::vector<uint256> removedOffers;
1202 std::vector<uint256> removedTrustLines;
1203 std::vector<uint256> expiredNFTokenOffers;
1204 std::vector<uint256> expiredCredentials;
1205
1206 bool const doOffers =
1207 ((result == tecOVERSIZE) || (result == tecKILLED));
1208 bool const doLines = (result == tecINCOMPLETE);
1209 bool const doNFTokenOffers = (result == tecEXPIRED);
1210 bool const doCredentials = (result == tecEXPIRED);
1211 if (doOffers || doLines || doNFTokenOffers || doCredentials)
1212 {
1213 ctx_.visit([doOffers,
1214 &removedOffers,
1215 doLines,
1216 &removedTrustLines,
1217 doNFTokenOffers,
1218 &expiredNFTokenOffers,
1219 doCredentials,
1220 &expiredCredentials](
1221 uint256 const& index,
1222 bool isDelete,
1223 std::shared_ptr<SLE const> const& before,
1225 if (isDelete)
1226 {
1227 XRPL_ASSERT(
1228 before && after,
1229 "xrpl::Transactor::operator()::visit : non-null SLE "
1230 "inputs");
1231 if (doOffers && before && after &&
1232 (before->getType() == ltOFFER) &&
1233 (before->getFieldAmount(sfTakerPays) ==
1234 after->getFieldAmount(sfTakerPays)))
1235 {
1236 // Removal of offer found or made unfunded
1237 removedOffers.push_back(index);
1238 }
1239
1240 if (doLines && before && after &&
1241 (before->getType() == ltRIPPLE_STATE))
1242 {
1243 // Removal of obsolete AMM trust line
1244 removedTrustLines.push_back(index);
1245 }
1246
1247 if (doNFTokenOffers && before && after &&
1248 (before->getType() == ltNFTOKEN_OFFER))
1249 expiredNFTokenOffers.push_back(index);
1250
1251 if (doCredentials && before && after &&
1252 (before->getType() == ltCREDENTIAL))
1253 expiredCredentials.push_back(index);
1254 }
1255 });
1256 }
1257
1258 // Reset the context, potentially adjusting the fee.
1259 {
1260 auto const resetResult = reset(fee);
1261 if (!isTesSuccess(resetResult.first))
1262 result = resetResult.first;
1263
1264 fee = resetResult.second;
1265 }
1266
1267 // If necessary, remove any offers found unfunded during processing
1268 if ((result == tecOVERSIZE) || (result == tecKILLED))
1270 view(), removedOffers, ctx_.app.journal("View"));
1271
1272 if (result == tecEXPIRED)
1274 view(), expiredNFTokenOffers, ctx_.app.journal("View"));
1275
1276 if (result == tecINCOMPLETE)
1278 view(), removedTrustLines, ctx_.app.journal("View"));
1279
1280 if (result == tecEXPIRED)
1282 view(), expiredCredentials, ctx_.app.journal("View"));
1283
1284 applied = isTecClaim(result);
1285 }
1286
1287 if (applied)
1288 {
1289 // Check invariants: if `tecINVARIANT_FAILED` is not returned, we can
1290 // proceed to apply the tx
1291 result = ctx_.checkInvariants(result, fee);
1292
1293 if (result == tecINVARIANT_FAILED)
1294 {
1295 // if invariants checking failed again, reset the context and
1296 // attempt to only claim a fee.
1297 auto const resetResult = reset(fee);
1298 if (!isTesSuccess(resetResult.first))
1299 result = resetResult.first;
1300
1301 fee = resetResult.second;
1302
1303 // Check invariants again to ensure the fee claiming doesn't
1304 // violate invariants.
1305 if (isTesSuccess(result) || isTecClaim(result))
1306 result = ctx_.checkInvariants(result, fee);
1307 }
1308
1309 // We ran through the invariant checker, which can, in some cases,
1310 // return a tef error code. Don't apply the transaction in that case.
1311 if (!isTecClaim(result) && !isTesSuccess(result))
1312 applied = false;
1313 }
1314
1315 std::optional<TxMeta> metadata;
1316 if (applied)
1317 {
1318 // Transaction succeeded fully or (retries are not allowed and the
1319 // transaction could claim a fee)
1320
1321 // The transactor and invariant checkers guarantee that this will
1322 // *never* trigger but if it, somehow, happens, don't allow a tx
1323 // that charges a negative fee.
1324 if (fee < beast::zero)
1325 Throw<std::logic_error>("fee charged is negative!");
1326
1327 // Charge whatever fee they specified. The fee has already been
1328 // deducted from the balance of the account that issued the
1329 // transaction. We just need to account for it in the ledger
1330 // header.
1331 if (!view().open() && fee != beast::zero)
1332 ctx_.destroyXRP(fee);
1333
1334 // Once we call apply, we will no longer be able to look at view()
1335 metadata = ctx_.apply(result);
1336 }
1337
1338 if (ctx_.flags() & tapDRY_RUN)
1339 {
1340 applied = false;
1341 }
1342
1343 JLOG(j_.trace()) << (applied ? "applied " : "not applied ")
1344 << transToken(result);
1345
1346 return {result, applied, metadata};
1347}
1348
1349} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:41
Stream fatal() const
Definition Journal.h:333
Stream error() const
Definition Journal.h:327
Stream debug() const
Definition Journal.h:309
Stream info() const
Definition Journal.h:315
Stream trace() const
Severity stream access functions.
Definition Journal.h:303
Stream warn() const
Definition Journal.h:321
virtual HashRouter & getHashRouter()=0
virtual Config & config()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual beast::Journal journal(std::string const &name)=0
virtual std::optional< uint256 > const & trapTxID() const =0
State information when applying a tx.
std::size_t size()
Get the number of unapplied changes.
STTx const & tx
void destroyXRP(XRPAmount const &fee)
ApplyFlags const & flags() const
void discard()
Discard changes and start fresh.
std::optional< TxMeta > apply(TER)
Apply the transaction result to the base.
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
TER const preclaimResult
Application & app
void visit(std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func)
Visit unapplied changes.
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
uint32_t NETWORK_ID
Definition Config.h:138
RAII class to set and restore the current transaction rules.
Definition Rules.h:92
RAII class to set and restore the Number switchover.
Definition IOUAmount.h:192
A public key.
Definition PublicKey.h:43
A view into a ledger.
Definition ReadView.h:32
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
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:99
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:111
XRPAmount xrp() const
Definition STAmount.cpp:264
size_type size() const
Definition STArray.h:229
virtual std::string getFullText() const
Definition STBase.cpp:62
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:644
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:341
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:596
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:683
void add(Serializer &s) const override
Definition STObject.cpp:122
bool isFlag(std::uint32_t) const
Definition STObject.cpp:512
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:626
STBase const & peekAtField(SField const &field) const
Definition STObject.cpp:410
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
STAmount const & getFieldAmount(SField const &field) const
Definition STObject.cpp:652
std::uint32_t getFlags() const
Definition STObject.cpp:518
Json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:308
SeqProxy getSeqProxy() const
Definition STTx.cpp:197
uint256 getTransactionID() const
Definition STTx.h:199
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:57
constexpr bool isTicket() const
Definition SeqProxy.h:75
constexpr std::uint32_t value() const
Definition SeqProxy.h:63
constexpr bool isSeq() const
Definition SeqProxy.h:69
Slice slice() const noexcept
Definition Serializer.h:47
static 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:27
bool empty() const noexcept
Return true if the byte range is empty.
Definition Slice.h:51
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)
AccountID const account_
Definition Transactor.h:128
void trapTransaction(uint256) const
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
static NotTEC checkSign(PreclaimContext const &ctx)
static XRPAmount calculateOwnerReserveFee(ReadView const &view, STTx const &tx)
ApplyResult operator()()
Process the transaction.
static NotTEC checkPermission(ReadView const &view, STTx const &tx)
static XRPAmount minimumFee(Application &app, 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 preflightSigValidated(PreflightContext const &ctx)
static NotTEC checkBatchSign(PreclaimContext const &ctx)
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
beast::Journal const j_
Definition Transactor.h:126
virtual TER doApply()=0
static NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
ApplyView & view()
Definition Transactor.h:144
static NotTEC checkSingleSign(ReadView const &view, AccountID const &idSigner, AccountID const &idAccount, std::shared_ptr< SLE const > sleAccount, beast::Journal const j)
Transactor(Transactor const &)=delete
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
XRPAmount mSourceBalance
Definition Transactor.h:130
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
XRPAmount mPriorBalance
Definition Transactor.h:129
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:124
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)
T empty(T... args)
T is_same_v
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
NotTEC preflightCheckSigningKey(STObject const &sigObject, beast::Journal j)
Checks the validity of the transactor signing key.
std::optional< NotTEC > preflightCheckSimulateKeys(ApplyFlags flags, STObject const &sigObject, beast::Journal j)
Checks the special signing key state needed for simulation.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Definition Indexes.cpp:312
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Definition Indexes.cpp:409
static ticket_t const ticket
Definition Indexes.h:152
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:356
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:256
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Definition Indexes.cpp:447
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:166
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:535
bool deleteTokenOffer(ApplyView &view, std::shared_ptr< SLE > const &offer)
Deletes the given token offer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ telWRONG_NETWORK
Definition TER.h:46
@ telNETWORK_ID_MAKES_TX_NON_CANONICAL
Definition TER.h:48
@ telINSUF_FEE_P
Definition TER.h:38
@ telREQUIRES_NETWORK_ID
Definition TER.h:47
@ terPRE_SEQ
Definition TER.h:202
@ terINSUF_FEE_B
Definition TER.h:197
@ terNO_DELEGATE_PERMISSION
Definition TER.h:211
@ terNO_ACCOUNT
Definition TER.h:198
@ terPRE_TICKET
Definition TER.h:207
static void removeExpiredNFTokenOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
bool isLegalAmount(XRPAmount const &amount)
Returns true if the amount does not exceed the initial XRP in existence.
@ SigBad
Signature is bad. Didn't do local checks.
std::size_t constexpr expiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Definition Protocol.h:32
constexpr std::uint32_t tfInnerBatchTxn
Definition TxFlags.h:42
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
static void removeExpiredCredentials(ApplyView &view, std::vector< uint256 > const &creds, 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:29
uint256 getTicketIndex(AccountID const &account, std::uint32_t uSequence)
Definition Indexes.cpp:138
@ tefBAD_QUORUM
Definition TER.h:161
@ tefMAX_LEDGER
Definition TER.h:159
@ tefMASTER_DISABLED
Definition TER.h:158
@ tefALREADY
Definition TER.h:148
@ tefBAD_LEDGER
Definition TER.h:151
@ tefWRONG_PRIOR
Definition TER.h:157
@ tefNO_TICKET
Definition TER.h:166
@ tefBAD_SIGNATURE
Definition TER.h:160
@ tefINTERNAL
Definition TER.h:154
@ tefBAD_AUTH
Definition TER.h:150
@ tefPAST_SEQ
Definition TER.h:156
@ tefNOT_MULTI_SIGNING
Definition TER.h:162
std::uint16_t constexpr maxDeletableAMMTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
Definition Protocol.h:266
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
static void removeUnfundedOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
Definition View.cpp:3463
std::string transToken(TER code)
Definition TER.cpp:245
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Definition View.cpp:1226
std::size_t constexpr oversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
Definition Protocol.h:35
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1134
@ open
We haven't closed our ledger yet, but others might have.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3922
NotTEC checkTxPermission(std::shared_ptr< SLE const > const &delegate, STTx const &tx)
Check if the delegate account has permission to execute the transaction.
AccountID calcAccountID(PublicKey const &pk)
static void removeDeletedTrustLines(ApplyView &view, std::vector< uint256 > const &trustLines, beast::Journal viewJ)
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Definition apply.cpp:25
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1903
ApplyFlags
Definition ApplyView.h:11
@ tapDRY_RUN
Definition ApplyView.h:30
@ tapFAIL_HARD
Definition ApplyView.h:16
@ tapUNLIMITED
Definition ApplyView.h:23
@ tapBATCH
Definition ApplyView.h:26
@ temBAD_FEE
Definition TER.h:73
@ temINVALID
Definition TER.h:91
@ temINVALID_FLAG
Definition TER.h:92
@ temBAD_SRC_ACCOUNT
Definition TER.h:87
@ temSEQ_AND_TICKET
Definition TER.h:107
@ temDISABLED
Definition TER.h:95
@ temUNKNOWN
Definition TER.h:105
@ temBAD_SIGNATURE
Definition TER.h:86
@ temBAD_SIGNER
Definition TER.h:96
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
bool isTesSuccess(TER x) noexcept
Definition TER.h:659
std::size_t constexpr unfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
Definition Protocol.h:29
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid.
@ tecINSUFF_FEE
Definition TER.h:284
@ tecINCOMPLETE
Definition TER.h:317
@ tecINVARIANT_FAILED
Definition TER.h:295
@ tecEXPIRED
Definition TER.h:296
@ tecKILLED
Definition TER.h:298
@ tecOVERSIZE
Definition TER.h:293
bool isTecClaim(TER x) noexcept
Definition TER.h:666
@ lsfDisableMaster
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition Slice.h:225
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:590
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:810
@ tesSUCCESS
Definition TER.h:226
std::string to_short_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:618
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:44
T push_back(T... args)
T size(T... args)
Reflects the fee settings for a particular ledger.
XRPAmount increment
XRPAmount base
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
Application & app
Definition Transactor.h:63
beast::Journal const j
Definition Transactor.h:69
std::optional< uint256 const > const parentBatchId
Definition Transactor.h:68
State information when preflighting a tx.
Definition Transactor.h:16
beast::Journal const j
Definition Transactor.h:23
Application & app
Definition Transactor.h:18
std::optional< uint256 const > parentBatchId
Definition Transactor.h:22