Skip to content

Commit

Permalink
rpcdaemon: ensure chain configuration is valid (erigontech#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Sep 20, 2023
1 parent 427fd07 commit a04cfee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions silkworm/silkrpc/commands/debug_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <silkworm/core/common/util.hpp>
#include <silkworm/core/execution/address.hpp>
#include <silkworm/core/types/evmc_bytes32.hpp>
#include <silkworm/infra/common/ensure.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/node/db/tables.hpp>
#include <silkworm/node/db/util.hpp>
Expand Down Expand Up @@ -311,6 +312,7 @@ Task<void> DebugRpcApi::handle_debug_account_at(const nlohmann::json& request, n
SILK_DEBUG << "Block number: " << block_number << " #tnx: " << transactions.size();

auto chain_config_ptr = co_await chain_storage->read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");
auto this_executor = co_await boost::asio::this_coro::executor;

auto result = co_await boost::asio::async_compose<decltype(boost::asio::use_awaitable), void(nlohmann::json)>(
Expand Down
2 changes: 2 additions & 0 deletions silkworm/silkrpc/commands/ots_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Task<void> OtsRpcApi::handle_ots_get_block_details(const nlohmann::json& request
block_with_hash->block.transactions.size(), block_with_hash->block.ommers};
const auto receipts = co_await core::get_receipts(tx_database, *block_with_hash);
const auto chain_config = co_await chain_storage->read_chain_config();
ensure(chain_config.has_value(), "cannot read chain config");
const IssuanceDetails issuance = get_issuance(*chain_config, *block_with_hash);
const intx::uint256 total_fees = get_block_fees(*chain_config, *block_with_hash, receipts, block_number);
const BlockDetailsResponse block_details_response{block_details, issuance, total_fees};
Expand Down Expand Up @@ -167,6 +168,7 @@ Task<void> OtsRpcApi::handle_ots_get_block_details_by_hash(const nlohmann::json&
block_with_hash->block.transactions.size(), block_with_hash->block.ommers};
const auto receipts = co_await core::get_receipts(tx_database, *block_with_hash);
const auto chain_config = co_await chain_storage->read_chain_config();
ensure(chain_config.has_value(), "cannot read chain config");
const IssuanceDetails issuance = get_issuance(*chain_config, *block_with_hash);
const intx::uint256 total_fees = get_block_fees(*chain_config, *block_with_hash, receipts, block_number);
const BlockDetailsResponse block_details_response{block_details, issuance, total_fees};
Expand Down
2 changes: 2 additions & 0 deletions silkworm/silkrpc/core/call_many.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <evmone/instructions.hpp>
#include <intx/intx.hpp>

#include <silkworm/infra/common/ensure.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/silkrpc/common/clock_time.hpp>
#include <silkworm/silkrpc/common/util.hpp>
Expand Down Expand Up @@ -165,6 +166,7 @@ Task<CallManyResult> CallExecutor::execute(
}

const auto chain_config_ptr = co_await chain_storage->read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

const auto block_with_hash = co_await rpc::core::read_block_by_number_or_hash(block_cache_, *chain_storage, tx_database, context.block_number);
if (!block_with_hash) {
Expand Down
4 changes: 4 additions & 0 deletions silkworm/silkrpc/core/evm_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <silkworm/core/execution/address.hpp>
#include <silkworm/core/types/evmc_bytes32.hpp>
#include <silkworm/infra/common/ensure.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/silkrpc/common/util.hpp>
#include <silkworm/silkrpc/core/cached_chain.hpp>
Expand Down Expand Up @@ -365,6 +366,7 @@ Task<void> DebugExecutor::execute(json::Stream& stream, const ChainStorage& stor
SILK_DEBUG << "execute: block_number: " << block_number << " #txns: " << transactions.size() << " config: " << config_;

const auto chain_config_ptr = co_await storage.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");
auto current_executor = co_await boost::asio::this_coro::executor;

co_await boost::asio::async_compose<decltype(boost::asio::use_awaitable), void(void)>(
Expand Down Expand Up @@ -433,6 +435,7 @@ Task<void> DebugExecutor::execute(
<< " config: " << config_;

const auto chain_config_ptr = co_await storage.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");
auto current_executor = co_await boost::asio::this_coro::executor;

co_await boost::asio::async_compose<decltype(boost::asio::use_awaitable), void(void)>(
Expand Down Expand Up @@ -496,6 +499,7 @@ Task<void> DebugExecutor::execute(
<< " config: " << config_;

const auto chain_config_ptr = co_await storage.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;
co_await boost::asio::async_compose<decltype(boost::asio::use_awaitable), void(void)>(
Expand Down
10 changes: 10 additions & 0 deletions silkworm/silkrpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <silkworm/core/execution/address.hpp>
#include <silkworm/core/protocol/ethash_rule_set.hpp>
#include <silkworm/core/types/evmc_bytes32.hpp>
#include <silkworm/infra/common/ensure.hpp>
#include <silkworm/infra/common/log.hpp>
#include <silkworm/silkrpc/common/util.hpp>
#include <silkworm/silkrpc/core/cached_chain.hpp>
Expand Down Expand Up @@ -1189,6 +1190,7 @@ Task<std::vector<Trace>> TraceCallExecutor::trace_block(const BlockWithHash& blo
}

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");
const auto rule_set_factory = protocol::rule_set_factory(*chain_config_ptr);
const auto block_rewards = rule_set_factory->compute_reward(block_with_hash.block);

Expand Down Expand Up @@ -1246,6 +1248,7 @@ Task<std::vector<TraceCallResult>> TraceCallExecutor::trace_block_transactions(c
SILK_TRACE << "trace_block_transactions: block_number: " << std::dec << block_number << " #txns: " << transactions.size() << " config: " << config;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1323,6 +1326,7 @@ Task<TraceManyCallResult> TraceCallExecutor::trace_calls(const silkworm::Block&
<< " #trace_calls: " << calls.size();

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;
const auto ret_result = co_await boost::asio::async_compose<decltype(boost::asio::use_awaitable), void(TraceManyCallResult)>(
Expand Down Expand Up @@ -1391,6 +1395,7 @@ Task<TraceDeployResult> TraceCallExecutor::trace_deploy_transaction(const silkwo
SILK_TRACE << "trace_deploy_transaction: block_number: " << std::dec << block_number << " #txns: " << transactions.size();

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1463,6 +1468,7 @@ Task<TraceEntriesResult> TraceCallExecutor::trace_transaction_entries(const Tran
auto block_number = transaction_with_block.block_with_hash.block.header.number;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1495,6 +1501,7 @@ Task<std::string> TraceCallExecutor::trace_transaction_error(const TransactionWi
auto block_number = transaction_with_block.block_with_hash.block.header.number;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1528,6 +1535,7 @@ Task<TraceOperationsResult> TraceCallExecutor::trace_operations(const Transactio
auto block_number = transaction_with_block.block_with_hash.block.header.number;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1560,6 +1568,7 @@ Task<bool> TraceCallExecutor::trace_touch_transaction(const silkworm::Block& blo
auto block_number = block.header.number;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down Expand Up @@ -1659,6 +1668,7 @@ Task<TraceCallResult> TraceCallExecutor::execute(
<< " config: " << config;

const auto chain_config_ptr = co_await chain_storage_.read_chain_config();
ensure(chain_config_ptr.has_value(), "cannot read chain config");

auto current_executor = co_await boost::asio::this_coro::executor;

Expand Down

0 comments on commit a04cfee

Please sign in to comment.