Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
dev::eth::TransactionQueue Class Reference

A queue of Transactions, each stored as RLP. More...

#include <TransactionQueue.h>

Collaboration diagram for dev::eth::TransactionQueue:
[legend]

Classes

struct  Limits
 
struct  PriorityCompare
 
struct  Status
 
struct  UnverifiedTransaction
 Transaction pending verification. More...
 
struct  VerifiedTransaction
 Verified and imported transaction. More...
 

Public Member Functions

 TransactionQueue (unsigned _limit=1024, unsigned _futureLimit=1024)
 TransactionQueue. More...
 
 TransactionQueue (Limits const &_l)
 
 ~TransactionQueue ()
 
void enqueue (RLP const &_data, h512 const &_nodeId)
 Add transaction to the queue to be verified and imported. More...
 
ImportResult import (bytes const &_tx, IfDropped _ik=IfDropped::Ignore)
 Verify and add transaction to the queue synchronously. More...
 
ImportResult import (Transaction const &_tx, IfDropped _ik=IfDropped::Ignore)
 Verify and add transaction to the queue synchronously. More...
 
void drop (h256 const &_txHash)
 Remove transaction from the queue. More...
 
unsigned waiting (Address const &_a) const
 Get number of pending transactions for account. More...
 
Transactions topTransactions (unsigned _limit, h256Hash const &_avoid=h256Hash()) const
 Get top transactions from the queue. More...
 
h256Hash knownTransactions () const
 Get a hash set of transactions in the queue. More...
 
u256 maxNonce (Address const &_a) const
 Get max nonce for an account. More...
 
void setFuture (h256 const &_t)
 Mark transaction as future. More...
 
void dropGood (Transaction const &_t)
 Drop a trasnaction from the list if exists and move following future trasnactions to current (if any) More...
 
Status status () const
 
Limits limits () const
 
void clear ()
 Clear the queue. More...
 
template<class T >
Handler onReady (T const &_t)
 Register a handler that will be called once there is a new transaction imported. More...
 
template<class T >
Handler< ImportResult, h256 const &, h512 const & > onImport (T const &_t)
 Register a handler that will be called once asynchronous verification is comeplte an transaction has been imported. More...
 
template<class T >
Handler< h256 const & > onReplaced (T const &_t)
 Register a handler that will be called once asynchronous verification is comeplte an transaction has been imported. More...
 

Private Types

using PriorityQueue = std::multiset< VerifiedTransaction, PriorityCompare >
 

Private Member Functions

ImportResult import (bytesConstRef _tx, IfDropped _ik=IfDropped::Ignore)
 
ImportResult check_WITH_LOCK (h256 const &_h, IfDropped _ik)
 
ImportResult manageImport_WITH_LOCK (h256 const &_h, Transaction const &_transaction)
 
void insertCurrent_WITH_LOCK (std::pair< h256, Transaction > const &_p)
 
void makeCurrent_WITH_LOCK (Transaction const &_t)
 
bool remove_WITH_LOCK (h256 const &_txHash)
 
u256 maxNonce_WITH_LOCK (Address const &_a) const
 
void verifierBody ()
 

Private Attributes

SharedMutex m_lock
 General lock. More...
 
h256Hash m_known
 Headers of transactions in both sets. More...
 
std::unordered_map< h256, std::function< void(ImportResult)> > m_callbacks
 Called once. More...
 
h256Hash m_dropped
 Transactions that have previously been dropped. More...
 
PriorityQueue m_current
 
std::unordered_map< h256, PriorityQueue::iterator > m_currentByHash
 Transaction hash to set ref. More...
 
std::unordered_map< Address, std::map< u256, PriorityQueue::iterator > > m_currentByAddressAndNonce
 Transactions grouped by account and nonce. More...
 
std::unordered_map< Address, std::map< u256, VerifiedTransaction > > m_future
 
Signal m_onReady
 Future transactions. More...
 
Signal< ImportResult, h256 const &, h512 const & > m_onImport
 Called for each import attempt. Arguments are result, transaction id an node id. Be nice and exit fast. More...
 
Signal< h256 const & > m_onReplaced
 Called whan transction is dropped during a call to import() to make room for another transaction. More...
 
unsigned m_limit
 Max number of pending transactions. More...
 
unsigned m_futureLimit
 Max number of future transactions. More...
 
unsigned m_futureSize = 0
 Current number of future transactions. More...
 
std::condition_variable m_queueReady
 Signaled when m_unverified has a new entry. More...
 
std::vector< std::thread > m_verifiers
 
std::deque< UnverifiedTransactionm_unverified
 Pending verification queue. More...
 
Mutex x_queue
 Verification queue mutex. More...
 
std::atomic< bool > m_aborting = {false}
 Exit condition for verifier. More...
 

Detailed Description

A queue of Transactions, each stored as RLP.

