Skip to content

Commit 10922d7

Browse files
committed
Use JsonTypeDef for PostSyncDuties request
1 parent f8c58ca commit 10922d7

File tree

8 files changed

+61
-186
lines changed

8 files changed

+61
-186
lines changed

Diff for: data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostSyncDutiesIntegrationTest.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1717
import static org.mockito.Mockito.when;
18+
import static tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDutiesBuilder.SYNC_COMMITTEE_DUTIES_TYPE;
1819
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
1920
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
21+
import static tech.pegasys.teku.infrastructure.json.JsonUtil.parse;
2022
import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE;
2123

2224
import it.unimi.dsi.fastutil.ints.IntList;
@@ -27,8 +29,6 @@
2729
import okhttp3.Response;
2830
import org.assertj.core.api.Assertions;
2931
import org.junit.jupiter.api.Test;
30-
import tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse;
31-
import tech.pegasys.teku.api.schema.BLSPubKey;
3232
import tech.pegasys.teku.beacon.sync.events.SyncState;
3333
import tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest;
3434
import tech.pegasys.teku.beaconrestapi.handlers.v1.validator.PostSyncDuties;
@@ -68,11 +68,9 @@ void shouldGetSyncCommitteeDuties() throws IOException {
6868
post(PostSyncDuties.ROUTE.replace("{epoch}", "1"), jsonProvider.objectToJSON(validators));
6969

7070
Assertions.assertThat(response.code()).isEqualTo(SC_OK);
71-
final PostSyncDutiesResponse dutiesResponse =
72-
jsonProvider.jsonToObject(response.body().string(), PostSyncDutiesResponse.class);
73-
assertThat(dutiesResponse.data.get(0))
74-
.isEqualTo(
75-
new tech.pegasys.teku.api.response.v1.validator.SyncCommitteeDuty(
76-
new BLSPubKey(VALIDATOR_KEYS.get(1).getPublicKey()), ONE, IntSet.of(11)));
71+
final SyncCommitteeDuties committeeDuties =
72+
parse(response.body().string(), SYNC_COMMITTEE_DUTIES_TYPE);
73+
assertThat(committeeDuties.getDuties().get(0))
74+
.isEqualTo(new SyncCommitteeDuty(VALIDATOR_KEYS.get(1).getPublicKey(), 1, IntSet.of(11)));
7775
}
7876
}

Diff for: data/serializer/src/main/java/tech/pegasys/teku/api/response/v1/validator/PostSyncDutiesResponse.java

-57
This file was deleted.

Diff for: data/serializer/src/main/java/tech/pegasys/teku/api/response/v1/validator/SyncCommitteeDuty.java

-83
This file was deleted.

