Skip to content

Commit b9d9dea

Browse files
author
ABW
committed
add counter of dropped transactions and size of mempool to block stats
Also colony_basic_test was used to show how dropping looks in practice (transactions are dropped once when test switches from 2MB blocks to 64kB blocks).
1 parent f299532 commit b9d9dea

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

libraries/chain/block_flow_control.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ void block_flow_control::on_end_of_apply_block() const
7272
current_phase = phase::APPLIED;
7373
}
7474

75-
void block_flow_control::on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _lib ) const
75+
void block_flow_control::on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _drop_txs, size_t _mempool_size, uint32_t _lib ) const
7676
{
77-
stats.on_cleanup( _exp_txs, _fail_txs, _ok_txs, _post_txs, _lib );
77+
stats.on_cleanup( _exp_txs, _fail_txs, _ok_txs, _post_txs, _drop_txs, _mempool_size, _lib );
7878
if( !except && current_phase == phase::APPLIED )
7979
current_phase = phase::END;
8080
}
@@ -173,7 +173,13 @@ fc::variant_object block_flow_control::get_report( report_type rt ) const
173173
( "exp", stats.get_txs_expired_after_block() )
174174
( "fail", stats.get_txs_failed_after_block() )
175175
( "appl", stats.get_txs_reapplied_after_block() )
176-
( "post", stats.get_txs_postponed_after_block() );
176+
( "post", stats.get_txs_postponed_after_block() )
177+
( "drop", stats.get_txs_dropped_after_block() );
178+
if( rt == report_type::FULL )
179+
{
180+
after
181+
( "size", stats.get_size_of_txs_left_after_block() );
182+
}
177183
report( "after", after.get() );
178184
}
179185
if( rt != report_type::MINIMAL )

libraries/chain/include/hive/chain/block_flow_control.hpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ class block_stats
3434
end_work = fc::time_point::now();
3535
}
3636

37-
void on_cleanup( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _lib )
37+
void on_cleanup( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _drop_txs, size_t _mempool_size, uint32_t _lib )
3838
{
3939
end_cleanup = fc::time_point::now();
4040
txs_expired = _exp_txs;
4141
txs_failed = _fail_txs;
4242
txs_reapplied = _ok_txs;
4343
txs_postponed = _post_txs;
44+
txs_dropped = _drop_txs;
45+
txs_size = _mempool_size;
4446
last_irreversible_block_num = _lib;
4547
}
4648

@@ -62,6 +64,9 @@ class block_stats
6264
uint32_t get_txs_failed_after_block() const { return txs_failed; }
6365
uint32_t get_txs_reapplied_after_block() const { return txs_reapplied; }
6466
uint32_t get_txs_postponed_after_block() const { return txs_postponed; }
67+
uint32_t get_txs_dropped_after_block() const { return txs_dropped; }
68+
69+
size_t get_size_of_txs_left_after_block() const { return txs_size; }
6570

6671
uint32_t get_last_irreversible_block_num() const { return last_irreversible_block_num; }
6772

@@ -91,6 +96,12 @@ class block_stats
9196
uint32_t txs_reapplied = 0;
9297
//number of transactions that were not touched during pending reapplication due to time limit
9398
uint32_t txs_postponed = 0;
99+
//number of would-be-postponed transactions that were dropped during pending reapplication due to mempool size limit
100+
uint32_t txs_dropped = 0;
101+
102+
//sum of packed sizes of transactions left in mempool after pending reapplication
103+
size_t txs_size = 0;
104+
94105
//last irreversible block at the time block work was done
95106
uint32_t last_irreversible_block_num = 0;
96107
};
@@ -150,7 +161,7 @@ class block_flow_control
150161
virtual void on_end_of_apply_block() const;
151162

152163
// after reapplication of pending transactions (only overridden in tests)
153-
virtual void on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _lib ) const;
164+
virtual void on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _drop_txs, size_t _mempool_size, uint32_t _lib ) const;
154165

155166
// in case of exception
156167
virtual void on_failure( const fc::exception& e ) const;

libraries/chain/include/hive/chain/db_with.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct pending_transactions_restorer
195195
_db._popped_tx.clear();
196196
} );
197197

198-
_block_ctrl.on_end_of_processing( expired_txs, failed_txs, applied_txs, postponed_txs, _db.get_last_irreversible_block_num() );
198+
_block_ctrl.on_end_of_processing( expired_txs, failed_txs, applied_txs, postponed_txs, dropped_txs, pending_size, _db.get_last_irreversible_block_num() );
199199
if( in_sync && ( postponed_txs || expired_txs ) )
200200
{
201201
wlog("Postponed ${postponed_txs} pending transactions. ${applied_txs} were applied. ${expired_txs} expired.",

tests/unit/plugin_tests/witness_tests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,8 @@ BOOST_AUTO_TEST_CASE( colony_basic_test )
12821282
config_line_t( { "colony-reply", { R"~({"min":30,"max":1000,"weight":110,"exponent":5})~" } } ),
12831283
config_line_t( { "colony-vote", { R"~({"weight":2070})~" } } ),
12841284
config_line_t( { "colony-transfer", { R"~({"min":0,"max":350,"weight":87,"exponent":4})~" } } ),
1285-
config_line_t( { "colony-custom", { R"~({"min":20,"max":400,"weight":6006,"exponent":1})~" } } )
1285+
config_line_t( { "colony-custom", { R"~({"min":20,"max":400,"weight":6006,"exponent":1})~" } } ),
1286+
config_line_t( { "max-mempool-size", { "0" } } ),
12861287
}, "1G" );
12871288

12881289
fc::thread api_thread;

tests/unit/tests/block_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1471,11 +1471,11 @@ class test_block_flow_control : public BASE
14711471
verify( expectation::END_OF_BLOCK );
14721472
}
14731473

1474-
virtual void on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _lib ) const override
1474+
virtual void on_end_of_processing( uint32_t _exp_txs, uint32_t _fail_txs, uint32_t _ok_txs, uint32_t _post_txs, uint32_t _drop_txs, size_t _mempool_size, uint32_t _lib ) const override
14751475
{
14761476
// pending transactions are actually reapplied even after failed block and that is before exception
14771477
// is passed to the block flow control; it means we can't be sure on what is current phase
1478-
BASE::on_end_of_processing( _exp_txs, _fail_txs, _ok_txs, _post_txs, _lib );
1478+
BASE::on_end_of_processing( _exp_txs, _fail_txs, _ok_txs, _post_txs, _drop_txs, _mempool_size, _lib );
14791479
verify( expectation::END_PROCESSING );
14801480
}
14811481

0 commit comments

Comments
 (0)