From 4cdd824db64cb7c8969fe57f9852f5312c579b3f Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 11 Mar 2020 14:10:19 -0500 Subject: [PATCH 1/4] Add last_irreverisble_timestamp() --- libraries/chain/controller.cpp | 5 +++++ libraries/chain/include/eosio/chain/controller.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index b6c7a87cd8e..e6070ae987d 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2830,6 +2830,11 @@ block_id_type controller::last_irreversible_block_id() const { return get_block_id_for_num( lib_num ); } +block_timestamp_type controller::last_irreversible_block_timestamp() const { + return my->fork_db.root()->header.timestamp; +} + + const dynamic_global_property_object& controller::get_dynamic_global_properties()const { return my->db.get(); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 7ee604154e9..b517123910f 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -228,6 +228,7 @@ namespace eosio { namespace chain { uint32_t last_irreversible_block_num() const; block_id_type last_irreversible_block_id() const; + block_timestamp_type last_irreversible_block_timestamp() const; signed_block_ptr fetch_block_by_number( uint32_t block_num )const; signed_block_ptr fetch_block_by_id( block_id_type id )const; From ed51b1e2fe8447e1c8f8be2e6fc8b08c579ddd13 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 11 Mar 2020 14:15:36 -0500 Subject: [PATCH 2/4] Use lib time for expiration of blacklisted scheduled transactions --- plugins/producer_plugin/producer_plugin.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 7d7ae505c51..be0b5c14145 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1640,12 +1640,14 @@ bool producer_plugin_impl::remove_expired_blacklisted_trxs( const fc::time_point { bool exhausted = false; auto& blacklist_by_expiry = _blacklisted_transactions.get(); - auto now = fc::time_point::now(); if(!blacklist_by_expiry.empty()) { + const chain::controller& chain = chain_plug->chain(); + const auto lib_time = chain.last_irreversible_block_timestamp().to_time_point(); + int num_expired = 0; int orig_count = _blacklisted_transactions.size(); - while (!blacklist_by_expiry.empty() && blacklist_by_expiry.begin()->expiry <= now) { + while (!blacklist_by_expiry.empty() && blacklist_by_expiry.begin()->expiry <= lib_time) { if (deadline <= fc::time_point::now()) { exhausted = true; break; @@ -1751,12 +1753,13 @@ void producer_plugin_impl::process_scheduled_and_incoming_trxs( const fc::time_p continue; // do not allow schedule and execute in same block } - const transaction_id_type trx_id = sch_itr->trx_id; // make copy since reference could be invalidated - if (blacklist_by_id.find(trx_id) != blacklist_by_id.end()) { + if (blacklist_by_id.find(sch_itr->trx_id) != blacklist_by_id.end()) { ++sch_itr; continue; } + const transaction_id_type trx_id = sch_itr->trx_id; // make copy since reference could be invalidated + const auto sch_expiration = sch_itr->expiration; auto sch_itr_next = sch_itr; // save off next since sch_itr may be invalidated by loop ++sch_itr_next; const auto next_delay_until = sch_itr_next != sch_idx.end() ? sch_itr_next->delay_until : sch_itr->delay_until; @@ -1806,9 +1809,8 @@ void producer_plugin_impl::process_scheduled_and_incoming_trxs( const fc::time_p } // do not blacklist } else { - auto expiration = fc::time_point::now() + fc::seconds(chain.get_global_properties().configuration.deferred_trx_expiration_window); // this failed our configured maximum transaction time, we don't want to replay it add it to a blacklist - _blacklisted_transactions.insert(transaction_id_with_expiry{trx_id, expiration}); + _blacklisted_transactions.insert(transaction_id_with_expiry{trx_id, sch_expiration}); num_failed++; } } else { From 9b865cbd46bcc0e62255ac0574724f820577d999 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 11 Mar 2020 14:27:33 -0500 Subject: [PATCH 3/4] Rename and return time_point to match other controller methods --- libraries/chain/controller.cpp | 4 ++-- libraries/chain/include/eosio/chain/controller.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index e6070ae987d..85c0bdc2742 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -2830,8 +2830,8 @@ block_id_type controller::last_irreversible_block_id() const { return get_block_id_for_num( lib_num ); } -block_timestamp_type controller::last_irreversible_block_timestamp() const { - return my->fork_db.root()->header.timestamp; +time_point controller::last_irreversible_block_time() const { + return my->fork_db.root()->header.timestamp.to_time_point(); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index b517123910f..0c2fa85d0a8 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -228,7 +228,7 @@ namespace eosio { namespace chain { uint32_t last_irreversible_block_num() const; block_id_type last_irreversible_block_id() const; - block_timestamp_type last_irreversible_block_timestamp() const; + time_point last_irreversible_block_time() const; signed_block_ptr fetch_block_by_number( uint32_t block_num )const; signed_block_ptr fetch_block_by_id( block_id_type id )const; From 998c51abb7741dabd0d399a9a250889395a22b79 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 11 Mar 2020 14:28:12 -0500 Subject: [PATCH 4/4] Renamed chain.last_irreversible_block_timestamp() --- plugins/producer_plugin/producer_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index be0b5c14145..1d0759e2231 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1642,7 +1642,7 @@ bool producer_plugin_impl::remove_expired_blacklisted_trxs( const fc::time_point auto& blacklist_by_expiry = _blacklisted_transactions.get(); if(!blacklist_by_expiry.empty()) { const chain::controller& chain = chain_plug->chain(); - const auto lib_time = chain.last_irreversible_block_timestamp().to_time_point(); + const auto lib_time = chain.last_irreversible_block_time(); int num_expired = 0; int orig_count = _blacklisted_transactions.size();