@Test public void importBlock_errorDuringWeakSubjectivityCheck() throws Exception { final SignedBeaconBlock block = otherChain.createBlockAtSlot(UInt64.ONE); localChain.setSlot(block.getSlot()); doThrow(new RuntimeException("oops")) .when(weakSubjectivityValidator) .validateLatestFinalizedCheckpoint(any(), any()); final BlockImportResult result = blockImporter.importBlock(block).get(); assertWeakSubjectivityWasChecked(); assertImportFailed(result, FailureReason.INTERNAL_ERROR); }
@CheckReturnValue public SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block) { if (recentChainData.containsBlock(block.getMessage().hash_tree_root())) { LOG.trace( "Importing known block {}. Return successful result without re-processing.", () -> formatBlock(block)); return SafeFuture.completedFuture(BlockImportResult.knownBlock(block)); } if (!weakSubjectivityValidator.isBlockValid(block, getForkChoiceStrategy())) { return SafeFuture.completedFuture(BlockImportResult.FAILED_WEAK_SUBJECTIVITY_CHECKS); } return validateFinalizedCheckpointIsWithinWeakSubjectivityPeriod() .thenCompose(__ -> recentChainData.retrieveBlockState(block.getParent_root())) .thenCompose(preState -> forkChoice.onBlock(block, preState)) .thenApply( result -> { if (!result.isSuccessful()) { LOG.trace( "Failed to import block for reason {}: {}", result::getFailureReason, () -> formatBlock(block)); return result; } LOG.trace("Successfully imported block {}", () -> formatBlock(block)); final Optional<BlockProcessingRecord> record = result.getBlockProcessingRecord(); eventBus.post(new ImportedBlockEvent(block)); if (result.isBlockOnCanonicalChain()) { notifyBlockOperationSubscribers(block); } record.ifPresent(eventBus::post); return result; }) .exceptionally( (e) -> { LOG.error("Internal error while importing block: {}", formatBlock(block), e); return BlockImportResult.internalError(e); }); }
BlockImporter { @CheckReturnValue public SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block) { if (recentChainData.containsBlock(block.getMessage().hash_tree_root())) { LOG.trace( "Importing known block {}. Return successful result without re-processing.", () -> formatBlock(block)); return SafeFuture.completedFuture(BlockImportResult.knownBlock(block)); } if (!weakSubjectivityValidator.isBlockValid(block, getForkChoiceStrategy())) { return SafeFuture.completedFuture(BlockImportResult.FAILED_WEAK_SUBJECTIVITY_CHECKS); } return validateFinalizedCheckpointIsWithinWeakSubjectivityPeriod() .thenCompose(__ -> recentChainData.retrieveBlockState(block.getParent_root())) .thenCompose(preState -> forkChoice.onBlock(block, preState)) .thenApply( result -> { if (!result.isSuccessful()) { LOG.trace( "Failed to import block for reason {}: {}", result::getFailureReason, () -> formatBlock(block)); return result; } LOG.trace("Successfully imported block {}", () -> formatBlock(block)); final Optional<BlockProcessingRecord> record = result.getBlockProcessingRecord(); eventBus.post(new ImportedBlockEvent(block)); if (result.isBlockOnCanonicalChain()) { notifyBlockOperationSubscribers(block); } record.ifPresent(eventBus::post); return result; }) .exceptionally( (e) -> { LOG.error("Internal error while importing block: {}", formatBlock(block), e); return BlockImportResult.internalError(e); }); } }
BlockImporter { @CheckReturnValue public SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block) { if (recentChainData.containsBlock(block.getMessage().hash_tree_root())) { LOG.trace( "Importing known block {}. Return successful result without re-processing.", () -> formatBlock(block)); return SafeFuture.completedFuture(BlockImportResult.knownBlock(block)); } if (!weakSubjectivityValidator.isBlockValid(block, getForkChoiceStrategy())) { return SafeFuture.completedFuture(BlockImportResult.FAILED_WEAK_SUBJECTIVITY_CHECKS); } return validateFinalizedCheckpointIsWithinWeakSubjectivityPeriod() .thenCompose(__ -> recentChainData.retrieveBlockState(block.getParent_root())) .thenCompose(preState -> forkChoice.onBlock(block, preState)) .thenApply( result -> { if (!result.isSuccessful()) { LOG.trace( "Failed to import block for reason {}: {}", result::getFailureReason, () -> formatBlock(block)); return result; } LOG.trace("Successfully imported block {}", () -> formatBlock(block)); final Optional<BlockProcessingRecord> record = result.getBlockProcessingRecord(); eventBus.post(new ImportedBlockEvent(block)); if (result.isBlockOnCanonicalChain()) { notifyBlockOperationSubscribers(block); } record.ifPresent(eventBus::post); return result; }) .exceptionally( (e) -> { LOG.error("Internal error while importing block: {}", formatBlock(block), e); return BlockImportResult.internalError(e); }); } BlockImporter(
      final RecentChainData recentChainData,
      final ForkChoice forkChoice,
      final WeakSubjectivityValidator weakSubjectivityValidator,
      final EventBus eventBus); }
