Kagome
Polkadot Runtime Engine in C++17
kagome::transaction_pool::TransactionPoolImpl Class Reference

#include <transaction_pool_impl.hpp>

Inheritance diagram for kagome::transaction_pool::TransactionPoolImpl:
Collaboration diagram for kagome::transaction_pool::TransactionPoolImpl:

Public Member Functions

 TransactionPoolImpl (std::shared_ptr< runtime::TaggedTransactionQueue > ttq, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< network::TransactionsTransmitter > tx_transmitter, std::unique_ptr< PoolModerator > moderator, std::shared_ptr< blockchain::BlockHeaderRepository > header_repo, std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine > sub_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > ext_key_repo, Limits limits)
 
 TransactionPoolImpl (TransactionPoolImpl &&)=default
 
 TransactionPoolImpl (const TransactionPoolImpl &)=delete
 
 ~TransactionPoolImpl () override=default
 
TransactionPoolImploperator= (TransactionPoolImpl &&)=delete
 
TransactionPoolImploperator= (const TransactionPoolImpl &)=delete
 
const std::unordered_map< Transaction::Hash, std::shared_ptr< Transaction > > & getPendingTransactions () const override
 
outcome::result< Transaction::Hash > submitExtrinsic (primitives::TransactionSource source, primitives::Extrinsic extrinsic) override
 
outcome::result< void > submitOne (Transaction &&tx) override
 
outcome::result< Transaction > removeOne (const Transaction::Hash &tx_hash) override
 
std::map< Transaction::Hash, std::shared_ptr< Transaction > > getReadyTransactions () const override
 
outcome::result< std::vector< Transaction > > removeStale (const primitives::BlockId &at) override
 
Status getStatus () const override
 
outcome::result< primitives::TransactionconstructTransaction (primitives::TransactionSource source, primitives::Extrinsic extrinsic) const override
 
- Public Member Functions inherited from kagome::transaction_pool::TransactionPool
virtual ~TransactionPool ()=default
 

Private Member Functions

outcome::result< void > submitOne (const std::shared_ptr< Transaction > &tx)
 
outcome::result< void > processTransaction (const std::shared_ptr< Transaction > &tx)
 
outcome::result< void > processTransactionAsReady (const std::shared_ptr< Transaction > &tx)
 
outcome::result< void > processTransactionAsWaiting (const std::shared_ptr< Transaction > &tx)
 
outcome::result< void > ensureSpace () const
 
bool hasSpaceInReady () const
 
void addTransactionAsWaiting (const std::shared_ptr< Transaction > &tx)
 
void delTransactionAsWaiting (const std::shared_ptr< Transaction > &tx)
 
void postponeTransaction (const std::shared_ptr< Transaction > &tx)
 Postpone ready transaction (in case ready limit was enreach before) More...
 
void processPostponedTransactions ()
 Process postponed transactions (in case appearing space for them) More...
 
void provideTag (const Transaction::Tag &tag)
 
void unprovideTag (const Transaction::Tag &tag)
 
void commitRequiredTags (const std::shared_ptr< Transaction > &tx)
 
void commitProvidedTags (const std::shared_ptr< Transaction > &tx)
 
void rollbackRequiredTags (const std::shared_ptr< Transaction > &tx)
 
void rollbackProvidedTags (const std::shared_ptr< Transaction > &tx)
 
bool checkForReady (const std::shared_ptr< const Transaction > &tx) const
 
void setReady (const std::shared_ptr< Transaction > &tx)
 
void unsetReady (const std::shared_ptr< Transaction > &tx)
 
bool isInReady (const std::shared_ptr< const Transaction > &tx) const
 

Private Attributes

std::shared_ptr< blockchain::BlockHeaderRepositoryheader_repo_
 
log::Logger logger_ = log::createLogger("TransactionPool", "transactions")
 
std::shared_ptr< primitives::events::ExtrinsicSubscriptionEnginesub_engine_
 
std::shared_ptr< subscription::ExtrinsicEventKeyRepositoryext_key_repo_
 
std::shared_ptr< runtime::TaggedTransactionQueuettq_
 
std::shared_ptr< crypto::Hasherhasher_
 
std::shared_ptr< network::TransactionsTransmittertx_transmitter_
 
std::unique_ptr< PoolModeratormoderator_
 bans stale and invalid transactions for some amount of time More...
 
std::unordered_map< Transaction::Hash, std::shared_ptr< Transaction > > imported_txs_
 All of imported transaction, contained in the pool. More...
 
std::unordered_map< Transaction::Hash, std::weak_ptr< Transaction > > ready_txs_
 Collection transaction with full-satisfied dependencies. More...
 
std::list< std::weak_ptr< Transaction > > postponed_txs_
 List of ready transaction over limit. It will be process first of all. More...
 
std::multimap< Transaction::Tag, std::weak_ptr< Transaction > > tx_provides_tag_
 Transactions which provides specific tags. More...
 
std::multimap< Transaction::Tag, std::weak_ptr< Transaction > > tx_depends_on_tag_
 Transactions with resolved requirement of a specific tag. More...
 
std::multimap< Transaction::Tag, std::weak_ptr< Transaction > > tx_waits_tag_
 Transactions with unresolved require of specific tags. More...
 
Limits limits_
 
metrics::RegistryPtr metrics_registry_ = metrics::createRegistry()
 
metrics::Gaugemetric_ready_txs_
 

Detailed Description

Definition at line 31 of file transaction_pool_impl.hpp.

Constructor & Destructor Documentation

kagome::transaction_pool::TransactionPoolImpl::TransactionPoolImpl ( std::shared_ptr< runtime::TaggedTransactionQueue ttq,
std::shared_ptr< crypto::Hasher hasher,
std::shared_ptr< network::TransactionsTransmitter tx_transmitter,
std::unique_ptr< PoolModerator moderator,
std::shared_ptr< blockchain::BlockHeaderRepository header_repo,
std::shared_ptr< primitives::events::ExtrinsicSubscriptionEngine sub_engine,
std::shared_ptr< subscription::ExtrinsicEventKeyRepository ext_key_repo,
Limits  limits 
)

Definition at line 27 of file transaction_pool_impl.cpp.

kagome::transaction_pool::TransactionPoolImpl::TransactionPoolImpl ( TransactionPoolImpl &&  )
default
kagome::transaction_pool::TransactionPoolImpl::TransactionPoolImpl ( const TransactionPoolImpl )
delete
kagome::transaction_pool::TransactionPoolImpl::~TransactionPoolImpl ( )
overridedefault

Member Function Documentation

void kagome::transaction_pool::TransactionPoolImpl::addTransactionAsWaiting ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 190 of file transaction_pool_impl.cpp.

bool kagome::transaction_pool::TransactionPoolImpl::checkForReady ( const std::shared_ptr< const Transaction > &  tx) const
private

Definition at line 303 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::commitProvidedTags ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 339 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::commitRequiredTags ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 324 of file transaction_pool_impl.cpp.

outcome::result< primitives::Transaction > kagome::transaction_pool::TransactionPoolImpl::constructTransaction ( primitives::TransactionSource  source,
primitives::Extrinsic  extrinsic 
) const
overridevirtual
void kagome::transaction_pool::TransactionPoolImpl::delTransactionAsWaiting ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 242 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::ensureSpace ( ) const
private

Definition at line 182 of file transaction_pool_impl.cpp.

const std::unordered_map< Transaction::Hash, std::shared_ptr< Transaction > > & kagome::transaction_pool::TransactionPoolImpl::getPendingTransactions ( ) const
overridevirtual
Returns
pending transactions

Implements kagome::transaction_pool::TransactionPool.

Definition at line 267 of file transaction_pool_impl.cpp.

std::map< Transaction::Hash, std::shared_ptr< Transaction > > kagome::transaction_pool::TransactionPoolImpl::getReadyTransactions ( ) const
overridevirtual
Returns
transactions ready to included in the next block

Implements kagome::transaction_pool::TransactionPool.

Definition at line 256 of file transaction_pool_impl.cpp.

TransactionPoolImpl::Status kagome::transaction_pool::TransactionPoolImpl::getStatus ( ) const
overridevirtual
bool kagome::transaction_pool::TransactionPoolImpl::hasSpaceInReady ( ) const
private

Definition at line 160 of file transaction_pool_impl.cpp.

bool kagome::transaction_pool::TransactionPoolImpl::isInReady ( const std::shared_ptr< const Transaction > &  tx) const
private

Definition at line 297 of file transaction_pool_impl.cpp.

TransactionPoolImpl& kagome::transaction_pool::TransactionPoolImpl::operator= ( TransactionPoolImpl &&  )
delete
TransactionPoolImpl& kagome::transaction_pool::TransactionPoolImpl::operator= ( const TransactionPoolImpl )
delete
void kagome::transaction_pool::TransactionPoolImpl::postponeTransaction ( const std::shared_ptr< Transaction > &  tx)
private

Postpone ready transaction (in case ready limit was enreach before)

Definition at line 164 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::processPostponedTransactions ( )
private

Process postponed transactions (in case appearing space for them)

Definition at line 224 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::processTransaction ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 138 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::processTransactionAsReady ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 149 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::processTransactionAsWaiting ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 173 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::provideTag ( const Transaction::Tag &  tag)
private

Definition at line 348 of file transaction_pool_impl.cpp.

outcome::result< Transaction > kagome::transaction_pool::TransactionPoolImpl::removeOne ( const Transaction::Hash &  txHash)
overridevirtual

Remove transaction from the pool

Parameters
txHash- hash of the removed transaction
Returns
removed transaction or error

Implements kagome::transaction_pool::TransactionPool.

Definition at line 201 of file transaction_pool_impl.cpp.

outcome::result< std::vector< Transaction > > kagome::transaction_pool::TransactionPoolImpl::removeStale ( const primitives::BlockId at)
overridevirtual

Remove from the pool and temporarily ban transactions which longevity is expired

Parameters
ata block that is considered current for removal (transaction t is banned if 'block number when t got to pool' + 't.longevity' <= block number of at)
Returns
removed transactions

Implements kagome::transaction_pool::TransactionPool.

Definition at line 271 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::rollbackProvidedTags ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 381 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::rollbackRequiredTags ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 374 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::setReady ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 312 of file transaction_pool_impl.cpp.

outcome::result< Transaction::Hash > kagome::transaction_pool::TransactionPoolImpl::submitExtrinsic ( primitives::TransactionSource  source,
primitives::Extrinsic  extrinsic 
)
overridevirtual

Builds and validates transaction for provided extrinsic, and submit result transaction into pool

Parameters
sourcehow extrinsic was received (for example external or submitted through offchain worker)
extrinsicset of bytes representing either transaction or inherent
Returns
hash of successfully submitted transaction or error if state is invalid or unknown

Implements kagome::transaction_pool::TransactionPool.

Definition at line 96 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::submitOne ( Transaction &&  tx)
overridevirtual

Import one verified transaction to the pool. If it has unresolved dependencies (requires tags of transactions that are not in the pool yet), it will wait in the pool until its dependencies are solved, in which case it becomes ready and may be pruned, or it is banned from the pool for some amount of time as its longevity is reached or the pool is overflown

Implements kagome::transaction_pool::TransactionPool.

Definition at line 110 of file transaction_pool_impl.cpp.

outcome::result< void > kagome::transaction_pool::TransactionPoolImpl::submitOne ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 114 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::unprovideTag ( const Transaction::Tag &  tag)
private

Definition at line 396 of file transaction_pool_impl.cpp.

void kagome::transaction_pool::TransactionPoolImpl::unsetReady ( const std::shared_ptr< Transaction > &  tx)
private

Definition at line 362 of file transaction_pool_impl.cpp.

Member Data Documentation

std::shared_ptr<subscription::ExtrinsicEventKeyRepository> kagome::transaction_pool::TransactionPoolImpl::ext_key_repo_
private

Definition at line 128 of file transaction_pool_impl.hpp.

std::shared_ptr<crypto::Hasher> kagome::transaction_pool::TransactionPoolImpl::hasher_
private

Definition at line 131 of file transaction_pool_impl.hpp.

std::shared_ptr<blockchain::BlockHeaderRepository> kagome::transaction_pool::TransactionPoolImpl::header_repo_
private

Definition at line 122 of file transaction_pool_impl.hpp.

std::unordered_map<Transaction::Hash, std::shared_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::imported_txs_
private

All of imported transaction, contained in the pool.

Definition at line 139 of file transaction_pool_impl.hpp.

Limits kagome::transaction_pool::TransactionPoolImpl::limits_
private

Definition at line 159 of file transaction_pool_impl.hpp.

log::Logger kagome::transaction_pool::TransactionPoolImpl::logger_ = log::createLogger("TransactionPool", "transactions")
private

Definition at line 124 of file transaction_pool_impl.hpp.

metrics::Gauge* kagome::transaction_pool::TransactionPoolImpl::metric_ready_txs_
private

Definition at line 163 of file transaction_pool_impl.hpp.

metrics::RegistryPtr kagome::transaction_pool::TransactionPoolImpl::metrics_registry_ = metrics::createRegistry()
private

Definition at line 162 of file transaction_pool_impl.hpp.

std::unique_ptr<PoolModerator> kagome::transaction_pool::TransactionPoolImpl::moderator_
private

bans stale and invalid transactions for some amount of time

Definition at line 135 of file transaction_pool_impl.hpp.

std::list<std::weak_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::postponed_txs_
private

List of ready transaction over limit. It will be process first of all.

Definition at line 146 of file transaction_pool_impl.hpp.

std::unordered_map<Transaction::Hash, std::weak_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::ready_txs_
private

Collection transaction with full-satisfied dependencies.

Definition at line 143 of file transaction_pool_impl.hpp.

std::shared_ptr<primitives::events::ExtrinsicSubscriptionEngine> kagome::transaction_pool::TransactionPoolImpl::sub_engine_
private

Definition at line 127 of file transaction_pool_impl.hpp.

std::shared_ptr<runtime::TaggedTransactionQueue> kagome::transaction_pool::TransactionPoolImpl::ttq_
private

Definition at line 130 of file transaction_pool_impl.hpp.

std::multimap<Transaction::Tag, std::weak_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::tx_depends_on_tag_
private

Transactions with resolved requirement of a specific tag.

Definition at line 154 of file transaction_pool_impl.hpp.

std::multimap<Transaction::Tag, std::weak_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::tx_provides_tag_
private

Transactions which provides specific tags.

Definition at line 150 of file transaction_pool_impl.hpp.

std::shared_ptr<network::TransactionsTransmitter> kagome::transaction_pool::TransactionPoolImpl::tx_transmitter_
private

Definition at line 132 of file transaction_pool_impl.hpp.

std::multimap<Transaction::Tag, std::weak_ptr<Transaction> > kagome::transaction_pool::TransactionPoolImpl::tx_waits_tag_
private

Transactions with unresolved require of specific tags.

Definition at line 157 of file transaction_pool_impl.hpp.


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