Skip to content

Commit 8407996

Browse files
authored
rpcademon: remove erigon_cumulativeChainTraffic (#2109)
1 parent e3a5921 commit 8407996

File tree

9 files changed

+0
-177
lines changed

9 files changed

+0
-177
lines changed

silkworm/rpc/commands/erigon_api.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -579,41 +579,6 @@ Task<void> ErigonRpcApi::handle_erigon_block_number(const nlohmann::json& reques
579579
co_return;
580580
}
581581

582-
// https://eth.wiki/json-rpc/API#erigon_cumulativeChainTraffic
583-
Task<void> ErigonRpcApi::handle_erigon_cumulative_chain_traffic(const nlohmann::json& request, nlohmann::json& reply) {
584-
const auto& params = request["params"];
585-
if (params.size() != 1) {
586-
auto error_msg = "invalid erigon_cumulativeChainTraffic params: " + params.dump();
587-
SILK_ERROR << error_msg;
588-
reply = make_json_error(request, 100, error_msg);
589-
co_return;
590-
}
591-
const auto block_id = params[0].get<std::string>();
592-
593-
SILK_DEBUG << "block_id: " << block_id;
594-
595-
auto tx = co_await database_->begin();
596-
597-
ChainTraffic chain_traffic;
598-
599-
try {
600-
const auto block_number = co_await core::get_block_number(block_id, *tx);
601-
chain_traffic.cumulative_transactions_count = co_await core::rawdb::read_cumulative_transaction_count(*tx, block_number);
602-
chain_traffic.cumulative_gas_used = co_await core::rawdb::read_cumulative_gas_used(*tx, block_number);
603-
604-
reply = make_json_content(request, chain_traffic);
605-
} catch (const std::exception& e) {
606-
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
607-
reply = make_json_content(request, chain_traffic);
608-
} catch (...) {
609-
SILK_ERROR << "unexpected exception processing request: " << request.dump();
610-
reply = make_json_error(request, 100, "unexpected exception");
611-
}
612-
613-
co_await tx->close(); // RAII not (yet) available with coroutines
614-
co_return;
615-
}
616-
617582
// https://eth.wiki/json-rpc/API#erigon_nodeInfo
618583
Task<void> ErigonRpcApi::handle_erigon_node_info(const nlohmann::json& request, nlohmann::json& reply) {
619584
try {

silkworm/rpc/commands/erigon_api.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class ErigonRpcApi {
5858
Task<void> handle_erigon_get_logs_by_hash(const nlohmann::json& request, nlohmann::json& reply);
5959
Task<void> handle_erigon_forks(const nlohmann::json& request, nlohmann::json& reply);
6060
Task<void> handle_erigon_watch_the_burn(const nlohmann::json& request, nlohmann::json& reply);
61-
Task<void> handle_erigon_cumulative_chain_traffic(const nlohmann::json& request, nlohmann::json& reply);
6261
Task<void> handle_erigon_node_info(const nlohmann::json& request, nlohmann::json& reply);
6362

6463
// GLAZE

silkworm/rpc/commands/erigon_api_test.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class ErigonRpcApi_ForTest : public ErigonRpcApi {
5050
Task<void> erigon_block_number(const nlohmann::json& request, nlohmann::json& reply) {
5151
co_return co_await ErigonRpcApi::handle_erigon_block_number(request, reply);
5252
}
53-
Task<void> erigon_cumulative_chain_traffic(const nlohmann::json& request, nlohmann::json& reply) {
54-
co_return co_await ErigonRpcApi::handle_erigon_cumulative_chain_traffic(request, reply);
55-
}
5653
Task<void> erigon_node_info(const nlohmann::json& request, nlohmann::json& reply) {
5754
co_return co_await ErigonRpcApi::handle_erigon_node_info(request, reply);
5855
}
@@ -273,38 +270,6 @@ TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_block_number", "
273270
}
274271
}
275272

276-
TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_cumulative_chain_traffic", "[rpc][erigon_api]") {
277-
nlohmann::json reply;
278-
279-
SECTION("request invalid params number") {
280-
CHECK_NOTHROW(run<&ErigonRpcApi_ForTest::erigon_cumulative_chain_traffic>(
281-
R"({
282-
"jsonrpc":"2.0",
283-
"id":1,
284-
"method":"erigon_cumulativeChainTraffic",
285-
"params":[]
286-
})"_json,
287-
reply));
288-
CHECK(reply == R"({
289-
"jsonrpc":"2.0",
290-
"id":1,
291-
"error":{"code":100,"message":"invalid erigon_cumulativeChainTraffic params: []"}
292-
})"_json);
293-
}
294-
295-
SECTION("request block_number") {
296-
CHECK_THROWS_AS(run<&ErigonRpcApi_ForTest::erigon_cumulative_chain_traffic>(
297-
R"({
298-
"jsonrpc":"2.0",
299-
"id":1,
300-
"method":"erigon_cumulativeChainTraffic",
301-
"params":["100"]
302-
})"_json,
303-
reply),
304-
std::exception);
305-
}
306-
}
307-
308273
TEST_CASE_METHOD(ErigonRpcApiTest, "ErigonRpcApi::handle_erigon_node_info", "[rpc][erigon_api]") {
309274
nlohmann::json reply;
310275

silkworm/rpc/commands/rpc_api_table.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ void RpcApiTable::add_erigon_handlers() {
192192
method_handlers_[json_rpc::method::k_erigon_getLogsByHash] = &commands::RpcApi::handle_erigon_get_logs_by_hash;
193193
method_handlers_[json_rpc::method::k_erigon_forks] = &commands::RpcApi::handle_erigon_forks;
194194
method_handlers_[json_rpc::method::k_erigon_watchTheBurn] = &commands::RpcApi::handle_erigon_watch_the_burn;
195-
method_handlers_[json_rpc::method::k_erigon_cumulative_chain_traffic] = &commands::RpcApi::handle_erigon_cumulative_chain_traffic;
196195
method_handlers_[json_rpc::method::k_erigon_nodeInfo] = &commands::RpcApi::handle_erigon_node_info;
197196

198197
// GLAZE methods

silkworm/rpc/core/rawdb/chain.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
namespace silkworm::rpc::core::rawdb {
3535

3636
/* Local Routines */
37-
static Task<silkworm::Bytes> read_body_rlp(ethdb::Transaction& tx, const evmc::bytes32& block_hash, BlockNum block_number);
38-
3937
Task<uint64_t> read_header_number(ethdb::Transaction& tx, const evmc::bytes32& block_hash) {
4038
const silkworm::ByteView block_hash_bytes{block_hash.bytes, silkworm::kHashLength};
4139
const auto value{co_await tx.get_one(db::table::kHeaderNumbersName, block_hash_bytes)};
@@ -85,31 +83,6 @@ Task<evmc::bytes32> read_head_header_hash(ethdb::Transaction& tx) {
8583
co_return head_header_hash;
8684
}
8785

88-
Task<uint64_t> read_cumulative_transaction_count(ethdb::Transaction& tx, uint64_t block_number) {
89-
const auto block_hash = co_await read_canonical_block_hash(tx, block_number);
90-
const auto data = co_await read_body_rlp(tx, block_hash, block_number);
91-
if (data.empty()) {
92-
throw std::runtime_error{"empty block body RLP in read_body"};
93-
}
94-
SILK_TRACE << "RLP data for block body #" << block_number << ": " << silkworm::to_hex(data);
95-
96-
try {
97-
silkworm::ByteView data_view{data};
98-
auto stored_body{silkworm::unwrap_or_throw(silkworm::decode_stored_block_body(data_view))};
99-
// 1 system txn in the beginning of block, and 1 at the end
100-
SILK_DEBUG << "base_txn_id: " << stored_body.base_txn_id + 1 << " txn_count: " << stored_body.txn_count - 2;
101-
co_return stored_body.base_txn_id + stored_body.txn_count - 1;
102-
} catch (const silkworm::DecodingException& error) {
103-
SILK_ERROR << "RLP decoding error for block body #" << block_number << " [" << error.what() << "]";
104-
throw std::runtime_error{"RLP decoding error for block body [" + std::string(error.what()) + "]"};
105-
}
106-
}
107-
108-
Task<silkworm::Bytes> read_body_rlp(ethdb::Transaction& tx, const evmc::bytes32& block_hash, BlockNum block_number) {
109-
const auto block_key = silkworm::db::block_key(block_number, block_hash.bytes);
110-
co_return co_await tx.get_one(db::table::kBlockBodiesName, block_key);
111-
}
112-
11386
Task<intx::uint256> read_total_issued(ethdb::Transaction& tx, BlockNum block_number) {
11487
const auto block_key = silkworm::db::block_key(block_number);
11588
const auto value = co_await tx.get_one(db::table::kIssuanceName, block_key);
@@ -135,15 +108,4 @@ Task<intx::uint256> read_total_burnt(ethdb::Transaction& tx, BlockNum block_numb
135108
co_return total_burnt;
136109
}
137110

138-
Task<intx::uint256> read_cumulative_gas_used(ethdb::Transaction& tx, BlockNum block_number) {
139-
const auto block_key = silkworm::db::block_key(block_number);
140-
const auto value = co_await tx.get_one(db::table::kCumulativeGasIndexName, block_key);
141-
intx::uint256 cumulative_gas_index = 0;
142-
if (!value.empty()) {
143-
cumulative_gas_index = std::stoul(silkworm::to_hex(value), nullptr, 16);
144-
}
145-
SILK_DEBUG << "rawdb::read_cumulative_gas_used: " << cumulative_gas_index;
146-
co_return cumulative_gas_index;
147-
}
148-
149111
} // namespace silkworm::rpc::core::rawdb

silkworm/rpc/core/rawdb/chain.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ Task<intx::uint256> read_total_difficulty(ethdb::Transaction& tx, const evmc::by
4141

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

44-
Task<uint64_t> read_cumulative_transaction_count(ethdb::Transaction& tx, BlockNum block_number);
45-
4644
Task<intx::uint256> read_total_issued(ethdb::Transaction& tx, BlockNum block_number);
4745

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

50-
Task<intx::uint256> read_cumulative_gas_used(ethdb::Transaction& tx, BlockNum block_number);
51-
5248
} // namespace silkworm::rpc::core::rawdb

silkworm/rpc/core/rawdb/chain_test.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -153,43 +153,6 @@ TEST_CASE("read_total_difficulty") {
153153
}
154154
}
155155

156-
TEST_CASE("read_cumulative_transaction_count") {
157-
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
158-
SECTION("block found and matching") {
159-
WorkerPool pool{1};
160-
test::MockTransaction transaction;
161-
const uint64_t block_number{4'000'000};
162-
EXPECT_CALL(transaction, get_one(db::table::kCanonicalHashesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return *silkworm::from_hex("9816753229fc0736bf86a5048de4bc9fcdede8c91dadf88c828c76b2281dff"); }));
163-
EXPECT_CALL(transaction, get_one(db::table::kBlockBodiesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return kBody; }));
164-
auto result = boost::asio::co_spawn(pool, read_cumulative_transaction_count(transaction, block_number), boost::asio::use_future);
165-
CHECK(result.get() == 6939740);
166-
}
167-
168-
SECTION("block found empty") {
169-
WorkerPool pool{1};
170-
test::MockTransaction transaction;
171-
const uint64_t block_number{4'000'000};
172-
EXPECT_CALL(transaction, get_one(db::table::kCanonicalHashesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return *silkworm::from_hex("9816753229fc0736bf86a5048de4bc9fcdede8c91dadf88c828c76b2281dff"); }));
173-
EXPECT_CALL(transaction, get_one(db::table::kBlockBodiesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return silkworm::Bytes{}; }));
174-
auto result = boost::asio::co_spawn(pool, read_cumulative_transaction_count(transaction, block_number), boost::asio::use_future);
175-
#ifdef SILKWORM_SANITIZE // Avoid comparison against exception message: it triggers a TSAN data race seemingly related to libstdc++ string implementation
176-
CHECK_THROWS_AS(result.get(), std::runtime_error);
177-
#else
178-
CHECK_THROWS_MATCHES(result.get(), std::runtime_error, Message("empty block body RLP in read_body"));
179-
#endif // SILKWORM_SANITIZE
180-
}
181-
182-
SECTION("block invalid") {
183-
WorkerPool pool{1};
184-
test::MockTransaction transaction;
185-
const uint64_t block_number{4'000'000};
186-
EXPECT_CALL(transaction, get_one(db::table::kCanonicalHashesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return *silkworm::from_hex("9816753229fc0736bf86a5048de4bc9fcdede8c91dadf88c828c76b2281dff"); }));
187-
EXPECT_CALL(transaction, get_one(db::table::kBlockBodiesName, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return silkworm::Bytes{0x00, 0x01}; }));
188-
auto result = boost::asio::co_spawn(pool, read_cumulative_transaction_count(transaction, block_number), boost::asio::use_future);
189-
CHECK_THROWS_AS(result.get(), std::runtime_error);
190-
}
191-
}
192-
193156
TEST_CASE("read_total_issued") {
194157
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
195158
WorkerPool pool{1};
@@ -212,27 +175,4 @@ TEST_CASE("read_total_burnt") {
212175
CHECK(result.get() == 5);
213176
}
214177

215-
TEST_CASE("read_cumulative_gas_used") {
216-
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
217-
SECTION("read_cumulative_gas_used") {
218-
WorkerPool pool{1};
219-
test::MockTransaction transaction;
220-
221-
const uint64_t block_number{20'000};
222-
EXPECT_CALL(transaction, get_one(_, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return kCumulativeGasUsed; }));
223-
auto result = boost::asio::co_spawn(pool, read_cumulative_gas_used(transaction, block_number), boost::asio::use_future);
224-
CHECK(result.get() == 0x236);
225-
}
226-
227-
SECTION("read_cumulative_gas_used get_one return empty") {
228-
WorkerPool pool{1};
229-
test::MockTransaction transaction;
230-
231-
const uint64_t block_number{20'000};
232-
EXPECT_CALL(transaction, get_one(_, _)).WillOnce(InvokeWithoutArgs([]() -> Task<silkworm::Bytes> { co_return silkworm::Bytes{}; }));
233-
auto result = boost::asio::co_spawn(pool, read_cumulative_gas_used(transaction, block_number), boost::asio::use_future);
234-
CHECK(result.get() == 0);
235-
}
236-
}
237-
238178
} // namespace silkworm::rpc::core::rawdb

silkworm/rpc/json_rpc/methods.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ inline constexpr const char* k_erigon_getLatestLogs{"erigon_getLatestLogs"};
121121
inline constexpr const char* k_erigon_getLogsByHash{"erigon_getLogsByHash"};
122122
inline constexpr const char* k_erigon_forks{"erigon_forks"};
123123
inline constexpr const char* k_erigon_watchTheBurn{"erigon_watchTheBurn"};
124-
inline constexpr const char* k_erigon_cumulative_chain_traffic{"erigon_cumulativeChainTraffic"};
125124
inline constexpr const char* k_erigon_nodeInfo{"erigon_nodeInfo"};
126125

127126
inline constexpr const char* k_parity_getBlockReceipts{"parity_getBlockReceipts"};

silkworm/rpc/storage/chain_storage.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ class ChainStorage {
115115
// Task<intx::uint256> read_total_issued(BlockNum block_number);
116116

117117
// Task<intx::uint256> read_total_burnt(BlockNum block_number);
118-
119-
// Task<intx::uint256> read_cumulative_gas_used(BlockNum block_number);
120118
};
121119

122120
} // namespace silkworm::rpc

0 commit comments

Comments
 (0)