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

[Merge] add merge spec datastructures #4503

Merged
merged 12 commits into from
Oct 26, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ private BeaconBlock assertBlockCreated(final int blockSlot, final Spec spec)

assertThat(block).isNotNull();
assertThat(block.getSlot()).isEqualTo(newSlot);
assertThat(block.getBody().getRandao_reveal()).isEqualTo(randaoReveal);
assertThat(block.getBody().getEth1_data()).isEqualTo(ETH1_DATA);
assertThat(block.getBody().getRandaoReveal()).isEqualTo(randaoReveal);
assertThat(block.getBody().getEth1Data()).isEqualTo(ETH1_DATA);
assertThat(block.getBody().getDeposits()).isEqualTo(deposits);
assertThat(block.getBody().getAttestations()).isEqualTo(attestations);
assertThat(block.getBody().getAttester_slashings()).isEqualTo(attesterSlashings);
assertThat(block.getBody().getProposer_slashings()).isEqualTo(proposerSlashings);
assertThat(block.getBody().getVoluntary_exits()).isEqualTo(voluntaryExits);
assertThat(block.getBody().getAttesterSlashings()).isEqualTo(attesterSlashings);
assertThat(block.getBody().getProposerSlashings()).isEqualTo(proposerSlashings);
assertThat(block.getBody().getVoluntaryExits()).isEqualTo(voluntaryExits);
assertThat(block.getBody().getGraffiti()).isEqualTo(graffiti);
return block;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand Down Expand Up @@ -305,5 +307,16 @@ public BeaconBlockBodyBuilder syncAggregate(
this.syncAggregate = syncAggregateSupplier.get();
return this;
}

@Override
public BeaconBlockBodyBuilder executionPayload(
Supplier<ExecutionPayload> executionPayloadSupplier) {
return this;
}

