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

ExecutionPayload Add data_gas_used and change type of excess_data_gas #7215

Merged
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: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ allprojects {
}
}

def refTestVersion = 'v1.4.0-alpha.0' // Arbitrary change to refresh cache number: 1
def refTestVersion = 'v1.4.0-alpha.1' // Arbitrary change to refresh cache number: 1
def blsRefTestVersion = 'v0.1.2'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "ExecutionPayloadDeneb",
"type" : "object",
"required" : [ "parent_hash", "fee_recipient", "state_root", "receipts_root", "logs_bloom", "prev_randao", "block_number", "gas_limit", "gas_used", "timestamp", "extra_data", "base_fee_per_gas", "block_hash", "transactions", "withdrawals", "excess_data_gas" ],
"required" : [ "parent_hash", "fee_recipient", "state_root", "receipts_root", "logs_bloom", "prev_randao", "block_number", "gas_limit", "gas_used", "timestamp", "extra_data", "base_fee_per_gas", "block_hash", "transactions", "withdrawals", "data_gas_used", "excess_data_gas" ],
"properties" : {
"parent_hash" : {
"type" : "string",
Expand Down Expand Up @@ -96,11 +96,17 @@
"$ref" : "#/components/schemas/Withdrawal"
}
},
"data_gas_used" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"excess_data_gas" : {
"type" : "string",
"description" : "unsigned 256 bit integer",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint256"
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "ExecutionPayloadHeaderDeneb",
"type" : "object",
"required" : [ "parent_hash", "fee_recipient", "state_root", "receipts_root", "logs_bloom", "prev_randao", "block_number", "gas_limit", "gas_used", "timestamp", "extra_data", "base_fee_per_gas", "block_hash", "transactions_root", "withdrawals_root", "excess_data_gas" ],
"required" : [ "parent_hash", "fee_recipient", "state_root", "receipts_root", "logs_bloom", "prev_randao", "block_number", "gas_limit", "gas_used", "timestamp", "extra_data", "base_fee_per_gas", "block_hash", "transactions_root", "withdrawals_root", "data_gas_used", "excess_data_gas" ],
"properties" : {
"parent_hash" : {
"type" : "string",
Expand Down Expand Up @@ -93,11 +93,17 @@
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"data_gas_used" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"excess_data_gas" : {
"type" : "string",
"description" : "unsigned 256 bit integer",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint256"
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@

public class ExecutionPayloadDeneb extends ExecutionPayloadCapella implements ExecutionPayload {

@JsonProperty("data_gas_used")
public final UInt64 dataGasUsed;

@JsonProperty("excess_data_gas")
public final UInt256 excessDataGas;
public final UInt64 excessDataGas;

@JsonCreator
public ExecutionPayloadDeneb(
Expand All @@ -52,7 +55,8 @@ public ExecutionPayloadDeneb(
@JsonProperty("block_hash") final Bytes32 blockHash,
@JsonProperty("transactions") final List<Bytes> transactions,
@JsonProperty("withdrawals") final List<Withdrawal> withdrawals,
@JsonProperty("excess_data_gas") final UInt256 excessDataGas) {
@JsonProperty("data_gas_used") final UInt64 dataGasUsed,
@JsonProperty("excess_data_gas") final UInt64 excessDataGas) {
super(
parentHash,
feeRecipient,
Expand All @@ -69,20 +73,24 @@ public ExecutionPayloadDeneb(
blockHash,
transactions,
withdrawals);
this.dataGasUsed = dataGasUsed;
this.excessDataGas = excessDataGas;
}

public ExecutionPayloadDeneb(
final tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload executionPayload) {
super(executionPayload);
this.dataGasUsed = executionPayload.toVersionDeneb().orElseThrow().getDataGasUsed();
this.excessDataGas = executionPayload.toVersionDeneb().orElseThrow().getExcessDataGas();
}

@Override
protected ExecutionPayloadBuilder applyToBuilder(
final ExecutionPayloadSchema<?> executionPayloadSchema,
final ExecutionPayloadBuilder builder) {
return super.applyToBuilder(executionPayloadSchema, builder).excessDataGas(() -> excessDataGas);
return super.applyToBuilder(executionPayloadSchema, builder)
.dataGasUsed(() -> dataGasUsed)
.excessDataGas(() -> excessDataGas);
}

@Override
Expand All @@ -95,19 +103,20 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof ExecutionPayloadDeneb)) {
return false;
}
if (!super.equals(o)) {
return false;
}
final ExecutionPayloadDeneb that = (ExecutionPayloadDeneb) o;
return Objects.equals(excessDataGas, that.excessDataGas);
return Objects.equals(dataGasUsed, that.dataGasUsed)
&& Objects.equals(excessDataGas, that.excessDataGas);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), excessDataGas);
return Objects.hash(super.hashCode(), dataGasUsed, excessDataGas);
}

@Override
Expand All @@ -128,6 +137,7 @@ public String toString() {
.add("blockHash", blockHash)
.add("transactions", transactions)
.add("withdrawals", withdrawals)
.add("dataGasUsed", dataGasUsed)
.add("excessDataGas", excessDataGas)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@

public class ExecutionPayloadHeaderDeneb extends ExecutionPayloadHeaderCapella {

@JsonProperty("data_gas_used")
public final UInt64 dataGasUsed;

@JsonProperty("excess_data_gas")
public final UInt256 excessDataGas;
public final UInt64 excessDataGas;

@JsonCreator
public ExecutionPayloadHeaderDeneb(
Expand All @@ -49,7 +52,8 @@ public ExecutionPayloadHeaderDeneb(
@JsonProperty("block_hash") final Bytes32 blockHash,
@JsonProperty("transactions_root") final Bytes32 transactionsRoot,
@JsonProperty("withdrawals_root") final Bytes32 withdrawalsRoot,
@JsonProperty("excess_data_gas") final UInt256 excessDataGas) {
@JsonProperty("data_gas_used") final UInt64 dataGasUsed,
@JsonProperty("excess_data_gas") final UInt64 excessDataGas) {
super(
parentHash,
feeRecipient,
Expand All @@ -66,6 +70,7 @@ public ExecutionPayloadHeaderDeneb(
blockHash,
transactionsRoot,
withdrawalsRoot);
this.dataGasUsed = dataGasUsed;
this.excessDataGas = excessDataGas;
}

Expand All @@ -86,6 +91,7 @@ public ExecutionPayloadHeaderDeneb(final ExecutionPayloadHeader executionPayload
executionPayloadHeader.getBlockHash(),
executionPayloadHeader.getTransactionsRoot(),
executionPayloadHeader.getOptionalWithdrawalsRoot().orElseThrow());
this.dataGasUsed = executionPayloadHeader.toVersionDeneb().orElseThrow().getDataGasUsed();
this.excessDataGas = executionPayloadHeader.toVersionDeneb().orElseThrow().getExcessDataGas();
}

Expand All @@ -110,6 +116,7 @@ public ExecutionPayloadHeader asInternalExecutionPayloadHeader(
.blockHash(blockHash)
.transactionsRoot(transactionsRoot)
.withdrawalsRoot(() -> withdrawalsRoot)
.dataGasUsed(() -> dataGasUsed)
.excessDataGas(() -> excessDataGas));
}

Expand All @@ -123,19 +130,20 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof ExecutionPayloadHeaderDeneb)) {
return false;
}
if (!super.equals(o)) {
return false;
}
final ExecutionPayloadHeaderDeneb that = (ExecutionPayloadHeaderDeneb) o;
return Objects.equals(excessDataGas, that.excessDataGas);
return Objects.equals(dataGasUsed, that.dataGasUsed)
&& Objects.equals(excessDataGas, that.excessDataGas);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), excessDataGas);
return Objects.hash(super.hashCode(), dataGasUsed, excessDataGas);
}

