Skip to content

Commit

Permalink
rpcdaemon: add blob gas fields on tx (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Sep 4, 2024
1 parent cc1d382 commit be6aba0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.45.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v0.46.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt
Expand Down
12 changes: 11 additions & 1 deletion silkworm/rpc/json/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,20 @@ void make_glaze_json_transaction(const silkworm::Transaction& tx, GlazeJsonTrans
} else {
rpc::to_quantity(std::span(json_tx.v), silkworm::endian::to_big_compact(tx.v()));
}
if (tx.type == silkworm::TransactionType::kDynamicFee) {
if (tx.type == silkworm::TransactionType::kDynamicFee ||
tx.type == silkworm::TransactionType::kBlob) {
json_tx.max_pri_fee_per_gas = std::make_optional(rpc::to_quantity(tx.max_priority_fee_per_gas));
json_tx.max_fee_per_gas = std::make_optional(rpc::to_quantity(tx.max_fee_per_gas));
}
if (tx.type == silkworm::TransactionType::kBlob) {
json_tx.max_fee_per_blob_gas = std::make_optional(rpc::to_quantity(tx.max_fee_per_blob_gas));
std::vector<std::string> hashes;
for (const auto& curr_hash : tx.blob_versioned_hashes) {
auto hash = silkworm::to_hex(curr_hash.bytes, /* with_prefix = */ true);
hashes.push_back(hash);
}
json_tx.blob_versioned_hashes = std::make_optional(hashes);
}
to_quantity(std::span(json_tx.value), tx.value);
to_quantity(std::span(json_tx.r), silkworm::endian::to_big_compact(tx.r));
to_quantity(std::span(json_tx.s), silkworm::endian::to_big_compact(tx.s));
Expand Down
6 changes: 5 additions & 1 deletion silkworm/rpc/json/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ struct GlazeJsonTransaction {
std::optional<std::string> chain_id;
std::optional<std::string> max_fee_per_gas;
std::optional<std::string> max_pri_fee_per_gas;
std::optional<std::vector<GlazeJsonAccessList>> access_list;
std::optional<std::string> max_fee_per_blob_gas;
std::optional<std::string> to;
std::optional<std::monostate> nullto;
std::optional<std::vector<GlazeJsonAccessList>> access_list;
std::optional<std::vector<std::string>> blob_versioned_hashes;

struct glaze {
using T = GlazeJsonTransaction;
Expand All @@ -68,6 +70,8 @@ struct GlazeJsonTransaction {
"chainId", &T::chain_id,
"maxPriorityFeePerGas", &T::max_pri_fee_per_gas,
"maxFeePerGas", &T::max_fee_per_gas,
"maxFeePerBlobGas", &T::max_fee_per_blob_gas,
"blobVersionedHashes", &T::blob_versioned_hashes,
"accessList", &T::access_list,
"to", &T::to,
"to", &T::nullto,
Expand Down
10 changes: 10 additions & 0 deletions silkworm/rpc/json/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ void to_json(nlohmann::json& json, const BlockTransactionsResponse& b) {
json["fullblock"]["withdrawals"] = *(b.withdrawals);
}

if (b.header.blob_gas_used) {
json["fullblock"]["blobGasUsed"] = rpc::to_quantity(*b.header.blob_gas_used);
}
if (b.header.excess_blob_gas) {
json["fullblock"]["excessBlobGas"] = rpc::to_quantity(*b.header.excess_blob_gas);
}
if (b.header.parent_beacon_block_root) {
json["fullblock"]["parentBeaconBlockRoot"] = silkworm::to_hex(*b.header.parent_beacon_block_root, /* with_prefix = */ true);
}

json["fullblock"]["transactions"] = b.transactions;
for (std::size_t i{0}; i < json["fullblock"]["transactions"].size(); i++) {
auto& json_txn = json["fullblock"]["transactions"][i];
Expand Down

0 comments on commit be6aba0

Please sign in to comment.