Search in sources :

Example 1 with Validator

use of tech.pegasys.web3signer.slashingprotection.dao.Validator in project web3signer by ConsenSys.

the class InterchangeV5Importer method parseValidator.

private void parseValidator(final Handle handle, final JsonNode node, final Optional<List<String>> pubkeys) throws JsonProcessingException {
    if (node.isArray()) {
        throw new IllegalStateException("Element of 'data' was not an object");
    }
    final ObjectNode parentNode = (ObjectNode) node;
    final String pubKey = parentNode.required("pubkey").textValue();
    if (pubkeys.isPresent() && !pubkeys.get().contains(pubKey)) {
        LOG.info("Skipping data import for validator " + pubKey);
        return;
    }
    final List<Validator> validators = validatorsDao.registerValidators(handle, List.of(Bytes.fromHexString(pubKey)));
    if (validators.isEmpty()) {
        throw new IllegalStateException("Unable to register validator " + pubKey);
    }
    final Validator validator = validators.get(0);
    final ArrayNode signedBlocksNode = parentNode.withArray("signed_blocks");
    importBlocks(handle, validator, signedBlocksNode);
    final ArrayNode signedAttestationNode = parentNode.withArray("signed_attestations");
    importAttestations(handle, validator, signedAttestationNode);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Validator(tech.pegasys.web3signer.slashingprotection.dao.Validator) GenesisValidatorRootValidator(tech.pegasys.web3signer.slashingprotection.validator.GenesisValidatorRootValidator)

Example 2 with Validator

use of tech.pegasys.web3signer.slashingprotection.dao.Validator in project web3signer by ConsenSys.

the class InterchangeV5ExporterTest method populateInterchangeDataThrowsUncheckedIOException.

@Test
public void populateInterchangeDataThrowsUncheckedIOException() {
    final DatabaseUtil.TestDatabaseInfo testDatabaseInfo = DatabaseUtil.createWithoutMigration();
    final Jdbi jdbi = testDatabaseInfo.getJdbi();
    final InterchangeV5Exporter exporter = new InterchangeV5Exporter(jdbi, validatorsDao, signedBlocksDao, signedAttestationsDao, metadataDao, lowWatermarkDao);
    final Validator validator = new Validator(1, Bytes.fromHexString(PUBLIC_KEY));
    when(validatorsDao.retrieveValidators(any(), any())).thenReturn(List.of(validator));
    when(lowWatermarkDao.findLowWatermarkForValidator(any(), eq(1))).thenReturn(Optional.of(new SigningWatermark()));
    // throw exception as the defaultAnswer as we don't care which json method is the cause
    final JsonGenerator mockJsonGenerator = mock(JsonGenerator.class, __ -> {
        throw new IOException("fake json error");
    });
    assertThatThrownBy(() -> exporter.populateInterchangeData(mockJsonGenerator, PUBLIC_KEY)).isInstanceOf(UncheckedIOException.class).hasMessage("Failed to construct a validator entry in json").hasRootCauseMessage("fake json error");
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) SigningWatermark(tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DatabaseUtil(db.DatabaseUtil) Validator(tech.pegasys.web3signer.slashingprotection.dao.Validator) Test(org.junit.jupiter.api.Test)

Aggregations

Validator (tech.pegasys.web3signer.slashingprotection.dao.Validator)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DatabaseUtil (db.DatabaseUtil)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Jdbi (org.jdbi.v3.core.Jdbi)1 Test (org.junit.jupiter.api.Test)1 SigningWatermark (tech.pegasys.web3signer.slashingprotection.dao.SigningWatermark)1 GenesisValidatorRootValidator (tech.pegasys.web3signer.slashingprotection.validator.GenesisValidatorRootValidator)1