Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Aug 1, 2024
1 parent c06c39f commit 7fd451c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ private AttestationData createAttestationData(
return spec.getGenericAttestationData(slot, state, block, committeeIndexUnsigned);
}

@Deprecated
@Override
public SafeFuture<Optional<Attestation>> createAggregate(
final UInt64 slot,
Expand All @@ -512,19 +511,6 @@ public SafeFuture<Optional<Attestation>> createAggregate(
.map(ValidatableAttestation::getAttestation));
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
final UInt64 slot, final Bytes32 attestationHashTreeRoot, final UInt64 committeeIndex) {
if (isSyncActive()) {
return NodeSyncingException.failedFuture();
}
return SafeFuture.completedFuture(
attestationPool
.createAggregateFor(attestationHashTreeRoot, Optional.of(committeeIndex))
.filter(attestation -> attestation.getData().getSlot().equals(slot))
.map(ValidatableAttestation::getAttestation));
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ public SafeFuture<Optional<Attestation>> createAggregate(
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
UInt64 slot, Bytes32 attestationHashTreeRoot, UInt64 committeeIndex) {
return SafeFuture.completedFuture(Optional.empty());
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
UInt64 slot, int subcommitteeIndex, Bytes32 beaconBlockRoot) {
Expand Down Expand Up @@ -240,9 +234,6 @@ SafeFuture<Optional<BlockContainerAndMetaData>> createUnsignedBlock(
SafeFuture<Optional<Attestation>> createAggregate(
UInt64 slot, Bytes32 attestationHashTreeRoot, Optional<UInt64> committeeIndex);

SafeFuture<Optional<Attestation>> createAggregateV2(
UInt64 slot, Bytes32 attestationHashTreeRoot, UInt64 committeeIndex);

SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
UInt64 slot, int subcommitteeIndex, Bytes32 beaconBlockRoot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public SafeFuture<Optional<AttestationData>> createAttestationData(
BeaconNodeRequestLabels.CREATE_ATTESTATION_METHOD);
}

@Deprecated
@Override
public SafeFuture<Optional<Attestation>> createAggregate(
final UInt64 slot,
Expand All @@ -166,14 +165,6 @@ public SafeFuture<Optional<Attestation>> createAggregate(
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD);
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
final UInt64 slot, final Bytes32 attestationHashTreeRoot, final UInt64 committeeIndex) {
return countOptionalDataRequest(
delegate.createAggregateV2(slot, attestationHashTreeRoot, committeeIndex),
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD);
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public SafeFuture<Optional<AttestationData>> createAttestationData(
BeaconNodeRequestLabels.CREATE_ATTESTATION_METHOD);
}

@Deprecated
@Override
public SafeFuture<Optional<Attestation>> createAggregate(
final UInt64 slot,
Expand All @@ -199,14 +198,6 @@ public SafeFuture<Optional<Attestation>> createAggregate(
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD);
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
final UInt64 slot, final Bytes32 attestationHashTreeRoot, final UInt64 committeeIndex) {
return tryRequestUntilSuccess(
apiChannel -> apiChannel.createAggregateV2(slot, attestationHashTreeRoot, committeeIndex),
BeaconNodeRequestLabels.CREATE_AGGREGATE_METHOD);
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockContainer;
import tech.pegasys.teku.spec.datastructures.builder.SignedValidatorRegistration;
import tech.pegasys.teku.spec.datastructures.genesis.GenesisData;
Expand Down Expand Up @@ -304,26 +305,24 @@ private List<SubmitDataError> convertPostDataFailureResponseToSubmitDataErrors(
.toList();
}

@Deprecated
@Override
public SafeFuture<Optional<Attestation>> createAggregate(
final UInt64 slot,
final Bytes32 attestationHashTreeRoot,
final Optional<UInt64> committeeIndex) {
if (spec.atSlot(slot).getMilestone().isGreaterThanOrEqualTo(SpecMilestone.ELECTRA)
&& committeeIndex.isPresent()) {
return sendRequest(
() -> typeDefClient.createAggregate(slot, attestationHashTreeRoot, committeeIndex.get()));
}

return sendRequest(
() ->
apiClient
.createAggregate(slot, attestationHashTreeRoot)
.map(attestation -> attestation.asInternalAttestation(spec)));
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
final UInt64 slot, final Bytes32 attestationHashTreeRoot, final UInt64 committeeIndex) {
return sendRequest(
() -> typeDefClient.createAggregate(slot, attestationHashTreeRoot, committeeIndex));
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public SafeFuture<Optional<AttestationData>> createAttestationData(
return dutiesProviderChannel.createAttestationData(slot, committeeIndex);
}

@Deprecated
@Override
public SafeFuture<Optional<Attestation>> createAggregate(
final UInt64 slot,
Expand All @@ -136,14 +135,6 @@ public SafeFuture<Optional<Attestation>> createAggregate(
.createAggregate(slot, attestationHashTreeRoot, committeeIndex);
}

@Override
public SafeFuture<Optional<Attestation>> createAggregateV2(
final UInt64 slot, final Bytes32 attestationHashTreeRoot, final UInt64 committeeIndex) {
return attestationPublisherChannel
.orElse(dutiesProviderChannel)
.createAggregateV2(slot, attestationHashTreeRoot, committeeIndex);
}

@Override
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -64,6 +65,7 @@
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuty;
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeSelectionProof;
import static tech.pegasys.teku.infrastructure.async.FutureUtil.ignoreFuture;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.StubAsyncRunner;
import tech.pegasys.teku.infrastructure.async.Waiter;
Expand Down Expand Up @@ -643,6 +645,35 @@ public void createAggregate_WhenFound_ReturnsAttestation() {
assertThatSszData(unwrapToValue(future)).isEqualByAllMeansTo(attestation);
}

@Test
public void createAggregate_ShouldUseV1Api() {
final UInt64 slot = dataStructureUtil.randomUInt64();
final Bytes32 attHashTreeRoot = Bytes32.random();

ignoreFuture(apiHandler.createAggregate(slot, attHashTreeRoot, Optional.empty()));
asyncRunner.executeQueuedActions();

verify(typeDefClient, never()).createAggregate(any(), any(), any());
verify(apiClient).createAggregate(slot, attHashTreeRoot);
}

@Test
public void createAggregate_ShouldUseV2ApiPostElectra() {
final UInt64 slot = dataStructureUtil.randomUInt64();
final Bytes32 attHashTreeRoot = Bytes32.random();
final UInt64 committeeIndex = dataStructureUtil.randomUInt64();
final Spec electraSpec = TestSpecFactory.createMainnetElectra();

apiHandler =
new RemoteValidatorApiHandler(
endpoint, electraSpec, apiClient, typeDefClient, asyncRunner, true);
ignoreFuture(apiHandler.createAggregate(slot, attHashTreeRoot, Optional.of(committeeIndex)));
asyncRunner.executeQueuedActions();

verify(apiClient, never()).createAggregate(any(), any());
verify(typeDefClient).createAggregate(slot, attHashTreeRoot, committeeIndex);
}

@SuppressWarnings("unchecked")
@Test
public void sendsAggregateAndProof_InvokeApiWithCorrectRequest() {
Expand Down

0 comments on commit 7fd451c

Please sign in to comment.