Skip to content

Commit

Permalink
Make build green
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Sep 6, 2024
1 parent 2a33fc7 commit 1f0e536
Show file tree
Hide file tree
Showing 53 changed files with 1,485 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.execution.PayloadAttestationData;
import tech.pegasys.teku.spec.datastructures.genesis.GenesisData;
import tech.pegasys.teku.spec.datastructures.metadata.BlockContainerAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationData;
import tech.pegasys.teku.spec.datastructures.operations.PayloadAttestationMessage;
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import tech.pegasys.teku.api.schema.deneb.BeaconStateDeneb;
import tech.pegasys.teku.api.schema.deneb.BlindedBeaconBlockBodyDeneb;
import tech.pegasys.teku.api.schema.deneb.BlindedBlockDeneb;
import tech.pegasys.teku.api.schema.eip7732.BeaconBlockBodyEip7732;
import tech.pegasys.teku.api.schema.eip7732.BeaconBlockEip7732;
import tech.pegasys.teku.api.schema.eip7732.BeaconStateEip7732;
import tech.pegasys.teku.api.schema.electra.BeaconBlockBodyElectra;
import tech.pegasys.teku.api.schema.electra.BeaconBlockElectra;
import tech.pegasys.teku.api.schema.electra.BeaconStateElectra;
Expand Down Expand Up @@ -130,7 +133,13 @@ public BeaconBlock getBlindedBlock(
block.getParentRoot(),
block.getStateRoot(),
getBlindedBlockBodyElectra(block.getBody()));
case EIP7732 -> throw new UnsupportedOperationException("EIP7732 TODO");
case EIP7732 ->
new BeaconBlockEip7732(
block.getSlot(),
block.getProposerIndex(),
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyEip7732(block.getBody()));
};
}

Expand Down Expand Up @@ -180,7 +189,13 @@ public BeaconBlock getBeaconBlock(
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyElectra(block.getBody()));
case EIP7732 -> throw new UnsupportedOperationException("EIP7732 TODO");
case EIP7732 ->
new BeaconBlockEip7732(
block.getSlot(),
block.getProposerIndex(),
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyEip7732(block.getBody()));
};
}

Expand Down Expand Up @@ -219,6 +234,13 @@ private BeaconBlockBodyElectra getBeaconBlockBodyElectra(
.BeaconBlockBodyElectra.required(body));
}

private BeaconBlockBodyEip7732 getBeaconBlockBodyEip7732(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BeaconBlockBodyEip7732(
tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732
.BeaconBlockBodyEip7732.required(body));
}

