Skip to content

Commit

Permalink
HeaderChain
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Sep 17, 2024
1 parent 2cb48ea commit 3230c06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions silkworm/sync/internals/header_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ HeaderChain::HeaderChain(protocol::RuleSetPtr rule_set, std::optional<intx::uint
}

RandomNumber random(100'000'000, 1'000'000'000);
request_id_prefix = random.generate_one();
SILK_TRACE << "HeaderChain: request id prefix=" << request_id_prefix;
request_id_prefix_ = random.generate_one();
SILK_TRACE << "HeaderChain: request id prefix=" << request_id_prefix_;
}

void HeaderChain::set_target_block(BlockNum target_block) {
Expand Down Expand Up @@ -1048,14 +1048,14 @@ void HeaderChain::set_preverified_hashes(PreverifiedHashes& ph) {
}

uint64_t HeaderChain::generate_request_id() {
request_count++;
if (request_count >= 10000) request_count = 0;
return request_id_prefix * 10000 + request_count;
request_count_++;
if (request_count_ >= 10000) request_count_ = 0;
return request_id_prefix_ * 10000 + request_count_;
}

uint64_t HeaderChain::is_valid_request_id(uint64_t request_id) const {
uint64_t prefix = request_id / 10000;
return request_id_prefix == prefix;
return request_id_prefix_ == prefix;
}

const DownloadStatistics& HeaderChain::statistics() const { return statistics_; }
Expand Down
4 changes: 2 additions & 2 deletions silkworm/sync/internals/header_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class HeaderChain {
uint64_t generate_request_id();
uint64_t is_valid_request_id(uint64_t request_id) const;

uint64_t request_id_prefix;
uint64_t request_count = 0;
uint64_t request_id_prefix_;
uint64_t request_count_ = 0;

DownloadStatistics statistics_;
std::string skeleton_condition_;
Expand Down

0 comments on commit 3230c06

Please sign in to comment.