Skip to content

Commit

Permalink
Merge branch 'master' into save-earliest-slot-block-in-dbvariable
Browse files Browse the repository at this point in the history
  • Loading branch information
gfukushima authored Oct 21, 2024
2 parents a5a4afc + 3bb201d commit 9df9590
Show file tree
Hide file tree
Showing 103 changed files with 2,366 additions and 859 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
- Clean up old beacon states when switching from ARCHIVE to PRUNE or MINIMAL data storage mode

### Bug Fixes
- Fixed a block production issue for Validator Client (24.10.0 to 24.10.2 teku VC), where required headers were not provided for JSON payloads. Default SSZ block production was unaffected.
- Block production now uses json data (more like 24.8.0 did than 24.10) if the Eth-Consensus-version header is absent.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.Arrays;
import java.util.Locale;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
Expand All @@ -34,8 +35,9 @@
public class BlockProposalAcceptanceTest extends AcceptanceTestBase {
private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex");

@Test
void shouldHaveCorrectFeeRecipientAndGraffiti() throws Exception {
@ParameterizedTest(name = "ssz_encode={0}")
@ValueSource(booleans = {true, false})
void shouldHaveCorrectFeeRecipientAndGraffiti(final boolean useSszBlocks) throws Exception {
final String networkName = "swift";

final ValidatorKeystores validatorKeystores =
Expand Down Expand Up @@ -69,6 +71,7 @@ void shouldHaveCorrectFeeRecipientAndGraffiti() throws Exception {
.withValidatorProposerDefaultFeeRecipient(defaultFeeRecipient)
.withInteropModeDisabled()
.withBeaconNodes(beaconNode)
.withBeaconNodeSszBlocksEnabled(useSszBlocks)
.withGraffiti(userGraffiti)
.withNetwork("auto")
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private IndexedAttestation randomIndexedAttestation(
secretKey,
signingRootUtil.signingRootForSignAttestationData(attestationData, forkInfo));

final 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 @@ -530,6 +530,12 @@ public TekuNodeConfigBuilder withValidatorProposerDefaultFeeRecipient(
return this;
}

public TekuNodeConfigBuilder withBeaconNodeSszBlocksEnabled(final boolean enabled) {
LOG.debug("beacon-node-ssz-blocks-enabled={}", enabled);
configMap.put("beacon-node-ssz-blocks-enabled", enabled);
return this;
}

public TekuNodeConfigBuilder withStartupTargetPeerCount(final int startupTargetPeerCount) {
mustBe(NodeType.BEACON_NODE);
LOG.debug("Xstartup-target-peer-count={}", startupTargetPeerCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashing.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));
assertThat(response.code()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
}

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

verify(attesterSlashingPool).addLocal(slashing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.mockito.Mockito.when;
import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V1;
import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V2;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;

import java.io.IOException;
Expand Down Expand Up @@ -204,14 +203,7 @@ private <T extends SszData> void postRequestAndAssert(
JsonUtil.serialize(request, signedBlockContainerSchema.getJsonTypeDefinition()),
params,
versionHeader)) {
if (version == V2 && versionHeader.isEmpty()) {
// the version header is required in V2 APIs
assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
} else {
// the version header is not required for V1 APIs, the header selector should fall back to
// the slot selector
assertThat(response.code()).isEqualTo(SC_OK);
}
assertThat(response.code()).isEqualTo(SC_OK);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));
assertThat(response.code()).isEqualTo(500);
Expand All @@ -99,9 +97,7 @@ public void shouldReturnSuccessWhenRequestBodyIsValid() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

public class AttesterSlashingEvent extends Event<AttesterSlashing> {
AttesterSlashingEvent(final AttesterSlashing attesterSlashing) {
super(
attesterSlashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition(),
attesterSlashing);
super(attesterSlashing.getSchema().getJsonTypeDefinition(), attesterSlashing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ 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 @@ -16,7 +16,7 @@
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelector;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelectorWithSlotFallback;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
Expand Down Expand Up @@ -114,8 +114,9 @@ broadcast but a different status code is returned (202). Pre-Bellatrix, this end
.milestoneAtSlot(blockContainer.getSlot())
.equals(milestone)),
context ->
headerBasedSelector(
headerBasedSelectorWithSlotFallback(
context.getHeaders(),
context.getBody(),
schemaDefinitionCache,
SchemaDefinitions::getSignedBlindedBlockContainerSchema),
spec::deserializeSignedBlindedBlockContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelector;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelectorWithSlotFallback;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
Expand Down Expand Up @@ -114,8 +114,9 @@ validation, a separate success response code (202) is used to indicate that the
.milestoneAtSlot(blockContainer.getSlot())
.equals(milestone)),
context ->
headerBasedSelector(
headerBasedSelectorWithSlotFallback(
context.getHeaders(),
context.getBody(),
schemaDefinitionCache,
SchemaDefinitions::getSignedBlockContainerSchema),
spec::deserializeSignedBlockContainer)
Expand Down
Original file line number Diff line number Diff line change
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 All @@ -58,10 +58,9 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AttesterSlashing)) {
if (!(o instanceof AttesterSlashing that)) {
return false;
}
AttesterSlashing that = (AttesterSlashing) o;
return Objects.equals(attestation_1, that.attestation_1)
&& Objects.equals(attestation_2, that.attestation_2);
}
Expand Down
Original file line number Diff line number Diff line change
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 All @@ -74,10 +74,9 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof IndexedAttestation)) {
if (!(o instanceof IndexedAttestation that)) {
return false;
}
IndexedAttestation that = (IndexedAttestation) o;
return Objects.equals(attesting_indices, that.attesting_indices)
&& Objects.equals(data, that.data)
&& Objects.equals(signature, that.signature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.api.schema.bellatrix.SignedBlindedBeaconBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.SignedBlindedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.deneb.SignedBlindedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.electra.SignedBlindedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;

@Schema(
Expand All @@ -26,6 +27,7 @@
SignedBeaconBlockAltair.class,
SignedBlindedBeaconBlockBellatrix.class,
SignedBlindedBeaconBlockCapella.class,
SignedBlindedBeaconBlockDeneb.class
SignedBlindedBeaconBlockDeneb.class,
SignedBlindedBeaconBlockElectra.class
})
public interface SignedBlindedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.api.schema.bellatrix.SignedBeaconBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.SignedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.deneb.SignedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.electra.SignedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;

@Schema(
Expand All @@ -26,6 +27,7 @@
SignedBeaconBlockAltair.class,
SignedBeaconBlockBellatrix.class,
SignedBeaconBlockCapella.class,
SignedBeaconBlockDeneb.class
SignedBeaconBlockDeneb.class,
SignedBeaconBlockElectra.class
})
public interface SignedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.api.schema.bellatrix.BeaconStateBellatrix;
import tech.pegasys.teku.api.schema.capella.BeaconStateCapella;
import tech.pegasys.teku.api.schema.deneb.BeaconStateDeneb;
import tech.pegasys.teku.api.schema.electra.BeaconStateElectra;
import tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0;

@Schema(
Expand All @@ -26,6 +27,7 @@
BeaconStateAltair.class,
BeaconStateBellatrix.class,
BeaconStateCapella.class,
BeaconStateDeneb.class
BeaconStateDeneb.class,
BeaconStateElectra.class
})
public interface State {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.api.schema.bellatrix.BlindedBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.BlindedBlockCapella;
import tech.pegasys.teku.api.schema.deneb.BlindedBlockDeneb;
import tech.pegasys.teku.api.schema.electra.BlindedBlockElectra;
import tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0;

@Schema(
Expand All @@ -26,6 +27,7 @@
BeaconBlockAltair.class,
BlindedBlockBellatrix.class,
BlindedBlockCapella.class,
BlindedBlockDeneb.class
BlindedBlockDeneb.class,
BlindedBlockElectra.class
})
public interface UnsignedBlindedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.api.schema.bellatrix.BeaconBlockBellatrix;
import tech.pegasys.teku.api.schema.capella.BeaconBlockCapella;
import tech.pegasys.teku.api.schema.deneb.BeaconBlockDeneb;
import tech.pegasys.teku.api.schema.electra.BeaconBlockElectra;
import tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0;