Maintains a transaction queue sorted by nonce diff and gas price.

Definition at line 48 of file TransactionQueue.h.

Member Typedef Documentation

Definition at line 180 of file TransactionQueue.h.

Constructor & Destructor Documentation

TransactionQueue::TransactionQueue ( unsigned  _limit = 1024,
unsigned  _futureLimit = 1024 
)

TransactionQueue.

Parameters
_limitMaximum number of pending transactions in the queue.
_futureLimitMaximum number of future nonce transactions.

Definition at line 36 of file TransactionQueue.cpp.

Here is the call graph for this function:

dev::eth::TransactionQueue::TransactionQueue ( Limits const &  _l)
inline

Definition at line 57 of file TransactionQueue.h.

TransactionQueue::~TransactionQueue ( )

Definition at line 49 of file TransactionQueue.cpp.

Member Function Documentation

ImportResult TransactionQueue::check_WITH_LOCK ( h256 const &  _h,
IfDropped  _ik 
)
private

Definition at line 90 of file TransactionQueue.cpp.

Here is the caller graph for this function:

void TransactionQueue::clear ( )

Clear the queue.

Definition at line 363 of file TransactionQueue.cpp.

Here is the caller graph for this function:

void TransactionQueue::drop ( h256 const &  _txHash)

Remove transaction from the queue.

Parameters
_txHashTrasnaction hash

Definition at line 342 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TransactionQueue::dropGood ( Transaction const &  _t)

Drop a trasnaction from the list if exists and move following future trasnactions to current (if any)

Parameters
_tTransaction hash

Definition at line 354 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TransactionQueue::enqueue ( RLP const &  _data,
h512 const &  _nodeId 
)

Add transaction to the queue to be verified and imported.

Parameters
_dataRLP encoded transaction data.
_nodeIdOptional network identified of a node transaction comes from.

Definition at line 374 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

ImportResult dev::eth::TransactionQueue::import ( bytes const &  _tx,
IfDropped  _ik = IfDropped::Ignore 
)
inline

Verify and add transaction to the queue synchronously.

Parameters
_txRLP encoded transaction data.
_ikSet to Retry to force re-addinga transaction that was previously dropped.
Returns
Import result code.

Definition at line 68 of file TransactionQueue.h.

Here is the caller graph for this function:

ImportResult TransactionQueue::import ( Transaction const &  _tx,
IfDropped  _ik = IfDropped::Ignore 
)

Verify and add transaction to the queue synchronously.

Parameters
_txTrasnaction data.
_ikSet to Retry to force re-addinga transaction that was previously dropped.
Returns
Import result code.

Definition at line 101 of file TransactionQueue.cpp.

Here is the call graph for this function:

ImportResult TransactionQueue::import ( bytesConstRef  _tx,
IfDropped  _ik = IfDropped::Ignore 
)
private

Definition at line 58 of file TransactionQueue.cpp.

Here is the call graph for this function:

void TransactionQueue::insertCurrent_WITH_LOCK ( std::pair< h256, Transaction > const &  _p)
private

Definition at line 222 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

h256Hash TransactionQueue::knownTransactions ( ) const

Get a hash set of transactions in the queue.

Returns
A hash set of all transactions in the queue

Definition at line 132 of file TransactionQueue.cpp.

Here is the caller graph for this function:

Limits dev::eth::TransactionQueue::limits ( ) const
inline
Returns
the transacrtion limits on current/future.

Definition at line 117 of file TransactionQueue.h.

void TransactionQueue::makeCurrent_WITH_LOCK ( Transaction const &  _t)
private

Definition at line 299 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

ImportResult TransactionQueue::manageImport_WITH_LOCK ( h256 const &  _h,
Transaction const &  _transaction 
)
private

Definition at line 138 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 TransactionQueue::maxNonce ( Address const &  _a) const

Get max nonce for an account.

Returns
Max transaction nonce for account in the queue

Definition at line 204 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 TransactionQueue::maxNonce_WITH_LOCK ( Address const &  _a) const
private

Definition at line 210 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
Handler<ImportResult, h256 const&, h512 const&> dev::eth::TransactionQueue::onImport ( T const &  _t)
inline

Register a handler that will be called once asynchronous verification is comeplte an transaction has been imported.

Definition at line 126 of file TransactionQueue.h.

Here is the caller graph for this function:

template<class T >
Handler dev::eth::TransactionQueue::onReady ( T const &  _t)
inline

Register a handler that will be called once there is a new transaction imported.

Definition at line 123 of file TransactionQueue.h.

Here is the caller graph for this function:

template<class T >
Handler<h256 const&> dev::eth::TransactionQueue::onReplaced ( T const &  _t)
inline

Register a handler that will be called once asynchronous verification is comeplte an transaction has been imported.

