Replace getByBlockNumber by getByBlockHeader (#5127)

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
pull/5184/head
Gabriel Fukushima 2 years ago committed by GitHub
parent 19eef239e2
commit bf0198103f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java
  2. 2
      besu/src/main/java/org/hyperledger/besu/chainimport/RlpBlockImporter.java
  3. 3
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  4. 21
      besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java
  5. 3
      besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java
  6. 2
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  7. 4
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionBackwardSyncContext.java
  8. 26
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java
  9. 13
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java
  10. 102
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/TransitionProtocolScheduleTest.java
  11. 2
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java
  12. 3
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java
  13. 3
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java
  14. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/DebugReplayBlock.java
  15. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetBadBlocks.java
  16. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugResyncWorldstate.java
  17. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java
  18. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHash.java
  19. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/FlatTraceGenerator.java
  20. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/RewardTraceGenerator.java
  21. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java
  22. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
  23. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java
  24. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetBadBlockTest.java
  25. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFileTest.java
  26. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockHashTest.java
  27. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetMinerDataByBlockNumberTest.java
  28. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/RewardTraceGeneratorTest.java
  29. 11
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesTest.java
  30. 2
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/BlockMiner.java
  31. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionSimulator.java
  32. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/storage/migration/PrivateStorageMigration.java
  33. 3
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java
  34. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java
  35. 6
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java
  36. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastImportBlocksStep.java
  37. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullImportBlockStep.java
  38. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/range/RangeHeadersValidationStep.java
  39. 4
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java
  40. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTask.java
  41. 8
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java
  42. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersValidationStepTest.java
  43. 6
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastImportBlocksStepTest.java
  44. 7
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullImportBlockStepTest.java
  45. 4
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java
  46. 2
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestImportRawBlock.java
  47. 2
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java

@ -153,10 +153,7 @@ public class JsonBlockImporter {
private void importBlock(final Block block) {
final BlockImporter importer =
controller
.getProtocolSchedule()
.getByBlockNumber(block.getHeader().getNumber())
.getBlockImporter();
controller.getProtocolSchedule().getByBlockHeader(block.getHeader()).getBlockImporter();
final BlockImportResult importResult =
importer.importBlock(controller.getProtocolContext(), block, HeaderValidationMode.NONE);

@ -127,7 +127,7 @@ public class RlpBlockImporter implements Closeable {
if (previousHeader == null) {
previousHeader = lookupPreviousHeader(blockchain, header);
}
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockNumber);
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(header);
final BlockHeader lastHeader = previousHeader;
final CompletableFuture<Void> validationFuture =

@ -427,8 +427,7 @@ public final class RunnerTest {
for (int i = 1; i < count + 1; ++i) {
final Block block = blocks.get(i);
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final BlockImportResult result =
blockImporter.importBlock(protocolContext, block, HeaderValidationMode.FULL);

@ -16,7 +16,6 @@ package org.hyperledger.besu.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@ -131,8 +130,8 @@ public class TransitionControllerBuilderTest {
var preMergeProtocolSpec = mock(ProtocolSpec.class);
when(mergeContext.isPostMerge()).thenReturn(Boolean.FALSE);
when(mergeContext.getFinalized()).thenReturn(Optional.empty());
when(preMergeProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(preMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeader(mockBlock))
when(preMergeProtocolSchedule.getByBlockHeader(any())).thenReturn(preMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(mockBlock))
.isEqualTo(preMergeProtocolSpec);
}
@ -141,8 +140,8 @@ public class TransitionControllerBuilderTest {
var mockBlock = new BlockHeaderTestFixture().buildHeader();
var postMergeProtocolSpec = mock(ProtocolSpec.class);
when(mergeContext.getFinalized()).thenReturn(Optional.of(mockBlock));
when(postMergeProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(postMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeader(mockBlock))
when(postMergeProtocolSchedule.getByBlockHeader(any())).thenReturn(postMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(mockBlock))
.isEqualTo(postMergeProtocolSpec);
}
@ -164,8 +163,8 @@ public class TransitionControllerBuilderTest {
when(mockBlockchain.getTotalDifficultyByHash(any()))
.thenReturn(Optional.of(Difficulty.of(1335L)));
when(preMergeProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(preMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeader(mockBlock))
when(preMergeProtocolSchedule.getByBlockHeader(any())).thenReturn(preMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(mockBlock))
.isEqualTo(preMergeProtocolSpec);
}
@ -187,8 +186,8 @@ public class TransitionControllerBuilderTest {
when(mockBlockchain.getTotalDifficultyByHash(any()))
.thenReturn(Optional.of(Difficulty.of(1337L)));
when(postMergeProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(postMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeader(mockBlock))
when(postMergeProtocolSchedule.getByBlockHeader(any())).thenReturn(postMergeProtocolSpec);
assertThat(transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(mockBlock))
.isEqualTo(postMergeProtocolSpec);
}
@ -213,7 +212,7 @@ public class TransitionControllerBuilderTest {
var preMergeProtocolSpec = mock(ProtocolSpec.class);
when(preMergeProtocolSpec.getBlockHeaderValidator()).thenReturn(validator);
when(preMergeProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(preMergeProtocolSpec);
when(preMergeProtocolSchedule.getByBlockHeader(any())).thenReturn(preMergeProtocolSpec);
var mockParentBlock =
new BlockHeaderTestFixture()
@ -235,7 +234,7 @@ public class TransitionControllerBuilderTest {
var mergeFriendlyValidation =
transitionProtocolSchedule
.getPreMergeSchedule()
.getByBlockNumber(1L)
.getByBlockHeader(mockBlock)
.getBlockHeaderValidator()
.validateHeader(
mockBlock, mockParentBlock, protocolContext, HeaderValidationMode.DETACHED_ONLY);

@ -17,7 +17,6 @@ package org.hyperledger.besu.services;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -125,7 +124,7 @@ public class BesuEventsImplTest {
when(mockEthPeers.streamAvailablePeers()).thenAnswer(z -> Stream.empty());
when(mockProtocolContext.getBlockchain()).thenReturn(blockchain);
when(mockProtocolContext.getWorldStateArchive()).thenReturn(mockWorldStateArchive);
when(mockProtocolSchedule.getByBlockNumber(anyLong())).thenReturn(mockProtocolSpec);
when(mockProtocolSchedule.getByBlockHeader(any())).thenReturn(mockProtocolSpec);
when(mockProtocolSpec.getTransactionValidator()).thenReturn(mockTransactionValidator);
when(mockProtocolSpec.getFeeMarket()).thenReturn(FeeMarket.london(0L));
when(mockTransactionValidator.validate(any(), any(Optional.class), any()))

@ -176,7 +176,7 @@ public class CliqueProtocolScheduleTest {
final BlockHeader parentBlockHeader) {
return schedule
.getByBlockNumber(blockHeader.getNumber())
.getByBlockHeader(blockHeader)
.getBlockHeaderValidator()
.validateHeader(blockHeader, parentBlockHeader, null, HeaderValidationMode.LIGHT);
}

@ -64,6 +64,8 @@ public class TransitionBackwardSyncContext extends BackwardSyncContext {
*/
@Override
public BlockValidator getBlockValidatorForBlock(final Block block) {
return transitionProtocolSchedule.getByBlockHeader(block.getHeader()).getBlockValidator();
return transitionProtocolSchedule
.getByBlockHeaderWithTransitionReorgHandling(block.getHeader())
.getBlockValidator();
}
}

@ -103,13 +103,29 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
}
/**
* Gets by block header.
* Gets protocol spec by block header.
*
* @param blockHeader the block header
* @return the by block header
* @return the ProtocolSpec to be used by the provided block
*/
@Override
public ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) {
return this.timestampSchedule
.getByTimestamp(blockHeader.getTimestamp())
.orElseGet(
() ->
transitionUtils.dispatchFunctionAccordingToMergeState(
protocolSchedule -> protocolSchedule.getByBlockHeader(blockHeader)));
}
/**
* Gets the protocol spec by block header, with some additional logic used by backwards sync (BWS)
*
* @param blockHeader the block header
* @return the ProtocolSpec to be used by the provided block
*/
public ProtocolSpec getByBlockHeaderWithTransitionReorgHandling(
final ProcessableBlockHeader blockHeader) {
return this.timestampSchedule
.getByTimestamp(blockHeader.getTimestamp())
.orElseGet(() -> getByBlockHeaderFromTransitionUtils(blockHeader));
@ -126,7 +142,7 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
.setMessage("for {} returning a pre-merge schedule because we are not post-merge")
.addArgument(blockHeader::toLogString)
.log();
return getPreMergeSchedule().getByBlockNumber(blockHeader.getNumber());
return getPreMergeSchedule().getByBlockHeader(blockHeader);
}
// otherwise check to see if this block represents a re-org TTD block:
@ -152,7 +168,7 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
.setMessage("returning a pre-merge schedule because block {} is pre-merge or TTD")
.addArgument(blockHeader::toLogString)
.log();
return getPreMergeSchedule().getByBlockNumber(blockHeader.getNumber());
return getPreMergeSchedule().getByBlockHeader(blockHeader);
}
}
// else return post-merge schedule
@ -160,7 +176,7 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
.setMessage(" for {} returning a post-merge schedule")
.addArgument(blockHeader::toLogString)
.log();
return getPostMergeSchedule().getByBlockNumber(blockHeader.getNumber());
return getPostMergeSchedule().getByBlockHeader(blockHeader);
}
/**

@ -729,9 +729,9 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
@Override
public Optional<Hash> getLatestValidAncestor(final Hash blockHash) {
final var chain = protocolContext.getBlockchain();
final var chainHeadNum = chain.getChainHeadBlockNumber();
final var chainHeadHeader = chain.getChainHeadHeader();
return findValidAncestor(
chain, blockHash, protocolSchedule.getByBlockNumber(chainHeadNum).getBadBlocksManager());
chain, blockHash, protocolSchedule.getByBlockHeader(chainHeadHeader).getBadBlocksManager());
}
@Override
@ -740,8 +740,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
final var self = chain.getBlockHeader(blockHeader.getHash());
if (self.isEmpty()) {
final var badBlocks =
protocolSchedule.getByBlockNumber(blockHeader.getNumber()).getBadBlocksManager();
final var badBlocks = protocolSchedule.getByBlockHeader(blockHeader).getBadBlocksManager();
return findValidAncestor(chain, blockHeader.getParentHash(), badBlocks);
}
return self.map(BlockHeader::getHash);
@ -872,7 +871,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
@Override
public void addBadBlock(final Block block, final Optional<Throwable> maybeCause) {
protocolSchedule
.getByBlockNumber(protocolContext.getBlockchain().getChainHeadBlockNumber())
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager()
.addBadBlock(block, maybeCause);
}
@ -887,7 +886,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
private BadBlockManager getBadBlockManager() {
final BadBlockManager badBlocksManager =
protocolSchedule
.getByBlockNumber(protocolContext.getBlockchain().getChainHeadBlockNumber())
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager();
return badBlocksManager;
}
@ -895,7 +894,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
@Override
public Optional<Hash> getLatestValidHashOfBadBlock(Hash blockHash) {
return protocolSchedule
.getByBlockNumber(protocolContext.getBlockchain().getChainHeadBlockNumber())
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager()
.getLatestValidHash(blockHash);
}

@ -15,6 +15,8 @@
package org.hyperledger.besu.consensus.merge;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
@ -71,11 +73,10 @@ public class TransitionProtocolScheduleTest {
@Test
public void returnPostMergeIfFinalizedExists() {
when(mergeContext.getFinalized()).thenReturn(Optional.of(mock(BlockHeader.class)));
when(blockHeader.getNumber()).thenReturn(BLOCK_NUMBER);
transitionProtocolSchedule.getByBlockHeader(blockHeader);
transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(blockHeader);
verifyPostMergeProtocolScheduleReturned();
verifyPostMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
@ -83,11 +84,9 @@ public class TransitionProtocolScheduleTest {
when(mergeContext.getFinalized()).thenReturn(Optional.empty());
when(mergeContext.isPostMerge()).thenReturn(false);
when(blockHeader.getNumber()).thenReturn(BLOCK_NUMBER);
transitionProtocolSchedule.getByBlockHeader(blockHeader);
transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(blockHeader);
verifyPreMergeProtocolScheduleReturned();
verifyPreMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
@ -98,15 +97,14 @@ public class TransitionProtocolScheduleTest {
final Hash parentHash = Hash.fromHexStringLenient("0xabc123");
when(blockHeader.getNumber()).thenReturn(BLOCK_NUMBER);
when(blockHeader.getParentHash()).thenReturn(parentHash);
when(blockHeader.getDifficulty()).thenReturn(Difficulty.of(10L));
when(blockchain.getTotalDifficultyByHash(parentHash))
.thenReturn(Optional.of(Difficulty.of(95L)));
transitionProtocolSchedule.getByBlockHeader(blockHeader);
transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(blockHeader);
verifyPreMergeProtocolScheduleReturned();
verifyPreMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
@ -117,15 +115,14 @@ public class TransitionProtocolScheduleTest {
final Hash parentHash = Hash.fromHexStringLenient("0xabc123");
when(blockHeader.getNumber()).thenReturn(BLOCK_NUMBER);
when(blockHeader.getParentHash()).thenReturn(parentHash);
when(blockHeader.getDifficulty()).thenReturn(Difficulty.of(2L));
when(blockchain.getTotalDifficultyByHash(parentHash))
.thenReturn(Optional.of(Difficulty.of(95L)));
transitionProtocolSchedule.getByBlockHeader(blockHeader);
transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(blockHeader);
verifyPreMergeProtocolScheduleReturned();
verifyPreMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
@ -142,20 +139,9 @@ public class TransitionProtocolScheduleTest {
when(blockchain.getTotalDifficultyByHash(parentHash))
.thenReturn(Optional.of(Difficulty.of(105L)));
transitionProtocolSchedule.getByBlockHeader(blockHeader);
transitionProtocolSchedule.getByBlockHeaderWithTransitionReorgHandling(blockHeader);
verifyPostMergeProtocolScheduleReturned();
}
@Test
public void getByBlockHeader_returnsTimestampScheduleIfPresent() {
when(timestampSchedule.getByTimestamp(TIMESTAMP))
.thenReturn(Optional.of(mock(ProtocolSpec.class)));
assertThat(transitionProtocolSchedule.getByBlockHeader(blockHeader)).isNotNull();
verify(timestampSchedule).getByTimestamp(TIMESTAMP);
verifyNoMergeScheduleInteractions();
verifyPostMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
@ -176,7 +162,7 @@ public class TransitionProtocolScheduleTest {
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
verifyPreMergeProtocolScheduleReturned();
verifyPreMergeProtocolScheduleReturnedUsingBlockNumber();
}
@Test
@ -186,25 +172,75 @@ public class TransitionProtocolScheduleTest {
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
verifyPostMergeProtocolScheduleReturned();
verifyPostMergeProtocolScheduleReturnedUsingBlockNumber();
}
@Test
public void getByBlockNumber_delegatesToPreMergeScheduleWhenTimestampScheduleDoesNotExist() {
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.of(blockHeader));
when(mergeContext.isPostMerge()).thenReturn(false);
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
verifyPreMergeProtocolScheduleReturnedUsingBlockNumber();
}
@Test
public void getByBlockNumber_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist() {
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.of(blockHeader));
when(mergeContext.isPostMerge()).thenReturn(true);
transitionProtocolSchedule.getByBlockNumber(BLOCK_NUMBER);
verifyPostMergeProtocolScheduleReturned();
verifyPostMergeProtocolScheduleReturnedUsingBlockNumber();
}
@Test
public void getByBlockHeader_returnsTimestampScheduleIfPresent() {
when(timestampSchedule.getByTimestamp(TIMESTAMP))
.thenReturn(Optional.of(mock(ProtocolSpec.class)));
assertThat(transitionProtocolSchedule.getByBlockHeader(blockHeader)).isNotNull();
verify(timestampSchedule).getByTimestamp(TIMESTAMP);
verifyNoMergeScheduleInteractions();
}
@Test
public void getByBlockHeader_delegatesToPreMergeScheduleWhenTimestampScheduleDoesNotExist() {
when(mergeContext.isPostMerge()).thenReturn(false);
transitionProtocolSchedule.getByBlockHeader(blockHeader);
verifyPreMergeProtocolScheduleReturnedUsingBlockHeader();
}
@Test
public void getByBlockHeader_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist() {
when(mergeContext.isPostMerge()).thenReturn(true);
transitionProtocolSchedule.getByBlockHeader(blockHeader);
verifyPostMergeProtocolScheduleReturnedUsingBlockHeader();
}
private void verifyPreMergeProtocolScheduleReturnedUsingBlockNumber() {
verify(preMergeProtocolSchedule).getByBlockNumber(anyLong());
verifyNoInteractions(postMergeProtocolSchedule);
}
private void verifyPostMergeProtocolScheduleReturnedUsingBlockNumber() {
verify(postMergeProtocolSchedule).getByBlockNumber(anyLong());
verifyNoInteractions(preMergeProtocolSchedule);
}
private void verifyPreMergeProtocolScheduleReturned() {
verify(preMergeProtocolSchedule).getByBlockNumber(BLOCK_NUMBER);
private void verifyPreMergeProtocolScheduleReturnedUsingBlockHeader() {
verify(preMergeProtocolSchedule).getByBlockHeader(any());
verifyNoInteractions(postMergeProtocolSchedule);
}
private void verifyPostMergeProtocolScheduleReturned() {
verify(postMergeProtocolSchedule).getByBlockNumber(BLOCK_NUMBER);
private void verifyPostMergeProtocolScheduleReturnedUsingBlockHeader() {
verify(postMergeProtocolSchedule).getByBlockHeader(any());
verifyNoInteractions(preMergeProtocolSchedule);
}

@ -181,7 +181,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
return spec;
})
.when(protocolSchedule)
.getByBlockNumber(anyLong());
.getByBlockHeader(any(BlockHeader.class));
protocolContext = new ProtocolContext(blockchain, worldStateArchive, mergeContext);
var mutable = worldStateArchive.getMutable();

@ -82,8 +82,7 @@ public class JsonRpcTestMethodsFactory {
this.synchronizer = mock(Synchronizer.class);
for (final Block block : importer.getBlocks()) {
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
}

@ -71,8 +71,7 @@ public class EthGetBlockByNumberLatestDesyncIntegrationTest {
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
}

@ -69,20 +69,18 @@ public class DebugReplayBlock extends AbstractBlockParameterMethod {
return new JsonRpcErrorResponse(request.getRequest().getId(), UNKNOWN_BLOCK);
}
final Block block = maybeBlock.get();
// rewind to the block before the one we want to replay
protocolContext.getBlockchain().rewindToBlock(blockNumber - 1);
try {
// replay block and persist it
protocolSchedule
.getByBlockNumber(blockNumber)
.getByBlockHeader(block.getHeader())
.getBlockValidator()
.validateAndProcessBlock(
protocolContext,
maybeBlock.get(),
HeaderValidationMode.FULL,
HeaderValidationMode.NONE,
true);
protocolContext, block, HeaderValidationMode.FULL, HeaderValidationMode.NONE, true);
} catch (Exception e) {
LOG.error(e.getMessage());
return new JsonRpcErrorResponse(request.getRequest().getId(), INTERNAL_ERROR);

@ -50,7 +50,7 @@ public class DebugGetBadBlocks implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final List<BadBlockResult> response =
protocolSchedule
.getByBlockNumber(blockchain.headBlockNumber())
.getByBlockHeader(blockchain.headBlockHeader())
.getBadBlocksManager()
.getBadBlocks()
.stream()

@ -44,7 +44,7 @@ public class DebugResyncWorldstate implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
protocolSchedule
.getByBlockNumber(blockchain.getChainHeadBlockNumber())
.getByBlockHeader(blockchain.getChainHeadHeader())
.getBadBlocksManager()
.reset();
return new JsonRpcSuccessResponse(

@ -60,7 +60,7 @@ public class DebugStandardTraceBadBlockToFile extends DebugStandardTraceBlockToF
final Blockchain blockchain = blockchainQueries.get().getBlockchain();
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(blockchain.getChainHeadHeader().getNumber());
protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader());
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
return badBlockManager

@ -79,7 +79,7 @@ public class EthGetMinerDataByBlockHash implements JsonRpcMethod {
final ProtocolSchedule protocolSchedule,
final BlockchainQueries blockchainQueries) {
final BlockHeader blockHeader = block.getHeader();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);
final Wei staticBlockReward = protocolSpec.getBlockReward();
final Wei transactionFee =
block.getTransactions().stream()

@ -336,7 +336,7 @@ public class FlatTraceGenerator {
if ("STOP".equals(traceFrame.getOpcode()) && resultBuilder.isGasUsedEmpty()) {
final long callStipend =
protocolSchedule
.getByBlockNumber(block.getHeader().getNumber())
.getByBlockHeader(block.getHeader())
.getGasCalculator()
.getAdditionalCallStipend();
tracesContexts.stream()

@ -46,7 +46,7 @@ public class RewardTraceGenerator {
final BlockHeader blockHeader = block.getHeader();
final List<BlockHeader> ommers = block.getBody().getOmmers();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);
final Wei blockReward = protocolSpec.getBlockReward();
final MiningBeneficiaryCalculator miningBeneficiaryCalculator =
protocolSpec.getMiningBeneficiaryCalculator();

@ -89,7 +89,7 @@ public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMetho
public GasCalculator getGasCalculator() {
return protocolSchedule
.getByBlockNumber(blockchainQueries.headBlockNumber())
.getByBlockHeader(blockchainQueries.headBlockHeader())
.getGasCalculator();
}

@ -141,6 +141,15 @@ public class BlockchainQueries {
return blockchain.getChainHeadBlockNumber();
}
/**
* Return the header of the head of the chain.
*
* @return The header of the head of the chain.
*/
public BlockHeader headBlockHeader() {
return blockchain.getChainHeadHeader();
}
/**
* Return the header of the last finalized block.
*

@ -214,8 +214,7 @@ public abstract class AbstractEthGraphQLHttpServiceTest {
void importBlock(final int n) {
final Block block = BLOCKS.get(n);
final ProtocolSpec protocolSpec =
PROTOCOL_SCHEDULE.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = PROTOCOL_SCHEDULE.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
}

@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -95,9 +95,8 @@ public class DebugGetBadBlockTest {
badBlockManager.addBadBlock(badBlockWithTransaction, Optional.empty());
badBlockManager.addBadBlock(badBlockWoTransaction, Optional.empty());
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
final JsonRpcRequestContext request =
@ -125,7 +124,8 @@ public class DebugGetBadBlockTest {
@Test
public void shouldReturnCorrectResponseWhenNoInvalidBlockFound() {
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
final JsonRpcRequestContext request =

@ -88,7 +88,7 @@ public class DebugStandardTraceBadBlockToFileTest {
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
when(blockchain.getChainHeadHeader()).thenReturn(new BlockHeaderTestFixture().buildHeader());
when(protocolSchedule.getByBlockNumber(blockHeader.getNumber())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(blockHeader)).thenReturn(protocolSpec);
when(transactionTracer.traceTransactionToFile(eq(block.getHash()), any(), any()))
.thenReturn(paths);
final JsonRpcSuccessResponse response =

@ -78,7 +78,7 @@ public class EthGetMinerDataByBlockHashTest {
header, Collections.emptyList(), Collections.emptyList(), Difficulty.of(100L), 5);
when(blockchainQueries.blockByHash(any())).thenReturn(Optional.of(blockWithMetadata));
when(protocolSchedule.getByBlockNumber(header.getNumber())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(header)).thenReturn(protocolSpec);
when(protocolSpec.getBlockReward()).thenReturn(Wei.fromEth(2));
when(blockchainQueries.getBlockchain()).thenReturn(blockChain);

@ -76,7 +76,7 @@ public class EthGetMinerDataByBlockNumberTest {
header, Collections.emptyList(), Collections.emptyList(), Difficulty.of(100L), 5);
when(blockchainQueries.blockByNumber(anyLong())).thenReturn(Optional.of(blockWithMetadata));
when(protocolSchedule.getByBlockNumber(header.getNumber())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(header)).thenReturn(protocolSpec);
when(protocolSpec.getBlockReward()).thenReturn(Wei.fromEth(2));
when(blockchainQueries.getBlockchain()).thenReturn(blockChain);

@ -72,7 +72,7 @@ public class RewardTraceGeneratorTest {
final BlockHeader blockHeader =
gen.header(0x0A, blockBody, new BlockDataGenerator.BlockOptions());
block = new Block(blockHeader, blockBody);
when(protocolSchedule.getByBlockNumber(block.getHeader().getNumber())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(block.getHeader())).thenReturn(protocolSpec);
when(protocolSpec.getBlockReward()).thenReturn(blockReward);
when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(miningBeneficiaryCalculator);
when(miningBeneficiaryCalculator.calculateBeneficiary(block.getHeader()))

@ -196,6 +196,17 @@ public class BlockchainQueriesTest {
assertThat(result).isEqualTo(3L);
}
@Test
public void getHeadBlockHeader() {
final BlockchainWithData data = setupBlockchain(3);
final BlockchainQueries queries = data.blockchainQueries;
final BlockHeader targetBlockHeader = data.blockData.get(2).block.getHeader();
BlockHeader result = queries.headBlockHeader();
assertThat(targetBlockHeader).isEqualTo(result);
}
@Test
public void getAccountStorageBlockNumber() {
final List<Address> addresses = Arrays.asList(gen.address(), gen.address(), gen.address());

@ -141,7 +141,7 @@ public class BlockMiner<M extends AbstractBlockCreator> implements Runnable {
block.getBody().getTransactions().size());
final BlockImporter importer =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber()).getBlockImporter();
protocolSchedule.getByBlockHeader(block.getHeader()).getBlockImporter();
final BlockImportResult blockImportResult =
importer.importBlock(protocolContext, block, HeaderValidationMode.FULL);
if (blockImportResult.isImported()) {

@ -125,7 +125,7 @@ public class PrivateTransactionSimulator {
final PrivateTransaction transaction =
getPrivateTransaction(callParams, header, privacyGroupId, disposablePrivateState);
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(header.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(header);
final PrivateTransactionProcessor privateTransactionProcessor =
protocolSpec.getPrivateTransactionProcessor();

@ -93,7 +93,7 @@ public class PrivateStorageMigration {
final int lastPmtIndex = findLastPMTIndexInBlock(block);
if (lastPmtIndex >= 0) {
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockNumber);
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(blockHeader);
final PrivateMigrationBlockProcessor privateMigrationBlockProcessor =
privateMigrationBlockProcessorBuilder.apply(protocolSpec);

@ -243,8 +243,7 @@ public class BlockchainSetupUtil {
if (block.getHeader().getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) {
continue;
}
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final BlockImportResult result =
blockImporter.importBlock(protocolContext, block, HeaderValidationMode.FULL);

@ -607,8 +607,7 @@ public class BlockPropagationManager implements UnverifiedForkchoiceListener {
new IllegalArgumentException(
"Incapable of retrieving header from non-existent parent of "
+ block.toLogString()));
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockHeaderValidator blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
return ethContext

@ -261,12 +261,12 @@ public class BackwardSyncContext {
return protocolContext;
}
public BlockValidator getBlockValidator(final long blockNumber) {
return protocolSchedule.getByBlockNumber(blockNumber).getBlockValidator();
public BlockValidator getBlockValidator(final BlockHeader blockHeader) {
return protocolSchedule.getByBlockHeader(blockHeader).getBlockValidator();
}
public BlockValidator getBlockValidatorForBlock(final Block block) {
return getBlockValidator(block.getHeader().getNumber());
return getBlockValidator(block.getHeader());
}
public boolean isReady() {

@ -115,7 +115,7 @@ public class FastImportBlocksStep implements Consumer<List<BlockWithReceipts>> {
protected boolean importBlock(final BlockWithReceipts blockWithReceipts) {
final BlockImporter importer =
protocolSchedule.getByBlockNumber(blockWithReceipts.getNumber()).getBlockImporter();
protocolSchedule.getByBlockHeader(blockWithReceipts.getHeader()).getBlockImporter();
final BlockImportResult blockImportResult =
importer.fastImportBlock(
protocolContext,

@ -58,7 +58,7 @@ public class FullImportBlockStep implements Consumer<Block> {
final long blockNumber = block.getHeader().getNumber();
final String blockHash = block.getHash().toHexString();
final BlockImporter importer =
protocolSchedule.getByBlockNumber(blockNumber).getBlockImporter();
protocolSchedule.getByBlockHeader(block.getHeader()).getBlockImporter();
final BlockImportResult blockImportResult =
importer.importBlock(protocolContext, block, HeaderValidationMode.SKIP_DETACHED);
if (!blockImportResult.isImported()) {

@ -75,8 +75,7 @@ public class RangeHeadersValidationStep implements Function<RangeHeaders, Stream
}
private boolean isValid(final BlockHeader expectedParent, final BlockHeader firstHeaderToImport) {
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(firstHeaderToImport.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(firstHeaderToImport);
final BlockHeaderValidator validator = protocolSpec.getBlockHeaderValidator();
return validator.validateHeader(
firstHeaderToImport,

@ -199,7 +199,7 @@ public class DownloadHeaderSequenceTask extends AbstractRetryingPeerTask<List<Bl
child =
(headerIndex == segmentLength - 1) ? referenceHeader : headers[headerIndex + 1];
}
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(child.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(child);
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
if (!validateHeader(child, header)) {
@ -258,7 +258,7 @@ public class DownloadHeaderSequenceTask extends AbstractRetryingPeerTask<List<Bl
return false;
}
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(child.getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(child);
final BlockHeaderValidator blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
return blockHeaderValidator.validateHeader(
child, header, protocolContext, validationPolicy.getValidationModeForNextBlock());

@ -194,8 +194,7 @@ public class PersistBlockTask extends AbstractEthTask<Block> {
@Override
protected void executeTask() {
try {
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
LOG.atDebug()
.setMessage("Running import task for block {}")

@ -264,7 +264,7 @@ public class TransactionPool implements BlockAddedObserver {
private MainnetTransactionValidator getTransactionValidator() {
return protocolSchedule
.getByBlockNumber(protocolContext.getBlockchain().getChainHeadBlockNumber())
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getTransactionValidator();
}
@ -293,7 +293,7 @@ public class TransactionPool implements BlockAddedObserver {
}
final FeeMarket feeMarket =
protocolSchedule.getByBlockNumber(chainHeadBlockHeader.getNumber()).getFeeMarket();
protocolSchedule.getByBlockHeader(chainHeadBlockHeader).getFeeMarket();
final TransactionInvalidReason priceInvalidReason =
validatePrice(transaction, isLocal, feeMarket);
@ -404,8 +404,8 @@ public class TransactionPool implements BlockAddedObserver {
&& transactionReplaySupportedAtBlock(chainHeadBlockHeader);
}
private boolean transactionReplaySupportedAtBlock(final BlockHeader block) {
return protocolSchedule.getByBlockNumber(block.getNumber()).isReplayProtectionSupported();
private boolean transactionReplaySupportedAtBlock(final BlockHeader blockHeader) {
return protocolSchedule.getByBlockHeader(blockHeader).isReplayProtectionSupported();
}
public Optional<Transaction> getTransactionByHash(final Hash hash) {

@ -18,7 +18,7 @@ import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.DETACHED_ONLY;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@ -52,6 +52,7 @@ public class RangeHeadersValidationStepTest {
@Mock private BlockHeaderValidator headerValidator;
@Mock private ValidationPolicy validationPolicy;
@Mock private EthPeer syncTarget;
private final BlockDataGenerator gen = new BlockDataGenerator();
private RangeHeadersValidationStep validationStep;
@ -65,7 +66,7 @@ public class RangeHeadersValidationStepTest {
@Before
public void setUp() {
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(any(BlockHeader.class))).thenReturn(protocolSpec);
when(protocolSpec.getBlockHeaderValidator()).thenReturn(headerValidator);
when(validationPolicy.getValidationModeForNextBlock()).thenReturn(DETACHED_ONLY);
@ -79,7 +80,7 @@ public class RangeHeadersValidationStepTest {
.thenReturn(true);
final Stream<BlockHeader> result = validationStep.apply(rangeHeaders);
verify(protocolSchedule).getByBlockNumber(firstHeader.getNumber());
verify(protocolSchedule).getByBlockHeader(firstHeader);
verify(validationPolicy).getValidationModeForNextBlock();
verify(headerValidator).validateHeader(firstHeader, rangeStart, protocolContext, DETACHED_ONLY);
verifyNoMoreInteractions(headerValidator, validationPolicy);

@ -19,7 +19,7 @@ import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.FULL;
import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.LIGHT;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -60,7 +60,7 @@ public class FastImportBlocksStepTest {
@BeforeEach
public void setUp() {
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
when(validationPolicy.getValidationModeForNextBlock()).thenReturn(FULL);
when(ommerValidationPolicy.getValidationModeForNextBlock()).thenReturn(LIGHT);
@ -95,7 +95,7 @@ public class FastImportBlocksStepTest {
importBlocksStep.accept(blocksWithReceipts);
for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) {
verify(protocolSchedule).getByBlockNumber(blockWithReceipts.getNumber());
verify(protocolSchedule).getByBlockHeader(blockWithReceipts.getHeader());
}
verify(validationPolicy, times(blocks.size())).getValidationModeForNextBlock();
}

@ -16,13 +16,14 @@ package org.hyperledger.besu.ethereum.eth.sync.fullsync;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.SKIP_DETACHED;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.eth.sync.tasks.exceptions.InvalidBlockException;
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult;
@ -48,7 +49,7 @@ public class FullImportBlockStepTest {
@Before
public void setUp() {
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
when(protocolSchedule.getByBlockHeader(any(BlockHeader.class))).thenReturn(protocolSpec);
when(protocolSpec.getBlockImporter()).thenReturn(blockImporter);
importBlocksStep =
@ -64,7 +65,7 @@ public class FullImportBlockStepTest {
.thenReturn(new BlockImportResult(true));
importBlocksStep.accept(block);
verify(protocolSchedule).getByBlockNumber(block.getHeader().getNumber());
verify(protocolSchedule).getByBlockHeader(block.getHeader());
verify(blockImporter).importBlock(protocolContext, block, SKIP_DETACHED);
}

@ -272,8 +272,8 @@ public class RetestethContext {
return blockchain.getChainHeadBlockNumber();
}
public ProtocolSpec getProtocolSpec(final long blockNumber) {
return getProtocolSchedule().getByBlockNumber(blockNumber);
public ProtocolSpec getProtocolSpec(final BlockHeader blockHeader) {
return getProtocolSchedule().getByBlockHeader(blockHeader);
}
public BlockHeader getBlockHeader(final long blockNumber) {

@ -79,7 +79,7 @@ public class TestImportRawBlock implements JsonRpcMethod {
} else {
// otherwise attempt to import the block
final BlockImporter blockImporter =
context.getProtocolSpec(block.getHeader().getNumber()).getBlockImporter();
context.getProtocolSpec(block.getHeader()).getBlockImporter();
final BlockImportResult result =
blockImporter.importBlock(
protocolContext,

@ -81,7 +81,7 @@ public class TestMineBlocks implements JsonRpcMethod {
retesethClock.advanceSeconds(1);
final BlockImporter blockImporter =
protocolSchedule.getByBlockNumber(blockchain.getChainHeadBlockNumber()).getBlockImporter();
protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()).getBlockImporter();
final BlockImportResult result =
blockImporter.importBlock(
protocolContext, block, headerValidationMode, headerValidationMode);

Loading…
Cancel
Save