From 8ee750102845b9081d9e0eaf1bee848a0be27eb5 Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Fri, 10 Jan 2025 22:43:04 +0100 Subject: [PATCH] Fix Fulu Metadata + test --- .../pegasys/teku/api/schema/Metadata.java | 8 +++---- .../MetadataMessageFulu.java} | 12 +++++----- .../MetadataMessageSchemaFulu.java | 18 +++++++-------- .../spec/schemas/SchemaDefinitionsFulu.java | 2 +- .../pegasys/teku/spec/TestSpecFactory.java | 2 +- .../AbstractRpcMethodIntegrationTest.java | 6 ++++- .../eth2/GetMetadataIntegrationTest.java | 23 ++++++++++--------- .../rpc/beaconchain/BeaconChainMethods.java | 8 +++---- 8 files changed, 42 insertions(+), 37 deletions(-) rename ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/{eip7594/MetadataMessageEip7594.java => fulu/MetadataMessageFulu.java} (85%) rename ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/{eip7594 => fulu}/MetadataMessageSchemaFulu.java (84%) diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Metadata.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Metadata.java index 8aae8791421..f17194feb95 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Metadata.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Metadata.java @@ -24,7 +24,7 @@ import java.util.Objects; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.altair.MetadataMessageAltair; -import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.eip7594.MetadataMessageEip7594; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.fulu.MetadataMessageFulu; @Schema( description = @@ -81,15 +81,15 @@ public Metadata(final MetadataMessage metadataMessage) { this.attestationSubnetSubscriptions = metadataMessage.getAttnets().sszSerialize().toHexString().toLowerCase(Locale.ROOT); - if (metadataMessage instanceof MetadataMessageEip7594) { + if (metadataMessage instanceof MetadataMessageFulu) { this.syncCommitteeSubscriptions = - ((MetadataMessageEip7594) metadataMessage) + ((MetadataMessageFulu) metadataMessage) .getSyncnets() .sszSerialize() .toHexString() .toLowerCase(Locale.ROOT); this.custodySubnetCount = - ((MetadataMessageEip7594) metadataMessage).getCustodySubnetCount().toString(); + ((MetadataMessageFulu) metadataMessage).getCustodySubnetCount().toString(); } else if (metadataMessage instanceof MetadataMessageAltair) { this.syncCommitteeSubscriptions = ((MetadataMessageAltair) metadataMessage) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageEip7594.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageFulu.java similarity index 85% rename from ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageEip7594.java rename to ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageFulu.java index 0136beb107a..15fbc2369eb 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageEip7594.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageFulu.java @@ -11,7 +11,7 @@ * specific language governing permissions and limitations under the License. */ -package tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.eip7594; +package tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.fulu; import java.util.Optional; import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; @@ -21,19 +21,19 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage; -public class MetadataMessageEip7594 - extends Container4 +public class MetadataMessageFulu + extends Container4 implements MetadataMessage { - MetadataMessageEip7594(final MetadataMessageSchemaFulu schema) { + MetadataMessageFulu(final MetadataMessageSchemaFulu schema) { super(schema); } - MetadataMessageEip7594(final MetadataMessageSchemaFulu schema, final TreeNode backingNode) { + MetadataMessageFulu(final MetadataMessageSchemaFulu schema, final TreeNode backingNode) { super(schema, backingNode); } - MetadataMessageEip7594( + MetadataMessageFulu( final MetadataMessageSchemaFulu schema, final UInt64 seqNumber, final SszBitvector attNets, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageSchemaFulu.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageSchemaFulu.java similarity index 84% rename from ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageSchemaFulu.java rename to ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageSchemaFulu.java index 2d98a70ba99..7261f7a6b15 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/eip7594/MetadataMessageSchemaFulu.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/networking/libp2p/rpc/metadata/versions/fulu/MetadataMessageSchemaFulu.java @@ -11,7 +11,7 @@ * specific language governing permissions and limitations under the License. */ -package tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.eip7594; +package tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.fulu; import java.util.Optional; import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; @@ -27,8 +27,8 @@ public class MetadataMessageSchemaFulu extends ContainerSchema4< - MetadataMessageEip7594, SszUInt64, SszBitvector, SszBitvector, SszUInt64> - implements MetadataMessageSchema { + MetadataMessageFulu, SszUInt64, SszBitvector, SszBitvector, SszUInt64> + implements MetadataMessageSchema { public MetadataMessageSchemaFulu(final NetworkingSpecConfig networkingSpecConfig) { super( "MetadataMessage", @@ -41,12 +41,12 @@ public MetadataMessageSchemaFulu(final NetworkingSpecConfig networkingSpecConfig } @Override - public MetadataMessageEip7594 create( + public MetadataMessageFulu create( final UInt64 seqNumber, final Iterable attnets, final Iterable syncnets, final Optional custodySubnetCount) { - return new MetadataMessageEip7594( + return new MetadataMessageFulu( this, seqNumber, getAttnestSchema().ofBits(attnets), @@ -55,13 +55,13 @@ public MetadataMessageEip7594 create( } @Override - public MetadataMessageEip7594 createDefault() { - return new MetadataMessageEip7594(this); + public MetadataMessageFulu createDefault() { + return new MetadataMessageFulu(this); } @Override - public MetadataMessageEip7594 createFromBackingNode(final TreeNode node) { - return new MetadataMessageEip7594(this, node); + public MetadataMessageFulu createFromBackingNode(final TreeNode node) { + return new MetadataMessageFulu(this, node); } private SszBitvectorSchema getAttnestSchema() { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsFulu.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsFulu.java index e7a8bc85a1d..05b47823832 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsFulu.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsFulu.java @@ -24,7 +24,7 @@ import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.DataColumnSidecarsByRangeRequestMessage; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.DataColumnSidecarsByRootRequestMessageSchema; -import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.eip7594.MetadataMessageSchemaFulu; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.fulu.MetadataMessageSchemaFulu; import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; public class SchemaDefinitionsFulu extends SchemaDefinitionsElectra { diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java index 22bf2f1ab09..3f712a97a43 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/TestSpecFactory.java @@ -197,7 +197,7 @@ public static Spec createMinimalWithElectraForkEpoch(final UInt64 electraForkEpo public static Spec createMinimalWithFuluForkEpoch(final UInt64 fuluForkEpoch) { final SpecConfigAndParent config = getFuluSpecConfig(Eth2Network.MINIMAL, ZERO, ZERO, fuluForkEpoch); - return create(config, SpecMilestone.ELECTRA); + return create(config, SpecMilestone.FULU); } public static Spec createMinimalPhase0() { diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java index 3f3fa221ae2..5ec179a7f7d 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/AbstractRpcMethodIntegrationTest.java @@ -84,7 +84,11 @@ private void setUpNextSpec(final SpecMilestone nextSpecMilestone) { checkState(nextSpecMilestone.equals(SpecMilestone.ELECTRA), "next spec should be electra"); nextSpec = Optional.of(TestSpecFactory.createMinimalWithElectraForkEpoch(nextSpecEpoch)); } - case ELECTRA, FULU -> + case ELECTRA -> { + checkState(nextSpecMilestone.equals(SpecMilestone.FULU), "next spec should be fulu"); + nextSpec = Optional.of(TestSpecFactory.createMinimalWithFuluForkEpoch(nextSpecEpoch)); + } + case FULU -> throw new RuntimeException("Base spec is already latest supported milestone"); } nextSpecSlot = nextSpec.orElseThrow().computeStartSlotAtEpoch(nextSpecEpoch); diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java index c329ce9a154..7d9eb8eda4c 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/GetMetadataIntegrationTest.java @@ -14,6 +14,7 @@ package tech.pegasys.teku.networking.eth2; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assumptions.assumeThat; import static tech.pegasys.teku.infrastructure.async.SafeFutureAssert.safeJoin; import static tech.pegasys.teku.infrastructure.async.Waiter.waitFor; @@ -30,10 +31,9 @@ import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.altair.MetadataMessageAltair; -import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.eip7594.MetadataMessageEip7594; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.fulu.MetadataMessageFulu; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.phase0.MetadataMessagePhase0; -// TODO: Eip7594 correct testing public class GetMetadataIntegrationTest extends AbstractRpcMethodIntegrationTest { @ParameterizedTest(name = "{0}") @@ -75,7 +75,7 @@ public void requestMetadata_shouldSendLatestSyncnets( peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(1); peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(2); MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS); - assertThat(md3).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageEip7594.class); + assertThat(md3).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageFulu.class); // Check metadata assertThat(md3.getSeqNumber()).isGreaterThan(md2.getSeqNumber()); @@ -86,7 +86,7 @@ public void requestMetadata_shouldSendLatestSyncnets( // Unsubscribe from sync committee subnet peerAndNetwork.network().unsubscribeFromSyncCommitteeSubnetId(2); MetadataMessage md4 = peer.requestMetadata().get(10, TimeUnit.SECONDS); - assertThat(md4).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageEip7594.class); + assertThat(md4).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageFulu.class); // Check metadata assertThat(md4.getSeqNumber()).isGreaterThan(md3.getSeqNumber()); @@ -111,7 +111,7 @@ public void requestMetadata_shouldSendLatestAttnetsAndSyncnets( peerAndNetwork.network().subscribeToSyncCommitteeSubnetId(1); peerAndNetwork.network().setLongTermAttestationSubnetSubscriptions(List.of(0, 1, 8)); MetadataMessage md3 = peer.requestMetadata().get(10, TimeUnit.SECONDS); - assertThat(md3).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageEip7594.class); + assertThat(md3).isInstanceOfAny(MetadataMessageAltair.class, MetadataMessageFulu.class); assertThat(md3.getSeqNumber()).isGreaterThan(md2.getSeqNumber()); assertThat(md3.getOptionalSyncnets().orElseThrow().getBitCount()).isEqualTo(1); @@ -131,8 +131,8 @@ public void requestMetadata_shouldIncludeCustodySubnetCount( final Eth2Peer peer = peerAndNetwork.peer(); MetadataMessage md1 = peer.requestMetadata().get(10, TimeUnit.SECONDS); - Assumptions.assumeTrue(md1 instanceof MetadataMessageEip7594, "Milestone skipped"); - assertThat(((MetadataMessageEip7594) md1).getCustodySubnetCount().isGreaterThan(0)).isTrue(); + Assumptions.assumeTrue(md1 instanceof MetadataMessageFulu, "Milestone skipped"); + assertThat(((MetadataMessageFulu) md1).getCustodySubnetCount().isGreaterThan(0)).isTrue(); } @ParameterizedTest(name = "{0} => {1}, nextSpecEnabledLocally={2}, nextSpecEnabledRemotely={3}") @@ -156,15 +156,16 @@ public void requestMetadata_withDisparateVersionsEnabled( final MetadataMessage metadata = safeJoin(res); assertThat(metadata).isInstanceOf(expectedType); // There will be update of custody_subnet_count in this case - assumeThat(nextMilestone == SpecMilestone.ELECTRA && nextSpecEnabledRemotely).isFalse(); - assertThat(metadata.getSeqNumber()).isEqualTo(UInt64.ZERO); + if(!(nextMilestone == SpecMilestone.FULU && nextSpecEnabledRemotely)) { + assertThat(metadata.getSeqNumber()).isEqualTo(UInt64.ZERO); + } } private static Class milestoneToMetadataClass(final SpecMilestone milestone) { return switch (milestone) { case PHASE0 -> MetadataMessagePhase0.class; - case ALTAIR, BELLATRIX, CAPELLA, DENEB -> MetadataMessageAltair.class; - case ELECTRA, FULU -> MetadataMessageEip7594.class; + case ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA -> MetadataMessageAltair.class; + case FULU -> MetadataMessageFulu.class; }; } } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/BeaconChainMethods.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/BeaconChainMethods.java index 058b689667a..c7f978c7531 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/BeaconChainMethods.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/BeaconChainMethods.java @@ -493,14 +493,14 @@ private static Eth2RpcMethod createMetadata( new ArrayList<>(); if (spec.isMilestoneSupported(SpecMilestone.FULU)) { - final SszSchema eip7594MetadataSchema = + final SszSchema fuluMetadataSchema = SszSchema.as( MetadataMessage.class, SchemaDefinitionsFulu.required( spec.forMilestone(SpecMilestone.FULU).getSchemaDefinitions()) .getMetadataMessageSchema()); - final RpcContextCodec eip7594ContextCodec = - RpcContextCodec.noop(eip7594MetadataSchema); + final RpcContextCodec fuluContextCodec = + RpcContextCodec.noop(fuluMetadataSchema); final SingleProtocolEth2RpcMethod v3Method = new SingleProtocolEth2RpcMethod<>( @@ -510,7 +510,7 @@ private static Eth2RpcMethod createMetadata( rpcEncoding, requestType, expectResponse, - eip7594ContextCodec, + fuluContextCodec, messageHandler, peerLookup); versionedMethods.add(v3Method);