@Override
public BeaconBlockBody build() {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ public BeaconBlockBody(

public BeaconBlockBody(
tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
this.randao_reveal = new BLSSignature(body.getRandao_reveal().toSSZBytes());
this.eth1_data = new Eth1Data(body.getEth1_data());
this.randao_reveal = new BLSSignature(body.getRandaoReveal().toSSZBytes());
this.eth1_data = new Eth1Data(body.getEth1Data());
this.graffiti = body.getGraffiti();
this.proposer_slashings =
body.getProposer_slashings().stream()
body.getProposerSlashings().stream()
.map(ProposerSlashing::new)
.collect(Collectors.toList());
this.attester_slashings =
body.getAttester_slashings().stream()
body.getAttesterSlashings().stream()
.map(AttesterSlashing::new)
.collect(Collectors.toList());
this.attestations =
body.getAttestations().stream().map(Attestation::new).collect(Collectors.toList());
this.deposits = body.getDeposits().stream().map(Deposit::new).collect(Collectors.toList());
this.voluntary_exits =
body.getVoluntary_exits().stream()
body.getVoluntaryExits().stream()
.map(SignedVoluntaryExit::new)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tech.pegasys.teku.api.schema.interfaces.State;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair;
import tech.pegasys.teku.ssz.SszList;
import tech.pegasys.teku.ssz.collections.SszBitvector;
import tech.pegasys.teku.ssz.primitive.SszByte;
Expand Down Expand Up @@ -125,7 +126,8 @@ protected void applyAdditionalFields(final MutableBeaconState state) {
beaconStateAltair -> {
final tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema
syncCommitteeSchema =
beaconStateAltair.getBeaconStateSchema().getCurrentSyncCommitteeSchema();
((BeaconStateSchemaAltair) beaconStateAltair.getBeaconStateSchema())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajsutton going down to that path I found this. do you think we should then implement the toVersion<Milestone> pattern in BeaconStateSchema too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it's more likely a required kind of pattern where it just throws an exception if it's the wrong type (with useful detail). Code like this won't be able to handle getting an empty Optional back. But yes that's definitely better than casting.

.getCurrentSyncCommitteeSchema();
final SszList<SszByte> previousEpochParticipation =
beaconStateAltair
.getPreviousEpochParticipation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ protected BeaconBlockBody createContainer() {
.createBlockBody(
builder ->
builder
.randaoReveal(beaconBlockBody.getRandao_reveal())
.eth1Data(beaconBlockBody.getEth1_data())
.randaoReveal(beaconBlockBody.getRandaoReveal())
.eth1Data(beaconBlockBody.getEth1Data())
.graffiti(beaconBlockBody.getGraffiti())
.attestations(beaconBlockBody.getAttestations())
.proposerSlashings(beaconBlockBody.getProposer_slashings())
.attesterSlashings(beaconBlockBody.getAttester_slashings())
.proposerSlashings(beaconBlockBody.getProposerSlashings())
.attesterSlashings(beaconBlockBody.getAttesterSlashings())
.deposits(beaconBlockBody.getDeposits())
.voluntaryExits(beaconBlockBody.getVoluntary_exits()));
.voluntaryExits(beaconBlockBody.getVoluntaryExits()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public static void iterateData(PendingAttestation pa, Blackhole bh) {
}

public static void iterateData(BeaconBlockBody bbb, Blackhole bh) {
bh.consume(bbb.getRandao_reveal());
iterateData(bbb.getEth1_data(), bh);
bh.consume(bbb.getRandaoReveal());
iterateData(bbb.getEth1Data(), bh);
bh.consume(bbb.getGraffiti());
bbb.getProposer_slashings().forEach(s -> iterateData(s, bh));
bbb.getAttester_slashings().forEach(s -> iterateData(s, bh));
bbb.getProposerSlashings().forEach(s -> iterateData(s, bh));
bbb.getAttesterSlashings().forEach(s -> iterateData(s, bh));
bbb.getAttestations().forEach(a -> iterateData(a, bh));
bbb.getDeposits().forEach(d -> iterateData(d, bh));
bbb.getVoluntary_exits().forEach(d -> iterateData(d, bh));
bbb.getVoluntaryExits().forEach(d -> iterateData(d, bh));
}

public static void iterateData(SignedVoluntaryExit d, Blackhole bh) {
Expand Down
1 change: 1 addition & 0 deletions ethereum/spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
testFixturesImplementation project(':infrastructure:unsigned')
testFixturesImplementation testFixtures(project(':bls'))
testFixturesImplementation project(':infrastructure:io')
testFixturesImplementation 'org.apache.tuweni:tuweni-units'

testFixturesApi project(':ethereum:pow:api')
testFixturesApi 'com.google.guava:guava'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
import tech.pegasys.teku.spec.config.SpecConfigMerge;
import tech.pegasys.teku.spec.logic.DelegatingSpecLogic;
import tech.pegasys.teku.spec.logic.SpecLogic;
import tech.pegasys.teku.spec.logic.versions.altair.SpecLogicAltair;
Expand Down Expand Up @@ -46,6 +47,8 @@ static Optional<SpecVersion> create(final SpecMilestone milestone, final SpecCon
return Optional.of(createPhase0(specConfig));
case ALTAIR:
return specConfig.toVersionAltair().map(SpecVersion::createAltair);
case MERGE:
return specConfig.toVersionMerge().map(SpecVersion::createMerge);
default:
throw new UnsupportedOperationException("Unknown milestone requested: " + milestone);
}
Expand All @@ -63,6 +66,12 @@ static SpecVersion createAltair(final SpecConfigAltair specConfig) {
return new SpecVersion(SpecMilestone.ALTAIR, specConfig, schemaDefinitions, specLogic);
}

static SpecVersion createMerge(final SpecConfigMerge specConfig) {
final SchemaDefinitionsAltair schemaDefinitions = new SchemaDefinitionsAltair(specConfig);
final SpecLogic specLogic = SpecLogicAltair.create(specConfig, schemaDefinitions);
return new SpecVersion(SpecMilestone.MERGE, specConfig, schemaDefinitions, specLogic);
}

public SpecMilestone getMilestone() {
return milestone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodyAltair;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.merge.BeaconBlockBodyMerge;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand All @@ -27,24 +28,30 @@
import tech.pegasys.teku.ssz.SszList;

public interface BeaconBlockBody extends SszContainer {
BLSSignature getRandao_reveal();
BLSSignature getRandaoReveal();

Eth1Data getEth1_data();
Eth1Data getEth1Data();

Bytes32 getGraffiti();

SszList<ProposerSlashing> getProposer_slashings();
SszList<ProposerSlashing> getProposerSlashings();

SszList<AttesterSlashing> getAttester_slashings();
SszList<AttesterSlashing> getAttesterSlashings();

SszList<Attestation> getAttestations();

SszList<Deposit> getDeposits();

SszList<SignedVoluntaryExit> getVoluntary_exits();
SszList<SignedVoluntaryExit> getVoluntaryExits();

@Override
BeaconBlockBodySchema<? extends BeaconBlockBody> getSchema();

Optional<BeaconBlockBodyAltair> toVersionAltair();
default Optional<BeaconBlockBodyAltair> toVersionAltair() {
return Optional.empty();
}

default Optional<BeaconBlockBodyMerge> toVersionMerge() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand Down Expand Up @@ -45,4 +46,9 @@ public interface BeaconBlockBodyBuilder {

// Not required by all hard forks so provided via a Supplier that is only invoked when needed.
BeaconBlockBodyBuilder syncAggregate(Supplier<SyncAggregate> syncAggregateSupplier);

// Not required by all hard forks so provided via a Supplier that is only invoked when needed.
BeaconBlockBodyBuilder executionPayload(Supplier<ExecutionPayload> executionPayloadSupplier);
tbenr marked this conversation as resolved.
Show resolved Hide resolved

BeaconBlockBody build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody;

import java.util.Optional;
import java.util.function.Consumer;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.merge.BeaconBlockBodySchemaMerge;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
Expand All @@ -24,9 +27,9 @@
import tech.pegasys.teku.ssz.tree.TreeNode;

public interface BeaconBlockBodySchema<T extends BeaconBlockBody> extends SszContainerSchema<T> {
T createBlockBody(Consumer<BeaconBlockBodyBuilder> bodyBuilder);
BeaconBlockBody createBlockBody(Consumer<BeaconBlockBodyBuilder> bodyBuilder);

T createEmpty();
BeaconBlockBody createEmpty();

@Override
T createFromBackingNode(TreeNode node);
Expand All @@ -40,4 +43,12 @@ public interface BeaconBlockBodySchema<T extends BeaconBlockBody> extends SszCon
SszListSchema<Deposit, ?> getDepositsSchema();

SszListSchema<SignedVoluntaryExit, ?> getVoluntaryExitsSchema();

default Optional<BeaconBlockBodySchemaAltair<?>> toVersionAltair() {
return Optional.empty();
}

default Optional<BeaconBlockBodySchemaMerge<?>> toVersionMerge() {
return Optional.empty();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public enum BlockBodyFields {
ATTESTATIONS,
DEPOSITS,
VOLUNTARY_EXITS,
SYNC_AGGREGATE
SYNC_AGGREGATE,
EXECUTION_PAYLOAD
}
Loading