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";
63 if (
id == beast::zero)
65 JLOG(ctx.
j.
warn()) <<
"preflight1: bad account id";
71 if (!fee.native() || fee.negative() || !
isLegalAmount(fee.xrp()))
73 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid fee";
81 JLOG(ctx.
j.
debug()) <<
"preflight1: invalid signing key";
96 JLOG(ctx.
j.
debug()) <<
"preflight2: bad signature. " << sigValid.second;
110 : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_)
135 return baseFee + (signerCount * baseFee);
141 return tx[
sfFee].xrp();
171 if (ctx.
view.
open() && feePaid < feeDue)
178 if (feePaid == beast::zero)
186 auto const balance = (*sle)[
sfBalance].xrp();
188 if (balance < feePaid)
190 JLOG(ctx.
j.
trace()) <<
"Insufficient balance:"
194 if ((balance > beast::zero) && !ctx.
view.
open())
236 <<
"applyTransaction: delay: source account does not exist "
249 <<
"applyTransaction: has future sequence number "
250 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seq;
257 JLOG(ctx.
j.
trace()) <<
"applyTransaction: has past sequence number "
258 <<
"a_seq=" << a_seq <<
" t_seq=" << t_seq;
308 assert(sle !=
nullptr ||
account_ == beast::zero);
346 <<
"checkSingleSign: signing public key type is unknown";
368 if (!isMasterDisabled && idAccount == idSigner)
374 if (isMasterDisabled && idAccount == idSigner)
383 if (idSigner == idAccount)
386 if (isMasterDisabled)
397 <<
"checkSingleSign: Not authorized to use account.";
405 <<
"checkSingleSign: Not authorized to use account.";
420 if (!sleAccountSigners)
423 <<
"applyTransaction: Invalid: Not a multi-signing account.";
432 auto accountSigners =
435 return accountSigners.second;
447 auto iter = accountSigners.first.begin();
448 for (
auto const& txSigner : txSigners)
453 while (iter->account < txSignerAcctID)
455 if (++iter == accountSigners.first.end())
458 <<
"applyTransaction: Invalid SigningAccount.Account.";
462 if (iter->account != txSignerAcctID)
466 <<
"applyTransaction: Invalid SigningAccount.Account.";
478 <<
"checkMultiSign: signing public key type is unknown";
482 AccountID const signingAcctIDFromPubKey =
512 if (signingAcctIDFromPubKey == txSignerAcctID)
519 sleTxSignerRoot->getFieldU32(
sfFlags);
524 <<
"applyTransaction: Signer:Account lsfDisableMaster.";
533 if (!sleTxSignerRoot)
535 JLOG(ctx.
j.
trace()) <<
"applyTransaction: Non-phantom signer "
536 "lacks account root.";
543 <<
"applyTransaction: Account lacks RegularKey.";
546 if (signingAcctIDFromPubKey !=
550 <<
"applyTransaction: Account doesn't match RegularKey.";
555 weightSum += iter->weight;
562 <<
"applyTransaction: Signers failed to meet quorum.";
580 for (
auto const& index : offers)
605 auto const balance = txnAcct->getFieldAmount(
sfBalance).xrp();
608 assert(balance != beast::zero && (!
view().
open() || balance >= fee));
617 txnAcct->setFieldAmount(
sfBalance, balance - fee);
640 JLOG(
j_.
fatal()) <<
"Transaction serdes mismatch";
657 stream <<
"preclaim result: " <<
transToken(result);
690 assert(before &&
after);
691 if (before &&
after && (before->getType() ==
ltOFFER) &&
744 if (fee < beast::zero)
745 Throw<std::logic_error>(
"fee charged is negative!");
751 if (!
view().
open() && fee != beast::zero)
758 JLOG(
j_.
trace()) << (applied ?
"applied" :
"not applied")
761 return {result, applied};
static XRPAmount calculateMaxSpend(STTx const &tx)
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.
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")
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.
XRPAmount reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
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.
const SF_Amount sfTakerPays(access, STI_AMOUNT, 4, "TakerPays")
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.
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)
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.
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
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
virtual bool isEquivalent(const STBase &t) const override
const SF_U32 sfLastLedgerSequence(access, STI_UINT32, 27, "LastLedgerSequence")
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
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
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.
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.
std::uint32_t getSequence() const
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.
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
Rules controlling protocol behavior.
static NotTEC checkSeq(PreclaimContext const &ctx)
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 XRPAmount calculateFeePaid(STTx const &tx)
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