diff --git a/silkworm/rpc/commands/erigon_api.cpp b/silkworm/rpc/commands/erigon_api.cpp index cc2f31f3da..855b29011a 100644 --- a/silkworm/rpc/commands/erigon_api.cpp +++ b/silkworm/rpc/commands/erigon_api.cpp @@ -167,7 +167,7 @@ Task ErigonRpcApi::handle_erigon_get_block_by_timestamp(const nlohmann::js 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_get_block_by_timestamè: core::read_block_by_number: " << error_msg << request.dump(); + SILK_ERROR << "erigon_get_block_by_timestamp: core::read_block_by_number: " << error_msg << request.dump(); make_glaze_json_error(request, 100, error_msg, reply); co_await tx->close(); // RAII not (yet) available with coroutines co_return; @@ -259,7 +259,8 @@ Task ErigonRpcApi::handle_erigon_get_header_by_hash(const nlohmann::json& const auto header{co_await chain_storage->read_header(block_hash)}; if (!header) { - reply = make_json_error(request, 100, "block not found"); + auto error_msg = "block header not found: 0x" + silkworm::to_hex(block_hash); + reply = make_json_error(request, -32000, error_msg); } else { reply = make_json_content(request, *header); } @@ -305,7 +306,8 @@ Task ErigonRpcApi::handle_erigon_get_header_by_number(const nlohmann::json const auto header{co_await chain_storage->read_canonical_header(block_number)}; if (!header) { - reply = make_json_error(request, 100, "block not found"); + const auto error_msg = "block header not found: " + std::to_string(block_number); + reply = make_json_error(request, -32000, error_msg); } else { reply = make_json_content(request, *header); } diff --git a/silkworm/rpc/json/types.cpp b/silkworm/rpc/json/types.cpp index 700f966a47..796c78558a 100644 --- a/silkworm/rpc/json/types.cpp +++ b/silkworm/rpc/json/types.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace silkworm::rpc { @@ -226,7 +227,21 @@ void to_json(nlohmann::json& json, const BlockHeader& header) { } else { json["baseFeePerGas"] = nullptr; } - json["withdrawalsRoot"] = nullptr; // waiting EIP-4895 + if (rpc::compatibility::is_erigon_json_api_compatibility_required()) { + json["AuRaSeal"] = nullptr; + json["AuRaStep"] = 0; + json["Verkle"] = false; + json["VerkleKeyVals"] = nullptr; + json["VerkleProof"] = nullptr; + } + json["blobGasUsed"] = nullptr; + json["excessBlobGas"] = nullptr; + json["parentBeaconBlockRoot"] = nullptr; + if (header.withdrawals_root) { + json["withdrawalsRoot"] = *header.withdrawals_root; + } else { + json["withdrawalsRoot"] = nullptr; + } } } // namespace silkworm diff --git a/silkworm/rpc/json/types_test.cpp b/silkworm/rpc/json/types_test.cpp index 87aadcf42c..793869d87e 100644 --- a/silkworm/rpc/json/types_test.cpp +++ b/silkworm/rpc/json/types_test.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace silkworm::rpc { @@ -162,6 +163,7 @@ TEST_CASE("serialize non-empty bytes32", "[rpc][to_json]") { TEST_CASE("serialize empty block header", "[rpc][to_json]") { silkworm::BlockHeader header{}; + rpc::compatibility::set_erigon_json_api_compatibility_required(true); nlohmann::json j = header; CHECK(j == R"({ "baseFeePerGas":null, @@ -187,11 +189,20 @@ TEST_CASE("serialize empty block header", "[rpc][to_json]") { "timestamp":"0x0", "extraData":"0x", "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000", - "withdrawalsRoot":null + "withdrawalsRoot":null, + "AuRaSeal":null, + "AuRaStep":0, + "Verkle":false, + "VerkleKeyVals":null, + "VerkleProof":null, + "blobGasUsed":null, + "excessBlobGas": null, + "parentBeaconBlockRoot": null })"_json); } TEST_CASE("serialize block header", "[rpc][to_json]") { + rpc::compatibility::set_erigon_json_api_compatibility_required(true); silkworm::BlockHeader header{ 0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c_bytes32, 0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d_bytes32, @@ -233,11 +244,20 @@ TEST_CASE("serialize block header", "[rpc][to_json]") { "extraData":"0x0001ff0100", "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000001", "nonce":"0x00000000000000ff", - "withdrawalsRoot":null + "withdrawalsRoot":null, + "AuRaSeal":null, + "AuRaStep":0, + "Verkle":false, + "VerkleKeyVals":null, + "VerkleProof":null, + "blobGasUsed":null, + "excessBlobGas": null, + "parentBeaconBlockRoot": null })"_json); } TEST_CASE("serialize block header with baseFeePerGas", "[rpc][to_json]") { + rpc::compatibility::set_erigon_json_api_compatibility_required(true); silkworm::BlockHeader header{ 0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c_bytes32, 0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d_bytes32, @@ -282,7 +302,15 @@ TEST_CASE("serialize block header with baseFeePerGas", "[rpc][to_json]") { "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000001", "nonce":"0x0102030405060708", "baseFeePerGas":"0x3e8", - "withdrawalsRoot":null + "withdrawalsRoot":null, + "AuRaSeal":null, + "AuRaStep":0, + "Verkle":false, + "VerkleKeyVals":null, + "VerkleProof":null, + "blobGasUsed":null, + "excessBlobGas": null, + "parentBeaconBlockRoot": null })"_json); }