Skip to content

Commit

Permalink
statetest: Properly load blob transactions
Browse files Browse the repository at this point in the history
Handle JSON representation of blob transactions.
Also compute excess_data_gas for the current block.
  • Loading branch information
chfast authored and rodiazet committed Aug 23, 2023
1 parent d67f8a9 commit 75d4940
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,20 @@ state::BlockInfo from_json<state::BlockInfo>(const json::json& j)
block_hashes[from_json<int64_t>(j_num)] = from_json<hash256>(j_hash);
}

uint64_t excess_data_gas = 0;
if (const auto it = j.find("parentExcessDataGas"); it != j.end())
{
const auto parent_excess_data_gas = from_json<uint64_t>(*it);
const auto parent_data_gas_used = from_json<uint64_t>(j.at("parentDataGasUsed"));
static constexpr uint64_t TARGET_DATA_GAS_PER_BLOCK = 0x60000;
excess_data_gas =
std::max(parent_excess_data_gas + parent_data_gas_used, TARGET_DATA_GAS_PER_BLOCK) -
TARGET_DATA_GAS_PER_BLOCK;
}

return {from_json<int64_t>(j.at("currentNumber")), from_json<int64_t>(j.at("currentTimestamp")),
from_json<int64_t>(j.at("currentGasLimit")),
from_json<evmc::address>(j.at("currentCoinbase")), difficulty, base_fee,
from_json<evmc::address>(j.at("currentCoinbase")), difficulty, base_fee, excess_data_gas,
std::move(withdrawals), std::move(block_hashes)};
}

Expand Down Expand Up @@ -283,6 +294,13 @@ static void from_json_tx_common(const json::json& j, state::Transaction& o)
o.max_gas_price = from_json<intx::uint256>(j.at("maxFeePerGas"));
o.max_priority_gas_price = from_json<intx::uint256>(j.at("maxPriorityFeePerGas"));
}

if (const auto it = j.find("blobVersionedHashes"); it != j.end())
{
o.type = state::Transaction::Type::blob;
for (const auto& hash : *it)
o.blob_hashes.push_back(from_json<bytes32>(hash));
}
}

template <>
Expand Down

0 comments on commit 75d4940

Please sign in to comment.