use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.
the class AbstractBlockProcessor method processAttestations.
@Override
public void processAttestations(final MutableBeaconState state, final SszList<Attestation> attestations, final BLSSignatureVerifier signatureVerifier) throws BlockProcessingException {
final CapturingIndexedAttestationCache indexedAttestationCache = IndexedAttestationCache.capturing();
processAttestationsNoVerification(state, attestations, indexedAttestationCache);
final BlockValidationResult result = verifyAttestationSignatures(state, attestations, signatureVerifier, indexedAttestationCache);
if (!result.isValid()) {
throw new BlockProcessingException(result.getFailureReason());
}
}
use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.
the class ForkChoice method onBlock.
/**
* Import a block to the store. The supplied blockSlotState must already have empty slots
* processed to the same slot as the block.
*/
private SafeFuture<BlockImportResult> onBlock(final SignedBeaconBlock block, final Optional<BeaconState> blockSlotState, final ExecutionEngineChannel executionEngine) {
if (blockSlotState.isEmpty()) {
return SafeFuture.completedFuture(BlockImportResult.FAILED_UNKNOWN_PARENT);
}
checkArgument(block.getSlot().equals(blockSlotState.get().getSlot()), "State must have processed slots up to the block slot. Block slot %s, state slot %s", block.getSlot(), blockSlotState.get().getSlot());
final ForkChoicePayloadExecutor payloadExecutor = ForkChoicePayloadExecutor.create(spec, recentChainData, block, executionEngine);
final ForkChoiceUtil forkChoiceUtil = spec.atSlot(block.getSlot()).getForkChoiceUtil();
final BlockImportResult preconditionCheckResult = forkChoiceUtil.checkOnBlockConditions(block, blockSlotState.get(), recentChainData.getStore());
if (!preconditionCheckResult.isSuccessful()) {
reportInvalidBlock(block, preconditionCheckResult);
return SafeFuture.completedFuture(preconditionCheckResult);
}
final CapturingIndexedAttestationCache indexedAttestationCache = IndexedAttestationCache.capturing();
final BeaconState postState;
try {
postState = spec.getBlockProcessor(block.getSlot()).processAndValidateBlock(block, blockSlotState.get(), indexedAttestationCache, payloadExecutor);
} catch (final StateTransitionException e) {
final BlockImportResult result = BlockImportResult.failedStateTransition(e);
reportInvalidBlock(block, result);
return SafeFuture.completedFuture(result);
}
return payloadExecutor.getExecutionResult().thenApplyAsync(payloadResult -> importBlockAndState(block, blockSlotState.get(), forkChoiceUtil, indexedAttestationCache, postState, payloadResult), forkChoiceExecutor);
}
use of tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache in project teku by ConsenSys.
the class ForkChoice method applyVotesFromBlock.
private void applyVotesFromBlock(final ForkChoiceStrategy forkChoiceStrategy, final UInt64 currentEpoch, final CapturingIndexedAttestationCache indexedAttestationProvider) {
final VoteUpdater voteUpdater = recentChainData.startVoteUpdate();
indexedAttestationProvider.getIndexedAttestations().stream().filter(attestation -> validateBlockAttestation(forkChoiceStrategy, currentEpoch, attestation)).forEach(attestation -> forkChoiceStrategy.onAttestation(voteUpdater, attestation));
voteUpdater.commit();
}
Aggregations