20 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/LoadFeeTrack.h>
22 #include <ripple/app/tx/apply.h>
23 #include <ripple/app/tx/impl/SignerEntries.h>
24 #include <ripple/app/tx/impl/Transactor.h>
25 #include <ripple/app/tx/impl/details/NFTokenUtils.h>
26 #include <ripple/basics/Log.h>
27 #include <ripple/basics/contract.h>
28 #include <ripple/core/Config.h>
29 #include <ripple/json/to_string.h>
30 #include <ripple/ledger/View.h>
31 #include <ripple/protocol/Feature.h>
32 #include <ripple/protocol/Indexes.h>
33 #include <ripple/protocol/Protocol.h>
34 #include <ripple/protocol/STAccount.h>
35 #include <ripple/protocol/UintTypes.h>
62 if (*txNID != nodeNID)
69 if (txID == beast::zero)
72 <<
"applyTransaction: transaction id may not be zero";
96 if (
id == beast::zero)
98 JLOG(ctx.
j.
warn()) <<
"preflight1: bad account id";
104 if (!fee.native() || fee.negative() || !
isLegalAmount(fee.xrp()))
106 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid fee";
114 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid signing key";
139 JLOG(ctx.
j.
debug()) <<
"preflight2: bad signature. " << sigValid.second;
153 : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_)
160 : ctx_(ctx), j_(ctx.journal), account_(ctx.tx.getAccountID(
sfAccount))
179 return baseFee + (signerCount * baseFee);
198 auto const feePaid = ctx.
tx[
sfFee].xrp();
208 if (feePaid < feeDue)
211 <<
"Insufficient fee paid: " <<
to_string(feePaid) <<
"/"
217 if (feePaid == beast::zero)
225 auto const balance = (*sle)[
sfBalance].xrp();
227 if (balance < feePaid)
229 JLOG(ctx.
j.
trace()) <<
"Insufficient balance:"
233 if ((balance > beast::zero) && !ctx.
view.
open())
278 <<
"applyTransaction: delay: source account does not exist "
286 if (t_seqProx.
isSeq())
291 JLOG(j.
trace()) <<
"applyTransaction: has both a TicketSequence "
292 "and a non-zero Sequence number";
295 if (t_seqProx != a_seq)
297 if (a_seq < t_seqProx)
300 <<
"applyTransaction: has future sequence number "
301 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
305 JLOG(j.
trace()) <<
"applyTransaction: has past sequence number "
306 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
319 JLOG(j.
trace()) <<
"applyTransaction: has future ticket id "
320 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
328 <<
"applyTransaction: ticket already used or never created "
329 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
347 <<
"applyTransaction: delay: source account does not exist "
397 JLOG(j.
fatal()) <<
"Ticket disappeared from ledger.";
404 JLOG(j.
fatal()) <<
"Unable to delete Ticket from owner.";
413 JLOG(j.
fatal()) <<
"Could not find Ticket owner account root.";
419 if (*ticketCount == 1)
422 ticketCount = *ticketCount - 1;
426 JLOG(j.
fatal()) <<
"TicketCount field missing from account root.";
456 assert(sle !=
nullptr ||
account_ == beast::zero);
498 <<
"checkSingleSign: signing public key type is unknown";
520 if (!isMasterDisabled && idAccount == idSigner)
526 if (isMasterDisabled && idAccount == idSigner)
535 if (idSigner == idAccount)
538 if (isMasterDisabled)
549 <<
"checkSingleSign: Not authorized to use account.";
557 <<
"checkSingleSign: Not authorized to use account.";
572 if (!sleAccountSigners)
575 <<
"applyTransaction: Invalid: Not a multi-signing account.";
584 auto accountSigners =
587 return accountSigners.error();
599 auto iter = accountSigners->begin();
600 for (
auto const& txSigner : txSigners)
605 while (iter->account < txSignerAcctID)
607 if (++iter == accountSigners->end())
610 <<
"applyTransaction: Invalid SigningAccount.Account.";
614 if (iter->account != txSignerAcctID)
618 <<
"applyTransaction: Invalid SigningAccount.Account.";
630 <<
"checkMultiSign: signing public key type is unknown";
634 AccountID const signingAcctIDFromPubKey =
664 if (signingAcctIDFromPubKey == txSignerAcctID)
671 sleTxSignerRoot->getFieldU32(
sfFlags);
676 <<
"applyTransaction: Signer:Account lsfDisableMaster.";
685 if (!sleTxSignerRoot)
687 JLOG(ctx.
j.
trace()) <<
"applyTransaction: Non-phantom signer "
688 "lacks account root.";
695 <<
"applyTransaction: Account lacks RegularKey.";
698 if (signingAcctIDFromPubKey !=
702 <<
"applyTransaction: Account doesn't match RegularKey.";
707 weightSum += iter->weight;
714 <<
"applyTransaction: Signers failed to meet quorum.";
732 for (
auto const& index : offers)
752 for (
auto const& index : offers)
772 <<
"removeDeletedTrustLines: deleted trustlines exceed max "
773 << trustLines.
size();
777 for (
auto const& index : trustLines)
779 if (
auto const sleState = view.
peek({ltRIPPLE_STATE, index});
784 <<
"removeDeletedTrustLines: failed to delete AMM trustline";
802 auto const balance = txnAcct->getFieldAmount(
sfBalance).xrp();
805 assert(balance != beast::zero && (!
view().
open() || balance >= fee));
818 txnAcct->setFieldAmount(
sfBalance, balance - fee);
846 JLOG(
j_.
fatal()) <<
"Transaction serdes mismatch";
863 stream <<
"preclaim result: " <<
transToken(result);
894 bool const doOffers =
897 bool const doNFTokenOffers = (result ==
tecEXPIRED);
898 if (doOffers || doLines || doNFTokenOffers)
905 &expiredNFTokenOffers](
912 assert(before &&
after);
913 if (doOffers && before &&
after &&
914 (before->getType() ==
ltOFFER) &&
922 if (doLines && before &&
after &&
929 if (doNFTokenOffers && before &&
after &&
938 auto const resetResult =
reset(fee);
940 result = resetResult.first;
942 fee = resetResult.second;
971 auto const resetResult =
reset(fee);
973 result = resetResult.first;
975 fee = resetResult.second;
997 if (fee < beast::zero)
998 Throw<std::logic_error>(
"fee charged is negative!");
1004 if (!
view().
open() && fee != beast::zero)
1011 JLOG(
j_.
trace()) << (applied ?
"applied" :
"not applied")
1014 return {result, applied};
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
const SF_UINT32 sfSignerListID
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
const STArray & getFieldArray(SField const &field) const
RAII class to set and restore the STAmount canonicalize switchover.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
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)
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 checkMultiSign(PreclaimContext const &ctx)
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
bool isLegalAmount(XRPAmount const &amount)
Returns true if the amount does not exceed the initial XRP in existence.
const SF_UINT64 sfOwnerNode
Stream trace() const
Severity stream access functions.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string const &annotation)
static NotTEC checkSingleSign(PreclaimContext const &ctx)
const SF_UINT32 sfSequence
const SF_ACCOUNT sfRegularKey
std::pair< TER, bool > operator()()
Process the transaction.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
RAII class to set and restore the Number switchover.
const SF_VL sfSigningPubKey
const uint256 fixSTAmountCanonicalize
constexpr std::size_t expiredOfferRemoveLimit
The maximum number of expired offers to delete at once.
Keylet nftoffer(AccountID const &owner, std::uint32_t seq)
An offer from an account to buy or sell an NFT.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
static constexpr SeqProxy sequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
std::string transToken(TER code)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
constexpr std::uint16_t maxDeletableAMMTrustLines
The maximum number of trustlines to delete as part of AMM account deletion cleanup.
@ telNETWORK_ID_MAKES_TX_NON_CANONICAL
TER deleteAMMTrustLine(ApplyView &view, std::shared_ptr< SLE > sleState, std::optional< AccountID > const &ammAccountID, beast::Journal j)
Delete trustline to AMM.
SeqProxy getSeqProxy() const
const SF_UINT32 sfTicketSequence
static const ticket_t ticket
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
constexpr std::size_t unfundedOfferRemoveLimit
The maximum number of unfunded offers to delete at once.
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
uint256 getTicketIndex(AccountID const &account, std::uint32_t ticketSeq)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Writeable view to a ledger, for applying a transaction.
virtual LoadFeeTrack & getFeeTrack()=0
constexpr bool isTicket() const
const SF_UINT32 sfSignerQuorum
bool isEquivalent(const STBase &t) const override
constexpr bool isSeq() const
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
const SF_AMOUNT sfTakerPays
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
@ ltOFFER
A ledger object which describes an offer on the DEX.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
static NotTEC checkSign(PreclaimContext const &ctx)
Reflects the fee settings for a particular ledger.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
Keylet account(AccountID const &id) noexcept
AccountID root.
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.
AccountID getAccountID(SField const &field) const
void destroyXRP(XRPAmount const &fee)
virtual Config & config()=0
@ ltNFTOKEN_OFFER
A ledger object which identifies an offer to buy or sell an NFT.
AccountID calcAccountID(PublicKey const &pk)
const SF_UINT32 sfTicketCount
const SF_UINT256 sfAccountTxnID
void discard()
Discard changes and start fresh.
Slice slice() const noexcept
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
const uint256 fixMasterKeyAsRegularKey
State information when applying a tx.
Blob getSigningPubKey() const
A generic endpoint for log messages.
TER consumeSeqProxy(SLE::pointer const &sleAccount)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Json::Value getJson(JsonOptions options) const override
Transactor(Transactor const &)=delete
void apply(TER)
Apply the transaction result to the base.
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.
uint256 getTransactionID() const
PreflightContext(Application &app_, STTx const &tx_, Rules const &rules_, ApplyFlags flags_, beast::Journal j_)
State information when determining if a tx is likely to claim a fee.
void add(Serializer &s) const override
constexpr std::uint32_t value() const
std::pair< TER, XRPAmount > reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual beast::Journal journal(std::string const &name)=0
constexpr std::size_t oversizeMetaDataCap
The maximum number of metadata entries allowed in one transaction.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool isFieldPresent(SField const &field) const
const uint256 fixUniversalNumber
const SF_AMOUNT sfBalance
A type that represents either a sequence value or a ticket value.
Rules controlling protocol behavior.
const uint256 featureTicketBatch
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
XRPAmount scaleFeeLoad(XRPAmount fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
const SF_ACCOUNT sfAccount
@ ltRIPPLE_STATE
A ledger object which describes a bidirectional trust line.
static void removeExpiredNFTokenOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
const SF_UINT32 sfNetworkID
std::uint32_t getFieldU32(SField const &field) const
State information when preflighting a tx.
@ SigBad
Signature is bad. Didn't do local checks.
const SF_UINT32 sfLastLedgerSequence
static Keylet signers(AccountID const &account, std::uint32_t page) noexcept
std::size_t size()
Get the number of unapplied changes.
static void removeUnfundedOffers(ApplyView &view, std::vector< uint256 > const &offers, beast::Journal viewJ)
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual HashRouter & getHashRouter()=0
virtual void preCompute()
STAmount const & getFieldAmount(SField const &field) const
bool deleteTokenOffer(ApplyView &view, std::shared_ptr< SLE > const &offer)
Deletes the given token offer.
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
TERSubset< CanCvtToNotTEC > NotTEC
uint256 getFieldH256(SField const &field) const