private BlindedBeaconBlockBodyBellatrix getBlindedBlockBodyBellatrix(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BlindedBeaconBlockBodyBellatrix(
Expand Down Expand Up @@ -257,7 +279,7 @@ public BeaconState getBeaconState(
case CAPELLA -> new BeaconStateCapella(state);
case DENEB -> new BeaconStateDeneb(state);
case ELECTRA -> new BeaconStateElectra(state);
case EIP7732 -> throw new UnsupportedOperationException("EIP7732 TODO");
case EIP7732 -> new BeaconStateEip7732(state);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tech.pegasys.teku.api.schema.bellatrix.ExecutionPayloadHeaderBellatrix;
import tech.pegasys.teku.api.schema.capella.ExecutionPayloadHeaderCapella;
import tech.pegasys.teku.api.schema.deneb.ExecutionPayloadHeaderDeneb;
import tech.pegasys.teku.api.schema.eip7732.ExecutionPayloadHeaderEip7732;
import tech.pegasys.teku.api.schema.electra.ExecutionPayloadHeaderElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;

Expand All @@ -39,4 +40,8 @@ default Optional<ExecutionPayloadHeaderDeneb> toVersionDeneb() {
default Optional<ExecutionPayloadHeaderElectra> toVersionElectra() {
return Optional.empty();
}

default Optional<ExecutionPayloadHeaderEip7732> toVersionEip7732() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tech.pegasys.teku.api.schema.capella.SignedBlindedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.deneb.SignedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.deneb.SignedBlindedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.eip7732.SignedBeaconBlockEip7732;
import tech.pegasys.teku.api.schema.electra.SignedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.electra.SignedBlindedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.interfaces.SignedBlock;
Expand Down Expand Up @@ -65,6 +66,14 @@ public static SignedBeaconBlock create(
internalBlock.getMessage().getBody();

return Stream.of(
() ->
beaconBlock
.toBlindedVersionEip7732()
.map(__ -> new SignedBeaconBlockEip7732(internalBlock)),
() ->
beaconBlock
.toVersionEip7732()
.map(__ -> new SignedBeaconBlockEip7732(internalBlock)),
() ->
beaconBlock
.toBlindedVersionElectra()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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.eip7732;

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

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.api.schema.Attestation;
import tech.pegasys.teku.api.schema.AttesterSlashing;
import tech.pegasys.teku.api.schema.BLSSignature;
import tech.pegasys.teku.api.schema.Deposit;
import tech.pegasys.teku.api.schema.Eth1Data;
import tech.pegasys.teku.api.schema.ProposerSlashing;
import tech.pegasys.teku.api.schema.SignedVoluntaryExit;
import tech.pegasys.teku.api.schema.altair.BeaconBlockBodyAltair;
import tech.pegasys.teku.api.schema.altair.SyncAggregate;
import tech.pegasys.teku.api.schema.capella.SignedBlsToExecutionChange;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732.BeaconBlockBodySchemaEip7732;

public class BeaconBlockBodyEip7732 extends BeaconBlockBodyAltair {

@JsonProperty("bls_to_execution_changes")
public final List<SignedBlsToExecutionChange> blsToExecutionChanges;

@JsonProperty("signed_execution_payload_header")
public final SignedExecutionPayloadHeader signedExecutionPayloadHeader;

@JsonProperty("payload_attestations")
public final List<PayloadAttestation> payloadAttestations;

@JsonCreator
public BeaconBlockBodyEip7732(
@JsonProperty("randao_reveal") final BLSSignature randaoReveal,
@JsonProperty("eth1_data") final Eth1Data eth1Data,
@JsonProperty("graffiti") final Bytes32 graffiti,
@JsonProperty("proposer_slashings") final List<ProposerSlashing> proposerSlashings,
@JsonProperty("attester_slashings") final List<AttesterSlashing> attesterSlashings,
@JsonProperty("attestations") final List<Attestation> attestations,
@JsonProperty("deposits") final List<Deposit> deposits,
@JsonProperty("voluntary_exits") final List<SignedVoluntaryExit> voluntaryExits,
@JsonProperty("sync_aggregate") final SyncAggregate syncAggregate,
@JsonProperty("bls_to_execution_changes")
final List<SignedBlsToExecutionChange> blsToExecutionChanges,
@JsonProperty("signed_execution_payload_header")
final SignedExecutionPayloadHeader signedExecutionPayloadHeader,
@JsonProperty("payload_attestations") final List<PayloadAttestation> payloadAttestations) {
super(
randaoReveal,
eth1Data,
graffiti,
proposerSlashings,
attesterSlashings,
attestations,
deposits,
voluntaryExits,
syncAggregate);
checkNotNull(blsToExecutionChanges, "BlsToExecutionChanges is required for Eip7732 blocks");
this.blsToExecutionChanges = blsToExecutionChanges;
checkNotNull(
signedExecutionPayloadHeader,
"SignedExecutionPayloadHeader is required for Eip7732 blocks");
this.signedExecutionPayloadHeader = signedExecutionPayloadHeader;
checkNotNull(payloadAttestations, "PayloadAttestations is required for Eip7732 blocks");
this.payloadAttestations = payloadAttestations;
}

public BeaconBlockBodyEip7732(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732
.BeaconBlockBodyEip7732
message) {
super(message);
checkNotNull(
message.getBlsToExecutionChanges(),
"BlsToExecutionChanges are required for Eip7732 blocks");
this.blsToExecutionChanges =
message.getBlsToExecutionChanges().stream().map(SignedBlsToExecutionChange::new).toList();
checkNotNull(
message.getSignedExecutionPayloadHeader(),
"SignedExecutionPayloadHeader are required for Eip7732 blocks");
this.signedExecutionPayloadHeader =
new SignedExecutionPayloadHeader(message.getSignedExecutionPayloadHeader());
checkNotNull(
message.getPayloadAttestations(), "PayloadAttestations are required for Eip7732 blocks");
this.payloadAttestations =
message.getPayloadAttestations().stream().map(PayloadAttestation::new).toList();
}

@Override
public BeaconBlockBodySchemaEip7732<?> getBeaconBlockBodySchema(final SpecVersion spec) {
return (BeaconBlockBodySchemaEip7732<?>) spec.getSchemaDefinitions().getBeaconBlockBodySchema();
}

@Override
public BeaconBlockBody asInternalBeaconBlockBody(final SpecVersion spec) {
final SszListSchema<
tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange, ?>
blsToExecutionChangesSchema =
getBeaconBlockBodySchema(spec).getBlsToExecutionChangesSchema();
return super.asInternalBeaconBlockBody(
spec,
builder -> {
builder.blsToExecutionChanges(
this.blsToExecutionChanges.stream()
.map(b -> b.asInternalSignedBlsToExecutionChange(spec))
.collect(blsToExecutionChangesSchema.collector()));
builder.signedExecutionPayloadHeader(
signedExecutionPayloadHeader.asInternalSignedExecutionPayloadHeader(spec));
final SszListSchema<
tech.pegasys.teku.spec.datastructures.operations.PayloadAttestation, ?>
payloadAttestationsSchema =
getBeaconBlockBodySchema(spec).getPayloadAttestationsSchema();
builder.payloadAttestations(
this.payloadAttestations.stream()
.map(pa -> pa.asInternalPayloadAttestation(spec))
.collect(payloadAttestationsSchema.collector()));
return SafeFuture.COMPLETE;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.eip7732;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.api.schema.altair.BeaconBlockAltair;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7732;

public class BeaconBlockEip7732 extends BeaconBlockAltair {

public BeaconBlockEip7732(final BeaconBlock message) {
super(
message.getSlot(),
message.getProposerIndex(),
message.getParentRoot(),
message.getStateRoot(),
new BeaconBlockBodyEip7732(message.getBody().toVersionEip7732().orElseThrow()));
}

@Override
public BeaconBlock asInternalBeaconBlock(final Spec spec) {
final SpecVersion specVersion = spec.atSlot(slot);
return SchemaDefinitionsEip7732.required(specVersion.getSchemaDefinitions())
.getBeaconBlockSchema()
.create(
slot,
proposer_index,
parent_root,
state_root,
body.asInternalBeaconBlockBody(specVersion));
}

@JsonProperty("body")
@Override
public BeaconBlockBodyEip7732 getBody() {
return (BeaconBlockBodyEip7732) body;
}

@JsonCreator
public BeaconBlockEip7732(
@JsonProperty("slot") final UInt64 slot,
@JsonProperty("proposer_index") final UInt64 proposerIndex,
@JsonProperty("parent_root") final Bytes32 parentRoot,
@JsonProperty("state_root") final Bytes32 stateRoot,
@JsonProperty("body") final BeaconBlockBodyEip7732 body) {
super(slot, proposerIndex, parentRoot, stateRoot, body);
}
}
Loading

0 comments on commit 1f0e536

Please sign in to comment.