Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 8527-1
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfyone committed Sep 9, 2024
2 parents 9bdbfd1 + aeadce1 commit 0227b70
Show file tree
Hide file tree
Showing 59 changed files with 830 additions and 311 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Removed the deprecated [GetBlindedBlock](https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceBlindedBlock)
- Removed the deprecated [GetBlockV2](https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/produceBlockV2)
- Implemented [PostAggregateAndProofsV2](https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/publishAggregateAndProofsV2) (adding support for Electra)
- Renamed metrics `validator_attestation_publication_delay`,`validator_block_publication_delay` and `beacon_block_import_delay_counter` to include the suffix `_total` added by the current version of prometheus.

### Bug Fixes
- removed a warning from logs about non blinded blocks being requested (#8562)
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
Expand Down Expand Up @@ -281,7 +282,7 @@ private IndexedAttestation randomIndexedAttestation(
secretKey,
signingRootUtil.signingRootForSignAttestationData(attestationData, forkInfo));

final IndexedAttestation.IndexedAttestationSchema schema =
final IndexedAttestationSchema<?> schema =
spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema();
return schema.create(
Stream.of(index).collect(schema.getAttestingIndicesSchema().collectorUnboxed()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public static DutyMetrics create(
MetricsCountersByIntervals.create(
TekuMetricCategory.VALIDATOR,
metricsSystem,
"attestation_publication_delay",
"attestation_publication_delay_total",
"Counter of attestations published in different time intervals after their due time",
Collections.emptyList(),
Map.of(List.of(), List.of(1L, 500L, 1000L, 2000L, 3000L, 4000L, 5000L, 8000L)));
final MetricsCountersByIntervals blockTimings =
MetricsCountersByIntervals.create(
TekuMetricCategory.VALIDATOR,
metricsSystem,
"block_publication_delay",
"block_publication_delay_total",
"Counter of blocks published in different time intervals after their due time",
Collections.emptyList(),
Map.of(List.of(), List.of(1L, 500L, 1000L, 2000L, 3000L, 4000L, 5000L, 8000L, 12000L)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashing.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));
assertThat(response.code()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
}

Expand All @@ -76,7 +78,9 @@ public void shouldReturnSuccessWhenRequestBodyIsValid() throws Exception {
final Response response =
post(
PostAttesterSlashing.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));

verify(attesterSlashingPool).addLocal(slashing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));
assertThat(response.code()).isEqualTo(500);
Expand All @@ -97,7 +99,9 @@ public void shouldReturnSuccessWhenRequestBodyIsValid() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));

Expand All @@ -113,7 +117,9 @@ void shouldFailWhenMissingConsensusHeader() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));

assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);

Expand All @@ -133,7 +139,9 @@ void shouldFailWhenBadConsensusHeaderValue() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(badConsensusHeaderValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,20 @@ public class BeaconRestApiTypes {
public static final ParameterMetadata<SpecMilestone> ETH_CONSENSUS_VERSION_TYPE =
new ParameterMetadata<>(HEADER_CONSENSUS_VERSION, MILESTONE_TYPE);

@SuppressWarnings("unchecked")
public static DeserializableTypeDefinition<Attestation> electraAttestationTypeDef(
final SchemaDefinitionCache schemaDefinitionCache) {
return (DeserializableTypeDefinition<Attestation>)
schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.ELECTRA)
.getAttestationSchema()
.getJsonTypeDefinition();
return schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.ELECTRA)
.getAttestationSchema()
.getJsonTypeDefinition();
}

@SuppressWarnings("unchecked")
public static DeserializableTypeDefinition<Attestation> phase0AttestationTypeDef(
final SchemaDefinitionCache schemaDefinitionCache) {
return (DeserializableTypeDefinition<Attestation>)
schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.PHASE0)
.getAttestationSchema()
.getJsonTypeDefinition();
return schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.PHASE0)
.getAttestationSchema()
.getJsonTypeDefinition();
}

@SuppressWarnings("JavaCase")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ private static SerializableTypeDefinition<List<Attestation>> getResponseType(fin
.withField(
"data",
listOf(
spec.getGenesisSchemaDefinitions()
.getAttestationSchema()
.castTypeToAttestationSchema()
.getJsonTypeDefinition()),
spec.getGenesisSchemaDefinitions().getAttestationSchema().getJsonTypeDefinition()),
Function.identity())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

public class AttesterSlashingEvent extends Event<AttesterSlashing> {
AttesterSlashingEvent(final AttesterSlashing attesterSlashing) {
super(attesterSlashing.getSchema().getJsonTypeDefinition(), attesterSlashing);
super(
attesterSlashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition(),
attesterSlashing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static EndpointMetadata createMetadata(
schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.PHASE0)
.getAttesterSlashingSchema()
.castTypeToAttesterSlashingSchema()
.getJsonTypeDefinition();

final DeserializableTypeDefinition<AttesterSlashing> attesterSlashingElectraSchema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectra;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -124,39 +122,35 @@ void metadata_shouldHandle500() throws JsonProcessingException {
}

@Test
@SuppressWarnings("unchecked")
void metadata_shouldHandle200_phase0Attestations() throws IOException {
setHandler(
new GetBlockAttestationsV2(
chainDataProvider, new SchemaDefinitionCache(specMinimalPhase0)));
final String data = getResponseStringFromMetadata(handler, SC_OK, phase0responseData);

final AttestationSchema<AttestationPhase0> phase0AttestationSchema =
(AttestationSchema<AttestationPhase0>)
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.PHASE0).getAttestationSchema();
final List<AttestationPhase0> attestations =
final AttestationSchema<Attestation> phase0AttestationSchema =
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.PHASE0).getAttestationSchema();
final List<Attestation> attestations =
parseAttestationsFromResponse(data, phase0AttestationSchema);

assertThat(attestations).isNotEmpty();
assertThat(attestations).allMatch(att -> !att.requiresCommitteeBits());
}

@Test
@SuppressWarnings("unchecked")
void metadata_shouldHandle200_electraAttestations() throws IOException {
setHandler(
new GetBlockAttestationsV2(
chainDataProvider, new SchemaDefinitionCache(specMinimalElectra)));
final String data = getResponseStringFromMetadata(handler, SC_OK, electraResponseData);

final AttestationSchema<AttestationElectra> electraAttestationSchema =
(AttestationSchema<AttestationElectra>)
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.ELECTRA).getAttestationSchema();
final List<AttestationElectra> attestations =
final AttestationSchema<Attestation> electraAttestationSchema =
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.ELECTRA).getAttestationSchema();
final List<Attestation> attestations =
parseAttestationsFromResponse(data, electraAttestationSchema);