@Schema(
Expand All @@ -26,6 +27,7 @@
BeaconBlockAltair.class,
BeaconBlockBellatrix.class,
BeaconBlockCapella.class,
BeaconBlockDeneb.class
BeaconBlockDeneb.class,
BeaconBlockElectra.class
})
public interface UnsignedBlock {}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV4;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
import tech.pegasys.teku.ethereum.executionclient.schema.Response;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -76,6 +77,9 @@ SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV2(
SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV3(
ForkChoiceStateV1 forkChoiceState, Optional<PayloadAttributesV3> payloadAttributes);

SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV4(
ForkChoiceStateV1 forkChoiceState, Optional<PayloadAttributesV4> payloadAttributes);

SafeFuture<Response<List<String>>> exchangeCapabilities(List<String> capabilities);

SafeFuture<Response<List<ClientVersionV1>>> getClientVersionV1(ClientVersionV1 clientVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV4;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
import tech.pegasys.teku.ethereum.executionclient.schema.Response;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -144,6 +145,14 @@ public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV3(
() -> delegate.forkChoiceUpdatedV3(forkChoiceState, payloadAttributes));
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV4(
final ForkChoiceStateV1 forkChoiceState,
final Optional<PayloadAttributesV4> payloadAttributes) {
return taskQueue.queueTask(
() -> delegate.forkChoiceUpdatedV4(forkChoiceState, payloadAttributes));
}

@Override
public SafeFuture<Response<List<String>>> exchangeCapabilities(final List<String> capabilities) {
return taskQueue.queueTask(() -> delegate.exchangeCapabilities(capabilities));
Expand Down
Loading

0 comments on commit 9df9590

Please sign in to comment.