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 committed Jun 26, 2023
1 parent 38a109e commit a0716b1
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 @@ -181,9 +181,20 @@ state::BlockInfo from_json<state::BlockInfo>(const json::json& j)
}
}

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)};
}

Expand Down Expand Up @@ -271,6 +282,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 a0716b1

Please sign in to comment.