Skip to content

Commit

Permalink
rpcdaemon: remove erigon_watchTheBurn (#2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Jun 18, 2024
1 parent d763a4c commit 2eb9405
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 160 deletions.
79 changes: 0 additions & 79 deletions silkworm/rpc/commands/erigon_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,85 +467,6 @@ Task<void> ErigonRpcApi::handle_erigon_forks(const nlohmann::json& request, nloh
co_return;
}

// https://eth.wiki/json-rpc/API#erigon_WatchTheBurn
Task<void> ErigonRpcApi::handle_erigon_watch_the_burn(const nlohmann::json& request, nlohmann::json& reply) {
const auto& params = request["params"];
if (params.size() != 1) {
auto error_msg = "invalid erigon_watchTheBurn params: " + params.dump();
SILK_ERROR << error_msg;
reply = make_json_error(request, 100, error_msg);
co_return;
}
const auto block_id = params[0].get<std::string>();
SILK_DEBUG << "block_id: " << block_id;

auto tx = co_await database_->begin();

try {
const auto chain_storage = tx->create_storage();

const auto chain_config{co_await chain_storage->read_chain_config()};
ensure(chain_config.has_value(), "cannot read chain config");
SILK_DEBUG << "chain config: " << *chain_config;

Issuance issuance{}; // default is empty: no PoW => no issuance
if (std::holds_alternative<protocol::EthashConfig>(chain_config->rule_set_config)) {
const auto block_number = co_await core::get_block_number(block_id, *tx);
const auto block_with_hash{co_await core::read_block_by_number(*block_cache_, *chain_storage, block_number)};
if (!block_with_hash) {
const std::string error_msg = "block not found ";
SILK_ERROR << "erigon_watch_the_burn: core::read_block_by_number: " << error_msg << request.dump();
reply = make_json_error(request, 100, error_msg);
co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}
const auto rule_set_factory = protocol::rule_set_factory(*chain_config);
const auto block_reward{rule_set_factory->compute_reward(block_with_hash->block)};
intx::uint256 total_ommer_reward = 0;
for (const auto ommer_reward : block_reward.ommers) {
total_ommer_reward += ommer_reward;
}
intx::uint256 block_issuance = block_reward.miner + total_ommer_reward;
issuance.block_reward = "0x" + intx::hex(block_reward.miner);
issuance.ommer_reward = "0x" + intx::hex(total_ommer_reward);
issuance.issuance = "0x" + intx::hex(block_issuance);
intx::uint256 burnt;
if (block_with_hash->block.header.base_fee_per_gas) {
burnt = *block_with_hash->block.header.base_fee_per_gas * block_with_hash->block.header.gas_used;
} else {
burnt = 0;
}
issuance.burnt = "0x" + intx::hex(burnt);

const auto total_issued = co_await core::rawdb::read_total_issued(*tx, block_number);
const auto total_burnt = co_await core::rawdb::read_total_burnt(*tx, block_number);

issuance.total_issued = "0x" + intx::hex(total_issued);
issuance.total_burnt = "0x" + intx::hex(total_burnt);
intx::uint256 tips = 0;
if (block_with_hash->block.header.base_fee_per_gas) {
const auto receipts{co_await core::get_receipts(*tx, *block_with_hash)};
const auto block{block_with_hash->block};
for (size_t i{0}; i < block.transactions.size(); i++) {
auto tip = block.transactions[i].effective_gas_price(block.header.base_fee_per_gas.value_or(0));
tips += tip * receipts[i].gas_used;
}
}
issuance.tips = "0x" + intx::hex(tips);
}
reply = make_json_content(request, issuance);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, 100, e.what());
} catch (...) {
SILK_ERROR << "unexpected exception processing request: " << request.dump();
reply = make_json_error(request, 100, "unexpected exception");
}

co_await tx->close(); // RAII not (yet) available with coroutines
co_return;
}

// https://eth.wiki/json-rpc/API#erigon_blockNumber
Task<void> ErigonRpcApi::handle_erigon_block_number(const nlohmann::json& request, nlohmann::json& reply) {
const auto& params = request["params"];
Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/commands/erigon_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ErigonRpcApi {
Task<void> handle_erigon_get_latest_logs(const nlohmann::json& request, nlohmann::json& reply);
Task<void> handle_erigon_get_logs_by_hash(const nlohmann::json& request, nlohmann::json& reply);
Task<void> handle_erigon_forks(const nlohmann::json& request, nlohmann::json& reply);
Task<void> handle_erigon_watch_the_burn(const nlohmann::json& request, nlohmann::json& reply);
Task<void> handle_erigon_node_info(const nlohmann::json& request, nlohmann::json& reply);

// GLAZE
Expand Down
23 changes: 0 additions & 23 deletions silkworm/rpc/commands/erigon_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class ErigonRpcApi_ForTest : public ErigonRpcApi {
Task<void> erigon_forks(const nlohmann::json& request, nlohmann::json& reply) {
co_return co_await ErigonRpcApi::handle_erigon_forks(request, reply);
}
Task<void> erigon_watch_the_burn(const nlohmann::json& request, nlohmann::json& reply) {
co_return co_await ErigonRpcApi::handle_erigon_watch_the_burn(request, reply);
}
Task<void> erigon_block_number(const nlohmann::json& request, nlohmann::json& reply) {
co_return co_await ErigonRpcApi::handle_erigon_block_number(request, reply);
}
Expand Down Expand Up @@ -204,26 +201,6 @@ TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_forks", "[rpc][e
}
}

TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_watch_the_burn", "[rpc][erigon_api]") {
nlohmann::json reply;

SECTION("request invalid params number") {
CHECK_NOTHROW(run<&ErigonRpcApi_ForTest::erigon_watch_the_burn>(
R"({
"jsonrpc":"2.0",
"id":1,
"method":"erigon_watchTheBurn",
"params":["0x49BDEF", "0x2"]
})"_json,
reply));
CHECK(reply == R"({
"jsonrpc":"2.0",
"id":1,
"error":{"code":100,"message":"invalid erigon_watchTheBurn params: [\"0x49BDEF\",\"0x2\"]"}
})"_json);
}
}

TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_block_number", "[rpc][erigon_api]") {
nlohmann::json reply;

Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/commands/rpc_api_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ void RpcApiTable::add_erigon_handlers() {
method_handlers_[json_rpc::method::k_erigon_getLatestLogs] = &commands::RpcApi::handle_erigon_get_latest_logs;
method_handlers_[json_rpc::method::k_erigon_getLogsByHash] = &commands::RpcApi::handle_erigon_get_logs_by_hash;
method_handlers_[json_rpc::method::k_erigon_forks] = &commands::RpcApi::handle_erigon_forks;
method_handlers_[json_rpc::method::k_erigon_watchTheBurn] = &commands::RpcApi::handle_erigon_watch_the_burn;
method_handlers_[json_rpc::method::k_erigon_nodeInfo] = &commands::RpcApi::handle_erigon_node_info;

// GLAZE methods
Expand Down
26 changes: 0 additions & 26 deletions silkworm/rpc/core/rawdb/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,4 @@ Task<evmc::bytes32> read_head_header_hash(ethdb::Transaction& tx) {
SILK_DEBUG << "head header hash: " << silkworm::to_hex(head_header_hash);
co_return head_header_hash;
}

Task<intx::uint256> read_total_issued(ethdb::Transaction& tx, BlockNum block_number) {
const auto block_key = silkworm::db::block_key(block_number);
const auto value = co_await tx.get_one(db::table::kIssuanceName, block_key);
intx::uint256 total_issued = 0;
if (!value.empty()) {
total_issued = std::stoul(silkworm::to_hex(value), nullptr, 16);
}
SILK_DEBUG << "rawdb::read_total_issued: " << total_issued;
co_return total_issued;
}

Task<intx::uint256> read_total_burnt(ethdb::Transaction& tx, BlockNum block_number) {
const auto block_key = silkworm::db::block_key(block_number);
const std::string kBurnt{"burnt"};
silkworm::Bytes key{kBurnt.begin(), kBurnt.end()};
key.append(block_key.begin(), block_key.end());
const auto value = co_await tx.get_one(db::table::kIssuanceName, key);
intx::uint256 total_burnt = 0;
if (!value.empty()) {
total_burnt = std::stoul(silkworm::to_hex(value), nullptr, 16);
}
SILK_DEBUG << "rawdb::read_total_burnt: " << total_burnt;
co_return total_burnt;
}

} // namespace silkworm::rpc::core::rawdb
4 changes: 0 additions & 4 deletions silkworm/rpc/core/rawdb/chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@ Task<intx::uint256> read_total_difficulty(ethdb::Transaction& tx, const evmc::by

Task<evmc::bytes32> read_head_header_hash(ethdb::Transaction& tx);

Task<intx::uint256> read_total_issued(ethdb::Transaction& tx, BlockNum block_number);

Task<intx::uint256> read_total_burnt(ethdb::Transaction& tx, BlockNum block_number);

} // namespace silkworm::rpc::core::rawdb
22 changes: 0 additions & 22 deletions silkworm/rpc/core/rawdb/chain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,4 @@ TEST_CASE("read_total_difficulty") {
}
}

TEST_CASE("read_total_issued") {
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
WorkerPool pool{1};
test::MockTransaction transaction;

const uint64_t block_number{20'000};
EXPECT_CALL(transaction, get_one(_, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return kTotalIssued; }));
auto result = boost::asio::co_spawn(pool, read_total_issued(transaction, block_number), boost::asio::use_future);
CHECK(result.get() == 7);
}

TEST_CASE("read_total_burnt") {
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
WorkerPool pool{1};
test::MockTransaction transaction;

const uint64_t block_number{20'000};
EXPECT_CALL(transaction, get_one(_, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return kTotalBurnt; }));
auto result = boost::asio::co_spawn(pool, read_total_burnt(transaction, block_number), boost::asio::use_future);
CHECK(result.get() == 5);
}

} // namespace silkworm::rpc::core::rawdb
4 changes: 0 additions & 4 deletions silkworm/rpc/storage/chain_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ class ChainStorage {
// Task<Transactions> read_canonical_transactions(uint64_t base_txn_id, uint64_t txn_count);

// Task<Transactions> read_noncanonical_transactions(uint64_t base_txn_id, uint64_t txn_count);

// Task<intx::uint256> read_total_issued(BlockNum block_number);

// Task<intx::uint256> read_total_burnt(BlockNum block_number);
};

} // namespace silkworm::rpc

0 comments on commit 2eb9405

Please sign in to comment.