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/RippleLedgerHash.h>
27 #include <ripple/protocol/STTx.h>
28 #include <ripple/protocol/SeqProxy.h>
29 #include <ripple/protocol/TER.h>
30 #include <boost/circular_buffer.hpp>
31 #include <boost/intrusive/set.hpp>
69 explicit Setup() =
default;
201 int retriesRemaining_,
202 TER preflightResult_,
401 setup.standAlone ? setup.minimumTxnInLedgerSA
402 : setup.minimumTxnInLedger)
406 : setup.targetTxnInLedger)
408 setup.maximumTxnInLedger
411 : *setup.maximumTxnInLedger
412 :
std::optional<
std::size_t>(
std::nullopt))
500 Snapshot
const& snapshot,
707 TxMap::const_iterator
728 FeeMetrics::Snapshot
const& metricsSnapshot,
747 using FeeHook = boost::intrusive::member_hook<
749 boost::intrusive::set_member_hook<>,
753 multiset<MaybeTx, FeeHook, boost::intrusive::compare<OrderCandidates>>;
803 template <
size_t fillPercentage = 100>
816 AccountMap::iterator
const&,
821 FeeMultiSet::iterator_type
erase(FeeMultiSet::const_iterator_type);
827 FeeMultiSet::const_iterator_type);
829 TxQAccount::TxMap::iterator
832 TxQAccount::TxMap::const_iterator begin,
833 TxQAccount::TxMap::const_iterator end);
845 AccountMap::iterator
const& accountIter,
846 TxQAccount::TxMap::iterator,
876 return feeLevel.second;
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.
LedgerHash parentHash_
parentHash_ checks that no unexpected ledger transitions happen, and is only checked via debug assert...
std::optional< LedgerIndex > lastValid
LastValidLedger field of the queued transaction, if any.
FeeLevel64 minProcessingFeeLevel
Minimum fee level for a transaction to be considered for the open ledger or the queue.
std::shared_ptr< STTx const > txn
The complete transaction.
const beast::Journal j_
Journal.
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.
std::optional< TxQAccount::TxMap::iterator > removeFromByFee(std::optional< TxQAccount::TxMap::iterator > const &replacedTxIter, std::shared_ptr< STTx const > const &tx)
FeeMetrics(Setup const &setup, beast::Journal j)
Constructor.
OrderCandidates()=default
Default constructor.
Writable ledger view that accumulates state and tx changes.
std::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
Used to represent an account to the queue, and stores the transactions queued for that account by Seq...
std::vector< TxDetails > getTxs() const
Returns information about all transactions currently in the queue.
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.
FeeLevel< std::uint64_t > FeeLevel64
Snapshot getSnapshot() const
Get the current Snapshot.
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?
TER canBeHeld(STTx const &, ApplyFlags const, OpenView const &, std::shared_ptr< SLE const > const &sleAccount, AccountMap::iterator const &, std::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.
FeeLevel64 toFeeLevel(XRPAmount const &drops, XRPAmount const &baseFee)
const std::optional< std::size_t > maximumTxnCount_
Maximum value of txnsExpected.
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.
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...
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".
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.
std::vector< TxDetails > getAccountTxs(AccountID const &account) const
Returns information about the transactions currently in the queue for the account.
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::intrusive::multiset< MaybeTx, FeeHook, boost::intrusive::compare< OrderCandidates > > FeeMultiSet
MaybeTx & add(MaybeTx &&)
Add a transaction candidate to this account for queuing.
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...
std::optional< PreflightResult const > pfresult
Cached result of the preflight operation.
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".
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.
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.
std::mutex mutex_
Most queue operations are done under the master lock, but use this mutex for the RPC "fee" command,...
std::optional< size_t > maxSize_
Maximum number of transactions allowed in the queue based on the current metrics.
A type that represents either a sequence value or a ticket value.
static LedgerHash parentHashComp
The hash of the parent ledger.
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.
TxDetails(FeeLevel64 feeLevel_, std::optional< LedgerIndex > const &lastValid_, TxConsequences const &consequences_, AccountID const &account_, SeqProxy seqProxy_, std::shared_ptr< STTx const > const &txn_, int retriesRemaining_, TER preflightResult_, std::optional< TER > lastResult_)
Full initialization.
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...
Used for sorting MaybeTx.
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
std::optional< std::uint32_t > maximumTxnInLedger
Optional maximum allowed value of transactions per ledger before fee escalation kicks in.
FeeLevel64 openLedgerFeeLevel
Minimum fee level to get into the current open ledger, bypassing the queue.
std::optional< std::size_t > txQMaxSize
Max transactions currently allowed in queue.
std::size_t queueSizeMin
The smallest limit the queue is allowed.
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...
bool operator()(const MaybeTx &lhs, const MaybeTx &rhs) const
Sort MaybeTx by feeLevel descending, then by pseudo-randomized transaction ID ascending.
std::uint32_t minimumLastLedgerBuffer
Minimum difference between the current ledger sequence and a transaction's LastLedgerSequence for the...
const TxID txID
Transaction ID.
std::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
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.
const std::optional< LedgerIndex > lastValid
Expiration ledger for the transaction (sfLastLedgerSequence field).
std::uint32_t availableSeq
Class describing the consequences to the account of applying a transaction if the transaction consume...
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
const std::size_t txnsExpected
std::shared_ptr< STTx const > txn
The full transaction.
std::size_t txPerLedger
Number of transactions expected per ledger.