Skip to content

Commit

Permalink
Migrate to blobGas in execution-spec-tests (hyperledger#5745)
Browse files Browse the repository at this point in the history
Execution-spec-tests migrated from DataGas to BlobGas and checks for its
inclusion in tests now. Add needed support.

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Aug 2, 2023
1 parent 5f47188 commit ec6a6b1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

public class T8nExecutor {

record RejectedTransaction(int index, String error) {}
public record RejectedTransaction(int index, String error) {}

protected static List<Transaction> extractTransactions(
final PrintWriter out,
Expand Down Expand Up @@ -128,9 +128,9 @@ protected static List<Transaction> extractTransactions(
if (txNode.has("maxFeePerGas")) {
builder.maxFeePerGas(Wei.fromHexString(txNode.get("maxFeePerGas").textValue()));
}
if (txNode.has("maxFeePerDataGas")) {
if (txNode.has("maxFeePerBlobGas")) {
builder.maxFeePerDataGas(
Wei.fromHexString(txNode.get("maxFeePerDataGas").textValue()));
Wei.fromHexString(txNode.get("maxFeePerBlobGas").textValue()));
}

if (txNode.has("to")) {
Expand Down Expand Up @@ -251,8 +251,10 @@ static T8nResult runTest(
final MainnetTransactionProcessor processor = protocolSpec.getTransactionProcessor();
final WorldUpdater worldStateUpdater = worldState.updater();
final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber());
// Todo: EIP-4844 use the excessDataGas of the parent instead of DataGas.ZERO
final Wei dataGasPrice = protocolSpec.getFeeMarket().dataPricePerGas(DataGas.ZERO);
final Wei blobGasPrice =
protocolSpec
.getFeeMarket()
.dataPricePerGas(blockHeader.getExcessDataGas().orElse(DataGas.ZERO));

List<TransactionReceipt> receipts = new ArrayList<>();
List<RejectedTransaction> invalidTransactions = new ArrayList<>(rejections);
Expand All @@ -279,7 +281,7 @@ static T8nResult runTest(
false,
TransactionValidationParams.processingBlock(),
tracer,
dataGasPrice);
blobGasPrice);
tracerManager.disposeTracer(tracer);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -391,7 +393,7 @@ static T8nResult runTest(

resultObject.put(
"currentDifficulty",
blockHeader.getDifficultyBytes().trimLeadingZeros().size() > 0
!blockHeader.getDifficultyBytes().trimLeadingZeros().isEmpty()
? blockHeader.getDifficultyBytes().toShortHexString()
: null);
resultObject.put("gasUsed", Bytes.ofUnsignedLong(gasUsed).toQuantityHexString());
Expand All @@ -401,6 +403,17 @@ static T8nResult runTest(
blockHeader
.getWithdrawalsRoot()
.ifPresent(wr -> resultObject.put("withdrawalsRoot", wr.toHexString()));
blockHeader
.getDataGasUsed()
.ifPresentOrElse(
bgu -> resultObject.put("blobGasUsed", Bytes.ofUnsignedLong(bgu).toQuantityHexString()),
() ->
blockHeader
.getExcessDataGas()
.ifPresent(ebg -> resultObject.put("blobGasUsed", "0x0")));
blockHeader
.getExcessDataGas()
.ifPresent(ebg -> resultObject.put("currentExcessBlobGas", ebg.toShortHexString()));

ObjectNode allocObject = objectMapper.createObjectNode();
worldState
Expand All @@ -411,7 +424,7 @@ static T8nResult runTest(
ObjectNode accountObject =
allocObject.putObject(
account.getAddress().map(Address::toHexString).orElse("0x"));
if (account.getCode() != null && account.getCode().size() > 0) {
if (account.getCode() != null && !account.getCode().isEmpty()) {
accountObject.put("code", account.getCode().toHexString());
}
NavigableMap<Bytes32, AccountStorageEntry> storageEntries =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.hyperledger.besu.evmtool.T8nExecutor.RejectedTransaction;
import org.hyperledger.besu.util.LogConfigurator;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -168,8 +170,16 @@ public void disposeTracer(final OperationTracer tracer) {
req.response().setStatusCode(500).end(e.getMessage());
}
} catch (Throwable t) {
t.printStackTrace();
throw t;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8);
t.printStackTrace(ps);
ObjectNode json = objectMapper.createObjectNode();
json.put("error", t.getMessage());
json.put("stacktrace", baos.toString(StandardCharsets.UTF_8));

t.printStackTrace(System.out);

req.response().setStatusCode(500).end(json.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"ommers": [],
"withdrawals": [],
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"parentDataGasUsed": "0",
"parentExcessDataGas": "0"
"parentBlobGasUsed": "0",
"parentExcessBlobGas": "0"
}
},
"stdout": {
Expand Down Expand Up @@ -108,7 +108,9 @@
"currentDifficulty": null,
"gasUsed": "0x127bb",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x0",
"currentExcessBlobGas": "0x0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,54 @@
"ommers": [],
"withdrawals": [],
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"parentDataGasUsed": "0",
"parentExcessDataGas": "0"
"parentBlobGasUsed": "0",
"parentExcessBlobGas": "0"
}
},
"stdout": {
"alloc" : {
"0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
"code" : "0x3060005530ff00",
"storage" : {
"0x0000000000000000000000000000000000000000000000000000000000000000" : "0x000000000000000000000000095e7baea6a6c7c4c2dfeb977efac326af552d87"
"alloc": {
"0x095e7baea6a6c7c4c2dfeb977efac326af552d87": {
"code": "0x3060005530ff00",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x000000000000000000000000095e7baea6a6c7c4c2dfeb977efac326af552d87"
},
"balance" : "0xde0b6b3a76586a0"
"balance": "0xde0b6b3a76586a0"
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" : {
"balance" : "0x233c1"
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"balance": "0x233c1"
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
"balance" : "0xde0b6b3a75b2232",
"nonce" : "0x1"
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0xde0b6b3a75b2232",
"nonce": "0x1"
}
},
"body" : "0xf865f863800a830f424094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a0801ca07bb4986663aec020c016ea3db37ba36e62e9c7d355dc8ed8566b20ce7452b600a07da62397d8a969f674442837f419001f2671df0f19a45586ed3acfd93e819d82",
"result" : {
"stateRoot" : "0xddd3a541e86e2dd0293959736de63e1fad74ae95149f34740b1173378e82527a",
"txRoot" : "0x0cbd46498d79551ba2f4237443d408194f7493f1fd567dbeaf1d53b41b41485a",
"receiptsRoot" : "0xbc67bed8ee77b1d9dd8eb6d6e55abd11e49c50e16832f0c350ae07027c859f19",
"logsHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"receipts" : [
"body": "0xf865f863800a830f424094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a0801ca07bb4986663aec020c016ea3db37ba36e62e9c7d355dc8ed8566b20ce7452b600a07da62397d8a969f674442837f419001f2671df0f19a45586ed3acfd93e819d82",
"result": {
"stateRoot": "0xddd3a541e86e2dd0293959736de63e1fad74ae95149f34740b1173378e82527a",
"txRoot": "0x0cbd46498d79551ba2f4237443d408194f7493f1fd567dbeaf1d53b41b41485a",
"receiptsRoot": "0xbc67bed8ee77b1d9dd8eb6d6e55abd11e49c50e16832f0c350ae07027c859f19",
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"receipts": [
{
"root" : "0x",
"status" : "0x1",
"cumulativeGasUsed" : "0xbbeb",
"logsBloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"logs" : null,
"transactionHash" : "0xa87c1a093fe07f3d38db9cde21d05b407f527e88f7c698c9008b6138119d2487",
"contractAddress" : "0x0000000000000000000000000000000000000000",
"gasUsed" : "0xbbeb",
"blockHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionIndex" : "0x0"
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0xbbeb",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"logs": null,
"transactionHash": "0xa87c1a093fe07f3d38db9cde21d05b407f527e88f7c698c9008b6138119d2487",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0xbbeb",
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionIndex": "0x0"
}
],
"currentDifficulty" : null,
"gasUsed" : "0xbbeb",
"currentBaseFee" : "0x7",
"withdrawalsRoot" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
"currentDifficulty": null,
"gasUsed": "0xbbeb",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x0",
"currentExcessBlobGas": "0x0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"ommers": [],
"withdrawals": [],
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"parentDataGasUsed": "0",
"parentExcessDataGas": "0"
"parentBlobGasUsed": "0",
"parentExcessBlobGas": "0"
}
},
"stdout": {
Expand Down Expand Up @@ -92,7 +92,9 @@
"currentDifficulty": null,
"gasUsed": "0x181c6",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x0",
"currentExcessBlobGas": "0x0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"input": "0x",
"to": "0x0000000000000000000000000000000000000100",
"accessList": [],
"maxFeePerDataGas": "0x1",
"maxFeePerBlobGas": "0x1",
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"blobVersionedHashes": [
"0x0100000000000000000000000000000000000000000000000000000000000000"
Expand Down Expand Up @@ -65,8 +65,8 @@
"ommers": [],
"withdrawals": [],
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"currentExcessDataGas": "0",
"currentDataGasUsed": "0"
"currentExcessBlobGas": "0",
"currentBlobGasUsed": "0"
}
},
"stdout": {
Expand Down Expand Up @@ -109,7 +109,9 @@
"currentDifficulty": null,
"gasUsed": "0x5208",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"blobGasUsed": "0x0",
"currentExcessBlobGas": "0x0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.DataGas;
import org.hyperledger.besu.datatypes.GWei;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -77,9 +78,11 @@ Withdrawal asWithdrawal() {

private final Map<Long, Hash> blockHashes;

private final String parentExcessDataGas;
private final String parentExcessBlobGas;

private final String parentDataGasUsed;
private final String parentBlobGasUsed;

private final Hash beaconRoot;

/**
* Public constructor.
Expand Down Expand Up @@ -111,10 +114,11 @@ public ReferenceTestEnv(
@JsonProperty("parentUncleHash") final String _parentUncleHash,
@JsonProperty("withdrawals") final List<EnvWithdrawal> withdrawals,
@JsonProperty("blockHashes") final Map<String, String> blockHashes,
@JsonProperty("currentExcessDataGas") final String currentExcessDataGas,
@JsonProperty("currentDataGasUsed") final String currentDataGasUsed,
@JsonProperty("parentExcessDataGas") final String parentExcessDataGas,
@JsonProperty("parentDataGasUsed") final String parentDataGasUsed) {
@JsonProperty("currentExcessBlobGas") final String currentExcessBlobGas,
@JsonProperty("currentBlobGasUsed") final String currentBlobGasUsed,
@JsonProperty("parentExcessBlobGas") final String parentExcessBlobGas,
@JsonProperty("parentBlobGasUsed") final String parentBlobGasUsed,
@JsonProperty("beaconRoot") final String beaconRoot) {
super(
generateTestBlockHash(previousHash, number),
Hash.EMPTY_LIST_HASH, // ommersHash
Expand All @@ -133,17 +137,17 @@ public ReferenceTestEnv(
Optional.ofNullable(random).map(Difficulty::fromHexString).orElse(Difficulty.ZERO),
0L,
null, // withdrawalsRoot
null, // dataGasUsed
null, // excessDataGas
currentBlobGasUsed == null ? null : Long.decode(currentBlobGasUsed),
currentExcessBlobGas == null ? null : DataGas.fromHexString(currentExcessBlobGas),
null, // depositsRoot
new MainnetBlockHeaderFunctions());
this.parentDifficulty = parentDifficulty;
this.parentBaseFee = parentBaseFee;
this.parentGasUsed = parentGasUsed;
this.parentGasLimit = parentGasLimit;
this.parentTimestamp = parentTimestamp;
this.parentExcessDataGas = parentExcessDataGas;
this.parentDataGasUsed = parentDataGasUsed;
this.parentExcessBlobGas = parentExcessBlobGas;
this.parentBlobGasUsed = parentBlobGasUsed;
this.withdrawals =
withdrawals == null
? List.of()
Expand All @@ -157,6 +161,7 @@ public ReferenceTestEnv(
Map.entry(
Long.decode(entry.getKey()), Hash.fromHexString(entry.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
this.beaconRoot = beaconRoot == null ? null : Hash.fromHexString(beaconRoot);
}

@Override
Expand Down Expand Up @@ -206,6 +211,14 @@ public BlockHeader updateFromParentValues(final ProtocolSpec protocolSpec) {
.buildBlockHeader(),
null)));
}
if (excessDataGas == null && parentExcessBlobGas != null && parentBlobGasUsed != null) {
builder.excessDataGas(
DataGas.of(
protocolSpec
.getGasCalculator()
.computeExcessDataGas(
Long.decode(parentExcessBlobGas), Long.decode(parentGasUsed))));
}

return builder.buildBlockHeader();
}
Expand All @@ -228,9 +241,10 @@ public boolean equals(final Object o) {
&& Objects.equals(parentGasUsed, that.parentGasUsed)
&& Objects.equals(parentGasLimit, that.parentGasLimit)
&& Objects.equals(parentTimestamp, that.parentTimestamp)
&& Objects.equals(parentDataGasUsed, that.parentDataGasUsed)
&& Objects.equals(parentExcessDataGas, that.parentExcessDataGas)
&& Objects.equals(withdrawals, that.withdrawals);
&& Objects.equals(parentBlobGasUsed, that.parentBlobGasUsed)
&& Objects.equals(parentExcessBlobGas, that.parentExcessBlobGas)
&& Objects.equals(withdrawals, that.withdrawals)
&& Objects.equals(beaconRoot, that.beaconRoot);
}

@Override
Expand All @@ -242,8 +256,9 @@ public int hashCode() {
parentGasUsed,
parentGasLimit,
parentTimestamp,
parentDataGasUsed,
parentExcessDataGas,
withdrawals);
parentBlobGasUsed,
parentExcessBlobGas,
withdrawals,
beaconRoot);
}
}

0 comments on commit ec6a6b1

Please sign in to comment.