@Override
Expand All @@ -156,6 +164,7 @@ public String toString() {
.add("blockHash", blockHash)
.add("transactionsRoot", transactionsRoot)
.add("withdrawalsRoot", withdrawalsRoot)
.add("dataGasUsed", dataGasUsed)
.add("excessDataGas", excessDataGas)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -239,13 +240,18 @@ public void newPayloadV3_shouldBuildRequestAndResponseSuccessfully() {

final Map<String, Object> executionPayloadV3Parameter =
(Map<String, Object>) ((List<Object>) requestData.get("params")).get(0);
// 16 fields in ExecutionPayloadV3
assertThat(executionPayloadV3Parameter).hasSize(16);
// 17 fields in ExecutionPayloadV3
assertThat(executionPayloadV3Parameter).hasSize(17);
// sanity check
assertThat(executionPayloadV3Parameter.get("parentHash"))
.isEqualTo(executionPayloadV3.parentHash.toHexString());
assertThat(executionPayloadV3Parameter.get("dataGasUsed"))
.isEqualTo(
Bytes.ofUnsignedLong(executionPayloadV3.dataGasUsed.longValue()).toQuantityHexString());
assertThat(executionPayloadV3Parameter.get("excessDataGas"))
.isEqualTo(executionPayloadV3.excessDataGas.toHexString());
.isEqualTo(
StefanBratanov marked this conversation as resolved.
Show resolved Hide resolved
Bytes.ofUnsignedLong(executionPayloadV3.excessDataGas.longValue())
.toQuantityHexString());
assertThat(((List<Object>) requestData.get("params")).get(1))
.asInstanceOf(LIST)
.containsExactlyElementsOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexSerializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexSerializer;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.ssz.collections.impl.SszByteListImpl;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -34,9 +34,13 @@
import tech.pegasys.teku.spec.datastructures.execution.versions.deneb.ExecutionPayloadDeneb;

public class ExecutionPayloadV3 extends ExecutionPayloadV2 {
@JsonSerialize(using = UInt256AsHexSerializer.class)
@JsonDeserialize(using = UInt256AsHexDeserializer.class)
public final UInt256 excessDataGas;
@JsonSerialize(using = UInt64AsHexSerializer.class)
@JsonDeserialize(using = UInt64AsHexDeserializer.class)
public final UInt64 dataGasUsed;

@JsonSerialize(using = UInt64AsHexSerializer.class)
@JsonDeserialize(using = UInt64AsHexDeserializer.class)
public final UInt64 excessDataGas;

public ExecutionPayloadV3(
@JsonProperty("parentHash") Bytes32 parentHash,
Expand All @@ -54,7 +58,8 @@ public ExecutionPayloadV3(
@JsonProperty("blockHash") Bytes32 blockHash,
@JsonProperty("transactions") List<Bytes> transactions,
@JsonProperty("withdrawals") List<WithdrawalV1> withdrawals,
@JsonProperty("excessDataGas") UInt256 excessDataGas) {
@JsonProperty("dataGasUsed") UInt64 dataGasUsed,
@JsonProperty("excessDataGas") UInt64 excessDataGas) {
super(
parentHash,
feeRecipient,
Expand All @@ -71,6 +76,7 @@ public ExecutionPayloadV3(
blockHash,
transactions,
withdrawals);
this.dataGasUsed = dataGasUsed;
this.excessDataGas = excessDataGas;
}

Expand All @@ -96,6 +102,7 @@ public static ExecutionPayloadV3 fromInternalExecutionPayload(
.map(SszByteListImpl::getBytes)
.collect(Collectors.toList()),
withdrawalsList,
executionPayload.toVersionDeneb().map(ExecutionPayloadDeneb::getDataGasUsed).orElse(null),
executionPayload
.toVersionDeneb()
.map(ExecutionPayloadDeneb::getExcessDataGas)
Expand All @@ -107,7 +114,8 @@ protected ExecutionPayloadBuilder applyToBuilder(
final ExecutionPayloadSchema<?> executionPayloadSchema,
final ExecutionPayloadBuilder builder) {
return super.applyToBuilder(executionPayloadSchema, builder)
.dataGasUsed(() -> checkNotNull(dataGasUsed, "dataGasUsed not provided when required"))
.excessDataGas(
() -> checkNotNull(excessDataGas, "Excess data gas not provided when required"));
() -> checkNotNull(excessDataGas, "excessDataGas not provided when required"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private ExecutionPayloadHeader createExecutionPayloadHeaderWithGasLimit(
.blockHash(Bytes32.random())
.transactionsRoot(Bytes32.ZERO)
.withdrawalsRoot(() -> Bytes32.ZERO)
.excessDataGas(() -> UInt256.ONE));
.dataGasUsed(() -> UInt64.ONE)
.excessDataGas(() -> UInt64.ONE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public interface ExecutionPayloadBuilder {

ExecutionPayloadBuilder withdrawals(Supplier<List<Withdrawal>> withdrawalsSupplier);

ExecutionPayloadBuilder excessDataGas(Supplier<UInt256> excessDataGasSupplier);
ExecutionPayloadBuilder dataGasUsed(Supplier<UInt64> dataGasUsedSupplier);

ExecutionPayloadBuilder excessDataGas(Supplier<UInt64> excessDataGasSupplier);

ExecutionPayload build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ExecutionPayloadFields implements SszFieldName {
WITHDRAWALS,
TRANSACTIONS_ROOT,
WITHDRAWALS_ROOT,
DATA_GAS_USED,
EXCESS_DATA_GAS;

private final String sszFieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public interface ExecutionPayloadHeaderBuilder {

ExecutionPayloadHeaderBuilder withdrawalsRoot(Supplier<Bytes32> withdrawalsRootSupplier);

ExecutionPayloadHeaderBuilder excessDataGas(Supplier<UInt256> excessDataGasSupplier);
ExecutionPayloadHeaderBuilder dataGasUsed(Supplier<UInt64> dataGasUsedSupplier);

ExecutionPayloadHeaderBuilder excessDataGas(Supplier<UInt64> excessDataGasSupplier);

ExecutionPayloadHeader build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ public ExecutionPayloadBuilder withdrawals(final Supplier<List<Withdrawal>> with
}

@Override
public ExecutionPayloadBuilder excessDataGas(final Supplier<UInt256> excessDataGasSupplier) {
public ExecutionPayloadBuilder dataGasUsed(final Supplier<UInt64> dataGasUsedSupplier) {
return this;
}

@Override
public ExecutionPayloadBuilder excessDataGas(final Supplier<UInt64> excessDataGasSupplier) {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ public ExecutionPayloadHeaderBuilder withdrawalsRoot(
}

@Override
public ExecutionPayloadHeaderBuilder excessDataGas(
final Supplier<UInt256> excessDataGasSupplier) {
public ExecutionPayloadHeaderBuilder dataGasUsed(final Supplier<UInt64> dataGasUsedSupplier) {
return this;
}

@Override
public ExecutionPayloadHeaderBuilder excessDataGas(final Supplier<UInt64> excessDataGasSupplier) {
return this;
}

Expand Down
Loading