From 69c3db06a9d92c05348021f386791377162a03d3 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 21 Oct 2022 08:34:17 -0500 Subject: [PATCH 1/2] GH-290 clear expired transactions before generating snapshot or integrity hash. --- libraries/chain/controller.cpp | 13 ++++++++----- libraries/chain/include/eosio/chain/controller.hpp | 4 ++-- unittests/snapshot_tests.cpp | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6ec9aa111b..c746885dfe 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -795,7 +795,10 @@ struct controller_impl { }); } - void add_to_snapshot( const snapshot_writer_ptr& snapshot ) const { + void add_to_snapshot( const snapshot_writer_ptr& snapshot ) { + // clear in case the previous call to clear did not finish in time of deadline + clear_expired_input_transactions( fc::time_point::maximum() ); + snapshot->write_section([this]( auto §ion ){ section.add_row(chain_snapshot_header(), db); }); @@ -968,7 +971,7 @@ struct controller_impl { ); } - sha256 calculate_integrity_hash() const { + sha256 calculate_integrity_hash() { sha256::encoder enc; auto hash_writer = std::make_shared(enc); add_to_snapshot(hash_writer); @@ -2335,7 +2338,7 @@ struct controller_impl { //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(); + auto now = self.is_building_block() ? self.pending_block_time() : self.head_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) ) ) { @@ -3049,11 +3052,11 @@ block_id_type controller::get_block_id_for_num( uint32_t block_num )const { try return id; } FC_CAPTURE_AND_RETHROW( (block_num) ) } -sha256 controller::calculate_integrity_hash()const { try { +sha256 controller::calculate_integrity_hash() { try { return my->calculate_integrity_hash(); } FC_LOG_AND_RETHROW() } -void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) const { +void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) { EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" ); return my->add_to_snapshot(snapshot); } diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 3267495ece..b054dd7034 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -248,8 +248,8 @@ namespace eosio { namespace chain { block_id_type get_block_id_for_num( uint32_t block_num )const; - sha256 calculate_integrity_hash()const; - void write_snapshot( const snapshot_writer_ptr& snapshot )const; + sha256 calculate_integrity_hash(); + void write_snapshot( const snapshot_writer_ptr& snapshot ); bool sender_avoids_whitelist_blacklist_enforcement( account_name sender )const; void check_actor_list( const flat_set& actors )const; diff --git a/unittests/snapshot_tests.cpp b/unittests/snapshot_tests.cpp index d2d2a7f0d1..156275c45d 100644 --- a/unittests/snapshot_tests.cpp +++ b/unittests/snapshot_tests.cpp @@ -159,7 +159,7 @@ namespace { } template - void verify_integrity_hash(const controller& lhs, const controller& rhs) { + void verify_integrity_hash(controller& lhs, controller& rhs) { const auto lhs_integrity_hash = lhs.calculate_integrity_hash(); const auto rhs_integrity_hash = rhs.calculate_integrity_hash(); if (std::is_same_v && lhs_integrity_hash.str() != rhs_integrity_hash.str()) { From 36ac6e0ed7d58b8b6c67c1357a23a01ffbca7732 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Sat, 22 Oct 2022 09:45:31 -0500 Subject: [PATCH 2/2] GH-291 Remove unused variable --- libraries/chain/controller.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 29580fa250..0d4dd71a06 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -477,7 +477,6 @@ struct controller_impl { } auto blog_head = blog.head(); - auto blog_head_time = blog_head ? blog_head->timestamp.to_time_point() : fork_db.root()->header.timestamp.to_time_point(); replaying = true; auto start_block_num = head->block_num + 1; auto start = fc::time_point::now();