assertThat(attestations).isNotEmpty();
assertThat(attestations).allMatch(AttestationElectra::requiresCommitteeBits);
assertThat(attestations).allMatch(Attestation::requiresCommitteeBits);
}

private <T extends Attestation> List<T> parseAttestationsFromResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectra;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -122,35 +120,29 @@ void metadata_shouldHandle500() throws JsonProcessingException {
}

@Test
@SuppressWarnings("unchecked")
void metadata_shouldHandle200_phase0Attestation() throws IOException {
setHandler(
new GetAggregateAttestationV2(
validatorDataProvider, new SchemaDefinitionCache(specMinimalPhase0)));
final String data = getResponseStringFromMetadata(handler, SC_OK, phase0responseData);

final AttestationSchema<AttestationPhase0> phase0AttestationSchema =
(AttestationSchema<AttestationPhase0>)
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.PHASE0).getAttestationSchema();
final AttestationPhase0 attestation =
parseAttestationFromResponse(data, phase0AttestationSchema);
final AttestationSchema<Attestation> phase0AttestationSchema =
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.PHASE0).getAttestationSchema();
final Attestation attestation = parseAttestationFromResponse(data, phase0AttestationSchema);

assertThat(attestation.requiresCommitteeBits()).isFalse();
}

@Test
@SuppressWarnings("unchecked")
void metadata_shouldHandle200_electraAttestation() throws IOException {
setHandler(
new GetAggregateAttestationV2(
validatorDataProvider, new SchemaDefinitionCache(specMinimalElectra)));
final String data = getResponseStringFromMetadata(handler, SC_OK, electraResponseData);

final AttestationSchema<AttestationElectra> electraAttestationSchema =
(AttestationSchema<AttestationElectra>)
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.ELECTRA).getAttestationSchema();
final AttestationElectra attestation =
parseAttestationFromResponse(data, electraAttestationSchema);
final AttestationSchema<Attestation> electraAttestationSchema =
schemaDefinitionCache.getSchemaDefinition(SpecMilestone.ELECTRA).getAttestationSchema();
final Attestation attestation = parseAttestationFromResponse(data, electraAttestationSchema);

assertThat(attestation.requiresCommitteeBits()).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Objects;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema;

@SuppressWarnings("JavaCase")
public class AttesterSlashing {
Expand Down Expand Up @@ -46,7 +46,7 @@ public AttesterSlashing(

public tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing
asInternalAttesterSlashing(final SpecVersion spec) {
final AttesterSlashingSchema attesterSlashingSchema =
final AttesterSlashingSchema<?> attesterSlashingSchema =
spec.getSchemaDefinitions().getAttesterSlashingSchema();
return attesterSlashingSchema.create(
attestation_1.asInternalIndexedAttestation(spec),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema;
import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema;

@SuppressWarnings("JavaCase")
public class IndexedAttestation {
Expand Down Expand Up @@ -61,7 +61,7 @@ public IndexedAttestation(

public tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation
asInternalIndexedAttestation(final SpecVersion spec) {
final IndexedAttestationSchema indexedAttestationSchema =
final IndexedAttestationSchema<?> indexedAttestationSchema =
spec.getSchemaDefinitions().getIndexedAttestationSchema();
return indexedAttestationSchema.create(
indexedAttestationSchema.getAttestingIndicesSchema().of(attesting_indices),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected Attestation createContainer() {

@Override
protected AttestationSchema<Attestation> getContainerType() {
return spec.getGenesisSchemaDefinitions().getAttestationSchema().castTypeToAttestationSchema();
return spec.getGenesisSchemaDefinitions().getAttestationSchema();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.BlockBodyFields;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema;
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.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;

Expand Down Expand Up @@ -77,7 +78,6 @@ private BeaconBlockBodySchemaAltairImpl(

public static BeaconBlockBodySchemaAltairImpl create(
final SpecConfig specConfig,
final AttesterSlashingSchema attesterSlashingSchema,
final long maxValidatorsPerAttestation,
final String containerName) {
return new BeaconBlockBodySchemaAltairImpl(
Expand All @@ -91,7 +91,12 @@ public static BeaconBlockBodySchemaAltairImpl create(
ProposerSlashing.SSZ_SCHEMA, specConfig.getMaxProposerSlashings())),
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(attesterSlashingSchema, specConfig.getMaxAttesterSlashings())),
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
SszListSchema.create(
Expand Down
Loading

0 comments on commit 0227b70

Please sign in to comment.