Skip to content

Commit

Permalink
Fix Fulu Metadata + test
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Jan 10, 2025
1 parent 66c11d6 commit 8ee7501
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MetadataMessageEip7594, SszUInt64, SszBitvector, SszBitvector, SszUInt64>
public class MetadataMessageFulu
extends Container4<MetadataMessageFulu, SszUInt64, SszBitvector, SszBitvector, SszUInt64>
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,8 +27,8 @@

public class MetadataMessageSchemaFulu
extends ContainerSchema4<
MetadataMessageEip7594, SszUInt64, SszBitvector, SszBitvector, SszUInt64>
implements MetadataMessageSchema<MetadataMessageEip7594> {
MetadataMessageFulu, SszUInt64, SszBitvector, SszBitvector, SszUInt64>
implements MetadataMessageSchema<MetadataMessageFulu> {
public MetadataMessageSchemaFulu(final NetworkingSpecConfig networkingSpecConfig) {
super(
"MetadataMessage",
Expand All @@ -41,12 +41,12 @@ public MetadataMessageSchemaFulu(final NetworkingSpecConfig networkingSpecConfig
}

@Override
public MetadataMessageEip7594 create(
public MetadataMessageFulu create(
final UInt64 seqNumber,
final Iterable<Integer> attnets,
final Iterable<Integer> syncnets,
final Optional<UInt64> custodySubnetCount) {
return new MetadataMessageEip7594(
return new MetadataMessageFulu(
this,
seqNumber,
getAttnestSchema().ofBits(attnets),
Expand All @@ -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<SszBitvector> getAttnestSchema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static Spec createMinimalWithElectraForkEpoch(final UInt64 electraForkEpo
public static Spec createMinimalWithFuluForkEpoch(final UInt64 fuluForkEpoch) {
final SpecConfigAndParent<? extends SpecConfig> config =
getFuluSpecConfig(Eth2Network.MINIMAL, ZERO, ZERO, fuluForkEpoch);
return create(config, SpecMilestone.ELECTRA);
return create(config, SpecMilestone.FULU);
}

public static Spec createMinimalPhase0() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}")
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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}")
Expand All @@ -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;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,14 @@ private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
new ArrayList<>();

if (spec.isMilestoneSupported(SpecMilestone.FULU)) {
final SszSchema<MetadataMessage> eip7594MetadataSchema =
final SszSchema<MetadataMessage> fuluMetadataSchema =
SszSchema.as(
MetadataMessage.class,
SchemaDefinitionsFulu.required(
spec.forMilestone(SpecMilestone.FULU).getSchemaDefinitions())
.getMetadataMessageSchema());
final RpcContextCodec<?, MetadataMessage> eip7594ContextCodec =
RpcContextCodec.noop(eip7594MetadataSchema);
final RpcContextCodec<?, MetadataMessage> fuluContextCodec =
RpcContextCodec.noop(fuluMetadataSchema);

final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v3Method =
new SingleProtocolEth2RpcMethod<>(
Expand All @@ -510,7 +510,7 @@ private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(
rpcEncoding,
requestType,
expectResponse,
eip7594ContextCodec,
fuluContextCodec,
messageHandler,
peerLookup);
versionedMethods.add(v3Method);
Expand Down

0 comments on commit 8ee7501

Please sign in to comment.