diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 71b99a59a5..4e9c1439bc 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -483,7 +483,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(); @@ -821,7 +820,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); }); @@ -994,7 +996,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); @@ -2420,7 +2422,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) ) ) { @@ -3132,11 +3134,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 e49e1e9fa5..da6fe4c4d1 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -257,8 +257,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 5abe4e5305..9365e90a31 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()) {