Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Expire blacklisted scheduled transactions by LIB time - develop #8801

Merged
merged 4 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
arhag marked this conversation as resolved.
Show resolved Hide resolved
return my->fork_db.root()->header.timestamp;
}


const dynamic_global_property_object& controller::get_dynamic_global_properties()const {
return my->db.get<dynamic_global_property_object>();
}
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<by_expiry>();
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down