20#ifndef RIPPLE_TXQ_H_INCLUDED 
   21#define RIPPLE_TXQ_H_INCLUDED 
   23#include <xrpld/app/tx/applySteps.h> 
   25#include <xrpl/ledger/ApplyView.h> 
   26#include <xrpl/ledger/OpenView.h> 
   27#include <xrpl/protocol/RippleLedgerHash.h> 
   28#include <xrpl/protocol/STTx.h> 
   29#include <xrpl/protocol/SeqProxy.h> 
   30#include <xrpl/protocol/TER.h> 
   32#include <boost/circular_buffer.hpp> 
   33#include <boost/intrusive/set.hpp> 
  204            int retriesRemaining_,
 
  205            TER preflightResult_,
 
 
 
  404                  setup.standAlone ? setup.minimumTxnInLedgerSA
 
  405                                   : setup.minimumTxnInLedger)
 
  409                      : setup.targetTxnInLedger)
 
  411                  setup.maximumTxnInLedger
 
  414                          : *setup.maximumTxnInLedger
 
  415                      : 
std::optional<
std::size_t>(
std::nullopt))
 
 
  503            Snapshot 
const& snapshot,
 
 
  710        TxMap::const_iterator
 
 
  731        FeeMetrics::Snapshot 
const& metricsSnapshot,
 
  750    using FeeHook = boost::intrusive::member_hook<
 
  752        boost::intrusive::set_member_hook<>,
 
  756        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,
 
 
A generic endpoint for log messages.
 
Writable ledger view that accumulates state and tx changes.
 
static std::uint64_t const cMaxNativeN
 
A type that represents either a sequence value or a ticket value.
 
Class describing the consequences to the account of applying a transaction if the transaction consume...
 
Track and use the fee escalation metrics of the current open ledger.
 
std::size_t txnsExpected_
Number of transactions expected per ledger.
 
beast::Journal const j_
Journal.
 
FeeMetrics(Setup const &setup, beast::Journal j)
Constructor.
 
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...
 
std::size_t const minimumTxnCount_
Minimum value of txnsExpected.
 
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.
 
Snapshot getSnapshot() const
Get the current Snapshot.
 
std::optional< std::size_t > const maximumTxnCount_
Maximum value of txnsExpected.
 
std::size_t const targetTxnCount_
Number of transactions per ledger that fee escalation "works towards".
 
boost::circular_buffer< std::size_t > recentTxnCounts_
Recent history of transaction counts that exceed the targetTxnCount_.
 
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.
 
FeeLevel64 escalationMultiplier_
Based on the median fee of the LCL.
 
Represents a transaction in the queue which may be applied later to the open ledger.
 
SeqProxy const seqProxy
Transaction SeqProxy number (sfSequence or sfTicketSequence field).
 
ApplyResult apply(Application &app, OpenView &view, beast::Journal j)
Attempt to apply the queued transaction to the open ledger.
 
ApplyFlags const flags
Flags provided to apply.
 
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...
 
int retriesRemaining
A transaction at the front of the queue will be given several attempts to succeed before being droppe...
 
FeeLevel64 const feeLevel
Computed fee level that the transaction will pay.
 
std::optional< PreflightResult const  > pfresult
Cached result of the preflight operation.
 
static constexpr int retriesAllowed
Starting retry count for newly queued transactions.
 
AccountID const account
Account submitting the transaction.
 
TxDetails getTxDetails() const
Return a TxDetails based on contained information.
 
std::shared_ptr< STTx const  > txn
The complete transaction.
 
std::optional< LedgerIndex > const lastValid
Expiration ledger for the transaction (sfLastLedgerSequence field).
 
TxID const txID
Transaction ID.
 
static LedgerHash parentHashComp
The hash of the parent ledger.
 
std::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
 
TxConsequences const & consequences() const
Potential TxConsequences of applying this transaction to the open ledger.
 
Used for sorting MaybeTx.
 
OrderCandidates()=default
Default constructor.
 
