From 093b8e63c58edebf46dac8015419ef51e3fce70b Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Thu, 27 Jul 2023 18:33:28 +0200 Subject: [PATCH] rpcdaemon: adapt some erigon API to snapshots (#1369) --- silkworm/silkrpc/commands/erigon_api.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/silkworm/silkrpc/commands/erigon_api.cpp b/silkworm/silkrpc/commands/erigon_api.cpp index faca39eb7a..d257a864ab 100644 --- a/silkworm/silkrpc/commands/erigon_api.cpp +++ b/silkworm/silkrpc/commands/erigon_api.cpp @@ -120,10 +120,11 @@ awaitable ErigonRpcApi::handle_erigon_get_header_by_hash(const nlohmann::j try { ethdb::TransactionDatabase tx_database{*tx}; + const auto chain_storage = tx->create_storage(tx_database, backend_); - const auto header{co_await core::rawdb::read_header_by_hash(tx_database, block_hash)}; + const auto header{co_await chain_storage->read_header(block_hash)}; - reply = make_json_content(request["id"], header); + reply = make_json_content(request["id"], *header); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request["id"], 100, e.what()); @@ -160,11 +161,13 @@ awaitable ErigonRpcApi::handle_erigon_get_header_by_number(const nlohmann: try { ethdb::TransactionDatabase tx_database{*tx}; + const auto chain_storage = tx->create_storage(tx_database, backend_); const auto block_number = co_await core::get_block_number(block_id, tx_database); - const auto header{co_await core::rawdb::read_header_by_number(tx_database, block_number)}; + const auto block_hash = co_await chain_storage->read_canonical_hash(block_number); + const auto header{co_await chain_storage->read_header(block_number, *block_hash)}; - reply = make_json_content(request["id"], header); + reply = make_json_content(request["id"], *header); } catch (const std::exception& e) { SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump(); reply = make_json_error(request["id"], 100, e.what());