BlockImporter { @CheckReturnValue public SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block) { if (recentChainData.containsBlock(block.getMessage().hash_tree_root())) { LOG.trace( "Importing known block {}. Return successful result without re-processing.", () -> formatBlock(block)); return SafeFuture.completedFuture(BlockImportResult.knownBlock(block)); } if (!weakSubjectivityValidator.isBlockValid(block, getForkChoiceStrategy())) { return SafeFuture.completedFuture(BlockImportResult.FAILED_WEAK_SUBJECTIVITY_CHECKS); } return validateFinalizedCheckpointIsWithinWeakSubjectivityPeriod() .thenCompose(__ -> recentChainData.retrieveBlockState(block.getParent_root())) .thenCompose(preState -> forkChoice.onBlock(block, preState)) .thenApply( result -> { if (!result.isSuccessful()) { LOG.trace( "Failed to import block for reason {}: {}", result::getFailureReason, () -> formatBlock(block)); return result; } LOG.trace("Successfully imported block {}", () -> formatBlock(block)); final Optional<BlockProcessingRecord> record = result.getBlockProcessingRecord(); eventBus.post(new ImportedBlockEvent(block)); if (result.isBlockOnCanonicalChain()) { notifyBlockOperationSubscribers(block); } record.ifPresent(eventBus::post); return result; }) .exceptionally( (e) -> { LOG.error("Internal error while importing block: {}", formatBlock(block), e); return BlockImportResult.internalError(e); }); } BlockImporter(
      final RecentChainData recentChainData,
      final ForkChoice forkChoice,
      final WeakSubjectivityValidator weakSubjectivityValidator,
      final EventBus eventBus); @CheckReturnValue SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block); void subscribeToVerifiedBlockAttestations(
      VerifiedBlockOperationsListener<Attestation> verifiedBlockAttestationsListener); void subscribeToVerifiedBlockAttesterSlashings(
      VerifiedBlockOperationsListener<AttesterSlashing> verifiedBlockAttesterSlashingsListener); void subscribeToVerifiedBlockProposerSlashings(
      VerifiedBlockOperationsListener<ProposerSlashing> verifiedBlockProposerSlashingsListener); void subscribeToVerifiedBlockVoluntaryExits(
      VerifiedBlockOperationsListener<SignedVoluntaryExit> verifiedBlockVoluntaryExitsListener); }
BlockImporter { @CheckReturnValue public SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block) { if (recentChainData.containsBlock(block.getMessage().hash_tree_root())) { LOG.trace( "Importing known block {}. Return successful result without re-processing.", () -> formatBlock(block)); return SafeFuture.completedFuture(BlockImportResult.knownBlock(block)); } if (!weakSubjectivityValidator.isBlockValid(block, getForkChoiceStrategy())) { return SafeFuture.completedFuture(BlockImportResult.FAILED_WEAK_SUBJECTIVITY_CHECKS); } return validateFinalizedCheckpointIsWithinWeakSubjectivityPeriod() .thenCompose(__ -> recentChainData.retrieveBlockState(block.getParent_root())) .thenCompose(preState -> forkChoice.onBlock(block, preState)) .thenApply( result -> { if (!result.isSuccessful()) { LOG.trace( "Failed to import block for reason {}: {}", result::getFailureReason, () -> formatBlock(block)); return result; } LOG.trace("Successfully imported block {}", () -> formatBlock(block)); final Optional<BlockProcessingRecord> record = result.getBlockProcessingRecord(); eventBus.post(new ImportedBlockEvent(block)); if (result.isBlockOnCanonicalChain()) { notifyBlockOperationSubscribers(block); } record.ifPresent(eventBus::post); return result; }) .exceptionally( (e) -> { LOG.error("Internal error while importing block: {}", formatBlock(block), e); return BlockImportResult.internalError(e); }); } BlockImporter(
      final RecentChainData recentChainData,
      final ForkChoice forkChoice,
      final WeakSubjectivityValidator weakSubjectivityValidator,
      final EventBus eventBus); @CheckReturnValue SafeFuture<BlockImportResult> importBlock(SignedBeaconBlock block); void subscribeToVerifiedBlockAttestations(
      VerifiedBlockOperationsListener<Attestation> verifiedBlockAttestationsListener); void subscribeToVerifiedBlockAttesterSlashings(
      VerifiedBlockOperationsListener<AttesterSlashing> verifiedBlockAttesterSlashingsListener); void subscribeToVerifiedBlockProposerSlashings(
      VerifiedBlockOperationsListener<ProposerSlashing> verifiedBlockProposerSlashingsListener); void subscribeToVerifiedBlockVoluntaryExits(
      VerifiedBlockOperationsListener<SignedVoluntaryExit> verifiedBlockVoluntaryExitsListener);  }