20 #ifndef RIPPLE_TXQ_H_INCLUDED
21 #define RIPPLE_TXQ_H_INCLUDED
23 #include <ripple/app/tx/applySteps.h>
24 #include <ripple/ledger/ApplyView.h>
25 #include <ripple/ledger/OpenView.h>
26 #include <ripple/protocol/STTx.h>
27 #include <ripple/protocol/SeqProxy.h>
28 #include <ripple/protocol/TER.h>
29 #include <boost/circular_buffer.hpp>
30 #include <boost/intrusive/set.hpp>
67 explicit Setup() =
default;
194 boost::optional<LedgerIndex>
const& lastValid_,
199 int retriesRemaining_,
200 TER preflightResult_,
201 boost::optional<TER> lastResult_)
399 setup.standAlone ? setup.minimumTxnInLedgerSA
400 : setup.minimumTxnInLedger)
404 : setup.targetTxnInLedger)
406 setup.maximumTxnInLedger
409 : *setup.maximumTxnInLedger
498 Snapshot
const& snapshot,
678 TxMap::const_iterator
699 FeeMetrics::Snapshot
const& metricsSnapshot,
713 boost::optional<TxQAccount::TxMap::iterator>
715 boost::optional<TxQAccount::TxMap::iterator>
const& replacedTxIter,
718 using FeeHook = boost::intrusive::member_hook<
720 boost::intrusive::set_member_hook<>,
724 multiset<MaybeTx, FeeHook, boost::intrusive::compare<GreaterFee>>;
766 template <
size_t fillPercentage = 100>
779 AccountMap::iterator
const&,
780 boost::optional<TxQAccount::TxMap::iterator>
const&,
784 FeeMultiSet::iterator_type
erase(FeeMultiSet::const_iterator_type);
790 FeeMultiSet::const_iterator_type);
792 TxQAccount::TxMap::iterator
795 TxQAccount::TxMap::const_iterator begin,
796 TxQAccount::TxMap::const_iterator end);
808 AccountMap::iterator
const& accountIter,
809 TxQAccount::TxMap::iterator,
839 return feeLevel.second;
boost::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
const Setup setup_
Setup parameters used to control the behavior of the queue.
TxQ::Setup setup_TxQ(Config const &config)
Build a TxQ::Setup object from application configuration.
Metrics()=default
Default constructor.
std::pair< TER, bool > tryClearAccountQueueUpThruTx(Application &app, OpenView &view, STTx const &tx, AccountMap::iterator const &accountIter, TxQAccount::TxMap::iterator, FeeLevel64 feeLevelPaid, PreflightResult const &pfresult, std::size_t const txExtraCount, ApplyFlags flags, FeeMetrics::Snapshot const &metricsSnapshot, beast::Journal j)
All-or-nothing attempt to try to apply the queued txs for accountIter up to and including tx.
const boost::optional< std::size_t > maximumTxnCount_
Maximum value of txnsExpected.
FeeLevel64 minProcessingFeeLevel
Minimum fee level for a transaction to be considered for the open ledger or the queue.
boost::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
std::vector< TxDetails > getTxs(ReadView const &view) const
Returns information about all transactions currently in the queue.
std::shared_ptr< STTx const > txn
The complete transaction.
const beast::Journal j_
Journal.
TER canBeHeld(STTx const &, ApplyFlags const, OpenView const &, std::shared_ptr< SLE const > const &sleAccount, AccountMap::iterator const &, boost::optional< TxQAccount::TxMap::iterator > const &, std::lock_guard< std::mutex > const &lock)
Checks if the indicated transaction fits the conditions for being stored in the queue.
SeqProxy seqProxy
SeqProxy of the transaction.
std::pair< TER, bool > apply(Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, ApplyFlags flags, beast::Journal j)
Add a new transaction to the open ledger, hold it in the queue, or reject it.
FeeMetrics(Setup const &setup, beast::Journal j)
Constructor.
Writable ledger view that accumulates state and tx changes.
const boost::optional< LedgerIndex > lastValid
Expiration ledger for the transaction (sfLastLedgerSequence field).
Used to represent an account to the queue, and stores the transactions queued for that account by Seq...
FeeMultiSet::iterator_type eraseAndAdvance(FeeMultiSet::const_iterator_type)
Erase and return the next entry for the account (if fee level is higher), or next entry in byFee_ (lo...
FeeMultiSet::iterator_type erase(FeeMultiSet::const_iterator_type)
Erase and return the next entry in byFee_ (lower fee level)
Track and use the fee escalation metrics of the current open ledger.
boost::optional< std::size_t > txQMaxSize
Max transactions currently allowed in queue.
FeeLevel< std::uint64_t > FeeLevel64
Snapshot getSnapshot() const
Get the current Snapshot.
boost::intrusive::multiset< MaybeTx, FeeHook, boost::intrusive::compare< GreaterFee > > FeeMultiSet
Structure that describes a transaction in the queue waiting to be applied to the current open ledger.
SeqProxy nextQueuableSeqImpl(std::shared_ptr< SLE const > const &sleAccount, std::lock_guard< std::mutex > const &) const
bool remove(SeqProxy seqProx)
Remove the candidate with given SeqProxy value from this account.
const ApplyFlags flags
Flags provided to apply.
FeeLevel64 escalationMultiplier_
Based on the median fee of the LCL.
bool isFull() const
Is the queue at least fillPercentage full?
boost::optional< LedgerIndex > lastValid
LastValidLedger field of the queued transaction, if any.
FeeLevel64 toFeeLevel(XRPAmount const &drops, XRPAmount const &baseFee)
boost::circular_buffer< std::size_t > recentTxnCounts_
Recent history of transaction counts that exceed the targetTxnCount_.
std::pair< TER, bool > apply(Application &app, OpenView &view, beast::Journal j)
Attempt to apply the queued transaction to the open ledger.
TxMap transactions
Sequence number will be used as the key.
Structure returned by TxQ::getMetrics, expressed in reference fee level units.
bool accept(Application &app, OpenView &view)
Fill the new open ledger with transactions from the queue.
std::uint32_t maximumTxnPerAccount
Maximum number of transactions that can be queued by one account.
TxDetails(FeeLevel64 feeLevel_, boost::optional< LedgerIndex > const &lastValid_, TxConsequences const &consequences_, AccountID const &account_, SeqProxy seqProxy_, std::shared_ptr< STTx const > const &txn_, int retriesRemaining_, TER preflightResult_, boost::optional< TER > lastResult_)
Full initialization.
boost::intrusive::member_hook< MaybeTx, boost::intrusive::set_member_hook<>, &MaybeTx::byFeeListHook > FeeHook
std::size_t update(Application &app, ReadView const &view, bool timeLeap, TxQ::Setup const &setup)
Updates fee metrics based on the transactions in the ReadView for use in fee escalation calculations.
TxDetails getTxDetails() const
Return a TxDetails based on contained information.
std::uint32_t normalConsensusIncreasePercent
When the ledger has more transactions than "expected", and performance is humming along nicely,...
boost::intrusive::set_member_hook byFeeListHook
Used by the TxQ::FeeHook and TxQ::FeeMultiSet below to put each MaybeTx object into more than one set...
boost::optional< std::uint32_t > maximumTxnInLedger
Optional maximum allowed value of transactions per ledger before fee escalation kicks in.
const FeeLevel64 feeLevel
Computed fee level that the transaction will pay.
std::uint32_t targetTxnInLedger
Number of transactions per ledger that fee escalation "works towards".
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount const &baseFee)
MaybeTx(std::shared_ptr< STTx const > const &, TxID const &txID, FeeLevel64 feeLevel, ApplyFlags const flags, PreflightResult const &pfresult)
Constructor.
bool standAlone
Use standalone mode behavior.
FeeMultiSet byFee_
The queue itself: the collection of transactions ordered by fee level.
Describes the results of the preflight check.
Used for sorting MaybeTx by feeLevel
AccountID account
The account the transaction is queued for.
FeeMetrics feeMetrics_
Tracks the current state of the queue.
std::uint32_t minimumTxnInLedger
Minimum number of transactions to allow into the ledger before escalation, regardless of the prior le...
Structure used to customize TxQ behavior.
const AccountID account
The account.
TxMap::const_iterator getPrevTx(SeqProxy seqProx) const
Find the entry in transactions that precedes seqProx, if one does.
boost::optional< TxQAccount::TxMap::iterator > removeFromByFee(boost::optional< TxQAccount::TxMap::iterator > const &replacedTxIter, std::shared_ptr< STTx const > const &tx)
MaybeTx & add(MaybeTx &&)
Add a transaction candidate to this account for queuing.
bool operator()(const MaybeTx &lhs, const MaybeTx &rhs) const
Is the fee level of lhs greater than the fee level of rhs?
FeeAndSeq getTxRequiredFeeAndSeq(OpenView const &view, std::shared_ptr< STTx const > const &tx) const
Returns minimum required fee for tx and two sequences: first vaild sequence for this account in curre...
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
Represents a transaction in the queue which may be applied later to the open ledger.
int retriesRemaining
Number of times the transactor can return a retry / ter result when attempting to apply this transact...
std::uint32_t slowConsensusDecreasePercent
When consensus takes longer than appropriate, the expected ledger size is updated to the lesser of th...
A generic endpoint for log messages.
static constexpr FeeLevel64 baseLevel
Fee level for single-signed reference transaction.
static FeeLevel64 scaleFeeLevel(Snapshot const &snapshot, OpenView const &view)
Use the number of transactions in the current open ledger to compute the fee level a transaction must...
const std::size_t minimumTxnCount_
Minimum value of txnsExpected.
void processClosedLedger(Application &app, ReadView const &view, bool timeLeap)
Update fee metrics and clean up the queue in preparation for the next ledger.
const SeqProxy seqProxy
Transaction SeqProxy number (sfSequence or sfTicketSequence field).
Json::Value doRPC(Application &app) const
Summarize current fee metrics for the fee RPC command.
const std::size_t targetTxnCount_
Number of transactions per ledger that fee escalation "works towards".
boost::optional< PreflightResult const > pfresult
Cached result of the preflight operation.
TxConsequences const & consequences() const
Potential TxConsequences of applying this transaction to the open ledger.
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
TxConsequences consequences
Potential TxConsequences of applying the queued transaction to the open ledger.
virtual ~TxQ()
Destructor.
bool empty() const
Checks if this account has no transactions queued.
FeeLevel64 medFeeLevel
Median fee level of the last ledger.
Snapshot of the externally relevant FeeMetrics fields at any given time.
const FeeLevel64 escalationMultiplier
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TxQ(Setup const &setup, beast::Journal j)
Constructor.
std::size_t getTxnCount() const
Return the number of transactions currently queued for this account.
boost::optional< size_t > maxSize_
Maximum number of transactions allowed in the queue based on the current metrics.
FeeLevel64 getRequiredFeeLevel(OpenView &view, ApplyFlags flags, FeeMetrics::Snapshot const &metricsSnapshot, std::lock_guard< std::mutex > const &lock) const
const AccountID account
Account submitting the transaction.
Setup()=default
Default constructor.
std::size_t txInLedger
Number of transactions currently in the open ledger.
GreaterFee()=default
Default constructor.
std::mutex mutex_
Most queue operations are done under the master lock, but use this mutex for the RPC "fee" command,...
A type that represents either a sequence value or a ticket value.
static constexpr int retriesAllowed
Starting retry count for newly queued transactions.
const beast::Journal j_
Journal.
std::size_t txCount
Number of transactions in the queue.
std::uint32_t retrySequencePercent
Extra percentage required on the fee level of a queued transaction to replace that transaction with a...
std::uint32_t minimumTxnInLedgerSA
Like minimumTxnInLedger for standalone mode.
TER preflightResult
The intermediate result returned by preflight before this transaction was queued, or after it is queu...
TxQAccount(std::shared_ptr< STTx const > const &txn)
Construct from a transaction.
std::pair< bool, Dest > mulDiv(Source1 value, Dest mul, Source2 div)
std::optional< std::pair< TER, bool > > tryDirectApply(Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, ApplyFlags flags, beast::Journal j)
FeeLevel64 feeLevel
Fee level of the queued transaction.
static const std::uint64_t cMaxNativeN
FeeLevel64 openLedgerFeeLevel
Minimum fee level to get into the current open ledger, bypassing the queue.
std::size_t queueSizeMin
The smallest limit the queue is allowed.
std::vector< TxDetails > getAccountTxs(AccountID const &account, ReadView const &view) const
Returns information about the transactions currently in the queue for the account.
AccountMap byAccount_
All of the accounts which currently have any transactions in the queue.
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
std::size_t txnsExpected_
Number of transactions expected per ledger.
FeeLevel64 minimumEscalationMultiplier
Minimum value of the escalation multiplier, regardless of the prior ledger's median fee level.
int retriesRemaining
A transaction at the front of the queue will be given several attempts to succeed before being droppe...
std::uint32_t minimumLastLedgerBuffer
Minimum difference between the current ledger sequence and a transaction's LastLedgerSequence for the...
const TxID txID
Transaction ID.
static std::pair< bool, FeeLevel64 > escalatedSeriesFeeLevel(Snapshot const &snapshot, OpenView const &view, std::size_t extraCount, std::size_t seriesSize)
Computes the total fee level for all transactions in a series.
std::size_t ledgersInQueue
Number of ledgers' worth of transactions to allow in the queue.
std::uint32_t availableSeq
Class describing the consequences to the account of applying a transaction if the transaction consume...
const std::size_t txnsExpected
std::shared_ptr< STTx const > txn
The full transaction.
std::size_t txPerLedger
Number of transactions expected per ledger.