Commit c9fd3033 authored by Andrzej Lisak's avatar Andrzej Lisak
Browse files

detect expired transactions early and count them

Previously expired transactions would run up to check inside _apply_transaction and generate exception that was also logged.
Now such transactions are detected early (the same code as during building of new block) and just counted, so the log is not clobbered with unnecessary messages.
The check is also much faster (in case of many expired transactions previously only less than 5k would be dropped per block, now 100k+ can be dropped in the same timeframe).
parent b317018b
......@@ -53,11 +53,15 @@ struct pending_transactions_restorer
~pending_transactions_restorer()
{
auto head_block_time = _db.head_block_time();
_db._pending_tx.reserve( _db._popped_tx.size() + _pending_transactions.size() );
auto start = fc::time_point::now();
bool apply_trxs = true;
uint32_t applied_txs = 0;
uint32_t postponed_txs = 0;
uint32_t expired_txs = 0;
auto handle_tx = [&]( const signed_transaction& tx )
{
if( apply_trxs && fc::time_point::now() - start > HIVE_PENDING_TRANSACTION_EXECUTION_LIMIT )
......@@ -67,7 +71,11 @@ struct pending_transactions_restorer
{
try
{
if( !_db.is_known_transaction( tx.id() ) )
if( tx.expiration < head_block_time )
{
++expired_txs;
}
else if( !_db.is_known_transaction( tx.id() ) )
{
// since push_transaction() takes a signed_transaction,
// the operation_results field will be ignored.
......@@ -106,10 +114,10 @@ struct pending_transactions_restorer
for( const auto& tx : _pending_transactions )
handle_tx( tx );
if( postponed_txs )
if( postponed_txs || expired_txs )
{
wlog( "Postponed ${p} pending transactions. ${a} were applied.",
( "p", postponed_txs )( "a", applied_txs ) );
wlog( "Postponed ${p} pending transactions. ${a} were applied. ${e} expired.",
( "p", postponed_txs )( "a", applied_txs )( "e", expired_txs ) );
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment