Skip to content

Commit

Permalink
node: fix some snapshot issues (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mriccobene authored Jun 30, 2023
1 parent ebfa8ad commit 3e49f52
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions silkworm/node/bittorrent/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ bool BitTorrentClient::handle_alert(const lt::alert* alert) {
if (const auto sta = lt::alert_cast<lt::state_update_alert>(alert)) {
if (!sta->status.empty()) {
for (const auto& ts : sta->status) {
SILK_DEBUG << "Torrent: " << ts.name << " id: " << ts.handle.id() << " state: " << magic_enum::enum_name(ts.state) << " "
<< (ts.download_payload_rate / 1'000'000) << " MB/s " << (ts.total_done / 1'000'000) << " MB ("
<< (ts.progress_ppm / 10'000) << "%) downloaded (" << ts.num_peers << " peers)";
SILK_INFO << "Torrent: " << ts.name << " id: " << ts.handle.id() << " state: " << magic_enum::enum_name(ts.state) << " "
<< (ts.download_payload_rate / 1'000'000) << " MB/s " << (ts.total_done / 1'000'000) << " MB ("
<< (ts.progress_ppm / 10'000) << "%) downloaded (" << ts.num_peers << " peers)";
}
} else {
SILK_DEBUG << "Empty state update alert:" << sta->message();
Expand Down
4 changes: 3 additions & 1 deletion silkworm/node/db/access_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ BlockNum DataModel::highest_block_number() const {
const auto header_cursor{txn_.ro_cursor(db::table::kHeaders)};
const auto data{header_cursor->to_last(/*.throw_not_found*/ false)};
if (data.done && data.key.size() >= sizeof(uint64_t)) {
return endian::load_big_u64(static_cast<const unsigned char*>(data.key.data()));
ByteView key = from_slice(data.key);
ByteView block_num = key.substr(0, sizeof(BlockNum));
return endian::load_big_u64(block_num.data());
}

// If none is found on db, then ask the snapshot repository (if any) for highest block
Expand Down
1 change: 1 addition & 0 deletions silkworm/node/db/eth_status_data_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ EthStatusDataProvider::HeadInfo EthStatusDataProvider::read_head_info(ROTxn& db_
head_info.hash = head_hash.value();
} else {
log::Warning("EthStatusDataProvider") << "canonical hash at height " << std::to_string(head_height) << " not found in db";
return head_info;
}

auto head_total_difficulty = db::read_total_difficulty(db_tx_, head_height, *head_hash);
Expand Down
4 changes: 3 additions & 1 deletion silkworm/node/snapshot/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,16 @@ void SnapshotSync::update_block_headers(db::RWTxn& txn, BlockNum max_block_avail
repository_->for_each_header([&](const BlockHeader* header) -> bool {
log::Debug() << "[Snapshots] Header number: " << header->number << " hash: " << to_hex(header->hash());
const auto block_number = header->number;
if (block_number > max_block_available) return true;

const auto block_hash = header->hash();

// Write block header into kDifficulty table
total_difficulty += header->difficulty;
db::write_total_difficulty(txn, block_number, block_hash, total_difficulty);

// Write block header into kCanonicalHashes table
// db::write_canonical_hash(txn, block_number, block_hash);
db::write_canonical_hash(txn, block_number, block_hash);

// Collect entries for later loading kHeaderNumbers table
Bytes encoded_block_number{sizeof(uint64_t), '\0'};
Expand Down

0 comments on commit 3e49f52

Please sign in to comment.