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();
181 if (ctx.
view.
open() && feePaid < feeDue)
188 if (feePaid == beast::zero)
196 auto const balance = (*sle)[
sfBalance].xrp();
198 if (balance < feePaid)
200 JLOG(ctx.
j.
trace()) <<
"Insufficient balance:"
204 if ((balance > beast::zero) && !ctx.
view.
open())
249 <<
"applyTransaction: delay: source account does not exist "
257 if (t_seqProx.
isSeq() && t_seqProx != a_seq)
259 if (a_seq < t_seqProx)
261 JLOG(j.
trace()) <<
"applyTransaction: has future sequence number "
262 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
266 JLOG(j.
trace()) <<
"applyTransaction: has past sequence number "
267 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
279 JLOG(j.
trace()) <<
"applyTransaction: has future ticket id "
280 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
288 <<
"applyTransaction: ticket already used or never created "
289 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seqProx;
307 <<
"applyTransaction: delay: source account does not exist "
357 JLOG(j.
fatal()) <<
"Ticket disappeared from ledger.";
364 JLOG(j.
fatal()) <<
"Unable to delete Ticket from owner.";
373 JLOG(j.
fatal()) <<
"Could not find Ticket owner account root.";
379 if (*ticketCount == 1)
382 ticketCount = *ticketCount - 1;
386 JLOG(j.
fatal()) <<
"TicketCount field missing from account root.";
416 assert(sle !=
nullptr ||
account_ == beast::zero);
458 <<
"checkSingleSign: signing public key type is unknown";
480 if (!isMasterDisabled && idAccount == idSigner)
486 if (isMasterDisabled && idAccount == idSigner)
495 if (idSigner == idAccount)
498 if (isMasterDisabled)
509 <<
"checkSingleSign: Not authorized to use account.";
517 <<
"checkSingleSign: Not authorized to use account.";
532 if (!sleAccountSigners)
535 <<
"applyTransaction: Invalid: Not a multi-signing account.";
544 auto accountSigners =
547 return accountSigners.second;
559 auto iter = accountSigners.first.begin();
560 for (
auto const& txSigner : txSigners)
565 while (iter->account < txSignerAcctID)
567 if (++iter == accountSigners.first.end())
570 <<
"applyTransaction: Invalid SigningAccount.Account.";
574 if (iter->account != txSignerAcctID)
578 <<
"applyTransaction: Invalid SigningAccount.Account.";
590 <<
"checkMultiSign: signing public key type is unknown";
594 AccountID const signingAcctIDFromPubKey =
624 if (signingAcctIDFromPubKey == txSignerAcctID)
631 sleTxSignerRoot->getFieldU32(
sfFlags);
636 <<
"applyTransaction: Signer:Account lsfDisableMaster.";
645 if (!sleTxSignerRoot)
647 JLOG(ctx.
j.
trace()) <<
"applyTransaction: Non-phantom signer "
648 "lacks account root.";
655 <<
"applyTransaction: Account lacks RegularKey.";
658 if (signingAcctIDFromPubKey !=
662 <<
"applyTransaction: Account doesn't match RegularKey.";
667 weightSum += iter->weight;
674 <<
"applyTransaction: Signers failed to meet quorum.";
692 for (
auto const& index : offers)
717 auto const balance = txnAcct->getFieldAmount(
sfBalance).xrp();
720 assert(balance != beast::zero && (!
view().
open() || balance >= fee));
733 txnAcct->setFieldAmount(
sfBalance, balance - fee);
758 JLOG(
j_.
fatal()) <<
"Transaction serdes mismatch";
775 stream <<
"preclaim result: " <<
transToken(result);
808 assert(before &&
after);
809 if (before &&
after && (before->getType() ==
ltOFFER) &&
822 auto const resetResult =
reset(fee);
824 result = resetResult.first;
826 fee = resetResult.second;
847 auto const resetResult =
reset(fee);
849 result = resetResult.first;
851 fee = resetResult.second;
873 if (fee < beast::zero)
874 Throw<std::logic_error>(
"fee charged is negative!");
880 if (!
view().
open() && fee != beast::zero)
887 JLOG(
j_.
trace()) << (applied ?
"applied" :
"not applied")
890 return {result, applied};
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
const STArray & getFieldArray(SField const &field) const
const SF_Account sfRegularKey(access, STI_ACCOUNT, 8, "RegularKey")
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
const SF_U32 sfTicketCount(access, STI_UINT32, 40, "TicketCount")
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.
Stream trace() const
Severity stream access functions.
boost::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
const SField sfSigners(access, STI_ARRAY, 3, "Signers", SField::sMD_Default, SField::notSigning)
static NotTEC checkSingleSign(PreclaimContext const &ctx)
std::pair< TER, bool > operator()()
Process the transaction.
const SF_Blob sfSigningPubKey(access, STI_VL, 3, "SigningPubKey")
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
const SF_U32 sfSignerQuorum(access, STI_UINT32, 35, "SignerQuorum")
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
const SF_U32 sfFlags(access, STI_UINT32, 2, "Flags")
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)
const SF_Amount sfTakerPays(access, STI_AMOUNT, 4, "TakerPays")
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
static const ticket_t ticket
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
std::string to_string(ListDisposition disposition)
const SF_U64 sfOwnerNode(access, STI_UINT64, 4, "OwnerNode")
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.
const SF_U256 sfAccountTxnID(access, STI_HASH256, 9, "AccountTxnID")
Writeable view to a ledger, for applying a transaction.
virtual LoadFeeTrack & getFeeTrack()=0
constexpr bool isTicket() const
virtual 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.
const SF_U32 sfLastLedgerSequence(access, STI_UINT32, 27, "LastLedgerSequence")
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.
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
const SF_U32 sfSignerListID(access, STI_UINT32, 38, "SignerListID")
AccountID calcAccountID(PublicKey const &pk)
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)
const SF_Amount sfFee(access, STI_AMOUNT, 8, "Fee")
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.
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
virtual void add(Serializer &s) const override
const SF_Amount sfBalance(access, STI_AMOUNT, 2, "Balance")
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
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?
static std::pair< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string const &annotation)
std::uint32_t getFieldU32(SField const &field) const
State information when preflighting a tx.
@ SigBad
Signature is bad. Didn't do local checks.
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