Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaemon: add blob filed on receipt #2513

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set +e # Disable exit on error
cd "$1" || exit 1
rm -rf ./mainnet/results/

# eth_getBlockReceipts/test_07.json new blobFields
# debug_accountRange: new algo using TKV
# debug_storageRangeAt: new algo using TKV
# debug_traceCall/test_02.json: requested is_latest fix to support ethbackend
Expand Down Expand Up @@ -55,7 +54,6 @@ debug_traceTransaction/test_96.json,\
engine_,\
erigon_getBalanceChangesInBlock,\
erigon_getLatestLogs,\
eth_getBlockReceipts/test_07.json,\
eth_getLogs,\
ots_getTransactionBySenderAndNonce/test_04.json,\
ots_getTransactionBySenderAndNonce/test_07.json,\
Expand Down
8 changes: 8 additions & 0 deletions silkworm/rpc/core/receipts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Task<Receipts> get_receipts(db::kv::api::Transaction& tx, const silkworm::BlockW
}

auto& receipts = *raw_receipts;
auto& header = block_with_hash.block.header;

// Add derived fields to the receipts
auto& transactions = block_with_hash.block.transactions;
Expand All @@ -64,6 +65,13 @@ Task<Receipts> get_receipts(db::kv::api::Transaction& tx, const silkworm::BlockW
receipts[i].block_hash = block_hash;
receipts[i].block_number = block_number;

if (!transactions[i].blob_versioned_hashes.empty()) {
receipts[i].blob_gas_used = kGasPerBlob * transactions[i].blob_versioned_hashes.size();
if (header.excess_blob_gas) {
receipts[i].blob_gas_price = header.blob_gas_price();
}
}

// When tx receiver is not set, create a contract with address depending on tx sender and its nonce
if (!transactions[i].to.has_value()) {
receipts[i].contract_address = create_address(*transactions[i].sender(), transactions[i].nonce);
Expand Down
2 changes: 2 additions & 0 deletions silkworm/rpc/core/receipts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

namespace silkworm::rpc::core {

static constexpr int kGasPerBlob = 0x20000;

Task<Receipts> get_receipts(db::kv::api::Transaction& tx, const silkworm::BlockWithHash& block_with_hash, const db::chain::ChainStorage& chain_storage, WorkerPool& workers);

Task<std::optional<Receipts>> read_receipts(db::kv::api::Transaction& tx, BlockNum block_number);
Expand Down
7 changes: 7 additions & 0 deletions silkworm/rpc/json/receipt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void to_json(nlohmann::json& json, const Receipt& receipt) {
json["logs"] = receipt.logs;
json["logsBloom"] = "0x" + silkworm::to_hex(full_view(receipt.bloom));
json["status"] = to_quantity(receipt.success ? 1 : 0);

if (receipt.blob_gas_used) {
json["blobGasUsed"] = to_quantity(*(receipt.blob_gas_used));
}
if (receipt.blob_gas_price) {
json["blobGasPrice"] = to_quantity(*(receipt.blob_gas_price));
}
}

void from_json(const nlohmann::json& json, Receipt& receipt) {
Expand Down
2 changes: 2 additions & 0 deletions silkworm/rpc/types/receipt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct Receipt {
std::optional<evmc::address> to;
std::optional<uint8_t> type{std::nullopt}; // EIP-2718
intx::uint256 effective_gas_price{0};
std::optional<uint64_t> blob_gas_used{std::nullopt}; // EIP-4844
std::optional<intx::uint<256>> blob_gas_price{std::nullopt}; // EIP-4844
};

std::ostream& operator<<(std::ostream& out, const Receipt& r);
Expand Down
Loading