Skip to content

Commit

Permalink
Added Consolidation Request containers (Consensys#8392)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassaldanha authored Jun 24, 2024
1 parent 0480cde commit 8b256c0
Show file tree
Hide file tree
Showing 42 changed files with 1,751 additions and 270 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"title" : "ConsolidationRequest",
"type" : "object",
"required" : [ "source_address", "source_pubkey", "target_pubkey" ],
"properties" : {
"source_address" : {
"type" : "string",
"pattern" : "^0x[a-fA-F0-9]{2,}$",
"description" : "SSZ hexadecimal",
"format" : "bytes"
},
"source_pubkey" : {
"type" : "string",
"pattern" : "^0x[a-fA-F0-9]{2,}$",
"description" : "Bytes48 hexadecimal",
"format" : "bytes"
},
"target_pubkey" : {
"type" : "string",
"pattern" : "^0x[a-fA-F0-9]{2,}$",
"description" : "Bytes48 hexadecimal",
"format" : "bytes"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "ExecutionPayloadElectra",
"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", "blob_gas_used", "excess_blob_gas", "deposit_requests", "withdrawal_requests" ],
"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", "blob_gas_used", "excess_blob_gas", "deposit_requests", "withdrawal_requests", "consolidation_requests" ],
"properties" : {
"parent_hash" : {
"type" : "string",
Expand Down Expand Up @@ -119,6 +119,12 @@
"items" : {
"$ref" : "#/components/schemas/ExecutionLayerWithdrawalRequest"
}
},
"consolidation_requests" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ConsolidationRequest"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "ExecutionPayloadHeaderElectra",
"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", "blob_gas_used", "excess_blob_gas", "deposit_requests_root", "withdrawal_requests_root" ],
"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", "blob_gas_used", "excess_blob_gas", "deposit_requests_root", "withdrawal_requests_root", "consolidation_requests_root" ],
"properties" : {
"parent_hash" : {
"type" : "string",
Expand Down Expand Up @@ -116,6 +116,12 @@
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"consolidation_requests_root" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Consensys Software Inc., 2022
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.api.schema.electra;

import com.fasterxml.jackson.annotation.JsonProperty;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequestSchema;

public class ConsolidationRequest {

@JsonProperty("source_address")
private final Eth1Address sourceAddress;

@JsonProperty("source_pubkey")
private final BLSPublicKey sourcePubkey;

@JsonProperty("target_pubkey")
private final BLSPublicKey targetPubkey;

public ConsolidationRequest(
@JsonProperty("source_address") final Eth1Address sourceAddress,
@JsonProperty("source_pubkey") final BLSPublicKey sourcePubkey,
@JsonProperty("target_pubkey") final BLSPublicKey targetPubkey) {
this.sourceAddress = sourceAddress;
this.sourcePubkey = sourcePubkey;
this.targetPubkey = targetPubkey;
}

public ConsolidationRequest(
final tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequest
consolidationRequest) {
this.sourceAddress =
Eth1Address.fromBytes(consolidationRequest.getSourceAddress().getWrappedBytes());
this.sourcePubkey = consolidationRequest.getSourcePubkey();
this.targetPubkey = consolidationRequest.getTargetPubkey();
}

public final tech.pegasys.teku.spec.datastructures.execution.versions.electra.ConsolidationRequest
asInternalConsolidationRequest(final ConsolidationRequestSchema schema) {
return schema.create(sourceAddress, sourcePubkey, targetPubkey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class ExecutionPayloadElectra extends ExecutionPayloadDeneb implements Ex
@JsonProperty("withdrawal_requests")
public final List<ExecutionLayerWithdrawalRequest> withdrawalRequests;

@JsonProperty("consolidation_requests")
public final List<ConsolidationRequest> consolidationRequests;

@JsonCreator
public ExecutionPayloadElectra(
@JsonProperty("parent_hash") final Bytes32 parentHash,
Expand All @@ -57,7 +60,9 @@ public ExecutionPayloadElectra(
@JsonProperty("excess_blob_gas") final UInt64 excessBlobGas,
@JsonProperty("deposit_requests") final List<DepositRequest> depositRequests,
@JsonProperty("withdrawal_requests")
final List<ExecutionLayerWithdrawalRequest> withdrawalRequests) {
final List<ExecutionLayerWithdrawalRequest> withdrawalRequests,
@JsonProperty("consolidation_requests")
final List<ConsolidationRequest> consolidationRequests) {
super(
parentHash,
feeRecipient,
Expand All @@ -78,6 +83,7 @@ public ExecutionPayloadElectra(
excessBlobGas);
this.depositRequests = depositRequests;
this.withdrawalRequests = withdrawalRequests;
this.consolidationRequests = consolidationRequests;
}

public ExecutionPayloadElectra(
Expand All @@ -91,6 +97,10 @@ public ExecutionPayloadElectra(
executionPayload.toVersionElectra().orElseThrow().getWithdrawalRequests().stream()
.map(ExecutionLayerWithdrawalRequest::new)
.toList();
this.consolidationRequests =
executionPayload.toVersionElectra().orElseThrow().getConsolidationRequests().stream()
.map(ConsolidationRequest::new)
.toList();
}

@Override
Expand All @@ -114,6 +124,14 @@ protected ExecutionPayloadBuilder applyToBuilder(
exit.asInternalExecutionLayerWithdrawalRequest(
executionPayloadSchema
.getExecutionLayerWithdrawalRequestSchemaRequired()))
.toList())
.consolidationRequests(
() ->
consolidationRequests.stream()
.map(
exit ->
exit.asInternalConsolidationRequest(
executionPayloadSchema.getConsolidationSchemaRequired()))
.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ExecutionPayloadHeaderElectra extends ExecutionPayloadHeaderDeneb {
@JsonProperty("withdrawal_requests_root")
public final Bytes32 withdrawalRequestsRoot;

@JsonProperty("consolidation_requests_root")
public final Bytes32 consolidationRequestsRoot;

@JsonCreator
public ExecutionPayloadHeaderElectra(
@JsonProperty("parent_hash") final Bytes32 parentHash,
Expand All @@ -53,7 +56,8 @@ public ExecutionPayloadHeaderElectra(
@JsonProperty("blob_gas_used") final UInt64 blobGasUsed,
@JsonProperty("excess_blob_gas") final UInt64 excessBlobGas,
@JsonProperty("deposit_requests_root") final Bytes32 depositRequestsRoot,
@JsonProperty("withdrawal_requests_root") final Bytes32 withdrawalRequestsRoot) {
@JsonProperty("withdrawal_requests_root") final Bytes32 withdrawalRequestsRoot,
@JsonProperty("consolidation_requests_root") final Bytes32 consolidationRequestsRoot) {
super(
parentHash,
feeRecipient,
Expand All @@ -74,6 +78,7 @@ public ExecutionPayloadHeaderElectra(
excessBlobGas);
this.depositRequestsRoot = depositRequestsRoot;
this.withdrawalRequestsRoot = withdrawalRequestsRoot;
this.consolidationRequestsRoot = consolidationRequestsRoot;
}

public ExecutionPayloadHeaderElectra(final ExecutionPayloadHeader executionPayloadHeader) {
Expand All @@ -99,6 +104,8 @@ public ExecutionPayloadHeaderElectra(final ExecutionPayloadHeader executionPaylo
executionPayloadHeader.toVersionElectra().orElseThrow().getDepositRequestsRoot();
this.withdrawalRequestsRoot =
executionPayloadHeader.toVersionElectra().orElseThrow().getWithdrawalRequestsRoot();
this.consolidationRequestsRoot =
executionPayloadHeader.toVersionElectra().orElseThrow().getConsolidationRequestsRoot();
}

@Override
Expand All @@ -125,7 +132,8 @@ public ExecutionPayloadHeader asInternalExecutionPayloadHeader(
.blobGasUsed(() -> blobGasUsed)
.excessBlobGas(() -> excessBlobGas)
.depositRequestsRoot(() -> depositRequestsRoot)
.withdrawalRequestsRoot(() -> withdrawalRequestsRoot));
.withdrawalRequestsRoot(() -> withdrawalRequestsRoot)
.consolidationRequestsRoot(() -> consolidationRequestsRoot));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public void newPayloadV4_shouldBuildRequestAndResponseSuccessfully() {
final Map<String, Object> executionPayloadV4Parameter =
(Map<String, Object>) ((List<Object>) requestData.get("params")).get(0);
// 19 fields in ExecutionPayloadV4
assertThat(executionPayloadV4Parameter).hasSize(19);
assertThat(executionPayloadV4Parameter).hasSize(20);
// sanity check
assertThat(executionPayloadV4Parameter.get("parentHash"))
.isEqualTo(executionPayloadV4.parentHash.toHexString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
"blob_gas_used": "14779654655076927372",
"excess_blob_gas": "14778002167565275948",
"deposit_requests_root": "0x18cf2fce2e25d0ad50e8ea981c126622aabb342eb3b68a25beeaeca81f654969",
"withdrawal_requests_root": "0x18cf2fce2e25d0ad50e8ea981c126622aabb342eb3b68a25beeaeca81f654969"
"withdrawal_requests_root": "0x18cf2fce2e25d0ad50e8ea981c126622aabb342eb3b68a25beeaeca81f654969",
"consolidation_requests_root": "0x18cf2fce2e25d0ad50e8ea981c126622aabb342eb3b68a25beeaeca81f654969"
},
"bls_to_execution_changes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"transactions_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"withdrawals_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"deposit_requests_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"withdrawal_requests_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
"withdrawal_requests_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"consolidation_requests_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
},
"blob_kzg_commitments": [
"0xa94170080872584e54a1cf092d845703b13907f2e6b3b1c0ad573b910530499e3bcd48c6378846b80d2bfa58c81cf3d5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
"validator_pubkey": "0x802775e14fda679e4594ca8ccda68a706957fe82c10e66d258eafd21fe5b2877c226092004f82874fb4022d73b74eea6",
"amount": "4878191786651244561"
}
],
"consolidation_requests": [
{
"source_address": "0x240bd643529257f0285e4590ab814b7c9dcd5ff6",
"source_pubkey": "0x802775e14fda679e4594ca8ccda68a706957fe82c10e66d258eafd21fe5b2877c226092004f82874fb4022d73b74eea6",
"target_pubkey": "0x802775e14fda679e4594ca8ccda68a706957fe82c10e66d258eafd21fe5b2877c226092004f82874fb4022d73b74eea6"
}
]
},
"blobs_bundle": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright Consensys Software Inc., 2024
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.ethereum.executionclient.schema;

import static com.google.common.base.Preconditions.checkNotNull;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes20Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes20Serializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes48Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesSerializer;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;

public class ConsolidationRequestV1 {
@JsonSerialize(using = Bytes20Serializer.class)
@JsonDeserialize(using = Bytes20Deserializer.class)
public final Bytes20 sourceAddress;

@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = Bytes48Deserializer.class)
public final Bytes48 sourcePubkey;

@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = Bytes48Deserializer.class)
public final Bytes48 targetPubkey;

public ConsolidationRequestV1(
@JsonProperty("sourceAddress") final Bytes20 sourceAddress,
@JsonProperty("sourcePubkey") final Bytes48 sourcePubkey,
@JsonProperty("targetPubkey") final Bytes48 targetPubkey) {
checkNotNull(sourceAddress, "sourceAddress");
checkNotNull(sourcePubkey, "sourcePubkey");
checkNotNull(targetPubkey, "targetPubkey");
this.sourceAddress = sourceAddress;
this.sourcePubkey = sourcePubkey;
this.targetPubkey = targetPubkey;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ConsolidationRequestV1 that = (ConsolidationRequestV1) o;
return Objects.equals(sourceAddress, that.sourceAddress)
&& Objects.equals(sourcePubkey, that.sourcePubkey)
&& Objects.equals(targetPubkey, that.targetPubkey);
}

@Override
public int hashCode() {
return Objects.hash(sourceAddress, sourceAddress, targetPubkey);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("sourceAddress", sourceAddress)
.add("sourcePubkey", sourcePubkey)
.add("targetPubkey", targetPubkey)
.toString();
}
}
Loading

0 comments on commit 8b256c0

Please sign in to comment.