bool operator()(MaybeTx const &lhs, MaybeTx const &rhs) const
Sort MaybeTx by feeLevel descending, then by pseudo-randomized transaction ID ascending.
 
Used to represent an account to the queue, and stores the transactions queued for that account by Seq...
 
TxMap transactions
Sequence number will be used as the key.
 
std::size_t getTxnCount() const
Return the number of transactions currently queued for this account.
 
AccountID const account
The account.
 
TxMap::const_iterator getPrevTx(SeqProxy seqProx) const
Find the entry in transactions that precedes seqProx, if one does.
 
bool remove(SeqProxy seqProx)
Remove the candidate with given SeqProxy value from this account.
 
MaybeTx & add(MaybeTx &&)
Add a transaction candidate to this account for queuing.
 
bool empty() const
Checks if this account has no transactions queued.
 
boost::intrusive::multiset< MaybeTx, FeeHook, boost::intrusive::compare< OrderCandidates > > FeeMultiSet
 
std::vector< TxDetails > getTxs() const
Returns information about all transactions currently in the queue.
 
std::optional< TxQAccount::TxMap::iterator > removeFromByFee(std::optional< TxQAccount::TxMap::iterator > const &replacedTxIter, std::shared_ptr< STTx const > const &tx)
 
std::optional< size_t > maxSize_
Maximum number of transactions allowed in the queue based on the current metrics.
 
FeeMultiSet::iterator_type erase(FeeMultiSet::const_iterator_type)
Erase and return the next entry in byFee_ (lower fee level)
 
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
 
Json::Value doRPC(Application &app) const
Summarize current fee metrics for the fee RPC command.
 
FeeMultiSet byFee_
The queue itself: the collection of transactions ordered by fee level.
 
std::vector< TxDetails > getAccountTxs(AccountID const &account) const
Returns information about the transactions currently in the queue for the account.
 
beast::Journal const j_
Journal.
 
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.
 
SeqProxy nextQueuableSeq(std::shared_ptr< SLE const > const &sleAccount) const
Return the next sequence that would go in the TxQ for an account.
 
std::mutex mutex_
Most queue operations are done under the master lock, but use this mutex for the RPC "fee" command,...
 
AccountMap byAccount_
All of the accounts which currently have any transactions in the queue.
 
boost::intrusive::member_hook< MaybeTx, boost::intrusive::set_member_hook<>, &MaybeTx::byFeeListHook > FeeHook
 
LedgerHash parentHash_
parentHash_ used for logging only
 
SeqProxy nextQueuableSeqImpl(std::shared_ptr< SLE const > const &sleAccount, std::lock_guard< std::mutex > const &) const
 
ApplyResult 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.
 
bool isFull() const
Is the queue at least fillPercentage full?
 
FeeAndSeq getTxRequiredFeeAndSeq(OpenView const &view, std::shared_ptr< STTx const > const &tx) const
Returns minimum required fee for tx and two sequences: first valid sequence for this account in curre...
 
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...
 
FeeMetrics feeMetrics_
Tracks the current state of the queue.
 
virtual ~TxQ()
Destructor.
 
FeeLevel64 getRequiredFeeLevel(OpenView &view, ApplyFlags flags, FeeMetrics::Snapshot const &metricsSnapshot, std::lock_guard< std::mutex > const &lock) const
 
TxQAccount::TxMap::iterator erase(TxQAccount &txQAccount, TxQAccount::TxMap::const_iterator begin, TxQAccount::TxMap::const_iterator end)
Erase a range of items, based on TxQAccount::TxMap iterators.
 
bool accept(Application &app, OpenView &view)
Fill the new open ledger with transactions from the queue.
 
static constexpr FeeLevel64 baseLevel
Fee level for single-signed reference transaction.
 
Setup const setup_
Setup parameters used to control the behavior of the queue.
 
void processClosedLedger(Application &app, ReadView const &view, bool timeLeap)
Update fee metrics and clean up the queue in preparation for the next ledger.
 
