Search in sources :

Example 1 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class SlashingProtectedValidatorSource method addValidator.

@Override
public AddValidatorResult addValidator(final KeyStoreData keyStoreData, final String password, final BLSPublicKey publicKey) {
    AddValidatorResult delegateResult = delegate.addValidator(keyStoreData, password, publicKey);
    if (delegateResult.getSigner().isEmpty()) {
        return delegateResult;
    }
    final Signer signer = delegateResult.getSigner().get();
    return new AddValidatorResult(delegateResult.getResult(), Optional.of(new SlashingProtectedSigner(publicKey, slashingProtector, signer)));
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner)

Example 2 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class ChainBuilder method appendNewBlockToChain.

private SignedBlockAndState appendNewBlockToChain(final UInt64 slot, final BlockOptions options) {
    final SignedBlockAndState latestBlockAndState = getLatestBlockAndState();
    final BeaconState preState = latestBlockAndState.getState();
    final Bytes32 parentRoot = latestBlockAndState.getBlock().getMessage().hashTreeRoot();
    int proposerIndex = blockProposalTestUtil.getProposerIndexForSlot(preState, slot);
    if (options.getWrongProposer()) {
        proposerIndex = (proposerIndex == 0 ? 1 : proposerIndex - 1);
    }
    final Signer signer = getSigner(proposerIndex);
    final SignedBlockAndState nextBlockAndState;
    try {
        SszList<Attestation> attestations = BeaconBlockBodyLists.ofSpec(spec).createAttestations(options.getAttestations().toArray(new Attestation[0]));
        nextBlockAndState = blockProposalTestUtil.createBlock(signer, slot, preState, parentRoot, Optional.of(attestations), Optional.empty(), Optional.empty(), options.getEth1Data(), options.getTransactions(), options.getTerminalBlockHash(), options.getExecutionPayload(), options.getSkipStateTransition());
        trackBlock(nextBlockAndState);
        return nextBlockAndState;
    } catch (StateTransitionException | EpochProcessingException | SlotProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) LocalSigner(tech.pegasys.teku.core.signatures.LocalSigner) SlotProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException) EpochProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Example 3 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class BeaconChainUtil method createBlockAndStateAtSlot.

private SignedBlockAndState createBlockAndStateAtSlot(final UInt64 slot, boolean withValidProposer, Optional<SszList<Attestation>> attestations, Optional<SszList<Deposit>> deposits, Optional<SszList<SignedVoluntaryExit>> exits, Optional<Eth1Data> eth1Data) throws Exception {
    checkState(withValidProposer || validatorKeys.size() > 1, "Must have >1 validator in order to create a block from an invalid proposer.");
    final ChainHead bestBlockAndState = recentChainData.getChainHead().orElseThrow();
    final Bytes32 bestBlockRoot = bestBlockAndState.getRoot();
    final BeaconState preState = safeJoin(bestBlockAndState.getState());
    checkArgument(bestBlockAndState.getSlot().compareTo(slot) < 0, "Slot must be in the future.");
    final int correctProposerIndex = blockCreator.getProposerIndexForSlot(preState, slot);
    final int proposerIndex = withValidProposer ? correctProposerIndex : getWrongProposerIndex(correctProposerIndex);
    final Signer signer = getSigner(proposerIndex);
    return blockCreator.createBlock(signer, slot, preState, bestBlockRoot, attestations, deposits, exits, eth1Data, Optional.empty(), Optional.empty(), Optional.empty(), false);
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) LocalSigner(tech.pegasys.teku.core.signatures.LocalSigner) ChainHead(tech.pegasys.teku.storage.client.ChainHead) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class ActiveKeyManager method deleteValidator.

@VisibleForTesting
DeleteKeyResult deleteValidator(final Validator activeValidator, final SlashingProtectionIncrementalExporter exporter) {
    final Signer signer = activeValidator.getSigner();
    signer.delete();
    LOG.info("Removed validator: {}", activeValidator.getPublicKey().toString());
    final DeleteKeyResult deleteKeyResult = validatorLoader.deleteLocalMutableValidator(activeValidator.getPublicKey());
    if (deleteKeyResult.getStatus() == DeletionStatus.DELETED) {
        Optional<String> error = exporter.addPublicKeyToExport(activeValidator.getPublicKey(), LOG::debug);
        if (error.isPresent()) {
            return DeleteKeyResult.error(error.get());
        }
    }
    return deleteKeyResult;
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) DeleteKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class SlashingProtectionLoggerTest method createProtectedValidator.

private Validator createProtectedValidator(BLSPublicKey publicKey) {
    Signer localSigner = new NoOpLocalSigner();
    Signer signer = new SlashingProtectedSigner(publicKey, slashingProtector, localSigner);
    return new Validator(publicKey, signer, mock(GraffitiProvider.class));
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) ExternalSigner(tech.pegasys.teku.validator.client.signer.ExternalSigner) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner) NoOpLocalSigner(tech.pegasys.teku.core.signatures.NoOpLocalSigner) SlashingProtectedSigner(tech.pegasys.teku.core.signatures.SlashingProtectedSigner) GraffitiProvider(tech.pegasys.teku.validator.api.GraffitiProvider) NoOpLocalSigner(tech.pegasys.teku.core.signatures.NoOpLocalSigner) Validator(tech.pegasys.teku.validator.client.Validator)

Aggregations

Signer (tech.pegasys.teku.core.signatures.Signer)10 LocalSigner (tech.pegasys.teku.core.signatures.LocalSigner)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Test (org.junit.jupiter.api.Test)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SlashingProtectedSigner (tech.pegasys.teku.core.signatures.SlashingProtectedSigner)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1