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/basics/Log.h>
26 #include <ripple/basics/contract.h>
27 #include <ripple/core/Config.h>
28 #include <ripple/json/to_string.h>
29 #include <ripple/ledger/View.h>
30 #include <ripple/protocol/Feature.h>
31 #include <ripple/protocol/Indexes.h>
32 #include <ripple/protocol/Protocol.h>
33 #include <ripple/protocol/STAccount.h>
34 #include <ripple/protocol/UintTypes.h>
44 if (txID == beast::zero)
47 <<
"applyTransaction: transaction id may not be zero";
71 if (
id == beast::zero)
73 JLOG(ctx.
j.
warn()) <<
"preflight1: bad account id";
79 if (!fee.native() || fee.negative() || !
isLegalAmount(fee.xrp()))
81 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid fee";
89 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid signing key";
114 JLOG(ctx.
j.
debug()) <<
"preflight2: bad signature. " << sigValid.second;
128 : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_)
135 : ctx_(ctx), j_(ctx.journal), account_(ctx.tx.getAccountID(
sfAccount))
154 return baseFee + (signerCount * baseFee);
173 auto const feePaid = ctx.
tx[
sfFee].xrp();
183 if (feePaid < feeDue)
186 <<
"Insufficient fee paid: " <<
to_string(feePaid) <<
"/"
192 if (feePaid == beast::zero)
200 auto const balance = (*sle)[
sfBalance].xrp();
202 if (balance < feePaid)
204 JLOG(ctx.
j.
trace()) <<
"Insufficient balance:"
208 if ((balance > beast::zero) && !ctx.
view.
open())
253 <<
"applyTransaction: delay: source account does not exist "
261 if (t_seqProx.
isSeq())
266 JLOG(j.
trace()) <<
"applyTransaction: has both a TicketSequence "
267 "and a non-zero Sequence number";
270 if (t_seqProx != a_seq)
272 if (a_seq < t_seqProx)
275 <<
"applyTransaction: has future sequence number "
276 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
280 JLOG(j.
trace()) <<
"applyTransaction: has past sequence number "
281 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
294 JLOG(j.
trace()) <<
"applyTransaction: has future ticket id "
295 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
303 <<
"applyTransaction: ticket already used or never created "
304 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
322 <<
"applyTransaction: delay: source account does not exist "
372 JLOG(j.
fatal()) <<
"Ticket disappeared from ledger.";
379 JLOG(j.
fatal()) <<
"Unable to delete Ticket from owner.";
388 JLOG(j.
fatal()) <<
"Could not find Ticket owner account root.";
394 if (*ticketCount == 1)
397 ticketCount = *ticketCount - 1;
401 JLOG(j.
fatal()) <<
"TicketCount field missing from account root.";
431 assert(sle !=
nullptr ||
account_ == beast::zero);
473 <<
"checkSingleSign: signing public key type is unknown";
495 if (!isMasterDisabled && idAccount == idSigner)
501 if (isMasterDisabled && idAccount == idSigner)
510 if (idSigner == idAccount)
513 if (isMasterDisabled)
524 <<
"checkSingleSign: Not authorized to use account.";
532 <<
"checkSingleSign: Not authorized to use account.";
547 if (!sleAccountSigners)
550 <<
"applyTransaction: Invalid: Not a multi-signing account.";
559 auto accountSigners =
562 return accountSigners.error();
574 auto iter = accountSigners->begin();
575 for (
auto const& txSigner : txSigners)
580 while (iter->account < txSignerAcctID)
582 if (++iter == accountSigners->end())
585 <<
"applyTransaction: Invalid SigningAccount.Account.";
589 if (iter->account != txSignerAcctID)
593 <<
"applyTransaction: Invalid SigningAccount.Account.";
605 <<
"checkMultiSign: signing public key type is unknown";
609 AccountID const signingAcctIDFromPubKey =
639 if (signingAcctIDFromPubKey == txSignerAcctID)
646 sleTxSignerRoot->getFieldU32(
sfFlags);
651 <<
"applyTransaction: Signer:Account lsfDisableMaster.";
660 if (!sleTxSignerRoot)
662 JLOG(ctx.
j.
trace()) <<
"applyTransaction: Non-phantom signer "
663 "lacks account root.";
670 <<
"applyTransaction: Account lacks RegularKey.";
673 if (signingAcctIDFromPubKey !=
677 <<
"applyTransaction: Account doesn't match RegularKey.";
682 weightSum += iter->weight;
689 <<
"applyTransaction: Signers failed to meet quorum.";
707 for (
auto const& index : offers)
732 auto const balance = txnAcct->getFieldAmount(
sfBalance).xrp();
735 assert(balance != beast::zero && (!
view().
open() || balance >= fee));
748 txnAcct->setFieldAmount(
sfBalance, balance - fee);
775 JLOG(
j_.
fatal()) <<
"Transaction serdes mismatch";
792 stream <<
"preclaim result: " <<
transToken(result);
825 assert(before &&
after);
826 if (before &&
after && (before->getType() ==
ltOFFER) &&
839 auto const resetResult =
reset(fee);
841 result = resetResult.first;
843 fee = resetResult.second;
864 auto const resetResult =
reset(fee);
866 result = resetResult.first;
868 fee = resetResult.second;
890 if (fee < beast::zero)
891 Throw<std::logic_error>(
"fee charged is negative!");
897 if (!
view().
open() && fee != beast::zero)
904 JLOG(
j_.
trace()) << (applied ?
"applied" :
"not applied")
907 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 NotTEC checkMultiSign(PreclaimContext const &ctx)
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.
const SF_VL sfSigningPubKey
const uint256 fixSTAmountCanonicalize
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)
XRPAmount scaleFeeLoad(FeeUnit64 fee, LoadFeeTrack const &feeTrack, Fees const &fees, bool bUnlimited)
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
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.
static XRPAmount minimumFee(Application &app, FeeUnit64 baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
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.
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 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.
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
AccountID calcAccountID(PublicKey const &pk)
const SF_UINT32 sfTicketCount
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
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
State information when applying a tx.
Blob getSigningPubKey() const
A generic endpoint for log messages.
bool enabled(uint256 const &id) const
Returns true if a feature is enabled.
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.
const SF_HASH256 sfAccountTxnID
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 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.
const SF_ACCOUNT sfAccount
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)
static TER checkFee(PreclaimContext const &ctx, FeeUnit64 baseFee)
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
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