diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java index 39f5cb0f66f..00766cdf574 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/MainnetBlockValidator.java @@ -171,7 +171,12 @@ public BlockProcessingResult validateAndProcessBlock( Optional> maybeRequests = result.getYield().flatMap(BlockProcessingOutputs::getRequests); if (!blockBodyValidator.validateBody( - context, block, receipts, worldState.rootHash(), ommerValidationMode)) { + context, + block, + receipts, + worldState.rootHash(), + ommerValidationMode, + BodyValidationMode.FULL)) { result = new BlockProcessingResult("failed to validate output of imported block"); handleFailedBlockProcessing(block, result, shouldRecordBadBlock); return result; @@ -246,6 +251,12 @@ public boolean validateBlockForSyncing( final HeaderValidationMode headerValidationMode, final HeaderValidationMode ommerValidationMode, final BodyValidationMode bodyValidationMode) { + + if (bodyValidationMode == BodyValidationMode.FULL) { + throw new UnsupportedOperationException( + "Full body validation is not supported for syncing blocks"); + } + final BlockHeader header = block.getHeader(); if (!blockHeaderValidator.validateHeader(header, context, headerValidationMode)) { String description = String.format("Failed header validation (%s)", headerValidationMode); @@ -253,8 +264,11 @@ public boolean validateBlockForSyncing( return false; } - if (!blockBodyValidator.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode)) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (!blockBodyValidator.validateBodyLight(context, block, receipts, ommerValidationMode)) { badBlockManager.addBadBlock( block, BadBlockCause.fromValidationFailure("Failed body validation (light)")); return false; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java index 0d43a470228..62629dde665 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BaseFeeBlockBodyValidator.java @@ -41,11 +41,9 @@ public boolean validateBodyLight( final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { + final HeaderValidationMode ommerValidationMode) { - return super.validateBodyLight( - context, block, receipts, ommerValidationMode, bodyValidationMode) + return super.validateBodyLight(context, block, receipts, ommerValidationMode) && validateTransactionGasPrice(block); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java index 32000d12b96..53fb0f42432 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BlockBodyValidator.java @@ -33,14 +33,16 @@ public interface BlockBodyValidator { * @param worldStateRootHash The rootHash defining the world state after processing this block and * all of its transactions. * @param ommerValidationMode The validation mode to use for ommer headers + * @param bodyValidationMode The validation mode to use for the body * @return {@code true} if valid; otherwise {@code false} */ boolean validateBody( - ProtocolContext context, - Block block, - List receipts, - Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode); + final ProtocolContext context, + final Block block, + final List receipts, + final Hash worldStateRootHash, + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode); /** * Validates that the block body is valid, but skips state root validation. @@ -55,6 +57,5 @@ boolean validateBodyLight( ProtocolContext context, Block block, List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode); + final HeaderValidationMode ommerValidationMode); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java index 344a950e365..b8f7ca6028a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidationMode.java @@ -21,6 +21,9 @@ public enum BodyValidationMode { /** Skip receipts and transactions root validation */ LIGHT, + /** Validate transactions, state, and receipts root */ + ROOT_ONLY, + /** Fully validate the body */ FULL; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java index 1423183e945..ccb16a587ad 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java @@ -50,10 +50,39 @@ public boolean validateBody( final Block block, final List receipts, final Hash worldStateRootHash, - final HeaderValidationMode ommerValidationMode) { + final HeaderValidationMode ommerValidationMode, + final BodyValidationMode bodyValidationMode) { + if (bodyValidationMode == BodyValidationMode.NONE) { + return true; + } + + if (bodyValidationMode == BodyValidationMode.LIGHT + || bodyValidationMode == BodyValidationMode.FULL) { + if (!validateBodyLight(context, block, receipts, ommerValidationMode)) { + return false; + } + } + + if (bodyValidationMode == BodyValidationMode.ROOT_ONLY + || bodyValidationMode == BodyValidationMode.FULL) { + return validateBodyRoots(block, receipts, worldStateRootHash); + } + return true; + } + + @VisibleForTesting + protected boolean validateBodyRoots( + final Block block, final List receipts, final Hash worldStateRootHash) { + final BlockHeader header = block.getHeader(); + final BlockBody body = block.getBody(); + + final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); + if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { + return false; + } - if (!validateBodyLight( - context, block, receipts, ommerValidationMode, BodyValidationMode.FULL)) { + final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); + if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { return false; } @@ -65,7 +94,6 @@ public boolean validateBody( LOG.warn("Transaction receipt found in the invalid block {}", receipt.toString())); return false; } - return true; } @@ -74,27 +102,9 @@ public boolean validateBodyLight( final ProtocolContext context, final Block block, final List receipts, - final HeaderValidationMode ommerValidationMode, - final BodyValidationMode bodyValidationMode) { - if (bodyValidationMode == BodyValidationMode.NONE) { - return true; - } + final HeaderValidationMode ommerValidationMode) { final BlockHeader header = block.getHeader(); - final BlockBody body = block.getBody(); - - // these checks are only needed for full validation and can be skipped for light validation - if (bodyValidationMode == BodyValidationMode.FULL) { - final Bytes32 transactionsRoot = BodyValidation.transactionsRoot(body.getTransactions()); - if (!validateTransactionsRoot(header, header.getTransactionsRoot(), transactionsRoot)) { - return false; - } - - final Bytes32 receiptsRoot = BodyValidation.receiptsRoot(receipts); - if (!validateReceiptsRoot(header, header.getReceiptsRoot(), receiptsRoot)) { - return false; - } - } final long gasUsed = receipts.isEmpty() ? 0 : receipts.get(receipts.size() - 1).getCumulativeGasUsed(); @@ -113,15 +123,13 @@ public boolean validateBodyLight( if (!validateWithdrawals(block)) { return false; } - return true; } - @VisibleForTesting - protected boolean validateTransactionsRoot( + private boolean validateTransactionsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { - LOG.info( + LOG.warn( "Invalid block {}: transaction root mismatch (expected={}, actual={})", header.toLogString(), expected, @@ -160,8 +168,7 @@ private static boolean validateGasUsed( return true; } - @VisibleForTesting - protected boolean validateReceiptsRoot( + private boolean validateReceiptsRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( @@ -175,7 +182,7 @@ protected boolean validateReceiptsRoot( return true; } - private static boolean validateStateRoot( + private boolean validateStateRoot( final BlockHeader header, final Bytes32 expected, final Bytes32 actual) { if (!expected.equals(actual)) { LOG.warn( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java index f9a325f3d7e..06580ad4dea 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/BlockImportExceptionHandlingTest.java @@ -153,7 +153,8 @@ void shouldNotBadBlockWhenInternalErrorDuringPersisting() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -189,7 +190,8 @@ void shouldNotBadBlockWhenInternalErrorOnBlockLookup() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenReturn(true); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( @@ -257,7 +259,8 @@ void shouldNotBadBlockWhenInternalErrorDuringValidateBody() { eq(goodBlock), any(), any(), - eq(HeaderValidationMode.DETACHED_ONLY))) + eq(HeaderValidationMode.DETACHED_ONLY), + any())) .thenThrow(new StorageException("database problem")); assertThat(badBlockManager.getBadBlocks()).isEmpty(); mainnetBlockValidator.validateAndProcessBlock( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java index 255ea778395..96e8cafe191 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -97,8 +98,9 @@ public void setup() { when(worldStateArchive.getMutable()).thenReturn(worldState); when(blockHeaderValidator.validateHeader(any(), any(), any())).thenReturn(true); when(blockHeaderValidator.validateHeader(any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBody(any(), any(), any(), any(), any())).thenReturn(true); - when(blockBodyValidator.validateBodyLight(any(), any(), any(), any(), any())).thenReturn(true); + when(blockBodyValidator.validateBody(any(), any(), any(), any(), any(), any())) + .thenReturn(true); + when(blockBodyValidator.validateBodyLight(any(), any(), any(), any())).thenReturn(true); when(blockProcessor.processBlock(any(), any(), any())).thenReturn(successfulProcessingResult); when(blockProcessor.processBlock(any(), any(), any(), any())) .thenReturn(successfulProcessingResult); @@ -163,7 +165,8 @@ public void validateAndProcessBlock_whenHeaderInvalid() { @Test public void validateAndProcessBlock_whenBlockBodyInvalid() { - when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any())).thenReturn(false); + when(blockBodyValidator.validateBody(any(), eq(block), any(), any(), any(), any())) + .thenReturn(false); BlockProcessingResult result = mainnetBlockValidator.validateAndProcessBlock( @@ -350,7 +353,7 @@ public void validateBlockForSyncing_onSuccess() { Collections.emptyList(), HeaderValidationMode.FULL, HeaderValidationMode.FULL, - BodyValidationMode.FULL); + BodyValidationMode.LIGHT); assertThat(isValid).isTrue(); assertNoBadBlocks(); @@ -362,7 +365,6 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { when(blockHeaderValidator.validateHeader( any(BlockHeader.class), eq(protocolContext), eq(headerValidationMode))) .thenReturn(false); - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; final boolean isValid = mainnetBlockValidator.validateBlockForSyncing( @@ -371,7 +373,7 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); @@ -380,13 +382,8 @@ public void validateBlockValidation_onFailedHeaderForSyncing() { @Test public void validateBlockValidation_onFailedBodyForSyncing() { final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; - final BodyValidationMode bodyValidationMode = BodyValidationMode.FULL; when(blockBodyValidator.validateBodyLight( - eq(protocolContext), - eq(block), - any(), - eq(headerValidationMode), - eq(bodyValidationMode))) + eq(protocolContext), eq(block), any(), eq(headerValidationMode))) .thenReturn(false); final boolean isValid = @@ -396,12 +393,27 @@ public void validateBlockValidation_onFailedBodyForSyncing() { Collections.emptyList(), headerValidationMode, headerValidationMode, - bodyValidationMode); + BodyValidationMode.LIGHT); assertThat(isValid).isFalse(); assertBadBlockIsTracked(block); } + @Test + public void shouldThrowIfValidateForSyncingWithFullBodyValidation() { + final HeaderValidationMode headerValidationMode = HeaderValidationMode.FULL; + assertThrows( + UnsupportedOperationException.class, + () -> + mainnetBlockValidator.validateBlockForSyncing( + protocolContext, + block, + Collections.emptyList(), + headerValidationMode, + headerValidationMode, + BodyValidationMode.FULL)); + } + private void assertNoBadBlocks() { assertThat(badBlockManager.getBadBlocks()).isEmpty(); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java index 8c25d4f58ed..8665cb70ac3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidatorTest.java @@ -95,11 +95,7 @@ void validatesWithdrawals() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isTrue(); } @@ -123,11 +119,7 @@ void validationFailsIfWithdrawalsValidationFails() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -151,11 +143,7 @@ void validationFailsIfWithdrawalsRootValidationFails() { assertThat( new MainnetBlockBodyValidator(protocolSchedule) .validateBodyLight( - blockchainSetupUtil.getProtocolContext(), - block, - emptyList(), - NONE, - BodyValidationMode.FULL)) + blockchainSetupUtil.getProtocolContext(), block, emptyList(), NONE)) .isFalse(); } @@ -168,10 +156,11 @@ public void noneValidationModeDoesNothing() { final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); assertThat( - bodyValidator.validateBodyLight( + bodyValidator.validateBody( blockchainSetupUtil.getProtocolContext(), block, receipts, + Hash.ZERO, NONE, BodyValidationMode.NONE)) .isTrue(); @@ -180,66 +169,79 @@ public void noneValidationModeDoesNothing() { } @Test - public void lightValidationDoesNotCheckTransactionRootOrReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void lightValidationDoesNotCheckRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + Hash.ZERO, NONE, BodyValidationMode.LIGHT)) .isTrue(); - verify(bodyValidatorSpy, never()).validateReceiptsRoot(any(), any(), any()); - verify(bodyValidatorSpy, never()).validateTransactionsRoot(any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, never()).validateBodyRoots(any(), any(), any()); } @Test - public void fullValidationChecksTransactionRootAndReceiptRoot() { - final Block block = - blockDataGenerator.block( - new BlockOptions() - .setBlockNumber(1) - .setGasUsed(0) - .hasTransactions(false) - .hasOmmers(false) - .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) - .setLogsBloom(LogsBloomFilter.empty()) - .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) - .setWithdrawals(Optional.of(withdrawals))); - blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + public void hashOnlyValidationChecksOnlyRoots() { + final Block block = setupBlock(); final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); assertThat( - bodyValidatorSpy.validateBodyLight( + bodyValidatorSpy.validateBody( blockchainSetupUtil.getProtocolContext(), block, emptyList(), + block.getHeader().getStateRoot(), + NONE, + BodyValidationMode.ROOT_ONLY)) + .isTrue(); + + verify(bodyValidatorSpy, never()).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + @Test + public void fullValidationChecksRootsAndContent() { + final Block block = setupBlock(); + + final MainnetBlockBodyValidator bodyValidator = new MainnetBlockBodyValidator(protocolSchedule); + final MainnetBlockBodyValidator bodyValidatorSpy = spy(bodyValidator); + + assertThat( + bodyValidatorSpy.validateBody( + blockchainSetupUtil.getProtocolContext(), + block, + emptyList(), + block.getHeader().getStateRoot(), NONE, BodyValidationMode.FULL)) .isTrue(); - final Hash receiptsRoot = BodyValidation.receiptsRoot(emptyList()); - final Hash transactionsRoot = BodyValidation.transactionsRoot(emptyList()); - verify(bodyValidatorSpy, times(1)) - .validateReceiptsRoot(block.getHeader(), receiptsRoot, receiptsRoot); - verify(bodyValidatorSpy, times(1)) - .validateTransactionsRoot(block.getHeader(), transactionsRoot, transactionsRoot); + verify(bodyValidatorSpy, times(1)).validateBodyLight(any(), any(), any(), any()); + verify(bodyValidatorSpy, times(1)).validateBodyRoots(any(), any(), any()); + } + + private Block setupBlock() { + Block block = + blockDataGenerator.block( + new BlockOptions() + .setBlockNumber(1) + .setGasUsed(0) + .hasTransactions(false) + .hasOmmers(false) + .setReceiptsRoot(BodyValidation.receiptsRoot(emptyList())) + .setLogsBloom(LogsBloomFilter.empty()) + .setParentHash(blockchainSetupUtil.getBlockchain().getChainHeadHash()) + .setWithdrawals(Optional.of(withdrawals))); + blockchainSetupUtil.getBlockchain().appendBlock(block, Collections.emptyList()); + return block; } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index ac562608873..67085252e8f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -38,7 +38,6 @@ import org.hyperledger.besu.ethereum.eth.sync.range.SyncTargetRangeSource; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncTarget; -import org.hyperledger.besu.ethereum.mainnet.BodyValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -122,10 +121,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncT final int downloaderParallelism = syncConfig.getDownloaderParallelism(); final int headerRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final int singleHeaderBufferSize = headerRequestSize * downloaderParallelism; - final BodyValidationMode bodyValidationMode = - protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) - ? BodyValidationMode.NONE - : BodyValidationMode.LIGHT; + final SyncTargetRangeSource checkpointRangeSource = new SyncTargetRangeSource( new RangeHeadersFetcher( @@ -158,8 +154,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncT attachedValidationPolicy, ommerValidationPolicy, ethContext, - fastSyncState.getPivotBlockHeader().get(), - bodyValidationMode); + fastSyncState.getPivotBlockHeader().get()); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java index 20b9d84916a..4397ed011c7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStep.java @@ -54,15 +54,17 @@ public ImportBlocksStep( final ValidationPolicy headerValidationPolicy, final ValidationPolicy ommerValidationPolicy, final EthContext ethContext, - final BlockHeader pivotHeader, - final BodyValidationMode bodyValidationMode) { + final BlockHeader pivotHeader) { this.protocolSchedule = protocolSchedule; this.protocolContext = protocolContext; this.headerValidationPolicy = headerValidationPolicy; this.ommerValidationPolicy = ommerValidationPolicy; this.ethContext = ethContext; this.pivotHeader = pivotHeader; - this.bodyValidationMode = bodyValidationMode; + bodyValidationMode = + protocolSchedule.anyMatch(scheduledProtocolSpec -> scheduledProtocolSpec.spec().isPoS()) + ? BodyValidationMode.NONE + : BodyValidationMode.LIGHT; } @Override diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java index af4f45f6901..c26e730aa38 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/ImportBlocksStepTest.java @@ -73,8 +73,7 @@ public void setUp() { validationPolicy, ommerValidationPolicy, null, - pivotHeader, - BodyValidationMode.FULL); + pivotHeader); } @Test @@ -92,7 +91,7 @@ public void shouldImportBlocks() { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(true)); } importBlocksStep.accept(blocksWithReceipts); @@ -114,7 +113,7 @@ public void shouldThrowExceptionWhenValidationFails() { blockWithReceipts.getReceipts(), FULL, LIGHT, - BodyValidationMode.FULL)) + BodyValidationMode.LIGHT)) .thenReturn(new BlockImportResult(false)); assertThatThrownBy(() -> importBlocksStep.accept(singletonList(blockWithReceipts))) .isInstanceOf(InvalidBlockException.class);