Definition at line 129 of file TransactionQueue.h.

Here is the caller graph for this function:

bool TransactionQueue::remove_WITH_LOCK ( h256 const &  _txHash)
private

Definition at line 242 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TransactionQueue::setFuture ( h256 const &  _t)

Mark transaction as future.

It wont be retured in topTransactions list until a transaction with a preceeding nonce is imported or marked with dropGood

Parameters
_tTransaction hash

Definition at line 273 of file TransactionQueue.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Status dev::eth::TransactionQueue::status ( ) const
inline
Returns
the status of the transaction queue.

Definition at line 114 of file TransactionQueue.h.

Here is the caller graph for this function:

Transactions TransactionQueue::topTransactions ( unsigned  _limit,
h256Hash const &  _avoid = h256Hash() 
) const

Get top transactions from the queue.

Returned transactions are not removed from the queue automatically.

Parameters
_limitMax number of transactions to return.
_avoidTransactions to avoid returning.
Returns
up to _limit transactions ordered by nonce and gas price.

Definition at line 122 of file TransactionQueue.cpp.

Here is the caller graph for this function:

void TransactionQueue::verifierBody ( )
private

Definition at line 395 of file TransactionQueue.cpp.

Here is the call graph for this function:

unsigned TransactionQueue::waiting ( Address const &  _a) const

Get number of pending transactions for account.

Returns
Pending transaction count.

Definition at line 260 of file TransactionQueue.cpp.

Here is the caller graph for this function:

Member Data Documentation

std::atomic<bool> dev::eth::TransactionQueue::m_aborting = {false}
private

Exit condition for verifier.

Definition at line 214 of file TransactionQueue.h.

std::unordered_map<h256, std::function<void(ImportResult)> > dev::eth::TransactionQueue::m_callbacks
private

Called once.

Definition at line 195 of file TransactionQueue.h.

PriorityQueue dev::eth::TransactionQueue::m_current
private

Definition at line 198 of file TransactionQueue.h.

std::unordered_map<Address, std::map<u256, PriorityQueue::iterator> > dev::eth::TransactionQueue::m_currentByAddressAndNonce
private

Transactions grouped by account and nonce.

Definition at line 200 of file TransactionQueue.h.

std::unordered_map<h256, PriorityQueue::iterator> dev::eth::TransactionQueue::m_currentByHash
private

Transaction hash to set ref.

Definition at line 199 of file TransactionQueue.h.

h256Hash dev::eth::TransactionQueue::m_dropped
private

Transactions that have previously been dropped.

Definition at line 196 of file TransactionQueue.h.

std::unordered_map<Address, std::map<u256, VerifiedTransaction> > dev::eth::TransactionQueue::m_future
private

Definition at line 201 of file TransactionQueue.h.

unsigned dev::eth::TransactionQueue::m_futureLimit
private

Max number of future transactions.

Definition at line 207 of file TransactionQueue.h.

unsigned dev::eth::TransactionQueue::m_futureSize = 0
private

Current number of future transactions.

Definition at line 208 of file TransactionQueue.h.

h256Hash dev::eth::TransactionQueue::m_known
private

Headers of transactions in both sets.

Definition at line 193 of file TransactionQueue.h.

unsigned dev::eth::TransactionQueue::m_limit
private

Max number of pending transactions.

Definition at line 206 of file TransactionQueue.h.

SharedMutex dev::eth::TransactionQueue::m_lock
mutableprivate

General lock.

Definition at line 192 of file TransactionQueue.h.

Signal<ImportResult, h256 const&, h512 const&> dev::eth::TransactionQueue::m_onImport
private

Called for each import attempt. Arguments are result, transaction id an node id. Be nice and exit fast.

Definition at line 204 of file TransactionQueue.h.

Signal dev::eth::TransactionQueue::m_onReady
private

Future transactions.

Called when a subsequent call to import transactions will return a non-empty container. Be nice and exit fast.

Definition at line 203 of file TransactionQueue.h.

Signal<h256 const&> dev::eth::TransactionQueue::m_onReplaced
private

Called whan transction is dropped during a call to import() to make room for another transaction.

Definition at line 205 of file TransactionQueue.h.

std::condition_variable dev::eth::TransactionQueue::m_queueReady
private

Signaled when m_unverified has a new entry.

Definition at line 210 of file TransactionQueue.h.

std::deque<UnverifiedTransaction> dev::eth::TransactionQueue::m_unverified
private

Pending verification queue.

Definition at line 212 of file TransactionQueue.h.

std::vector<std::thread> dev::eth::TransactionQueue::m_verifiers
private

Definition at line 211 of file TransactionQueue.h.

Mutex dev::eth::TransactionQueue::x_queue
mutableprivate

Verification queue mutex.

Definition at line 213 of file TransactionQueue.h.


The documentation for this class was generated from the following files: