TARAXA
|
Classes | |
class | taraxa::GasPricer |
Basic gas price calculator. We calculate the gas price based on the lowest price in last number_of_blocks blocks. Then all of those values are sorted and current price is selected based on percentile. More... | |
class | taraxa::TransactionManager |
TransactionManager class verifies and inserts incoming transactions in memory pool and handles saving transactions and all transactions state change. More... | |
class | taraxa::TransactionQueue |
TransactionQueue keeps transactions in memory sorted by priority to be included in a proposed DAG block or which might be required by an incoming DAG block. More... | |
Enumerations | |
enum class | taraxa::TransactionStatus { taraxa::Inserted = 0 , taraxa::InsertedNonProposable , taraxa::Known , taraxa::Overflow } |
TransactionStatus enum class defines current transaction status. More... | |
class taraxa::GasPricer |
Basic gas price calculator. We calculate the gas price based on the lowest price in last number_of_blocks blocks. Then all of those values are sorted and current price is selected based on percentile.
Public Member Functions | |
GasPricer (const GasPriceConfig &config, bool is_light_node=false, std::shared_ptr< DbStorage > db={}) | |
~GasPricer () | |
GasPricer (const GasPricer &)=delete | |
GasPricer (GasPricer &&)=delete | |
GasPricer & | operator= (const GasPricer &)=delete |
GasPricer & | operator= (GasPricer &&)=delete |
u256 | bid () const |
returns current gas price More... | |
void | update (const SharedTransactions &trxs) |
updates gas price after each executed block More... | |
Private Member Functions | |
void | init (const std::shared_ptr< DbStorage > &db) |
initialize values on start from blocks in DB More... | |
Private Attributes | |
const uint64_t | kPercentile |
const u256 | kMinimumPrice |
const bool | kIsLightNode |
std::shared_mutex | mutex_ |
u256 | latest_price_ |
boost::circular_buffer< u256 > | price_list_ |
std::unique_ptr< std::thread > | init_daemon_ |
taraxa::GasPricer::GasPricer | ( | const GasPriceConfig & | config, |
bool | is_light_node = false , |
||
std::shared_ptr< DbStorage > | db = {} |
||
) |
taraxa::GasPricer::~GasPricer | ( | ) |
|
delete |
|
delete |
u256 taraxa::GasPricer::bid | ( | ) | const |
returns current gas price
|
private |
initialize values on start from blocks in DB
db |
void taraxa::GasPricer::update | ( | const SharedTransactions & | trxs | ) |
updates gas price after each executed block
trxs | from latest block |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
class taraxa::TransactionManager |
TransactionManager class verifies and inserts incoming transactions in memory pool and handles saving transactions and all transactions state change.
Incoming new transactions can be verified with verifyTransaction functions and than inserted in the transaction pool with insertValidatedTransaction. Transactions are kept in transactions memory pool until they are included in a proposed dag block or received in an incoming dag block. Transaction verification consist of:
Verified transaction inserted in TransactionManager can be in three state:
Transaction transition to non-finalized block state is done with call to saveTransactionsFromDagBlock. Transaction transition to finalized block state is done with call to updateFinalizedTransactionsStatus
Class is thread safe in general with exception of two special methods: updateFinalizedTransactionsStatus and removeNonFinalizedTransactions. See details in function descriptions.
Public Member Functions | |
TransactionManager (const FullNodeConfig &conf, std::shared_ptr< DbStorage > db, std::shared_ptr< final_chain::FinalChain > final_chain, addr_t node_addr) | |
uint64_t | estimateTransactionGas (std::shared_ptr< Transaction > trx, std::optional< PbftPeriod > proposal_period) const |
Estimates required gas value to execute transaction. More... | |
std::pair< SharedTransactions, std::vector< uint64_t > > | packTrxs (PbftPeriod proposal_period, uint64_t weight_limit) |
Gets transactions from pool to include in the block with specified weight limit. More... | |
std::vector< SharedTransactions > | getAllPoolTrxs () |
Gets all transactions from pool grouped per account. More... | |
void | saveTransactionsFromDagBlock (const SharedTransactions &trxs) |
std::pair< bool, std::string > | insertTransaction (const std::shared_ptr< Transaction > &trx) |
Inserts and verify new transaction to transaction pool. More... | |
void | blockFinalized (EthBlockNumber block_number) |
Invoked when block finalized in final chain. More... | |
TransactionStatus | insertValidatedTransaction (std::shared_ptr< Transaction > &&tx, bool insert_non_proposable=true) |
Inserts verified transaction to transaction pool. More... | |
bool | isTransactionKnown (const trx_hash_t &trx_hash) |
size_t | getTransactionPoolSize () const |
bool | isTransactionPoolFull (size_t percentage=100) const |
return true if transaction pool is full More... | |
bool | nonProposableTransactionsOverTheLimit () const |
return true if non proposable transactions are over the limit More... | |
size_t | getNonfinalizedTrxSize () const |
std::vector< std::shared_ptr< Transaction > > | getNonfinalizedTrx (const std::vector< trx_hash_t > &hashes) |
Get the Nonfinalized Trx objects from cache. More... | |
std::unordered_set< trx_hash_t > | excludeFinalizedTransactions (const std::vector< trx_hash_t > &hashes) |
Exclude Finalized transactions. More... | |
SharedTransactions | getBlockTransactions (const DagBlock &blk, PbftPeriod proposal_period) |
Get the block transactions. More... | |
SharedTransactions | getTransactions (const vec_trx_t &trxs_hashes, PbftPeriod proposal_period) |
Get the transactions. More... | |
void | updateFinalizedTransactionsStatus (const PeriodData &period_data) |
Updates the status of transactions to finalized IMPORTANT: This method is invoked on finalizing a pbft block, it needs to be protected with transactions_mutex_ but the mutex is locked from pbft manager for the entire pbft finalization process to make the finalization atomic. More... | |
void | initializeRecentlyFinalizedTransactions (const PeriodData &period_data) |
Initialize recently finalized transactions. More... | |
void | removeNonFinalizedTransactions (std::unordered_set< trx_hash_t > &&transactions) |
Removes non-finalized transactions from discarded old dag blocks IMPORTANT: This method is invoked on finalizing a pbft block, it needs to be protected with transactions_mutex_ but the mutex is locked from pbft manager for the entire pbft finalization process to make the finalization atomic. More... | |
std::shared_mutex & | getTransactionsMutex () |
Retrieves transactions mutex, only to be used when finalizing pbft block. More... | |
std::pair< std::vector< std::shared_ptr< Transaction > >, std::vector< trx_hash_t > > | getPoolTransactions (const std::vector< trx_hash_t > &trx_to_query) const |
Gets transactions from transactions pool. More... | |
bool | transactionsDropped () const |
Have transactions been recently dropped due to queue reaching max size This call is thread-safe. More... | |
std::shared_ptr< Transaction > | getTransaction (const trx_hash_t &hash) const |
std::shared_ptr< Transaction > | getNonFinalizedTransaction (const trx_hash_t &hash) const |
unsigned long | getTransactionCount () const |
void | recoverNonfinalizedTransactions () |
std::pair< bool, std::string > | verifyTransaction (const std::shared_ptr< Transaction > &trx) const |
Public Attributes | |
util::Event< TransactionManager, h256 > const | transaction_accepted_ {} |
Private Member Functions | |
addr_t | getFullNodeAddress () const |
Private Attributes | |
const FullNodeConfig & | kConf |
std::shared_mutex | transactions_mutex_ |
TransactionQueue | transactions_pool_ |
std::unordered_map< trx_hash_t, std::shared_ptr< Transaction > > | nonfinalized_transactions_in_dag_ |
std::unordered_map< trx_hash_t, std::shared_ptr< Transaction > > | recently_finalized_transactions_ |
std::unordered_map< PbftPeriod, std::vector< trx_hash_t > > | recently_finalized_transactions_per_period_ |
uint64_t | trx_count_ = 0 |
const uint64_t | kDagBlockGasLimit |
const uint64_t | kEstimateGasLimit = 200000 |
const uint64_t | kRecentlyFinalizedTransactionsMax = 50000 |
std::shared_ptr< DbStorage > | db_ {nullptr} |
std::shared_ptr< final_chain::FinalChain > | final_chain_ {nullptr} |
taraxa::TransactionManager::TransactionManager | ( | const FullNodeConfig & | conf, |
std::shared_ptr< DbStorage > | db, | ||
std::shared_ptr< final_chain::FinalChain > | final_chain, | ||
addr_t | node_addr | ||
) |
void taraxa::TransactionManager::blockFinalized | ( | EthBlockNumber | block_number | ) |
Invoked when block finalized in final chain.
block_number | block number finalized |
uint64_t taraxa::TransactionManager::estimateTransactionGas | ( | std::shared_ptr< Transaction > | trx, |
std::optional< PbftPeriod > | proposal_period | ||
) | const |
Estimates required gas value to execute transaction.
trx | transaction |
proposal_period | proposal period |
std::unordered_set< trx_hash_t > taraxa::TransactionManager::excludeFinalizedTransactions | ( | const std::vector< trx_hash_t > & | hashes | ) |
Exclude Finalized transactions.
hashes |
std::vector< SharedTransactions > taraxa::TransactionManager::getAllPoolTrxs | ( | ) |
Gets all transactions from pool grouped per account.
SharedTransactions taraxa::TransactionManager::getBlockTransactions | ( | const DagBlock & | blk, |
PbftPeriod | proposal_period | ||
) |
Get the block transactions.
blk | |
proposal_period |
|
private |
std::shared_ptr<Transaction> taraxa::TransactionManager::getNonFinalizedTransaction | ( | const trx_hash_t & | hash | ) | const |
std::vector< std::shared_ptr< Transaction > > taraxa::TransactionManager::getNonfinalizedTrx | ( | const std::vector< trx_hash_t > & | hashes | ) |
Get the Nonfinalized Trx objects from cache.
hashes |
size_t taraxa::TransactionManager::getNonfinalizedTrxSize | ( | ) | const |
std::pair< std::vector< std::shared_ptr< Transaction > >, std::vector< trx_hash_t > > taraxa::TransactionManager::getPoolTransactions | ( | const std::vector< trx_hash_t > & | trx_to_query | ) | const |
Gets transactions from transactions pool.
trx_to_query |
std::shared_ptr< Transaction > taraxa::TransactionManager::getTransaction | ( | const trx_hash_t & | hash | ) | const |
unsigned long taraxa::TransactionManager::getTransactionCount | ( | ) | const |
size_t taraxa::TransactionManager::getTransactionPoolSize | ( | ) | const |
SharedTransactions taraxa::TransactionManager::getTransactions | ( | const vec_trx_t & | trxs_hashes, |
PbftPeriod | proposal_period | ||
) |
Get the transactions.
trxs_hashes | |
proposal_period |
|
inline |
Retrieves transactions mutex, only to be used when finalizing pbft block.
void taraxa::TransactionManager::initializeRecentlyFinalizedTransactions | ( | const PeriodData & | period_data | ) |
Initialize recently finalized transactions.
period_data | period data |
std::pair< bool, std::string > taraxa::TransactionManager::insertTransaction | ( | const std::shared_ptr< Transaction > & | trx | ) |
Inserts and verify new transaction to transaction pool.
trx | transaction to be processed |
TransactionStatus taraxa::TransactionManager::insertValidatedTransaction | ( | std::shared_ptr< Transaction > && | tx, |
bool | insert_non_proposable = true |
||
) |
Inserts verified transaction to transaction pool.
tx | transaction to be processed |
insert_non_proposable | insert non proposable transactions |
bool taraxa::TransactionManager::isTransactionKnown | ( | const trx_hash_t & | trx_hash | ) |
trx_hash | transaction hash |
bool taraxa::TransactionManager::isTransactionPoolFull | ( | size_t | percentage = 100 | ) | const |
return true if transaction pool is full
percentage | defines percentage of fullness |
bool taraxa::TransactionManager::nonProposableTransactionsOverTheLimit | ( | ) | const |
return true if non proposable transactions are over the limit
std::pair< SharedTransactions, std::vector< uint64_t > > taraxa::TransactionManager::packTrxs | ( | PbftPeriod | proposal_period, |
uint64_t | weight_limit | ||
) |
Gets transactions from pool to include in the block with specified weight limit.
proposal_period | proposal period |
weight_limit | weight limit |
Retrieve transactions to be included in proposed block
void taraxa::TransactionManager::recoverNonfinalizedTransactions | ( | ) |
void taraxa::TransactionManager::removeNonFinalizedTransactions | ( | std::unordered_set< trx_hash_t > && | transactions | ) |
Removes non-finalized transactions from discarded old dag blocks IMPORTANT: This method is invoked on finalizing a pbft block, it needs to be protected with transactions_mutex_ but the mutex is locked from pbft manager for the entire pbft finalization process to make the finalization atomic.
transactions | transactions to remove |
void taraxa::TransactionManager::saveTransactionsFromDagBlock | ( | const SharedTransactions & | trxs | ) |
Saves transactions from dag block which was added to the DAG. Removes transactions from memory pool
bool taraxa::TransactionManager::transactionsDropped | ( | ) | const |
Have transactions been recently dropped due to queue reaching max size This call is thread-safe.
void taraxa::TransactionManager::updateFinalizedTransactionsStatus | ( | const PeriodData & | period_data | ) |
Updates the status of transactions to finalized IMPORTANT: This method is invoked on finalizing a pbft block, it needs to be protected with transactions_mutex_ but the mutex is locked from pbft manager for the entire pbft finalization process to make the finalization atomic.
period_data | period data |
Update transaction counters and state, it only has effect when PBFT syncing
std::pair< bool, std::string > taraxa::TransactionManager::verifyTransaction | ( | const std::shared_ptr< Transaction > & | trx | ) | const |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
util::Event<TransactionManager, h256> const taraxa::TransactionManager::transaction_accepted_ {} |
|
mutableprivate |
|
private |
|
private |
class taraxa::TransactionQueue |
TransactionQueue keeps transactions in memory sorted by priority to be included in a proposed DAG block or which might be required by an incoming DAG block.
TransactionQueue stores two type of transactions: Transactions that can be included in a proposed DAG block and non proposable transactions which are not to be used for proposal but an incoming DAG block could contain such transactions. Non proposable transactions can expire if no DAG block that contains them is received within the kNonProposableTransactionsPeriodExpiryLimit.
This is NOT thread safe class. It is proteced only by transactions_mutex_ in the TransactionsManager !!!
Public Member Functions | |
TransactionQueue (std::shared_ptr< final_chain::FinalChain > final_chain, size_t max_size=kMinTransactionPoolSize) | |
TransactionStatus | insert (std::shared_ptr< Transaction > &&transaction, bool proposable, uint64_t last_block_number=0) |
insert a transaction into the queue, sorted by priority More... | |
bool | erase (const trx_hash_t &hash) |
remove transaction from queue More... | |
std::shared_ptr< Transaction > | get (const trx_hash_t &hash) const |
returns the transaction or null More... | |
std::vector< std::shared_ptr< Transaction > > | getOrderedTransactions (uint64_t count) const |
returns up to the number of requested transaction sorted by priority. This call actually sorts the transaction so it is expensive and should be used only when needed More... | |
std::vector< SharedTransactions > | getAllTransactions () const |
returns all transactions grouped by transactions author More... | |
bool | contains (const trx_hash_t &hash) const |
returns true/false if the transaction is in the queue More... | |
size_t | size () const |
returns size of priority queue More... | |
void | blockFinalized (uint64_t block_number) |
Invoked when block finalized in final chain. More... | |
void | purge () |
Removes any transactions that are no longer proposable. More... | |
void | markTransactionKnown (const trx_hash_t &trx_hash) |
Marks transaction as known (was successfully pushed into the tx pool) This call is thread-safe. More... | |
bool | isTransactionKnown (const trx_hash_t &trx_hash) const |
bool | transactionsDropped () const |
Have transactions been recently dropped due to queue reaching max size This call is thread-safe. More... | |
bool | nonProposableTransactionsOverTheLimit () const |
return true if non proposable transactions are over the limit More... | |
Private Attributes | |
std::unordered_map< addr_t, std::map< val_t, std::shared_ptr< Transaction > > > | account_nonce_transactions_ |
std::unordered_map< trx_hash_t, std::shared_ptr< Transaction > > | queue_transactions_ |
std::unordered_map< trx_hash_t, std::pair< uint64_t, std::shared_ptr< Transaction > > > | non_proposable_transactions_ |
ExpirationCache< trx_hash_t > | known_txs_ |
std::chrono::system_clock::time_point | transaction_overflow_time_ |
const std::chrono::seconds | kTransactionOverflowTimeLimit {600} |
const size_t | kNonProposableTransactionsPeriodExpiryLimit = 10 |
const size_t | kNonProposableTransactionsLimitPercentage = 20 |
const size_t | kSingleAccountTransactionsLimitPercentage = 5 |
const size_t | kNonProposableTransactionsMaxSize |
const size_t | kMaxSize |
const size_t | kMaxSingleAccountTransactionsSize |
std::shared_ptr< final_chain::FinalChain > | final_chain_ |
taraxa::TransactionQueue::TransactionQueue | ( | std::shared_ptr< final_chain::FinalChain > | final_chain, |
size_t | max_size = kMinTransactionPoolSize |
||
) |
void taraxa::TransactionQueue::blockFinalized | ( | uint64_t | block_number | ) |
Invoked when block finalized in final chain.
block_number | block number finalized |
bool taraxa::TransactionQueue::contains | ( | const trx_hash_t & | hash | ) | const |
returns true/false if the transaction is in the queue
hash |
bool taraxa::TransactionQueue::erase | ( | const trx_hash_t & | hash | ) |
remove transaction from queue
hash |
std::shared_ptr< Transaction > taraxa::TransactionQueue::get | ( | const trx_hash_t & | hash | ) | const |
returns the transaction or null
hash |
std::vector< SharedTransactions > taraxa::TransactionQueue::getAllTransactions | ( | ) | const |
returns all transactions grouped by transactions author
SharedTransactions taraxa::TransactionQueue::getOrderedTransactions | ( | uint64_t | count | ) | const |
returns up to the number of requested transaction sorted by priority. This call actually sorts the transaction so it is expensive and should be used only when needed
count |
TransactionStatus taraxa::TransactionQueue::insert | ( | std::shared_ptr< Transaction > && | transaction, |
bool | proposable, | ||
uint64_t | last_block_number = 0 |
||
) |
insert a transaction into the queue, sorted by priority
transaction | |
last_block_number |
bool taraxa::TransactionQueue::isTransactionKnown | ( | const trx_hash_t & | trx_hash | ) | const |
trx_hash | transaction hash This call is thread-safe |
void taraxa::TransactionQueue::markTransactionKnown | ( | const trx_hash_t & | trx_hash | ) |
Marks transaction as known (was successfully pushed into the tx pool) This call is thread-safe.
trx_hash | transaction hash |
bool taraxa::TransactionQueue::nonProposableTransactionsOverTheLimit | ( | ) | const |
return true if non proposable transactions are over the limit
void taraxa::TransactionQueue::purge | ( | ) |
Removes any transactions that are no longer proposable.
final_chain |
size_t taraxa::TransactionQueue::size | ( | ) | const |
returns size of priority queue
|
inline |
Have transactions been recently dropped due to queue reaching max size This call is thread-safe.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
strong |