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