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)));
}
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);
}
}
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);
}
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;
}
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));
}
Aggregations