Diff for: validator/remote/src/main/java/tech/pegasys/teku/validator/remote/RemoteValidatorApiHandler.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import com.google.common.base.Throwables;
2121
import it.unimi.dsi.fastutil.ints.IntCollection;
22-
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
2322
import java.time.Duration;
2423
import java.util.ArrayList;
2524
import java.util.Collection;
@@ -39,7 +38,6 @@
3938
import tech.pegasys.teku.api.migrated.ValidatorLivenessAtEpoch;
4039
import tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse;
4140
import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus;
42-
import tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse;
4341
import tech.pegasys.teku.api.response.v1.validator.PostValidatorLivenessResponse;
4442
import tech.pegasys.teku.api.schema.altair.ContributionAndProof;
4543
import tech.pegasys.teku.bls.BLSPublicKey;
@@ -50,7 +48,6 @@
5048
import tech.pegasys.teku.ethereum.json.types.validator.BeaconCommitteeSelectionProof;
5149
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
5250
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDuties;
53-
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDuty;
5451
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeSelectionProof;
5552
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
5653
import tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable;
@@ -223,25 +220,7 @@ public SafeFuture<Optional<AttesterDuties>> getAttestationDuties(
223220
@Override
224221
public SafeFuture<Optional<SyncCommitteeDuties>> getSyncCommitteeDuties(
225222
final UInt64 epoch, final IntCollection validatorIndices) {
226-
return sendRequest(
227-
() ->
228-
apiClient
229-
.getSyncCommitteeDuties(epoch, validatorIndices)
230-
.map(this::responseToSyncCommitteeDuties));
231-
}
232-
233-
private SyncCommitteeDuties responseToSyncCommitteeDuties(final PostSyncDutiesResponse response) {
234-
return new SyncCommitteeDuties(
235-
response.executionOptimistic,
236-
response.data.stream()
237-
.map(
238-
duty ->
239-
new SyncCommitteeDuty(
240-
duty.pubkey.asBLSPublicKey(),
241-
duty.validatorIndex.intValue(),
242-
IntOpenHashSet.toSet(
243-
duty.committeeIndices.stream().mapToInt(UInt64::intValue))))
244-
.toList());
223+
return sendRequest(() -> typeDefClient.postSyncDuties(epoch, validatorIndices));
245224
}
246225

247226
@Override

Diff for: validator/remote/src/main/java/tech/pegasys/teku/validator/remote/apiclient/OkHttpValidatorRestApiClient.java

-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_GENESIS;
2222
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_PROPOSER_DUTIES;
2323
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_SYNC_COMMITTEE_CONTRIBUTION;
24-
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_SYNC_COMMITTEE_DUTIES;
2524
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_VALIDATORS;
2625
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.PREPARE_BEACON_PROPOSER;
2726
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.SEND_CONTRIBUTION_AND_PROOF;
@@ -64,7 +63,6 @@
6463
import tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse;
6564
import tech.pegasys.teku.api.response.v1.validator.GetSyncCommitteeContributionResponse;
6665
import tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse;
67-
import tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse;
6866
import tech.pegasys.teku.api.response.v1.validator.PostValidatorLivenessResponse;
6967
import tech.pegasys.teku.api.schema.Attestation;
7068
import tech.pegasys.teku.api.schema.SignedAggregateAndProof;
@@ -224,16 +222,6 @@ public Optional<PostDataFailureResponse> sendSyncCommitteeMessages(
224222
jsonProvider, PostDataFailureResponse.class));
225223
}
226224