std::optional< ApplyResult > tryDirectApply(Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, ApplyFlags flags, beast::Journal j)
 
ApplyResult 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.
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
TxQ::Setup setup_TxQ(Config const &config)
Build a TxQ::Setup object from application configuration.
 
FeeLevel64 toFeeLevel(XRPAmount const &drops, XRPAmount const &baseFee)
 
FeeLevel< std::uint64_t > FeeLevel64
 
XRPAmount toDrops(FeeLevel< T > const &level, XRPAmount baseFee)
 
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
 
Describes the results of the preflight check.
 
std::uint32_t availableSeq
 
Snapshot of the externally relevant FeeMetrics fields at any given time.
 
std::size_t const txnsExpected
 
FeeLevel64 const escalationMultiplier
 
Structure returned by TxQ::getMetrics, expressed in reference fee level units.
 
FeeLevel64 minProcessingFeeLevel
Minimum fee level for a transaction to be considered for the open ledger or the queue.
 
FeeLevel64 openLedgerFeeLevel
Minimum fee level to get into the current open ledger, bypassing the queue.
 
std::size_t txPerLedger
Number of transactions expected per ledger.
 
Metrics()=default
Default constructor.
 
std::optional< std::size_t > txQMaxSize
Max transactions currently allowed in queue.
 
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
 
std::size_t txInLedger
Number of transactions currently in the open ledger.
 
std::size_t txCount
Number of transactions in the queue.
 
FeeLevel64 medFeeLevel
Median fee level of the last ledger.
 
Structure used to customize TxQ behavior.
 
std::uint32_t slowConsensusDecreasePercent
When consensus takes longer than appropriate, the expected ledger size is updated to the lesser of th...
 
Setup()=default
Default constructor.
 
std::uint32_t minimumTxnInLedger
Minimum number of transactions to allow into the ledger before escalation, regardless of the prior le...
 
std::uint32_t maximumTxnPerAccount
Maximum number of transactions that can be queued by one account.
 
FeeLevel64 minimumEscalationMultiplier
Minimum value of the escalation multiplier, regardless of the prior ledger's median fee level.
 
std::size_t queueSizeMin
The smallest limit the queue is allowed.
 
std::optional< std::uint32_t > maximumTxnInLedger
Optional maximum allowed value of transactions per ledger before fee escalation kicks in.
 
std::uint32_t targetTxnInLedger
Number of transactions per ledger that fee escalation "works towards".
 
std::uint32_t retrySequencePercent
Extra percentage required on the fee level of a queued transaction to replace that transaction with a...
 
std::uint32_t minimumLastLedgerBuffer
Minimum difference between the current ledger sequence and a transaction's LastLedgerSequence for the...
 
std::uint32_t minimumTxnInLedgerSA
Like minimumTxnInLedger for standalone mode.
 
std::size_t ledgersInQueue
Number of ledgers' worth of transactions to allow in the queue.
 
bool standAlone
Use standalone mode behavior.
 
std::uint32_t normalConsensusIncreasePercent
When the ledger has more transactions than "expected", and performance is humming along nicely,...
 
Structure that describes a transaction in the queue waiting to be applied to the current open ledger.
 
std::optional< LedgerIndex > lastValid
LastValidLedger field of the queued transaction, if any.
 
SeqProxy seqProxy
SeqProxy of the transaction.
 
TER preflightResult
The intermediate result returned by preflight before this transaction was queued, or after it is queu...
 
TxConsequences consequences
Potential TxConsequences of applying the queued transaction to the open ledger.
 
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.
 
AccountID account
The account the transaction is queued for.
 
FeeLevel64 feeLevel
Fee level of the queued transaction.
 
std::shared_ptr< STTx const  > txn
The full transaction.
 
std::optional< TER > lastResult
If the transactor attempted to apply the transaction to the open ledger from the queue and failed,...
 
int retriesRemaining
Number of times the transactor can return a retry / ter result when attempting to apply this transact...