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/TER.h>
28 #include <boost/circular_buffer.hpp>
29 #include <boost/intrusive/set.hpp>
66 explicit Setup() =
default;
402 setup.standAlone ? setup.minimumTxnInLedgerSA
403 : setup.minimumTxnInLedger)
407 : setup.targetTxnInLedger)
409 setup.maximumTxnInLedger
412 : *setup.maximumTxnInLedger
501 Snapshot
const& snapshot,
674 using FeeHook = boost::intrusive::member_hook<
676 boost::intrusive::set_member_hook<>,
680 multiset<MaybeTx, FeeHook, boost::intrusive::compare<GreaterFee>>;
722 template <
size_t fillPercentage = 100>
734 AccountMap::iterator,
735 boost::optional<FeeMultiSet::iterator>);
738 FeeMultiSet::iterator_type
erase(FeeMultiSet::const_iterator_type);
744 FeeMultiSet::const_iterator_type);
746 TxQAccount::TxMap::iterator
749 TxQAccount::TxMap::const_iterator begin,
750 TxQAccount::TxMap::const_iterator end);
761 AccountMap::iterator
const& accountIter,
762 TxQAccount::TxMap::iterator,
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.
const TxSeq sequence
Transaction sequence number (sfSequence field).
const boost::optional< std::size_t > maximumTxnCount_
Maximum value of txnsExpected.
boost::optional< TxConsequences const > consequences
Potential TxConsequences of applying this transaction to the open ledger.
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::shared_ptr< STTx const > txn
The complete transaction.
const beast::Journal j_
Journal.
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.
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.
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.
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::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.
boost::optional< TxID > priorTxID
Prior transaction ID (sfAccountTxnID field).
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.
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".
bool remove(TxSeq const &sequence)
Remove the candidate with given sequence number from this account.
TxDetails()=default
Default constructor.
boost::optional< TxConsequences const > consequences
Potential TxConsequences of applying the queued transaction to the open ledger, if known.
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.
std::vector< TxDetails > getTxs(ReadView const &view) const
Returns information about all transactions currently in the queue.
boost::optional< LedgerIndex const > lastValid
LastValidLedger field of the queued transaction, if any.
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...
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...
std::map< TxSeq, AccountTxDetails const > getAccountTxs(AccountID const &account, ReadView const &view) const
Returns information about the transactions currently in the queue for the account.
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...
MaybeTx & add(MaybeTx &&)
Add a transaction candidate to this account for queuing.
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.
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.
FeeLevel64 zeroBaseFeeTransactionFeeLevel
So we don't deal with "infinite" fee levels, treat any transaction with a 0 base fee (i....
FeeLevel64 referenceFeeLevel
Reference transaction fee level.
Structure returned by TxQ::getAccountTxs to describe transactions in the queue for an account.
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.
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::pair< bool, FeeLevel64 > toFeeLevel(XRPAmount const &drops, XRPAmount const &baseFee)
std::pair< bool, XRPAmount > toDrops(FeeLevel< T > const &level, XRPAmount const &baseFee)
bool canBeHeld(STTx const &, ApplyFlags const, OpenView const &, AccountMap::iterator, boost::optional< FeeMultiSet::iterator >)
Checks if the indicated transaction fits the conditions for being stored in the queue.
std::mutex mutex_
Most queue operations are done under the master lock, but use this mutex for the RPC "fee" command,...
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::pair< TER, bool > tryClearAccountQueue(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 all the queued txs for accountIter up to and including tx.
std::uint32_t retrySequencePercent
Extra percentage required on the fee level of a queued transaction to replace that transaction with a...
boost::optional< LedgerIndex > lastValid
Expiration ledger for the transaction (sfLastLedgerSequence field).
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::int32_t multiTxnPercent
Extra percentage required on the fee level of a queued transaction to queue the transaction with the ...
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.
FeeLevel64 feeLevel
Fee level of the queued transaction.
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
const std::size_t txnsExpected
std::shared_ptr< STTx const > txn
The full transaction.
AccountTxDetails()=default
Default constructor.
std::size_t txPerLedger
Number of transactions expected per ledger.