From ce04fd8cd1356fd5ef546c7da7f40c655f3373d5 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 25 Feb 2022 22:16:49 -0600 Subject: [PATCH] Limit input transaction dedup time --- libraries/chain/controller.cpp | 23 +++++++++++++------ .../chain/include/eosio/chain/controller.hpp | 3 ++- plugins/producer_plugin/producer_plugin.cpp | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index b440f438aa2..c9a12b390f1 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1520,7 +1520,8 @@ struct controller_impl { uint16_t confirm_block_count, const vector& new_protocol_feature_activations, controller::block_status s, - const optional& producer_block_id ) + const optional& producer_block_id, + const fc::time_point& deadline ) { EOS_ASSERT( !pending, block_validate_exception, "pending block already exists" ); @@ -1665,7 +1666,7 @@ struct controller_impl { elog( "on block transaction failed due to unknown exception" ); } - clear_expired_input_transactions(); + clear_expired_input_transactions(deadline); update_producers_authority(); } @@ -1866,7 +1867,7 @@ struct controller_impl { const auto& new_protocol_feature_activations = bsp->get_new_protocol_feature_activations(); auto producer_block_id = b->id(); - start_block( b->timestamp, b->confirmed, new_protocol_feature_activations, s, producer_block_id); + start_block( b->timestamp, b->confirmed, new_protocol_feature_activations, s, producer_block_id, fc::time_point::maximum() ); const bool existing_trxs_metas = !bsp->trxs_metas().empty(); const bool pub_keys_recovered = bsp->is_pub_keys_recovered(); @@ -2232,14 +2233,21 @@ struct controller_impl { } - void clear_expired_input_transactions() { + void clear_expired_input_transactions(const fc::time_point& deadline) { //Look for expired transactions in the deduplication list, and remove them. auto& transaction_idx = db.get_mutable_index(); const auto& dedupe_index = transaction_idx.indices().get(); auto now = self.pending_block_time(); + const auto total = dedupe_index.size(); + uint32_t num_removed = 0; while( (!dedupe_index.empty()) && ( now > fc::time_point(dedupe_index.begin()->expiration) ) ) { transaction_idx.remove(*dedupe_index.begin()); + ++num_removed; + if( deadline <= fc::time_point::now() ) { + break; + } } + dlog("removed ${n} expired transactions of the ${t} input dedup list", ("n", num_removed)("t", total)); } bool sender_avoids_whitelist_blacklist_enforcement( account_name sender )const { @@ -2626,12 +2634,13 @@ void controller::start_block( block_timestamp_type when, uint16_t confirm_block_ } my->start_block( when, confirm_block_count, new_protocol_feature_activations, - block_status::incomplete, optional() ); + block_status::incomplete, optional(), fc::time_point::maximum() ); } void controller::start_block( block_timestamp_type when, uint16_t confirm_block_count, - const vector& new_protocol_feature_activations ) + const vector& new_protocol_feature_activations, + const fc::time_point& deadline ) { validate_db_available_size(); @@ -2640,7 +2649,7 @@ void controller::start_block( block_timestamp_type when, } my->start_block( when, confirm_block_count, new_protocol_feature_activations, - block_status::incomplete, optional() ); + block_status::incomplete, optional(), deadline ); } block_state_ptr controller::finalize_block( const signer_callback_type& signer_callback ) { diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 2d08e4239a4..fb87184addc 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -133,7 +133,8 @@ namespace eosio { namespace chain { */ void start_block( block_timestamp_type time, uint16_t confirm_block_count, - const vector& new_protocol_feature_activations ); + const vector& new_protocol_feature_activations, + const fc::time_point& deadline = fc::time_point::maximum() ); /** * @return transactions applied in aborted block diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 6da601f263e..a594c448788 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1499,6 +1499,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { const fc::time_point now = fc::time_point::now(); const fc::time_point block_time = calculate_pending_block_time(); + const fc::time_point preprocess_deadline = calculate_block_deadline(block_time); const pending_block_mode previous_pending_mode = _pending_block_mode; _pending_block_mode = pending_block_mode::producing; @@ -1637,12 +1638,11 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() { } } - chain.start_block( block_time, blocks_to_confirm, features_to_activate ); + chain.start_block( block_time, blocks_to_confirm, features_to_activate, preprocess_deadline ); } LOG_AND_DROP(); if( chain.is_building_block() ) { const auto& pending_block_signing_authority = chain.pending_block_signing_authority(); - const fc::time_point preprocess_deadline = calculate_block_deadline(block_time); if (_pending_block_mode == pending_block_mode::producing && pending_block_signing_authority != scheduled_producer.authority) { elog("Unexpected block signing authority, reverting to speculative mode! [expected: \"${expected}\", actual: \"${actual\"", ("expected", scheduled_producer.authority)("actual", pending_block_signing_authority));