Skip to content

Commit

Permalink
Merge pull request #390 from AntelopeIO/GH-290-expired-dedup-main
Browse files Browse the repository at this point in the history
[3.2 -> main] Clear expired transactions before snapshot and integrity hash
  • Loading branch information
heifner authored Oct 26, 2022
2 parents a472508 + 88a7d10 commit f03ac3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<chain_snapshot_header>([this]( auto &section ){
section.add_row(chain_snapshot_header(), db);
});
Expand Down Expand Up @@ -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<integrity_hash_snapshot_writer>(enc);
add_to_snapshot(hash_writer);
Expand Down Expand Up @@ -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<transaction_multi_index>();
const auto& dedupe_index = transaction_idx.indices().get<by_expiration>();
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) ) ) {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<account_name>& actors )const;
Expand Down
2 changes: 1 addition & 1 deletion unittests/snapshot_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace {
}

template <typename SNAPSHOT_SUITE>
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<SNAPSHOT_SUITE, variant_snapshot_suite> && lhs_integrity_hash.str() != rhs_integrity_hash.str()) {
Expand Down

0 comments on commit f03ac3c

Please sign in to comment.