227-
@Override
228-
public Optional<PostSyncDutiesResponse> getSyncCommitteeDuties( // todo remove
229-
final UInt64 epoch, final Collection<Integer> validatorIndices) {
230-
return post(
231-
GET_SYNC_COMMITTEE_DUTIES,
232-
Map.of("epoch", epoch.toString()),
233-
validatorIndices.stream().map(UInt64::valueOf).toList(),
234-
createHandler(PostSyncDutiesResponse.class));
235-
}
236-
237225
@Override
238226
public void subscribeToSyncCommitteeSubnets(
239227
final List<SyncCommitteeSubnetSubscription> subnetSubscriptions) {

Diff for: validator/remote/src/main/java/tech/pegasys/teku/validator/remote/apiclient/ValidatorRestApiClient.java

-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import tech.pegasys.teku.api.response.v1.beacon.ValidatorResponse;
2424
import tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse;
2525
import tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse;
26-
import tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse;
2726
import tech.pegasys.teku.api.response.v1.validator.PostValidatorLivenessResponse;
2827
import tech.pegasys.teku.api.schema.Attestation;
2928
import tech.pegasys.teku.api.schema.SignedAggregateAndProof;
@@ -64,9 +63,6 @@ Optional<PostDataFailureResponse> sendAggregateAndProofs(
6463
Optional<PostDataFailureResponse> sendSyncCommitteeMessages(
6564
List<SyncCommitteeMessage> syncCommitteeMessages);
6665

67-
Optional<PostSyncDutiesResponse> getSyncCommitteeDuties(
68-
UInt64 epoch, Collection<Integer> validatorIndices);
69-
7066
void subscribeToSyncCommitteeSubnets(List<SyncCommitteeSubnetSubscription> subnetSubscriptions);
7167

7268
void sendContributionAndProofs(

Diff for: validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/OkHttpValidatorTypeDefClient.java

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package tech.pegasys.teku.validator.remote.typedef;
1515

16+
import java.util.Collection;
1617
import java.util.List;
1718
import java.util.Optional;
1819
import okhttp3.HttpUrl;
@@ -24,6 +25,7 @@
2425
import tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorData;
2526
import tech.pegasys.teku.ethereum.json.types.validator.BeaconCommitteeSelectionProof;
2627
import tech.pegasys.teku.ethereum.json.types.validator.ProposerDuties;
28+
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDuties;
2729
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeSelectionProof;
2830
import tech.pegasys.teku.infrastructure.ssz.SszList;
2931
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
@@ -44,6 +46,7 @@
4446
import tech.pegasys.teku.validator.remote.typedef.handlers.GetStateValidatorsRequest;
4547
import tech.pegasys.teku.validator.remote.typedef.handlers.GetSyncingStatusRequest;
4648
import tech.pegasys.teku.validator.remote.typedef.handlers.PostStateValidatorsRequest;
49+
import tech.pegasys.teku.validator.remote.typedef.handlers.PostSyncDutiesRequest;
4750
import tech.pegasys.teku.validator.remote.typedef.handlers.ProduceBlockRequest;
4851
import tech.pegasys.teku.validator.remote.typedef.handlers.RegisterValidatorsRequest;
4952
import tech.pegasys.teku.validator.remote.typedef.handlers.SendSignedBlockRequest;
@@ -60,6 +63,7 @@ public class OkHttpValidatorTypeDefClient extends OkHttpValidatorMinimalTypeDefC
6063
private final GetProposerDutiesRequest getProposerDutiesRequest;
6164
private final GetStateValidatorsRequest getStateValidatorsRequest;
6265
private final PostStateValidatorsRequest postStateValidatorsRequest;
66+
private final PostSyncDutiesRequest postSyncDutiesRequest;
6367
private final SendSignedBlockRequest sendSignedBlockRequest;
6468
private final RegisterValidatorsRequest registerValidatorsRequest;
6569
private final CreateAttestationDataRequest createAttestationDataRequest;
@@ -79,6 +83,7 @@ public OkHttpValidatorTypeDefClient(
7983
this.getProposerDutiesRequest = new GetProposerDutiesRequest(baseEndpoint, okHttpClient);
8084
this.getStateValidatorsRequest = new GetStateValidatorsRequest(baseEndpoint, okHttpClient);
8185
this.postStateValidatorsRequest = new PostStateValidatorsRequest(baseEndpoint, okHttpClient);
86+
this.postSyncDutiesRequest = new PostSyncDutiesRequest(baseEndpoint, okHttpClient);
8287
this.sendSignedBlockRequest =
8388
new SendSignedBlockRequest(spec, baseEndpoint, okHttpClient, preferSszBlockEncoding);
8489
this.registerValidatorsRequest =
@@ -119,6 +124,11 @@ public Optional<List<StateValidatorData>> postStateValidators(final List<String>
119124
.map(ObjectAndMetaData::getData);
120125
}
121126

127+
public Optional<SyncCommitteeDuties> postSyncDuties(
128+
final UInt64 epoch, final Collection<Integer> validatorIndices) {
129+
return postSyncDutiesRequest.postSyncDuties(epoch, validatorIndices);
130+
}
131+
122132
public SendSignedBlockResult sendSignedBlock(final SignedBlockContainer blockContainer) {
123133
return sendSignedBlockRequest.sendSignedBlock(blockContainer);
124134
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Consensys Software Inc., 2024
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package tech.pegasys.teku.validator.remote.typedef.handlers;
15+
16+
import static tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDutiesBuilder.SYNC_COMMITTEE_DUTIES_TYPE;
17+
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.INTEGER_TYPE;
18+
import static tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition.listOf;
19+
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_SYNC_COMMITTEE_DUTIES;
20+
21+
import java.util.Collection;
22+
import java.util.Map;
23+
import java.util.Optional;
24+
import okhttp3.HttpUrl;
25+
import okhttp3.OkHttpClient;
26+
import tech.pegasys.teku.ethereum.json.types.validator.SyncCommitteeDuties;
27+
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
28+
import tech.pegasys.teku.validator.remote.typedef.ResponseHandler;
29+
30+
public class PostSyncDutiesRequest extends AbstractTypeDefRequest {
31+
public PostSyncDutiesRequest(final HttpUrl baseEndpoint, final OkHttpClient okHttpClient) {
32+
super(baseEndpoint, okHttpClient);
33+
}
34+
35+
public Optional<SyncCommitteeDuties> postSyncDuties(
36+
final UInt64 epoch, final Collection<Integer> validatorIndices) {
37+
return postJson(
38+
GET_SYNC_COMMITTEE_DUTIES,
39+
Map.of("epoch", epoch.toString()),
40+
validatorIndices.stream().toList(),
41+
listOf(INTEGER_TYPE, 1),
42+
new ResponseHandler<>(SYNC_COMMITTEE_DUTIES_TYPE));
43+
}
44+
}

0 commit comments

Comments
 (0)