Search in sources :

Example 1 with BLSPubKey

use of tech.pegasys.teku.api.schema.BLSPubKey in project teku by ConsenSys.

the class PostSyncDutiesIntegrationTest method shouldGetSyncCommitteeDuties.

@Test
void shouldGetSyncCommitteeDuties() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final SafeFuture<Optional<SyncCommitteeDuties>> out = SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(VALIDATOR_KEYS.get(1).getPublicKey(), 1, IntSet.of(11))))));
    when(syncService.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
    when(validatorApiChannel.getSyncCommitteeDuties(ONE, validators)).thenReturn(out);
    Response response = post(PostSyncDuties.ROUTE.replace("{epoch}", "1"), jsonProvider.objectToJSON(validators));
    Assertions.assertThat(response.code()).isEqualTo(SC_OK);
    final PostSyncDutiesResponse dutiesResponse = jsonProvider.jsonToObject(response.body().string(), PostSyncDutiesResponse.class);
    assertThat(dutiesResponse.data.get(0)).isEqualTo(new tech.pegasys.teku.api.response.v1.validator.SyncCommitteeDuty(new BLSPubKey(VALIDATOR_KEYS.get(1).getPublicKey()), ONE, IntSet.of(11)));
}
Also used : PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Response(okhttp3.Response) PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Optional(java.util.Optional) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with BLSPubKey

use of tech.pegasys.teku.api.schema.BLSPubKey in project teku by ConsenSys.

the class SlashingProtectionRepairer method readSlashProtectionFile.

private void readSlashProtectionFile(final File file) {
    final String filePrefix = file.getName().substring(0, file.getName().length() - ".yml".length());
    try {
        BLSPubKey pubkey = BLSPubKey.fromHexString(filePrefix);
        Optional<ValidatorSigningRecord> maybeRecord = syncDataAccessor.read(file.toPath()).map(ValidatorSigningRecord::fromBytes);
        if (maybeRecord.isEmpty() && invalidRecords.add(filePrefix)) {
            log.display(filePrefix + ": Empty slashing protection record");
            return;
        }
        if (updateAllEnabled) {
            log.display(filePrefix + ": looks valid");
        }
        ValidatorSigningRecord validatorSigningRecord = maybeRecord.get();
        signingHistoryList.add(new SigningHistory(pubkey, validatorSigningRecord));
    } catch (PublicKeyException e) {
        log.display(" --- " + file.getName() + " - invalid public key - ignoring file");
    } catch (Exception e) {
        if (invalidRecords.add(filePrefix)) {
            log.display(filePrefix + ": Incomplete or invalid slashing protection data");
        }
    }
}
Also used : SigningHistory(tech.pegasys.teku.data.slashinginterchange.SigningHistory) ValidatorSigningRecord(tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord) PublicKeyException(tech.pegasys.teku.api.schema.PublicKeyException) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) IOException(java.io.IOException) PublicKeyException(tech.pegasys.teku.api.schema.PublicKeyException)

Example 3 with BLSPubKey

use of tech.pegasys.teku.api.schema.BLSPubKey in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method getProposerDuties_WhenFound_ReturnsDuties.

@Test
public void getProposerDuties_WhenFound_ReturnsDuties() {
    final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
    final int validatorIndex = 472;
    final tech.pegasys.teku.api.response.v1.validator.ProposerDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.ProposerDuty(new BLSPubKey(blsPublicKey), validatorIndex, UInt64.ZERO);
    final ProposerDuty expectedValidatorDuties = new ProposerDuty(blsPublicKey, validatorIndex, UInt64.ZERO);
    final GetProposerDutiesResponse response = new GetProposerDutiesResponse(Bytes32.fromHexString("0x1234"), List.of(schemaValidatorDuties));
    when(apiClient.getProposerDuties(UInt64.ONE)).thenReturn(Optional.of(response));
    SafeFuture<Optional<ProposerDuties>> future = apiHandler.getProposerDuties(UInt64.ONE);
    ProposerDuties validatorDuties = unwrapToValue(future);
    assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
    assertThat(validatorDuties.getDependentRoot()).isEqualTo(response.dependentRoot);
}
Also used : Optional(java.util.Optional) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) GetProposerDutiesResponse(tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Example 4 with BLSPubKey

use of tech.pegasys.teku.api.schema.BLSPubKey in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method getAttestationDuties_WhenFound_ReturnsDuties.

@Test
public void getAttestationDuties_WhenFound_ReturnsDuties() {
    final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
    final int validatorIndex = 472;
    final int committeeLength = 2;
    final int committeeIndex = 1;
    final int validatorCommitteeIndex = 3;
    final int committeesAtSlot = 15;
    final tech.pegasys.teku.api.response.v1.validator.AttesterDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.AttesterDuty(new BLSPubKey(blsPublicKey), UInt64.valueOf(validatorIndex), UInt64.valueOf(committeeIndex), UInt64.valueOf(committeeLength), UInt64.valueOf(committeesAtSlot), UInt64.valueOf(validatorCommitteeIndex), UInt64.ZERO);
    final AttesterDuty expectedValidatorDuties = new AttesterDuty(blsPublicKey, validatorIndex, committeeLength, committeeIndex, committeesAtSlot, validatorCommitteeIndex, UInt64.ZERO);
    when(apiClient.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex))).thenReturn(Optional.of(new PostAttesterDutiesResponse(dataStructureUtil.randomBytes32(), List.of(schemaValidatorDuties))));
    SafeFuture<Optional<AttesterDuties>> future = apiHandler.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex));
    AttesterDuties validatorDuties = unwrapToValue(future);
    assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
}
Also used : Optional(java.util.Optional) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Aggregations

BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)4 Optional (java.util.Optional)3 Test (org.junit.jupiter.api.Test)3 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 IOException (java.io.IOException)1 Response (okhttp3.Response)1 GetProposerDutiesResponse (tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse)1 PostAttesterDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse)1 PostSyncDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse)1 PublicKeyException (tech.pegasys.teku.api.schema.PublicKeyException)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1 ValidatorSigningRecord (tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord)1 SigningHistory (tech.pegasys.teku.data.slashinginterchange.SigningHistory)1 AttesterDuties (tech.pegasys.teku.validator.api.AttesterDuties)1 AttesterDuty (tech.pegasys.teku.validator.api.AttesterDuty)1 ProposerDuties (tech.pegasys.teku.validator.api.ProposerDuties)1 ProposerDuty (tech.pegasys.teku.validator.api.ProposerDuty)1 SyncCommitteeDuties (tech.pegasys.teku.validator.api.SyncCommitteeDuties)1 SyncCommitteeDuty (tech.pegasys.teku.validator.api.SyncCommitteeDuty)1