diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java index 83e6389f681..5a25b3207ae 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java @@ -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; } diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java index b74112b06c6..86bb47859bb 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockOperationSelectorFactoryTest.java @@ -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; @@ -305,5 +307,16 @@ public BeaconBlockBodyBuilder syncAggregate( this.syncAggregate = syncAggregateSupplier.get(); return this; } + + @Override + public BeaconBlockBodyBuilder executionPayload( + Supplier executionPayloadSupplier) { + return this; + } + + @Override + public BeaconBlockBody build() { + return null; + } } } diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/BeaconBlockBody.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/BeaconBlockBody.java index a3f73002a2d..606a267b84b 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/BeaconBlockBody.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/BeaconBlockBody.java @@ -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()); } diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/altair/BeaconStateAltair.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/altair/BeaconStateAltair.java index 5e08dbcf371..f25238114c7 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/altair/BeaconStateAltair.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/altair/BeaconStateAltair.java @@ -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; @@ -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()) + .getCurrentSyncCommitteeSchema(); final SszList previousEpochParticipation = beaconStateAltair .getPreviousEpochParticipation() diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBeaconBlockBodyBenchmark.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBeaconBlockBodyBenchmark.java index 88dce35ad13..74c9c6487d9 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBeaconBlockBodyBenchmark.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBeaconBlockBodyBenchmark.java @@ -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 diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBenchUtil.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBenchUtil.java index 0c0c6e71b14..3bc1db478c3 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBenchUtil.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ssz/SszBenchUtil.java @@ -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) { diff --git a/ethereum/spec/build.gradle b/ethereum/spec/build.gradle index ab700412a7e..f7a9b4ae944 100644 --- a/ethereum/spec/build.gradle +++ b/ethereum/spec/build.gradle @@ -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' diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecVersion.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecVersion.java index 90e6d4ed4ca..adf2dc6e53c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecVersion.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/SpecVersion.java @@ -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; @@ -46,6 +47,8 @@ static Optional 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); } @@ -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; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBody.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBody.java index 8d53f234a0e..777668d0f63 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBody.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBody.java @@ -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; @@ -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 getProposer_slashings(); + SszList getProposerSlashings(); - SszList getAttester_slashings(); + SszList getAttesterSlashings(); SszList getAttestations(); SszList getDeposits(); - SszList getVoluntary_exits(); + SszList getVoluntaryExits(); @Override BeaconBlockBodySchema getSchema(); - Optional toVersionAltair(); + default Optional toVersionAltair() { + return Optional.empty(); + } + + default Optional toVersionMerge() { + return Optional.empty(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodyBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodyBuilder.java index dac8e68da86..688b90790a2 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodyBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodyBuilder.java @@ -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; @@ -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 syncAggregateSupplier); + + // Not required by all hard forks so provided via a Supplier that is only invoked when needed. + BeaconBlockBodyBuilder executionPayload(Supplier executionPayloadSupplier); + + BeaconBlockBody build(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodySchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodySchema.java index f55f2a6f4c3..0afffcac188 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodySchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/BeaconBlockBodySchema.java @@ -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; @@ -24,9 +27,9 @@ import tech.pegasys.teku.ssz.tree.TreeNode; public interface BeaconBlockBodySchema extends SszContainerSchema { - T createBlockBody(Consumer bodyBuilder); + BeaconBlockBody createBlockBody(Consumer bodyBuilder); - T createEmpty(); + BeaconBlockBody createEmpty(); @Override T createFromBackingNode(TreeNode node); @@ -40,4 +43,12 @@ public interface BeaconBlockBodySchema extends SszCon SszListSchema getDepositsSchema(); SszListSchema getVoluntaryExitsSchema(); + + default Optional> toVersionAltair() { + return Optional.empty(); + } + + default Optional> toVersionMerge() { + return Optional.empty(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyBuilder.java deleted file mode 100644 index fef00641110..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyBuilder.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2021 ConsenSys AG. - * - * 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.spec.datastructures.blocks.blockbody.common; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.apache.tuweni.bytes.Bytes32; -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder; -import tech.pegasys.teku.spec.datastructures.operations.Attestation; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.Deposit; -import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; -import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; -import tech.pegasys.teku.ssz.SszList; - -public abstract class AbstractBeaconBlockBodyBuilder implements BeaconBlockBodyBuilder { - - protected BLSSignature randaoReveal; - protected Eth1Data eth1Data; - protected Bytes32 graffiti; - protected SszList attestations; - protected SszList proposerSlashings; - protected SszList attesterSlashings; - protected SszList deposits; - protected SszList voluntaryExits; - - @Override - public BeaconBlockBodyBuilder randaoReveal(final BLSSignature randaoReveal) { - this.randaoReveal = randaoReveal; - return this; - } - - @Override - public BeaconBlockBodyBuilder eth1Data(final Eth1Data eth1Data) { - this.eth1Data = eth1Data; - return this; - } - - @Override - public BeaconBlockBodyBuilder graffiti(final Bytes32 graffiti) { - this.graffiti = graffiti; - return this; - } - - @Override - public BeaconBlockBodyBuilder attestations(final SszList attestations) { - this.attestations = attestations; - return this; - } - - @Override - public BeaconBlockBodyBuilder proposerSlashings( - final SszList proposerSlashings) { - this.proposerSlashings = proposerSlashings; - return this; - } - - @Override - public BeaconBlockBodyBuilder attesterSlashings( - final SszList attesterSlashings) { - this.attesterSlashings = attesterSlashings; - return this; - } - - @Override - public BeaconBlockBodyBuilder deposits(final SszList deposits) { - this.deposits = deposits; - return this; - } - - @Override - public BeaconBlockBodyBuilder voluntaryExits(final SszList voluntaryExits) { - this.voluntaryExits = voluntaryExits; - return this; - } - - protected void validate() { - checkNotNull(randaoReveal, "randaoReveal must be specified"); - checkNotNull(eth1Data, "eth1Data must be specified"); - checkNotNull(graffiti, "graffiti must be specified"); - checkNotNull(attestations, "attestations must be specified"); - checkNotNull(proposerSlashings, "proposerSlashings must be specified"); - checkNotNull(attesterSlashings, "attesterSlashings must be specified"); - checkNotNull(deposits, "deposits must be specified"); - checkNotNull(voluntaryExits, "voluntaryExits must be specified"); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/BlockBodyFields.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/BlockBodyFields.java index 3e31f0f47be..8f44072367b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/BlockBodyFields.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/BlockBodyFields.java @@ -22,5 +22,6 @@ public enum BlockBodyFields { ATTESTATIONS, DEPOSITS, VOLUNTARY_EXITS, - SYNC_AGGREGATE + SYNC_AGGREGATE, + EXECUTION_PAYLOAD } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairImpl.java index 9716caa0b54..f1172bb3a0c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairImpl.java @@ -85,12 +85,12 @@ public static BeaconBlockBodyAltair required(final BeaconBlockBody body) { } @Override - public BLSSignature getRandao_reveal() { + public BLSSignature getRandaoReveal() { return getField0().getSignature(); } @Override - public Eth1Data getEth1_data() { + public Eth1Data getEth1Data() { return getField1(); } @@ -100,12 +100,12 @@ public Bytes32 getGraffiti() { } @Override - public SszList getProposer_slashings() { + public SszList getProposerSlashings() { return getField3(); } @Override - public SszList getAttester_slashings() { + public SszList getAttesterSlashings() { return getField4(); } @@ -120,7 +120,7 @@ public SszList getDeposits() { } @Override - public SszList getVoluntary_exits() { + public SszList getVoluntaryExits() { return getField7(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyBuilderAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyBuilderAltair.java index 829cb6b8e1c..31214faa2c0 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyBuilderAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyBuilderAltair.java @@ -16,15 +16,16 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.function.Supplier; +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.common.AbstractBeaconBlockBodyBuilder; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.phase0.BeaconBlockBodyBuilderPhase0; import tech.pegasys.teku.spec.datastructures.type.SszSignature; import tech.pegasys.teku.ssz.primitive.SszBytes32; -public class BeaconBlockBodyBuilderAltair extends AbstractBeaconBlockBodyBuilder { +public class BeaconBlockBodyBuilderAltair extends BeaconBlockBodyBuilderPhase0 { private BeaconBlockBodySchemaAltairImpl schema; - private SyncAggregate syncAggregate; + protected SyncAggregate syncAggregate; public BeaconBlockBodyBuilderAltair schema(final BeaconBlockBodySchemaAltairImpl schema) { this.schema = schema; @@ -37,14 +38,19 @@ public BeaconBlockBodyBuilder syncAggregate(final Supplier syncAg return this; } + @Override + protected void validateSchema() { + checkNotNull(schema, "schema must be specified"); + } + @Override protected void validate() { super.validate(); - checkNotNull(schema, "schema must be specified"); checkNotNull(syncAggregate, "syncAggregate must be specified"); } - public BeaconBlockBodyAltairImpl build() { + @Override + public BeaconBlockBody build() { validate(); return new BeaconBlockBodyAltairImpl( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltair.java index f77d7a6a088..f62801470fc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltair.java @@ -15,6 +15,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import java.util.Optional; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; @@ -42,4 +43,9 @@ static BeaconBlockBodySchemaAltair required(final BeaconBlockBodySchema sc } SyncAggregateSchema getSyncAggregateSchema(); + + @Override + default Optional> toVersionAltair() { + return Optional.of(this); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java index 705ff51c295..39a3128484d 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java @@ -16,6 +16,7 @@ import java.util.function.Consumer; import tech.pegasys.teku.spec.config.SpecConfig; 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.common.BlockBodyFields; import tech.pegasys.teku.spec.datastructures.operations.Attestation; @@ -110,14 +111,12 @@ static BeaconBlockBodySchemaAltair create( } @Override - public BeaconBlockBodyAltairImpl createBlockBody( - final Consumer bodyBuilder) { - final BeaconBlockBodyBuilderAltair bodyContent = - new BeaconBlockBodyBuilderAltair().schema(this); + public BeaconBlockBody createBlockBody(final Consumer builderConsumer) { + final BeaconBlockBodyBuilderAltair builder = new BeaconBlockBodyBuilderAltair().schema(this); // Provide a default empty sync aggregate - bodyContent.syncAggregate(getSyncAggregateSchema()::createEmpty); - bodyBuilder.accept(bodyContent); - return bodyContent.build(); + builder.syncAggregate(getSyncAggregateSchema()::createEmpty); + builderConsumer.accept(builder); + return builder.build(); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyBuilderMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyBuilderMerge.java new file mode 100644 index 00000000000..e8cb66b8b44 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyBuilderMerge.java @@ -0,0 +1,69 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.function.Supplier; +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.versions.altair.BeaconBlockBodyBuilderAltair; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.ssz.primitive.SszBytes32; + +class BeaconBlockBodyBuilderMerge extends BeaconBlockBodyBuilderAltair { + private BeaconBlockBodySchemaMergeImpl schema; + protected ExecutionPayload executionPayload; + + public BeaconBlockBodyBuilderMerge schema(final BeaconBlockBodySchemaMergeImpl schema) { + this.schema = schema; + return this; + } + + @Override + public BeaconBlockBodyBuilder executionPayload( + Supplier executionPayloadSupplier) { + this.executionPayload = executionPayloadSupplier.get(); + return this; + } + + @Override + protected void validateSchema() { + checkNotNull(schema, "schema must be specified"); + } + + @Override + protected void validate() { + super.validate(); + checkNotNull(executionPayload, "executionPayload must be specified"); + } + + @Override + public BeaconBlockBody build() { + validate(); + return new BeaconBlockBodyMergeImpl( + schema, + new SszSignature(randaoReveal), + eth1Data, + SszBytes32.of(graffiti), + proposerSlashings, + attesterSlashings, + attestations, + deposits, + voluntaryExits, + syncAggregate, + executionPayload); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMerge.java new file mode 100644 index 00000000000..5dd4052a314 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMerge.java @@ -0,0 +1,43 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Optional; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodyAltair; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; + +/** A Beacon block body */ +public interface BeaconBlockBodyMerge extends BeaconBlockBodyAltair { + + static BeaconBlockBodyMerge required(final BeaconBlockBody body) { + checkArgument( + body instanceof BeaconBlockBodyMerge, + "Expected merge block body but got %s", + body.getClass()); + return (BeaconBlockBodyMerge) body; + } + + ExecutionPayload getExecutionPayload(); + + @Override + BeaconBlockBodySchemaMerge getSchema(); + + @Override + default Optional toVersionMerge() { + return Optional.of(this); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeImpl.java new file mode 100644 index 00000000000..4fb67901def --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeImpl.java @@ -0,0 +1,147 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import static com.google.common.base.Preconditions.checkArgument; + +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.bls.BLSSignature; +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.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; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.ssz.SszList; +import tech.pegasys.teku.ssz.containers.Container10; +import tech.pegasys.teku.ssz.primitive.SszBytes32; +import tech.pegasys.teku.ssz.tree.TreeNode; + +/** A Beacon block body */ +class BeaconBlockBodyMergeImpl + extends Container10< + BeaconBlockBodyMergeImpl, + SszSignature, + Eth1Data, + SszBytes32, + SszList, + SszList, + SszList, + SszList, + SszList, + SyncAggregate, + ExecutionPayload> + implements BeaconBlockBodyMerge { + + BeaconBlockBodyMergeImpl(BeaconBlockBodySchemaMergeImpl type) { + super(type); + } + + BeaconBlockBodyMergeImpl(BeaconBlockBodySchemaMergeImpl type, TreeNode backingNode) { + super(type, backingNode); + } + + BeaconBlockBodyMergeImpl( + BeaconBlockBodySchemaMergeImpl type, + SszSignature randaoReveal, + Eth1Data eth1_data, + SszBytes32 graffiti, + SszList proposerSlashings, + SszList attesterSlashings, + SszList attestations, + SszList deposits, + SszList voluntaryExits, + SyncAggregate syncAggregate, + ExecutionPayload executionPayload) { + super( + type, + randaoReveal, + eth1_data, + graffiti, + proposerSlashings, + attesterSlashings, + attestations, + deposits, + voluntaryExits, + syncAggregate, + executionPayload); + } + + public static BeaconBlockBodyMergeImpl required(final BeaconBlockBody body) { + checkArgument( + body instanceof BeaconBlockBodyMergeImpl, + "Expected merge block body but got %s", + body.getClass()); + return (BeaconBlockBodyMergeImpl) body; + } + + @Override + public BLSSignature getRandaoReveal() { + return getField0().getSignature(); + } + + @Override + public Eth1Data getEth1Data() { + return getField1(); + } + + @Override + public Bytes32 getGraffiti() { + return getField2().get(); + } + + @Override + public SszList getProposerSlashings() { + return getField3(); + } + + @Override + public SszList getAttesterSlashings() { + return getField4(); + } + + @Override + public SszList getAttestations() { + return getField5(); + } + + @Override + public SszList getDeposits() { + return getField6(); + } + + @Override + public SszList getVoluntaryExits() { + return getField7(); + } + + @Override + public SyncAggregate getSyncAggregate() { + return getField8(); + } + + @Override + public ExecutionPayload getExecutionPayload() { + return getField9(); + } + + @Override + public BeaconBlockBodySchemaMergeImpl getSchema() { + return (BeaconBlockBodySchemaMergeImpl) super.getSchema(); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMerge.java new file mode 100644 index 00000000000..a026061b3be --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMerge.java @@ -0,0 +1,44 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import java.util.Optional; +import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.config.SpecConfigMerge; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload.ExecutionPayloadSchema; + +public interface BeaconBlockBodySchemaMerge + extends BeaconBlockBodySchemaAltair { + + static BeaconBlockBodySchemaMerge create(final SpecConfig specConfig) { + return SpecConfigMerge.required( + specConfig, + config -> + BeaconBlockBodySchemaMergeImpl.create( + config.getMaxProposerSlashings(), + config.getMaxAttesterSlashings(), + config.getMaxAttestations(), + config.getMaxDeposits(), + config.getMaxVoluntaryExits(), + config.getSyncCommitteeSize())); + } + + ExecutionPayloadSchema getExecutionPayloadSchema(); + + @Override + default Optional> toVersionMerge() { + return Optional.of(this); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMergeImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMergeImpl.java new file mode 100644 index 00000000000..eec198b8ee1 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodySchemaMergeImpl.java @@ -0,0 +1,173 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import java.util.Optional; +import java.util.function.Consumer; +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.common.BlockBodyFields; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload.ExecutionPayloadSchema; +import tech.pegasys.teku.spec.datastructures.operations.Attestation; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.Deposit; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; +import tech.pegasys.teku.ssz.SszList; +import tech.pegasys.teku.ssz.containers.ContainerSchema10; +import tech.pegasys.teku.ssz.primitive.SszBytes32; +import tech.pegasys.teku.ssz.schema.SszListSchema; +import tech.pegasys.teku.ssz.schema.SszPrimitiveSchemas; +import tech.pegasys.teku.ssz.tree.TreeNode; + +class BeaconBlockBodySchemaMergeImpl + extends ContainerSchema10< + BeaconBlockBodyMergeImpl, + SszSignature, + Eth1Data, + SszBytes32, + SszList, + SszList, + SszList, + SszList, + SszList, + SyncAggregate, + ExecutionPayload> + implements BeaconBlockBodySchemaMerge { + + private BeaconBlockBodySchemaMergeImpl( + NamedSchema randaoRevealSchema, + NamedSchema eth1DataSchema, + NamedSchema graffitiSchema, + NamedSchema> proposerSlashingsSchema, + NamedSchema> attesterSlashingsSchema, + NamedSchema> attestationsSchema, + NamedSchema> depositsSchema, + NamedSchema> voluntaryExitsSchema, + NamedSchema syncAggregateSchema, + NamedSchema executionPayloadSchema) { + super( + "BeaconBlockBody", + randaoRevealSchema, + eth1DataSchema, + graffitiSchema, + proposerSlashingsSchema, + attesterSlashingsSchema, + attestationsSchema, + depositsSchema, + voluntaryExitsSchema, + syncAggregateSchema, + executionPayloadSchema); + } + + static BeaconBlockBodySchemaMergeImpl create( + final long maxProposerSlashings, + final long maxAttesterSlashings, + final long maxAttestations, + final long maxDeposits, + final long maxVoluntaryExits, + final int syncCommitteeSize) { + return new BeaconBlockBodySchemaMergeImpl( + namedSchema(BlockBodyFields.RANDAO_REVEAL.name(), SszSignatureSchema.INSTANCE), + namedSchema(BlockBodyFields.ETH1_DATA.name(), Eth1Data.SSZ_SCHEMA), + namedSchema(BlockBodyFields.GRAFFITI.name(), SszPrimitiveSchemas.BYTES32_SCHEMA), + namedSchema( + BlockBodyFields.PROPOSER_SLASHINGS.name(), + SszListSchema.create(ProposerSlashing.SSZ_SCHEMA, maxProposerSlashings)), + namedSchema( + BlockBodyFields.ATTESTER_SLASHINGS.name(), + SszListSchema.create(AttesterSlashing.SSZ_SCHEMA, maxAttesterSlashings)), + namedSchema( + BlockBodyFields.ATTESTATIONS.name(), + SszListSchema.create(Attestation.SSZ_SCHEMA, maxAttestations)), + namedSchema( + BlockBodyFields.DEPOSITS.name(), SszListSchema.create(Deposit.SSZ_SCHEMA, maxDeposits)), + namedSchema( + BlockBodyFields.VOLUNTARY_EXITS.name(), + SszListSchema.create(SignedVoluntaryExit.SSZ_SCHEMA, maxVoluntaryExits)), + namedSchema( + BlockBodyFields.SYNC_AGGREGATE.name(), SyncAggregateSchema.create(syncCommitteeSize)), + namedSchema(BlockBodyFields.EXECUTION_PAYLOAD.name(), ExecutionPayload.SSZ_SCHEMA)); + } + + @Override + public BeaconBlockBody createBlockBody(final Consumer builderConsumer) { + final BeaconBlockBodyBuilderMerge builder = new BeaconBlockBodyBuilderMerge().schema(this); + // Provide a default empty sync aggregate + builder.syncAggregate(getSyncAggregateSchema()::createEmpty); + builderConsumer.accept(builder); + return builder.build(); + } + + @Override + public BeaconBlockBodyMergeImpl createEmpty() { + return new BeaconBlockBodyMergeImpl(this); + } + + @SuppressWarnings("unchecked") + @Override + public SszListSchema getProposerSlashingsSchema() { + return (SszListSchema) getFieldSchema3(); + } + + @SuppressWarnings("unchecked") + @Override + public SszListSchema getAttesterSlashingsSchema() { + return (SszListSchema) getFieldSchema4(); + } + + @SuppressWarnings("unchecked") + @Override + public SszListSchema getAttestationsSchema() { + return (SszListSchema) getFieldSchema5(); + } + + @SuppressWarnings("unchecked") + @Override + public SszListSchema getDepositsSchema() { + return (SszListSchema) getFieldSchema6(); + } + + @SuppressWarnings("unchecked") + @Override + public SszListSchema getVoluntaryExitsSchema() { + return (SszListSchema) getFieldSchema7(); + } + + @Override + public SyncAggregateSchema getSyncAggregateSchema() { + return (SyncAggregateSchema) getFieldSchema8(); + } + + @Override + public BeaconBlockBodyMergeImpl createFromBackingNode(TreeNode node) { + return new BeaconBlockBodyMergeImpl(this, node); + } + + @Override + public ExecutionPayloadSchema getExecutionPayloadSchema() { + return (ExecutionPayloadSchema) getFieldSchema9(); + } + + @Override + public Optional> toVersionMerge() { + return Optional.of(this); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyBuilderPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyBuilderPhase0.java index ed72258f999..0d2bfc2ea4b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyBuilderPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyBuilderPhase0.java @@ -16,14 +16,82 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.function.Supplier; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.bls.BLSSignature; +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.common.AbstractBeaconBlockBodyBuilder; 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; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.ssz.SszList; import tech.pegasys.teku.ssz.primitive.SszBytes32; -public class BeaconBlockBodyBuilderPhase0 extends AbstractBeaconBlockBodyBuilder { +public class BeaconBlockBodyBuilderPhase0 implements BeaconBlockBodyBuilder { private BeaconBlockBodySchemaPhase0 schema; + protected BLSSignature randaoReveal; + protected Eth1Data eth1Data; + protected Bytes32 graffiti; + protected SszList attestations; + protected SszList proposerSlashings; + protected SszList attesterSlashings; + protected SszList deposits; + protected SszList voluntaryExits; + + @Override + public BeaconBlockBodyBuilder randaoReveal(final BLSSignature randaoReveal) { + this.randaoReveal = randaoReveal; + return this; + } + + @Override + public BeaconBlockBodyBuilder eth1Data(final Eth1Data eth1Data) { + this.eth1Data = eth1Data; + return this; + } + + @Override + public BeaconBlockBodyBuilder graffiti(final Bytes32 graffiti) { + this.graffiti = graffiti; + return this; + } + + @Override + public BeaconBlockBodyBuilder attestations(final SszList attestations) { + this.attestations = attestations; + return this; + } + + @Override + public BeaconBlockBodyBuilder proposerSlashings( + final SszList proposerSlashings) { + this.proposerSlashings = proposerSlashings; + return this; + } + + @Override + public BeaconBlockBodyBuilder attesterSlashings( + final SszList attesterSlashings) { + this.attesterSlashings = attesterSlashings; + return this; + } + + @Override + public BeaconBlockBodyBuilder deposits(final SszList deposits) { + this.deposits = deposits; + return this; + } + + @Override + public BeaconBlockBodyBuilder voluntaryExits(final SszList voluntaryExits) { + this.voluntaryExits = voluntaryExits; + return this; + } public BeaconBlockBodyBuilderPhase0 schema(final BeaconBlockBodySchemaPhase0 schema) { this.schema = schema; @@ -37,12 +105,30 @@ public BeaconBlockBodyBuilder syncAggregate(final Supplier syncAg } @Override - protected void validate() { - super.validate(); + public BeaconBlockBodyBuilder executionPayload( + Supplier executionPayloadSupplier) { + // No execution payload in phase 0 + return this; + } + + protected void validateSchema() { checkNotNull(schema, "schema must be specified"); } - public BeaconBlockBodyPhase0 build() { + protected void validate() { + checkNotNull(randaoReveal, "randaoReveal must be specified"); + checkNotNull(eth1Data, "eth1Data must be specified"); + checkNotNull(graffiti, "graffiti must be specified"); + checkNotNull(attestations, "attestations must be specified"); + checkNotNull(proposerSlashings, "proposerSlashings must be specified"); + checkNotNull(attesterSlashings, "attesterSlashings must be specified"); + checkNotNull(deposits, "deposits must be specified"); + checkNotNull(voluntaryExits, "voluntaryExits must be specified"); + validateSchema(); + } + + @Override + public BeaconBlockBody build() { validate(); return new BeaconBlockBodyPhase0( schema, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0.java index ee91678e3ba..78a8ef4fcb5 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0.java @@ -54,33 +54,33 @@ public class BeaconBlockBodyPhase0 BeaconBlockBodyPhase0( BeaconBlockBodySchemaPhase0 type, - SszSignature randao_reveal, - Eth1Data eth1_data, + SszSignature randaoReveal, + Eth1Data eth1Data, SszBytes32 graffiti, - SszList proposer_slashings, - SszList attester_slashings, + SszList proposerSlashings, + SszList attesterSlashings, SszList attestations, SszList deposits, - SszList voluntary_exits) { + SszList voluntaryExits) { super( type, - randao_reveal, - eth1_data, + randaoReveal, + eth1Data, graffiti, - proposer_slashings, - attester_slashings, + proposerSlashings, + attesterSlashings, attestations, deposits, - voluntary_exits); + voluntaryExits); } @Override - public BLSSignature getRandao_reveal() { + public BLSSignature getRandaoReveal() { return getField0().getSignature(); } @Override - public Eth1Data getEth1_data() { + public Eth1Data getEth1Data() { return getField1(); } @@ -90,12 +90,12 @@ public Bytes32 getGraffiti() { } @Override - public SszList getProposer_slashings() { + public SszList getProposerSlashings() { return getField3(); } @Override - public SszList getAttester_slashings() { + public SszList getAttesterSlashings() { return getField4(); } @@ -110,7 +110,7 @@ public SszList getDeposits() { } @Override - public SszList getVoluntary_exits() { + public SszList getVoluntaryExits() { return getField7(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java index ee453100eea..435ef43f342 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java @@ -16,6 +16,7 @@ import java.util.function.Consumer; import tech.pegasys.teku.spec.config.SpecConfig; 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.common.BlockBodyFields; @@ -103,8 +104,7 @@ private static BeaconBlockBodySchemaPhase0 create( } @Override - public BeaconBlockBodyPhase0 createBlockBody( - final Consumer builderConsumer) { + public BeaconBlockBody createBlockBody(final Consumer builderConsumer) { final BeaconBlockBodyBuilderPhase0 builder = new BeaconBlockBodyBuilderPhase0().schema(this); builderConsumer.accept(builder); return builder.build(); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconState.java index 3f343c48568..5ac5dc7bf19 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconState.java @@ -25,6 +25,7 @@ import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.analysis.ValidatorStats; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.BeaconStateMerge; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStatePhase0; import tech.pegasys.teku.ssz.SszContainer; import tech.pegasys.teku.ssz.SszList; @@ -172,4 +173,8 @@ default Optional toVersionPhase0() { default Optional toVersionAltair() { return Optional.empty(); } + + default Optional toVersionMerge() { + return Optional.empty(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconStateSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconStateSchema.java index 78dcd01bd39..636ae9581cd 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconStateSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/BeaconStateSchema.java @@ -13,15 +13,19 @@ package tech.pegasys.teku.spec.datastructures.state.beaconstate; +import static com.google.common.base.Preconditions.checkArgument; + import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data; +import tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema; import tech.pegasys.teku.spec.datastructures.state.Validator; import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; import tech.pegasys.teku.ssz.primitive.SszBytes32; import tech.pegasys.teku.ssz.primitive.SszUInt64; import tech.pegasys.teku.ssz.schema.SszContainerSchema; import tech.pegasys.teku.ssz.schema.SszListSchema; +import tech.pegasys.teku.ssz.schema.SszSchema; import tech.pegasys.teku.ssz.schema.collections.SszBitvectorSchema; import tech.pegasys.teku.ssz.schema.collections.SszBytes32VectorSchema; import tech.pegasys.teku.ssz.schema.collections.SszPrimitiveListSchema; @@ -82,4 +86,23 @@ default SszBitvectorSchema getJustificationBitsSchema() { return (SszBitvectorSchema) getChildSchema(getFieldIndex(BeaconStateFields.JUSTIFICATION_BITS.name())); } + + default SyncCommitteeSchema getCurrentSyncCommitteeSchemaOrThrow() { + return (SyncCommitteeSchema) getSchemaOrThrow(BeaconStateFields.CURRENT_SYNC_COMMITTEE); + } + + default SyncCommitteeSchema getNextSyncCommitteeSchemaOrThrow() { + return (SyncCommitteeSchema) getSchemaOrThrow(BeaconStateFields.NEXT_SYNC_COMMITTEE); + } + + private SszSchema getSchemaOrThrow(final BeaconStateFields field) { + final String fieldName = field.name(); + final int fieldIndex = getFieldIndex(fieldName); + checkArgument( + fieldIndex >= 0, + "Expected a %s field in schema %s but was not found", + fieldName, + getClass()); + return getChildSchema(fieldIndex); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/MutableBeaconState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/MutableBeaconState.java index 7704e61b1b6..f8426250e75 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/MutableBeaconState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/MutableBeaconState.java @@ -23,6 +23,7 @@ import tech.pegasys.teku.spec.datastructures.state.Validator; import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.MutableBeaconStateMerge; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.MutableBeaconStatePhase0; import tech.pegasys.teku.ssz.SszList; import tech.pegasys.teku.ssz.SszMutableList; @@ -204,4 +205,8 @@ default Optional toMutableVersionPhase0() { default Optional toMutableVersionAltair() { return Optional.empty(); } + + default Optional toMutableVersionMerge() { + return Optional.empty(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconState.java index c945224bdc7..9c681acd595 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractBeaconState.java @@ -52,10 +52,15 @@ protected AbstractBeaconState( transitionCaches = TransitionCaches.createNewEmpty(); } + @Override + public BeaconStateSchema getBeaconStateSchema() { + return (BeaconStateSchema) getSchema(); + } + @Override public BeaconState updated( Mutator mutator) throws E1, E2, E3 { - MutableBeaconState writableCopy = createWritableCopyPriv(); + MutableBeaconState writableCopy = createWritableCopy(); mutator.mutate(writableCopy); return writableCopy.commitChanges(); } @@ -87,5 +92,6 @@ public String toString() { protected abstract void describeCustomFields(ToStringHelper stringBuilder); - protected abstract TMutable createWritableCopyPriv(); + @Override + public abstract TMutable createWritableCopy(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractMutableBeaconState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractMutableBeaconState.java index 1ef92d92121..d2bddb1bd90 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractMutableBeaconState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/AbstractMutableBeaconState.java @@ -17,6 +17,7 @@ import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; import tech.pegasys.teku.ssz.SszData; import tech.pegasys.teku.ssz.cache.IntCache; @@ -42,6 +43,11 @@ protected AbstractMutableBeaconState(T backingImmutableView, boolean builder) { this.builder = builder; } + @Override + public BeaconStateSchema getBeaconStateSchema() { + return (BeaconStateSchema) getSchema(); + } + @Override protected T createImmutableSszComposite(TreeNode backingNode, IntCache viewCache) { return createImmutableBeaconState( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateFields.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateFields.java index 7420245a92a..9a2ee710579 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateFields.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateFields.java @@ -60,7 +60,9 @@ public enum BeaconStateFields { CURRENT_EPOCH_PARTICIPATION, INACTIVITY_SCORES, CURRENT_SYNC_COMMITTEE, - NEXT_SYNC_COMMITTEE; + NEXT_SYNC_COMMITTEE, + // Merge fields + LATEST_EXECUTION_PAYLOAD_HEADER; public static void copyCommonFieldsFromSource( final MutableBeaconState state, final BeaconState source) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltair.java index b7ab5fce8d7..21edfebc595 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltair.java @@ -23,11 +23,6 @@ public interface BeaconStateAltair extends BeaconState { - @Override - default BeaconStateSchemaAltair getBeaconStateSchema() { - return (BeaconStateSchemaAltair) getSchema(); - } - static BeaconStateAltair required(final BeaconState state) { return state .toVersionAltair() @@ -71,7 +66,14 @@ default Optional toVersionAltair() { return Optional.of(this); } - + @Override + MutableBeaconStateAltair createWritableCopy(); + + default BeaconStateAltair updatedAltair(Mutator mutator) - throws E1, E2, E3; + throws E1, E2, E3 { + MutableBeaconStateAltair writableCopy = createWritableCopy(); + mutator.mutate(writableCopy); + return writableCopy.commitChanges(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltairImpl.java index 1f67b9529ef..e8a834c6837 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateAltairImpl.java @@ -47,16 +47,12 @@ class BeaconStateAltairImpl extends AbstractBeaconState - BeaconStateAltair updatedAltair(Mutator mutator) - throws E1, E2, E3 { - MutableBeaconStateAltair writableCopy = createWritableCopyPriv(); - mutator.mutate(writableCopy); - return writableCopy.commitChanges(); + public BeaconStateSchemaAltair getBeaconStateSchema() { + return (BeaconStateSchemaAltair) getSchema(); } @Override - protected MutableBeaconStateAltair createWritableCopyPriv() { + public MutableBeaconStateAltair createWritableCopy() { return new MutableBeaconStateAltairImpl(this); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltair.java index 3fd111d52c1..d69bd9dc8dd 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/BeaconStateSchemaAltair.java @@ -49,7 +49,7 @@ public static BeaconStateSchemaAltair create(final SpecConfig specConfig) { return new BeaconStateSchemaAltair(specConfig); } - private static List getUniqueFields(final SpecConfig specConfig) { + public static List getUniqueFields(final SpecConfig specConfig) { final SszField previousEpochAttestationsField = new SszField( PREVIOUS_EPOCH_PARTICIPATION_FIELD_INDEX, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/MutableBeaconStateAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/MutableBeaconStateAltairImpl.java index 3427728ce11..97c117d87ab 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/MutableBeaconStateAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/MutableBeaconStateAltairImpl.java @@ -14,9 +14,7 @@ package tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair; import com.google.common.base.MoreObjects.ToStringHelper; -import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; -import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.AbstractMutableBeaconState; import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.TransitionCaches; import tech.pegasys.teku.ssz.SszData; @@ -34,6 +32,11 @@ class MutableBeaconStateAltairImpl extends AbstractMutableBeaconState viewCache, TransitionCaches transitionCache) { @@ -46,20 +49,12 @@ public BeaconStateAltair commitChanges() { } @Override - public BeaconState updated( - Mutator mutator) { - throw new UnsupportedOperationException(); - } - - @Override - public - BeaconStateAltair updatedAltair(Mutator mutator) - throws E1, E2, E3 { - throw new UnsupportedOperationException(); + protected void addCustomFields(ToStringHelper stringBuilder) { + BeaconStateAltairImpl.describeCustomFields(stringBuilder, this); } @Override - protected void addCustomFields(ToStringHelper stringBuilder) { - BeaconStateAltairImpl.describeCustomFields(stringBuilder, this); + public MutableBeaconStateAltair createWritableCopy() { + return (MutableBeaconStateAltair) super.createWritableCopy(); } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/ValidatorStatsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/ValidatorStatsAltair.java index ffa1b0014b7..29071f8652b 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/ValidatorStatsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/altair/ValidatorStatsAltair.java @@ -18,7 +18,7 @@ import tech.pegasys.teku.ssz.SszList; import tech.pegasys.teku.ssz.primitive.SszByte; -interface ValidatorStatsAltair extends BeaconStateAltair { +public interface ValidatorStatsAltair extends BeaconStateAltair { @Override default CorrectAndLiveValidators getValidatorStatsPreviousEpoch(final Bytes32 correctTargetRoot) { return getValidatorStats(getPreviousEpochParticipation()); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMerge.java new file mode 100644 index 00000000000..af5fe247a2e --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMerge.java @@ -0,0 +1,55 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.state.beaconstate.versions.merge; + +import java.util.Optional; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair; + +public interface BeaconStateMerge extends BeaconStateAltair { + + static BeaconStateMerge required(final BeaconState state) { + return state + .toVersionMerge() + .orElseThrow( + () -> + new IllegalArgumentException( + "Expected a merge state but got: " + state.getClass().getSimpleName())); + } + + // Execution + default ExecutionPayloadHeader getLatest_execution_payload_header() { + final int fieldIndex = + getSchema().getFieldIndex(BeaconStateFields.LATEST_EXECUTION_PAYLOAD_HEADER.name()); + return getAny(fieldIndex); + } + + @Override + default Optional toVersionMerge() { + return Optional.of(this); + } + + @Override + MutableBeaconStateMerge createWritableCopy(); + + default + BeaconStateMerge updatedMerge(Mutator mutator) + throws E1, E2, E3 { + MutableBeaconStateMerge writableCopy = createWritableCopy(); + mutator.mutate(writableCopy); + return writableCopy.commitChanges(); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMergeImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMergeImpl.java new file mode 100644 index 00000000000..85a94c2e491 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateMergeImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.state.beaconstate.versions.merge; + +import com.google.common.base.MoreObjects.ToStringHelper; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.AbstractBeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.TransitionCaches; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.ValidatorStatsAltair; +import tech.pegasys.teku.ssz.SszContainer; +import tech.pegasys.teku.ssz.SszData; +import tech.pegasys.teku.ssz.cache.IntCache; +import tech.pegasys.teku.ssz.schema.SszCompositeSchema; +import tech.pegasys.teku.ssz.schema.impl.AbstractSszContainerSchema; +import tech.pegasys.teku.ssz.tree.TreeNode; + +class BeaconStateMergeImpl extends AbstractBeaconState + implements BeaconStateMerge, BeaconStateCache, ValidatorStatsAltair { + + BeaconStateMergeImpl(final BeaconStateSchema schema) { + super(schema); + } + + BeaconStateMergeImpl( + SszCompositeSchema type, + TreeNode backingNode, + IntCache cache, + TransitionCaches transitionCaches) { + super(type, backingNode, cache, transitionCaches); + } + + BeaconStateMergeImpl( + AbstractSszContainerSchema type, TreeNode backingNode) { + super(type, backingNode); + } + + @Override + public BeaconStateSchemaMerge getBeaconStateSchema() { + return (BeaconStateSchemaMerge) getSchema(); + } + + @Override + public MutableBeaconStateMerge createWritableCopy() { + return new MutableBeaconStateMergeImpl(this); + } + + @Override + protected void describeCustomFields(ToStringHelper stringBuilder) { + describeCustomFields(stringBuilder, this); + } + + static void describeCustomFields(ToStringHelper stringBuilder, final BeaconStateMerge state) { + stringBuilder.add("execution_payload_header", state.getLatest_execution_payload_header()); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateSchemaMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateSchemaMerge.java new file mode 100644 index 00000000000..8364ecd5e55 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/BeaconStateSchemaMerge.java @@ -0,0 +1,120 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.state.beaconstate.versions.merge; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.annotations.VisibleForTesting; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader.ExecutionPayloadHeaderSchema; +import tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.AbstractBeaconStateSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair; +import tech.pegasys.teku.ssz.primitive.SszByte; +import tech.pegasys.teku.ssz.schema.collections.SszPrimitiveListSchema; +import tech.pegasys.teku.ssz.schema.collections.SszUInt64ListSchema; +import tech.pegasys.teku.ssz.sos.SszField; +import tech.pegasys.teku.ssz.tree.TreeNode; + +public class BeaconStateSchemaMerge + extends AbstractBeaconStateSchema { + + private static final int LATEST_EXECUTION_PAYLOAD_HEADER_FIELD_INDEX = 24; + + @VisibleForTesting + BeaconStateSchemaMerge(final SpecConfig specConfig) { + super("BeaconStateMerge", getUniqueFields(specConfig), specConfig); + } + + public static BeaconStateSchemaMerge create(final SpecConfig specConfig) { + return new BeaconStateSchemaMerge(specConfig); + } + + private static List getUniqueFields(final SpecConfig specConfig) { + final SszField latestExecutionPayloadHeaderField = + new SszField( + LATEST_EXECUTION_PAYLOAD_HEADER_FIELD_INDEX, + BeaconStateFields.LATEST_EXECUTION_PAYLOAD_HEADER.name(), + () -> ExecutionPayloadHeader.SSZ_SCHEMA); + return Stream.concat( + BeaconStateSchemaAltair.getUniqueFields(specConfig).stream(), + Stream.of(latestExecutionPayloadHeaderField)) + .collect(Collectors.toList()); + } + + public static BeaconStateSchemaMerge required(final BeaconStateSchema schema) { + checkArgument( + schema instanceof BeaconStateSchemaMerge, + "Expected a BeaconStateSchemaMerge but was %s", + schema.getClass()); + return (BeaconStateSchemaMerge) schema; + } + + @SuppressWarnings("unchecked") + public SszPrimitiveListSchema getPreviousEpochParticipationSchema() { + return (SszPrimitiveListSchema) + getChildSchema(getFieldIndex(BeaconStateFields.PREVIOUS_EPOCH_PARTICIPATION.name())); + } + + @SuppressWarnings("unchecked") + public SszPrimitiveListSchema getCurrentEpochParticipationSchema() { + return (SszPrimitiveListSchema) + getChildSchema(getFieldIndex(BeaconStateFields.CURRENT_EPOCH_PARTICIPATION.name())); + } + + public SszUInt64ListSchema getInactivityScoresSchema() { + return (SszUInt64ListSchema) + getChildSchema(getFieldIndex(BeaconStateFields.INACTIVITY_SCORES.name())); + } + + public SyncCommitteeSchema getCurrentSyncCommitteeSchema() { + return (SyncCommitteeSchema) + getChildSchema(getFieldIndex(BeaconStateFields.CURRENT_SYNC_COMMITTEE.name())); + } + + public SyncCommitteeSchema getNextSyncCommitteeSchema() { + return (SyncCommitteeSchema) + getChildSchema(getFieldIndex(BeaconStateFields.NEXT_SYNC_COMMITTEE.name())); + } + + public ExecutionPayloadHeader.ExecutionPayloadHeaderSchema getLastExecutionPayloadHeaderSchema() { + return (ExecutionPayloadHeaderSchema) + getChildSchema(getFieldIndex(BeaconStateFields.LATEST_EXECUTION_PAYLOAD_HEADER.name())); + } + + @Override + public BeaconStateMerge createFromBackingNode(TreeNode node) { + return new BeaconStateMergeImpl(this, node); + } + + @Override + public MutableBeaconStateMerge createBuilder() { + return new MutableBeaconStateMergeImpl(createEmptyBeaconStateImpl(), true); + } + + @Override + public BeaconStateMerge createEmpty() { + return createEmptyBeaconStateImpl(); + } + + private BeaconStateMergeImpl createEmptyBeaconStateImpl() { + return new BeaconStateMergeImpl(this); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMerge.java new file mode 100644 index 00000000000..81ac997da14 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMerge.java @@ -0,0 +1,54 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.state.beaconstate.versions.merge; + +import java.util.Optional; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateFields; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair; + +public interface MutableBeaconStateMerge extends MutableBeaconStateAltair, BeaconStateMerge { + + static MutableBeaconStateMerge required(final MutableBeaconState state) { + return state + .toMutableVersionMerge() + .orElseThrow( + () -> + new IllegalArgumentException( + "Expected a merge state but got: " + state.getClass().getSimpleName())); + } + + // Execution + default void setLatestExecutionPayloadHeader(ExecutionPayloadHeader executionPayloadHeader) { + final int fieldIndex = + getSchema().getFieldIndex(BeaconStateFields.LATEST_EXECUTION_PAYLOAD_HEADER.name()); + set(fieldIndex, executionPayloadHeader); + } + + @Override + BeaconStateMerge commitChanges(); + + @Override + default Optional toMutableVersionMerge() { + return Optional.of(this); + } + + @Override + default + BeaconStateMerge updatedMerge(Mutator mutator) + throws E1, E2, E3 { + throw new UnsupportedOperationException(); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMergeImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMergeImpl.java new file mode 100644 index 00000000000..188d7889144 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/merge/MutableBeaconStateMergeImpl.java @@ -0,0 +1,69 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.state.beaconstate.versions.merge; + +import com.google.common.base.MoreObjects.ToStringHelper; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.AbstractMutableBeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.TransitionCaches; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.ValidatorStatsAltair; +import tech.pegasys.teku.ssz.SszData; +import tech.pegasys.teku.ssz.cache.IntCache; +import tech.pegasys.teku.ssz.tree.TreeNode; + +class MutableBeaconStateMergeImpl extends AbstractMutableBeaconState + implements MutableBeaconStateMerge, BeaconStateCache, ValidatorStatsAltair { + + MutableBeaconStateMergeImpl(BeaconStateMergeImpl backingImmutableView) { + super(backingImmutableView); + } + + MutableBeaconStateMergeImpl(BeaconStateMergeImpl backingImmutableView, boolean builder) { + super(backingImmutableView, builder); + } + + @Override + public BeaconStateSchemaMerge getBeaconStateSchema() { + return (BeaconStateSchemaMerge) getSchema(); + } + + @Override + protected BeaconStateMergeImpl createImmutableBeaconState( + TreeNode backingNode, IntCache viewCache, TransitionCaches transitionCache) { + return new BeaconStateMergeImpl(getSchema(), backingNode, viewCache, transitionCache); + } + + @Override + public BeaconStateMerge commitChanges() { + return (BeaconStateMerge) super.commitChanges(); + } + + @Override + public BeaconState updated( + Mutator mutator) { + throw new UnsupportedOperationException(); + } + + @Override + protected void addCustomFields(ToStringHelper stringBuilder) { + BeaconStateMergeImpl.describeCustomFields(stringBuilder, this); + } + + @Override + public MutableBeaconStateMerge createWritableCopy() { + return (MutableBeaconStateMerge) super.createWritableCopy(); + } +} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStatePhase0Impl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStatePhase0Impl.java index a278c0bebe5..71a8c53c0bd 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStatePhase0Impl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/BeaconStatePhase0Impl.java @@ -46,17 +46,22 @@ class BeaconStatePhase0Impl extends AbstractBeaconState BeaconStatePhase0 updatedPhase0(Mutator mutator) throws E1, E2, E3 { - MutableBeaconStatePhase0 writableCopy = createWritableCopyPriv(); + MutableBeaconStatePhase0 writableCopy = createWritableCopy(); mutator.mutate(writableCopy); return writableCopy.commitChanges(); } @Override - protected MutableBeaconStatePhase0 createWritableCopyPriv() { + public MutableBeaconStatePhase0 createWritableCopy() { return new MutableBeaconStatePhase0Impl(this); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/MutableBeaconStatePhase0Impl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/MutableBeaconStatePhase0Impl.java index 755e5ad1fd5..75be03e0dcc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/MutableBeaconStatePhase0Impl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/versions/phase0/MutableBeaconStatePhase0Impl.java @@ -34,6 +34,11 @@ class MutableBeaconStatePhase0Impl extends AbstractMutableBeaconState viewCache, TransitionCaches transitionCache) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java index 7be96ba5e73..e67f92ffbfa 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java @@ -209,8 +209,8 @@ private BlockValidationResult verifyBlockSignatures( preState, blockBody.getAttestations(), signatureVerifier, indexedAttestationCache), () -> verifyRandao(preState, blockMessage, signatureVerifier), () -> - verifyProposerSlashings(preState, blockBody.getProposer_slashings(), signatureVerifier), - () -> verifyVoluntaryExits(preState, blockBody.getVoluntary_exits(), signatureVerifier)); + verifyProposerSlashings(preState, blockBody.getProposerSlashings(), signatureVerifier), + () -> verifyVoluntaryExits(preState, blockBody.getVoluntaryExits(), signatureVerifier)); } @CheckReturnValue @@ -345,7 +345,7 @@ protected void processRandaoNoValidation(MutableBeaconState state, BeaconBlockBo Bytes32 mix = beaconStateAccessors .getRandaoMix(state, epoch) - .xor(Hash.sha2_256(body.getRandao_reveal().toSSZBytes())); + .xor(Hash.sha2_256(body.getRandaoReveal().toSSZBytes())); int index = epoch.mod(specConfig.getEpochsPerHistoricalVector()).intValue(); state.getRandao_mixes().setElement(index, mix); }); @@ -359,17 +359,17 @@ protected BlockValidationResult verifyRandao( beaconStateAccessors.getValidatorPubKey(state, block.getProposerIndex()).orElseThrow(); final Bytes32 domain = getDomain(state, Domain.RANDAO); final Bytes signing_root = miscHelpers.computeSigningRoot(epoch, domain); - if (!bls.verify(proposerPublicKey, signing_root, block.getBody().getRandao_reveal())) { + if (!bls.verify(proposerPublicKey, signing_root, block.getBody().getRandaoReveal())) { return BlockValidationResult.failed("Randao reveal is invalid."); } return BlockValidationResult.SUCCESSFUL; } protected void processEth1Data(final MutableBeaconState state, final BeaconBlockBody body) { - state.getEth1_data_votes().append(body.getEth1_data()); - long vote_count = getVoteCount(state, body.getEth1_data()); + state.getEth1_data_votes().append(body.getEth1Data()); + long vote_count = getVoteCount(state, body.getEth1Data()); if (isEnoughVotesToUpdateEth1Data(vote_count)) { - state.setEth1_data(body.getEth1_data()); + state.setEth1_data(body.getEth1Data()); } } @@ -403,11 +403,11 @@ protected void processOperationsNoValidation( .longValue())), "process_operations: Verify that outstanding deposits are processed up to the maximum number of deposits"); - processProposerSlashingsNoValidation(state, body.getProposer_slashings()); - processAttesterSlashings(state, body.getAttester_slashings()); + processProposerSlashingsNoValidation(state, body.getProposerSlashings()); + processAttesterSlashings(state, body.getAttesterSlashings()); processAttestationsNoVerification(state, body.getAttestations(), indexedAttestationCache); processDeposits(state, body.getDeposits()); - processVoluntaryExitsNoValidation(state, body.getVoluntary_exits()); + processVoluntaryExitsNoValidation(state, body.getVoluntaryExits()); // @process_shard_receipt_proofs }); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java index 4b4e3b487d8..56aff5c81b6 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java @@ -38,5 +38,11 @@ public interface SchemaDefinitions { SszBitvectorSchema getSyncnetsENRFieldSchema(); - Optional toVersionAltair(); + default Optional toVersionAltair() { + return Optional.empty(); + } + + default Optional toVersionMerge() { + return Optional.empty(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java index bb1b42d5986..f580b50cd28 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java @@ -26,7 +26,10 @@ import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionDataSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessageSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair; public class SchemaDefinitionsAltair extends AbstractSchemaDefinitions { private final BeaconStateSchemaAltair beaconStateSchema; @@ -61,7 +64,8 @@ public static SchemaDefinitionsAltair required(final SchemaDefinitions schemaDef } @Override - public BeaconStateSchemaAltair getBeaconStateSchema() { + public BeaconStateSchema + getBeaconStateSchema() { return beaconStateSchema; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsMerge.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsMerge.java new file mode 100644 index 00000000000..cbd3534f6c2 --- /dev/null +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsMerge.java @@ -0,0 +1,66 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.schemas; + +import java.util.Optional; +import tech.pegasys.teku.spec.config.SpecConfigMerge; +import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockSchema; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.merge.BeaconBlockBodySchemaMerge; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.BeaconStateMerge; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.BeaconStateSchemaMerge; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.MutableBeaconStateMerge; + +public class SchemaDefinitionsMerge extends SchemaDefinitionsAltair { + private final BeaconStateSchemaMerge beaconStateSchema; + private final BeaconBlockBodySchemaMerge beaconBlockBodySchema; + private final BeaconBlockSchema beaconBlockSchema; + private final SignedBeaconBlockSchema signedBeaconBlockSchema; + + public SchemaDefinitionsMerge(final SpecConfigMerge specConfig) { + super(specConfig.toVersionAltair().orElseThrow()); + this.beaconStateSchema = BeaconStateSchemaMerge.create(specConfig); + this.beaconBlockBodySchema = BeaconBlockBodySchemaMerge.create(specConfig); + this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema); + this.signedBeaconBlockSchema = new SignedBeaconBlockSchema(beaconBlockSchema); + } + + @Override + public BeaconStateSchema + getBeaconStateSchema() { + return beaconStateSchema; + } + + @Override + public SignedBeaconBlockSchema getSignedBeaconBlockSchema() { + return signedBeaconBlockSchema; + } + + @Override + public BeaconBlockSchema getBeaconBlockSchema() { + return beaconBlockSchema; + } + + @Override + public BeaconBlockBodySchema getBeaconBlockBodySchema() { + return beaconBlockBodySchema; + } + + @Override + public Optional toVersionMerge() { + return Optional.of(this); + } +} diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java index bcb7969b041..74dae743b61 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/SpecVersionTest.java @@ -20,6 +20,7 @@ import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigAltair; import tech.pegasys.teku.spec.config.SpecConfigLoader; +import tech.pegasys.teku.spec.config.SpecConfigMerge; import tech.pegasys.teku.spec.config.TestConfigLoader; import tech.pegasys.teku.spec.networks.Eth2Network; @@ -53,6 +54,18 @@ void shouldCreateAltairSpec() { .hasSameClassAs(expectedVersion.getSchemaDefinitions()); } + @Test + void shouldCreateMergeSpec() { + final SpecConfigMerge mergeSpecConfig = SpecConfigMerge.required(minimalConfig); + final SpecVersion expectedVersion = SpecVersion.createMerge(mergeSpecConfig); + final Optional actualVersion = + SpecVersion.create(SpecMilestone.MERGE, minimalConfig); + assertThat(actualVersion).isPresent(); + assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.MERGE); + assertThat(actualVersion.get().getSchemaDefinitions()) + .hasSameClassAs(expectedVersion.getSchemaDefinitions()); + } + @Test void shouldReturnEmptyWhen_altairRequestedWithPhase0Config() { final Optional actualVersion = diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyTest.java index 7d294dbdc76..44175683038 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/common/AbstractBeaconBlockBodyTest.java @@ -30,6 +30,7 @@ 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.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; @@ -68,6 +69,7 @@ public abstract class AbstractBeaconBlockBodyTest { dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit()); + protected ExecutionPayload executionPayload = dataStructureUtil.randomExecutionPayload(); private final T defaultBlockBody = createDefaultBlockBody(); BeaconBlockBodySchema blockBodySchema = defaultBlockBody.getSchema(); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairTest.java index 8fe28174e10..78a6835bfce 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodyAltairTest.java @@ -24,7 +24,7 @@ class BeaconBlockBodyAltairTest extends AbstractBeaconBlockBodyTest { @Test - void shouldCreateWithEmtpySyncAggregate() { + void shouldCreateWithEmptySyncAggregate() { // This won't always be true but until we can calculate the actual SyncAggregate, use the empty // one to make the block valid @@ -39,7 +39,7 @@ void shouldCreateWithEmtpySyncAggregate() { @Override protected BeaconBlockBodyAltair createBlockBody( final Consumer contentProvider) { - return getBlockBodySchema().createBlockBody(contentProvider); + return (BeaconBlockBodyAltair) getBlockBodySchema().createBlockBody(contentProvider); } @Override diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeTest.java new file mode 100644 index 00000000000..fcba6db154d --- /dev/null +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/merge/BeaconBlockBodyMergeTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2021 ConsenSys AG. + * + * 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.spec.datastructures.blocks.blockbody.versions.merge; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.function.Consumer; +import org.junit.jupiter.api.Test; +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.common.AbstractBeaconBlockBodyTest; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema; + +class BeaconBlockBodyMergeTest extends AbstractBeaconBlockBodyTest { + + @Test + void shouldCreateWithEmptySyncAggregate() { + // This won't always be true but until we can calculate the actual SyncAggregate, use the empty + // one to make the block valid + + final BeaconBlockBodyMerge blockBody = createDefaultBlockBody(); + final SyncAggregate emptySyncAggregate = + SyncAggregateSchema.create( + spec.getGenesisSpecConfig().toVersionMerge().orElseThrow().getSyncCommitteeSize()) + .createEmpty(); + assertThat(blockBody.getSyncAggregate()).isEqualTo(emptySyncAggregate); + } + + @Override + protected BeaconBlockBodyMerge createBlockBody( + final Consumer contentProvider) { + return (BeaconBlockBodyMerge) getBlockBodySchema().createBlockBody(contentProvider); + } + + @Override + protected BeaconBlockBodySchema getBlockBodySchema() { + return BeaconBlockBodySchemaMerge.create(spec.getGenesisSpecConfig()); + } + + @Override + protected Consumer createContentProvider() { + return super.createContentProvider() + .andThen(builder -> builder.executionPayload(() -> executionPayload)); + } +} diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0Test.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0Test.java index b4fe57af7d9..e383114971b 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0Test.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodyPhase0Test.java @@ -23,7 +23,7 @@ public class BeaconBlockBodyPhase0Test extends AbstractBeaconBlockBodyTest contentProvider) { - return getBlockBodySchema().createBlockBody(contentProvider); + return (BeaconBlockBodyPhase0) getBlockBodySchema().createBlockBody(contentProvider); } @Override diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java index 2756f5b3e65..51796c19b3c 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java @@ -13,7 +13,10 @@ package tech.pegasys.teku.spec.util; +import static java.util.stream.Collectors.toList; +import static tech.pegasys.teku.spec.config.SpecConfig.BYTES_PER_LOGS_BLOOM; import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; +import static tech.pegasys.teku.spec.config.SpecConfig.MAX_EXTRA_DATA_BYTES; import static tech.pegasys.teku.spec.constants.NetworkConstants.SYNC_COMMITTEE_SUBNET_COUNT; import java.util.ArrayList; @@ -26,6 +29,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.bytes.Bytes48; +import org.apache.tuweni.units.bigints.UInt256; import tech.pegasys.teku.bls.BLS; import tech.pegasys.teku.bls.BLSKeyPair; import tech.pegasys.teku.bls.BLSPublicKey; @@ -55,6 +59,8 @@ import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema; import tech.pegasys.teku.spec.datastructures.eth1.Eth1Address; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; import tech.pegasys.teku.spec.datastructures.forkchoice.VoteTracker; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId; import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof; @@ -113,6 +119,8 @@ public final class DataStructureUtil { private static final Spec DEFAULT_SPEC_PROVIDER = TestSpecFactory.createMinimalPhase0(); + private static final int MAX_EP_RANDOM_TRANSACTIONS = 10; + private static final int MAX_EP_RANDOM_TRANSACTIONS_SIZE = 32; private final Spec spec; @@ -165,6 +173,10 @@ public UInt64 randomUInt64() { return UInt64.fromLongBits(randomLong()); } + public UInt256 randomUInt256() { + return UInt256.fromBytes(randomBytes(32)); + } + public Eth1Address randomEth1Address() { return new Eth1Address(randomBytes32().slice(0, 20)); } @@ -357,6 +369,48 @@ public SyncCommittee randomSyncCommittee(SszList validators) { new SszPublicKey(randomPublicKey())); } + public ExecutionPayloadHeader randomExecutionPayloadHeader() { + return new ExecutionPayloadHeader( + randomBytes32(), + randomBytes20(), + randomBytes32(), + randomBytes32(), + randomBytes(BYTES_PER_LOGS_BLOOM), + randomBytes32(), + randomUInt64(), + randomUInt64(), + randomUInt64(), + randomUInt64(), + randomBytes(randomInt(MAX_EXTRA_DATA_BYTES)), + randomUInt256(), + randomBytes32(), + randomBytes32()); + } + + public ExecutionPayload randomExecutionPayload() { + return new ExecutionPayload( + randomBytes32(), + randomBytes20(), + randomBytes32(), + randomBytes32(), + randomBytes(BYTES_PER_LOGS_BLOOM), + randomBytes32(), + randomUInt64(), + randomUInt64(), + randomUInt64(), + randomUInt64(), + randomBytes(randomInt(MAX_EXTRA_DATA_BYTES)), + randomUInt256(), + randomBytes32(), + randomExecutionPayloadTransactions()); + } + + public List randomExecutionPayloadTransactions() { + return IntStream.rangeClosed(0, randomInt(MAX_EP_RANDOM_TRANSACTIONS)) + .mapToObj(__ -> randomBytes(randomInt(MAX_EP_RANDOM_TRANSACTIONS_SIZE))) + .collect(toList()); + } + private BLSPublicKey randomValidatorKey(final SszList validators) { final int rand = new Random(nextSeed()).nextInt(); final int index = rand > 0 ? rand % validators.size() : (-1 * rand) % validators.size(); diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java index 4f55106665c..de841cbdaff 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java @@ -96,9 +96,9 @@ private void processNonCanonicalBlockOperations(Collection nonCanonical maybeBlock.ifPresentOrElse( block -> { BeaconBlockBody blockBody = block.getBody(); - proposerSlashingPool.addAll(blockBody.getProposer_slashings()); - attesterSlashingPool.addAll(blockBody.getAttester_slashings()); - exitPool.addAll(blockBody.getVoluntary_exits()); + proposerSlashingPool.addAll(blockBody.getProposerSlashings()); + attesterSlashingPool.addAll(blockBody.getAttesterSlashings()); + exitPool.addAll(blockBody.getVoluntaryExits()); processNonCanonicalBlockAttestations(blockBody.getAttestations(), root); }, @@ -152,9 +152,9 @@ private void processCanonicalBlockOperations(Collection canonicalBlockR maybeBlock.ifPresentOrElse( block -> { BeaconBlockBody blockBody = block.getBody(); - proposerSlashingPool.removeAll(blockBody.getProposer_slashings()); - attesterSlashingPool.removeAll(blockBody.getAttester_slashings()); - exitPool.removeAll(blockBody.getVoluntary_exits()); + proposerSlashingPool.removeAll(blockBody.getProposerSlashings()); + attesterSlashingPool.removeAll(blockBody.getAttesterSlashings()); + exitPool.removeAll(blockBody.getVoluntaryExits()); attestationPool.onAttestationsIncludedInBlock( block.getSlot(), blockBody.getAttestations()); }, diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/block/BlockImporter.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/block/BlockImporter.java index e9e7720e517..5abed9e8169 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/block/BlockImporter.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/block/BlockImporter.java @@ -165,13 +165,13 @@ private void notifyBlockOperationSubscribers(SignedBeaconBlock block) { block.getSlot(), block.getMessage().getBody().getAttestations())); attesterSlashingSubscribers.deliver( VerifiedBlockOperationsListener::onOperationsFromBlock, - block.getMessage().getBody().getAttester_slashings()); + block.getMessage().getBody().getAttesterSlashings()); proposerSlashingSubscribers.deliver( VerifiedBlockOperationsListener::onOperationsFromBlock, - block.getMessage().getBody().getProposer_slashings()); + block.getMessage().getBody().getProposerSlashings()); voluntaryExitSubscribers.deliver( VerifiedBlockOperationsListener::onOperationsFromBlock, - block.getMessage().getBody().getVoluntary_exits()); + block.getMessage().getBody().getVoluntaryExits()); } public void subscribeToVerifiedBlockAttestations( diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/OperationsReOrgManagerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/OperationsReOrgManagerTest.java index c412b96e9d0..a3a2f299bae 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/OperationsReOrgManagerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/OperationsReOrgManagerTest.java @@ -118,13 +118,13 @@ void shouldRequeueAndRemoveOperations() { verify(recentChainData).getAncestorsOnFork(commonAncestorSlot, fork1Block2.hashTreeRoot()); verify(attestationPool).onReorg(commonAncestorSlot); - verify(proposerSlashingOperationPool).addAll(fork1Block1.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).addAll(fork1Block1.getBody().getAttester_slashings()); - verify(exitOperationPool).addAll(fork1Block1.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).addAll(fork1Block1.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).addAll(fork1Block1.getBody().getAttesterSlashings()); + verify(exitOperationPool).addAll(fork1Block1.getBody().getVoluntaryExits()); - verify(proposerSlashingOperationPool).addAll(fork1Block2.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).addAll(fork1Block2.getBody().getAttester_slashings()); - verify(exitOperationPool).addAll(fork1Block2.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).addAll(fork1Block2.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).addAll(fork1Block2.getBody().getAttesterSlashings()); + verify(exitOperationPool).addAll(fork1Block2.getBody().getVoluntaryExits()); ArgumentCaptor argument = ArgumentCaptor.forClass(ValidateableAttestation.class); @@ -141,16 +141,16 @@ void shouldRequeueAndRemoveOperations() { .collect(Collectors.toList())); assertThat(argument.getAllValues()).containsExactlyInAnyOrderElementsOf(attestationList); - verify(proposerSlashingOperationPool).removeAll(fork2Block1.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).removeAll(fork2Block1.getBody().getAttester_slashings()); - verify(exitOperationPool).removeAll(fork2Block1.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).removeAll(fork2Block1.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).removeAll(fork2Block1.getBody().getAttesterSlashings()); + verify(exitOperationPool).removeAll(fork2Block1.getBody().getVoluntaryExits()); verify(attestationPool) .onAttestationsIncludedInBlock( fork2Block1.getSlot(), fork2Block1.getBody().getAttestations()); - verify(proposerSlashingOperationPool).removeAll(fork2Block2.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).removeAll(fork2Block2.getBody().getAttester_slashings()); - verify(exitOperationPool).removeAll(fork2Block2.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).removeAll(fork2Block2.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).removeAll(fork2Block2.getBody().getAttesterSlashings()); + verify(exitOperationPool).removeAll(fork2Block2.getBody().getVoluntaryExits()); verify(attestationPool) .onAttestationsIncludedInBlock( fork2Block2.getSlot(), fork2Block2.getBody().getAttestations()); @@ -198,15 +198,15 @@ void shouldOnlyRemoveOperations() { verify(attesterSlashingOperationPool, never()).addAll(any()); verify(attestationManager, never()).onAttestation(any()); - verify(proposerSlashingOperationPool).removeAll(block2.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).removeAll(block2.getBody().getAttester_slashings()); - verify(exitOperationPool).removeAll(block2.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).removeAll(block2.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).removeAll(block2.getBody().getAttesterSlashings()); + verify(exitOperationPool).removeAll(block2.getBody().getVoluntaryExits()); verify(attestationPool) .onAttestationsIncludedInBlock(block2.getSlot(), block2.getBody().getAttestations()); - verify(proposerSlashingOperationPool).removeAll(block1.getBody().getProposer_slashings()); - verify(attesterSlashingOperationPool).removeAll(block1.getBody().getAttester_slashings()); - verify(exitOperationPool).removeAll(block1.getBody().getVoluntary_exits()); + verify(proposerSlashingOperationPool).removeAll(block1.getBody().getProposerSlashings()); + verify(attesterSlashingOperationPool).removeAll(block1.getBody().getAttesterSlashings()); + verify(exitOperationPool).removeAll(block1.getBody().getVoluntaryExits()); verify(attestationPool) .onAttestationsIncludedInBlock(block1.getSlot(), block1.getBody().getAttestations()); }