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