[Issue 6301] Refactor BadBlockManager (#6559)

Signed-off-by: mbaxter <mbaxter.dev@gmail.com>
pull/6088/merge
mbaxter 9 months ago committed by GitHub
parent 1d2d0375cd
commit 5adad6a1be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  2. 3
      besu/src/main/java/org/hyperledger/besu/controller/CliqueBesuControllerBuilder.java
  3. 3
      besu/src/main/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilder.java
  4. 3
      besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java
  5. 6
      besu/src/main/java/org/hyperledger/besu/controller/MainnetBesuControllerBuilder.java
  6. 2
      besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java
  7. 3
      besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java
  8. 7
      besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java
  9. 19
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java
  10. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueDifficultyCalculatorTest.java
  11. 22
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  12. 29
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/NodeCanProduceNextBlockTest.java
  13. 7
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  14. 5
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockMinerTest.java
  15. 10
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java
  16. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueDifficultyValidationRuleTest.java
  17. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/headervalidationrules/CliqueExtraDataValidationRuleTest.java
  18. 14
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/MigratingProtocolContext.java
  19. 8
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilder.java
  20. 4
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java
  21. 7
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/MigratingProtocolContextTest.java
  22. 4
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java
  23. 15
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCoinbaseValidationRuleTest.java
  24. 16
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftCommitSealsValidationRuleTest.java
  25. 16
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftValidatorsValidationRuleTest.java
  26. 7
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/headervalidationrules/BftVanityDataValidationRuleTest.java
  27. 10
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/TestContextBuilder.java
  28. 4
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/round/IbftRoundIntegrationTest.java
  29. 15
      consensus/ibft/src/main/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleBuilder.java
  30. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java
  31. 7
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java
  32. 7
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/blockcreation/BftBlockCreatorTest.java
  33. 10
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  34. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java
  35. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java
  36. 15
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeProtocolSchedule.java
  37. 8
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java
  38. 42
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java
  39. 16
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java
  40. 17
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java
  41. 4
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeGenesisConfigHelper.java
  42. 4
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeReorgTest.java
  43. 10
      consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/support/TestContextBuilder.java
  44. 4
      consensus/qbft/src/integration-test/java/org/hyperledger/besu/consensus/qbft/test/round/QbftRoundIntegrationTest.java
  45. 22
      consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleBuilder.java
  46. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftBlockHeaderValidationRulesetFactoryTest.java
  47. 7
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java
  48. 13
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java
  49. 7
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftBlockHeightManagerTest.java
  50. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/statemachine/QbftRoundTest.java
  51. 10
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java
  52. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java
  53. 4
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/RoundChangeMessageValidatorTest.java
  54. 3
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/BlockchainImporter.java
  55. 5
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java
  56. 4
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthGetBlockByNumberLatestDesyncIntegrationTest.java
  57. 19
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetBadBlocks.java
  58. 19
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugResyncWorldstate.java
  59. 15
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFile.java
  60. 16
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/BlockReplay.java
  61. 8
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java
  62. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java
  63. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/TraceJsonRpcMethods.java
  64. 7
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/AbstractEthGraphQLHttpServiceTest.java
  65. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java
  66. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java
  67. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java
  68. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java
  69. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java
  70. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java
  71. 24
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetBadBlockTest.java
  72. 18
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStandardTraceBadBlockToFileTest.java
  73. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java
  74. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracerTest.java
  75. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java
  76. 4
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java
  77. 5
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java
  78. 10
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/BlockMinerTest.java
  79. 4
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java
  80. 4
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java
  81. 13
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java
  82. 21
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/ProtocolContext.java
  83. 23
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java
  84. 35
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java
  85. 18
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java
  86. 15
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java
  87. 1
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java
  88. 6
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockchainSetupUtil.java
  89. 8
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java
  90. 7
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ProtocolScheduleFixture.java
  91. 5
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java
  92. 4
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolScheduleTest.java
  93. 15
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java
  94. 7
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java
  95. 7
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/trie/bonsai/AbstractIsolationTests.java
  96. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/BlockPropagationManager.java
  97. 3
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java
  98. 6
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockBodiesMessageTest.java
  99. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/BlockHeadersMessageTest.java
  100. 6
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods;
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.BlockchainStorage;
import org.hyperledger.besu.ethereum.chain.ChainDataPruner;
@ -177,6 +178,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
protected EvmConfiguration evmConfiguration;
/** The Max peers. */
protected int maxPeers;
/** Manages a cache of bad blocks globally */
protected final BadBlockManager badBlockManager = new BadBlockManager();
private int maxRemotelyInitiatedPeers;
/** The Chain pruner configuration. */
@ -1068,7 +1071,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
transactionSelectorFactory,
badBlockManager);
}
private Optional<SnapProtocolManager> createSnapProtocolManager(

@ -116,7 +116,8 @@ public class CliqueBesuControllerBuilder extends BesuControllerBuilder {
nodeKey,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
@Override

@ -182,7 +182,8 @@ public class ConsensusScheduleBesuControllerBuilder extends BesuControllerBuilde
worldStateArchive,
protocolSchedule,
consensusContextFactory,
transactionSelectorFactory);
transactionSelectorFactory,
badBlockManager);
}
@Override

@ -278,7 +278,8 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder {
privacyParameters,
isRevertReasonEnabled,
bftExtraDataCodec().get(),
evmConfiguration);
evmConfiguration,
badBlockManager);
}
@Override

@ -91,7 +91,11 @@ public class MainnetBesuControllerBuilder extends BesuControllerBuilder {
@Override
protected ProtocolSchedule createProtocolSchedule() {
return MainnetProtocolSchedule.fromConfig(
configOptionsSupplier.get(), privacyParameters, isRevertReasonEnabled, evmConfiguration);
configOptionsSupplier.get(),
privacyParameters,
isRevertReasonEnabled,
evmConfiguration,
badBlockManager);
}
@Override

@ -173,7 +173,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder {
@Override
protected ProtocolSchedule createProtocolSchedule() {
return MergeProtocolSchedule.create(
configOptionsSupplier.get(), privacyParameters, isRevertReasonEnabled);
configOptionsSupplier.get(), privacyParameters, isRevertReasonEnabled, badBlockManager);
}
@Override

@ -318,7 +318,8 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
privacyParameters,
isRevertReasonEnabled,
bftExtraDataCodec().get(),
evmConfiguration);
evmConfiguration,
badBlockManager);
}
@Override

@ -28,6 +28,7 @@ import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule;
import org.hyperledger.besu.consensus.merge.PostMergeContext;
import org.hyperledger.besu.consensus.merge.TransitionProtocolSchedule;
import org.hyperledger.besu.consensus.merge.TransitionUtils;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -186,10 +187,12 @@ public class ForkIdsNetworkConfigTest {
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
MilestoneStreamingProtocolSchedule preMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig(configOptions));
(DefaultProtocolSchedule)
MainnetProtocolSchedule.fromConfig(configOptions, new BadBlockManager()));
MilestoneStreamingProtocolSchedule postMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule) MergeProtocolSchedule.create(configOptions, false));
(DefaultProtocolSchedule)
MergeProtocolSchedule.create(configOptions, false, new BadBlockManager()));
final MilestoneStreamingTransitionProtocolSchedule schedule =
new MilestoneStreamingTransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule);

@ -20,6 +20,7 @@ import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
@ -50,6 +51,7 @@ public class CliqueProtocolSchedule {
* @param privacyParameters the privacy parameters
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static ProtocolSchedule create(
@ -57,7 +59,8 @@ public class CliqueProtocolSchedule {
final NodeKey nodeKey,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions();
@ -83,7 +86,8 @@ public class CliqueProtocolSchedule {
builder)),
privacyParameters,
isRevertReasonEnabled,
evmConfiguration)
evmConfiguration,
badBlockManager)
.createProtocolSchedule();
}
@ -94,15 +98,22 @@ public class CliqueProtocolSchedule {
* @param nodeKey the node key
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final NodeKey nodeKey,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return create(
config, nodeKey, PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration);
config,
nodeKey,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
evmConfiguration,
badBlockManager);
}
private static ProtocolSpecBuilder applyCliqueSpecificModifications(

@ -24,6 +24,7 @@ import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
@ -58,7 +59,8 @@ public class CliqueDifficultyCalculatorTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -26,6 +26,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
@ -55,7 +56,8 @@ public class CliqueProtocolScheduleTest {
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
CliqueProtocolSchedule.create(
config, NODE_KEY, false, EvmConfiguration.DEFAULT, new BadBlockManager());
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1));
final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockHeader(blockHeader(2));
@ -74,7 +76,8 @@ public class CliqueProtocolScheduleTest {
GenesisConfigFile.DEFAULT.getConfigOptions(),
NODE_KEY,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.getByBlockHeader(blockHeader(0));
assertThat(homestead.getName()).isEqualTo("Frontier");
@ -92,7 +95,11 @@ public class CliqueProtocolScheduleTest {
assertThatThrownBy(
() ->
CliqueProtocolSchedule.create(
genesisConfig, NODE_KEY, false, EvmConfiguration.DEFAULT))
genesisConfig,
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
new BadBlockManager()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Epoch length in config must be greater than zero");
}
@ -106,7 +113,11 @@ public class CliqueProtocolScheduleTest {
assertThatThrownBy(
() ->
CliqueProtocolSchedule.create(
genesisConfig, NODE_KEY, false, EvmConfiguration.DEFAULT))
genesisConfig,
NODE_KEY,
false,
EvmConfiguration.DEFAULT,
new BadBlockManager()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Epoch length in config must be greater than zero");
}
@ -121,7 +132,8 @@ public class CliqueProtocolScheduleTest {
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
CliqueProtocolSchedule.create(
config, NODE_KEY, false, EvmConfiguration.DEFAULT, new BadBlockManager());
BlockHeader emptyFrontierParent =
headerBuilder

@ -28,6 +28,7 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.Block;
@ -80,7 +81,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -104,7 +107,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.number(1).parentHash(genesisBlock.getHash());
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -137,7 +142,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -166,7 +173,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(proposerKeyPair);
@ -210,7 +219,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.parentHash(genesisBlock.getHash()).number(1);
final Block block_1 = createEmptyBlock(otherNodeKeyPair);
@ -238,7 +249,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader =
@ -261,7 +274,9 @@ public class NodeCanProduceNextBlockTest {
final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(
blockChain, null, cliqueContext, Optional.empty(), new BadBlockManager());
headerBuilder.parentHash(Hash.ZERO).number(3);
final BlockHeader parentHeader = headerBuilder.buildHeader();

@ -41,6 +41,7 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
@ -102,7 +103,8 @@ public class CliqueBlockCreatorTest {
GenesisConfigFile.DEFAULT.getConfigOptions(),
proposerNodeKey,
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
validatorList.add(otherAddress);
@ -117,7 +119,8 @@ public class CliqueBlockCreatorTest {
GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock();
blockchain = createInMemoryBlockchain(genesis);
protocolContext =
new ProtocolContext(blockchain, stateArchive, cliqueContext, Optional.empty());
new ProtocolContext(
blockchain, stateArchive, cliqueContext, Optional.empty(), new BadBlockManager());
epochManager = new EpochManager(10);
// Add a block above the genesis

@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator;
import org.hyperledger.besu.ethereum.blockcreation.DefaultBlockScheduler;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -70,7 +71,7 @@ class CliqueBlockMinerTest {
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null);
final ProtocolContext protocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty());
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =
@ -125,7 +126,7 @@ class CliqueBlockMinerTest {
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, null);
final ProtocolContext protocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty());
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
final CliqueBlockCreator blockCreator = mock(CliqueBlockCreator.class);
final Function<BlockHeader, CliqueBlockCreator> blockCreatorSupplier =

@ -34,6 +34,7 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
@ -94,10 +95,15 @@ public class CliqueMinerExecutorTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
cliqueProtocolSchedule =
CliqueProtocolSchedule.create(
GENESIS_CONFIG_OPTIONS, proposerNodeKey, false, EvmConfiguration.DEFAULT);
GENESIS_CONFIG_OPTIONS,
proposerNodeKey,
false,
EvmConfiguration.DEFAULT,
new BadBlockManager());
cliqueEthContext = mock(EthContext.class, RETURNS_DEEP_STUBS);
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -27,6 +27,7 @@ import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
@ -58,7 +59,8 @@ public class CliqueDifficultyValidationRuleTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
blockHeaderBuilder = new BlockHeaderTestFixture();
}

@ -29,6 +29,7 @@ import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
@ -62,7 +63,8 @@ public class CliqueExtraDataValidationRuleTest {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, Optional.empty());
cliqueProtocolContext =
new ProtocolContext(null, null, cliqueContext, Optional.empty(), new BadBlockManager());
}
@Test

@ -17,6 +17,7 @@ package org.hyperledger.besu.consensus.common;
import org.hyperledger.besu.ethereum.ConsensusContext;
import org.hyperledger.besu.ethereum.ConsensusContextFactory;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
@ -36,13 +37,15 @@ public class MigratingProtocolContext extends ProtocolContext {
* @param worldStateArchive the world state archive
* @param consensusContextSchedule the consensus context schedule
* @param transactionSelectorFactory the optional transaction selector factory
* @param badBlockManager the cache to use to keep invalid blocks
*/
public MigratingProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ForksSchedule<ConsensusContext> consensusContextSchedule,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
super(blockchain, worldStateArchive, null, transactionSelectorFactory);
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
super(blockchain, worldStateArchive, null, transactionSelectorFactory, badBlockManager);
this.consensusContextSchedule = consensusContextSchedule;
}
@ -54,6 +57,7 @@ public class MigratingProtocolContext extends ProtocolContext {
* @param protocolSchedule the protocol schedule
* @param consensusContextFactory the consensus context factory
* @param transactionSelectorFactory the optional transaction selector factory
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol context
*/
public static ProtocolContext init(
@ -61,7 +65,8 @@ public class MigratingProtocolContext extends ProtocolContext {
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
final ConsensusContext consensusContext =
consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule);
final MigratingContext migratingContext = consensusContext.as(MigratingContext.class);
@ -69,7 +74,8 @@ public class MigratingProtocolContext extends ProtocolContext {
blockchain,
worldStateArchive,
migratingContext.getConsensusContextSchedule(),
transactionSelectorFactory);
transactionSelectorFactory,
badBlockManager);
}
@Override

@ -18,6 +18,7 @@ import org.hyperledger.besu.config.BftConfigOptions;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
@ -51,6 +52,7 @@ public abstract class BaseBftProtocolScheduleBuilder {
* @param isRevertReasonEnabled the is revert reason enabled
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public BftProtocolSchedule createProtocolSchedule(
@ -59,7 +61,8 @@ public abstract class BaseBftProtocolScheduleBuilder {
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
final Map<Long, Function<ProtocolSpecBuilder, ProtocolSpecBuilder>> specMap = new HashMap<>();
forksSchedule
@ -79,7 +82,8 @@ public abstract class BaseBftProtocolScheduleBuilder {
specAdapters,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration)
evmConfiguration,
badBlockManager)
.createProtocolSchedule();
return new BftProtocolSchedule((DefaultProtocolSchedule) protocolSchedule);
}

@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
@ -173,7 +174,8 @@ public class CombinedProtocolScheduleFactoryTest {
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
return new BftProtocolSchedule(
(DefaultProtocolSchedule) protocolScheduleBuilder.createProtocolSchedule());

@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ConsensusContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
@ -45,7 +46,11 @@ public class MigratingProtocolContextTest {
new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2)));
final MigratingProtocolContext migratingProtocolContext =
new MigratingProtocolContext(
blockchain, worldStateArchive, contextSchedule, Optional.empty());
blockchain,
worldStateArchive,
contextSchedule,
Optional.empty(),
new BadBlockManager());
assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class))
.isSameAs(context1);

@ -27,6 +27,7 @@ import org.hyperledger.besu.consensus.common.ForkSpec;
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
@ -241,7 +242,8 @@ public class BaseBftProtocolScheduleBuilderTest {
PrivacyParameters.DEFAULT,
false,
bftExtraDataCodec,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
}
private BftConfigOptions createBftConfig(final BigInteger blockReward) {

@ -22,6 +22,7 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Util;
@ -51,7 +52,12 @@ public class BftCoinbaseValidationRuleTest {
final List<Address> validators = Lists.newArrayList(proposerAddress);
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators), Optional.empty());
new ProtocolContext(
null,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule();
@ -71,7 +77,12 @@ public class BftCoinbaseValidationRuleTest {
final List<Address> validators = Lists.newArrayList(otherValidatorNodeAddress);
final ProtocolContext context =
new ProtocolContext(null, null, setupContextWithValidators(validators), Optional.empty());
new ProtocolContext(
null,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
final BftCoinbaseValidationRule coinbaseValidationRule = new BftCoinbaseValidationRule();

@ -28,6 +28,7 @@ import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Util;
@ -58,7 +59,8 @@ public class BftCommitSealsValidationRuleTest {
.collect(Collectors.toList());
final BftContext bftContext = setupContextWithValidators(committerAddresses);
final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty());
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(committerAddresses);
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isTrue();
@ -72,7 +74,8 @@ public class BftCommitSealsValidationRuleTest {
final List<Address> validators = singletonList(committerAddress);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty());
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any())).thenReturn(emptyList());
assertThat(commitSealsValidationRule.validate(blockHeader, null, context)).isFalse();
@ -89,7 +92,8 @@ public class BftCommitSealsValidationRuleTest {
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty());
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(singletonList(Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey())));
@ -136,7 +140,8 @@ public class BftCommitSealsValidationRuleTest {
final List<Address> validators = singletonList(committerAddress);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty());
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(List.of(committerAddress, committerAddress));
@ -155,7 +160,8 @@ public class BftCommitSealsValidationRuleTest {
Collections.sort(validators);
final BftContext bftContext = setupContextWithValidators(validators);
final ProtocolContext context = new ProtocolContext(null, null, bftContext, Optional.empty());
final ProtocolContext context =
new ProtocolContext(null, null, bftContext, Optional.empty(), new BadBlockManager());
when(bftContext.getBlockInterface().getCommitters(any()))
.thenReturn(validators.subList(0, committerCount));

@ -22,6 +22,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -46,7 +47,11 @@ public class BftValidatorsValidationRuleTest {
final ProtocolContext context =
new ProtocolContext(
null, null, setupContextWithBftExtraData(validators, bftExtraData), Optional.empty());
null,
null,
setupContextWithBftExtraData(validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isTrue();
@ -61,7 +66,11 @@ public class BftValidatorsValidationRuleTest {
final ProtocolContext context =
new ProtocolContext(
null, null, setupContextWithBftExtraData(validators, bftExtraData), Optional.empty());
null,
null,
setupContextWithBftExtraData(validators, bftExtraData),
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Lists.reverse(validators));
assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isFalse();
@ -82,7 +91,8 @@ public class BftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(storedValidators, bftExtraData),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Lists.reverse(reportedValidators));
assertThat(validatorsValidationRule.validate(blockHeader, null, context)).isFalse();

@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import java.util.Optional;
@ -47,7 +48,11 @@ public class BftVanityDataValidationRuleTest {
final ProtocolContext context =
new ProtocolContext(
null, null, setupContextWithBftExtraData(emptyList(), extraData), Optional.empty());
null,
null,
setupContextWithBftExtraData(emptyList(), extraData),
Optional.empty(),
new BadBlockManager());
return validationRule.validate(blockHeader, null, context);
}
}

@ -69,6 +69,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
@ -327,7 +328,11 @@ public class TestContextBuilder {
final BftProtocolSchedule protocolSchedule =
IbftProtocolScheduleBuilder.create(
genesisConfigOptions, forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
genesisConfigOptions,
forksSchedule,
IBFT_EXTRA_DATA_ENCODER,
EvmConfiguration.DEFAULT,
new BadBlockManager());
/////////////////////////////////////////////////////////////////////////////////////
// From here down is BASICALLY taken from IbftBesuController
@ -344,7 +349,8 @@ public class TestContextBuilder {
blockChain,
worldStateArchive,
new BftContext(validatorProvider, epochManager, blockInterface),
Optional.empty());
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =
ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build();

@ -41,6 +41,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -126,7 +127,8 @@ public class IbftRoundIntegrationTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(emptyList(), bftExtraDataEncoder),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test

@ -20,6 +20,7 @@ import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
@ -40,6 +41,7 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
* @param isRevertReasonEnabled the is revert reason enabled
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static BftProtocolSchedule create(
@ -48,7 +50,8 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return new IbftProtocolScheduleBuilder()
.createProtocolSchedule(
config,
@ -56,7 +59,8 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
privacyParameters,
isRevertReasonEnabled,
bftExtraDataCodec,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
/**
@ -66,20 +70,23 @@ public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
* @param forksSchedule the forks schedule
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<BftConfigOptions> forksSchedule,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return create(
config,
forksSchedule,
PrivacyParameters.DEFAULT,
false,
bftExtraDataCodec,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
@Override

@ -29,6 +29,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Difficulty;
@ -51,7 +52,8 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
null,
null,
setupContextWithBftExtraDataEncoder(validators, new IbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test

@ -37,6 +37,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -100,7 +101,8 @@ public class IbftProtocolScheduleTest {
PrivacyParameters.DEFAULT,
false,
bftExtraDataCodec,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
}
private boolean validateHeader(
@ -121,6 +123,7 @@ public class IbftProtocolScheduleTest {
null,
null,
setupContextWithBftExtraDataEncoder(BftContext.class, validators, bftExtraDataCodec),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
}

@ -36,6 +36,7 @@ import org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.Block;
@ -118,13 +119,15 @@ public class BftBlockCreatorTest {
PrivacyParameters.DEFAULT,
false,
bftExtraDataEncoder,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
final ProtocolContext protContext =
new ProtocolContext(
blockchain,
createInMemoryWorldStateArchive(),
setupContextWithBftExtraDataEncoder(initialValidatorList, bftExtraDataEncoder),
Optional.empty());
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =
ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build();

@ -63,6 +63,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -168,7 +169,11 @@ public class IbftBlockHeightManagerTest {
protocolContext =
new ProtocolContext(
blockchain, null, setupContextWithValidators(validators), Optional.empty());
blockchain,
null,
setupContextWithValidators(validators),
Optional.empty(),
new BadBlockManager());
final ProtocolScheduleBuilder protocolScheduleBuilder =
new ProtocolScheduleBuilder(
@ -177,7 +182,8 @@ public class IbftBlockHeightManagerTest {
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
ProtocolSchedule protocolSchedule =
new BftProtocolSchedule(

@ -49,6 +49,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -112,7 +113,8 @@ public class IbftRoundTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(emptyList(), new IbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
lenient().when(messageValidator.validateProposal(any())).thenReturn(true);
lenient().when(messageValidator.validatePrepare(any())).thenReturn(true);

@ -41,6 +41,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.Block;
@ -104,7 +105,8 @@ public class MessageValidatorTest {
mock(MutableBlockchain.class),
mock(WorldStateArchive.class),
mockBftCtx,
Optional.empty());
Optional.empty(),
new BadBlockManager());
lenient()
.when(protocolSchedule.getByBlockNumberOrTimestamp(anyLong(), anyLong()))

@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.merge;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -42,11 +43,14 @@ public class MergeProtocolSchedule {
*
* @param config the config
* @param isRevertReasonEnabled the is revert reason enabled
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static ProtocolSchedule create(
final GenesisConfigOptions config, final boolean isRevertReasonEnabled) {
return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled);
final GenesisConfigOptions config,
final boolean isRevertReasonEnabled,
final BadBlockManager badBlockManager) {
return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, badBlockManager);
}
/**
@ -55,12 +59,14 @@ public class MergeProtocolSchedule {
* @param config the config
* @param privacyParameters the privacy parameters
* @param isRevertReasonEnabled the is revert reason enabled
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled) {
final boolean isRevertReasonEnabled,
final BadBlockManager badBlockManager) {
Map<Long, Function<ProtocolSpecBuilder, ProtocolSpecBuilder>> postMergeModifications =
new HashMap<>();
@ -77,7 +83,8 @@ public class MergeProtocolSchedule {
new ProtocolSpecAdapters(postMergeModifications),
privacyParameters,
isRevertReasonEnabled,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
badBlockManager)
.createProtocolSchedule();
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.merge;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
@ -61,14 +62,15 @@ public class TransitionProtocolSchedule implements ProtocolSchedule {
*
* @param genesisConfigOptions {@link GenesisConfigOptions} containing the config options for the
* milestone starting points
* @param badBlockManager the cache to use to keep invalid blocks
* @return an initialised TransitionProtocolSchedule using post-merge defaults
*/
public static TransitionProtocolSchedule fromConfig(
final GenesisConfigOptions genesisConfigOptions) {
final GenesisConfigOptions genesisConfigOptions, final BadBlockManager badBlockManager) {
ProtocolSchedule preMergeProtocolSchedule =
MainnetProtocolSchedule.fromConfig(genesisConfigOptions);
MainnetProtocolSchedule.fromConfig(genesisConfigOptions, badBlockManager);
ProtocolSchedule postMergeProtocolSchedule =
MergeProtocolSchedule.create(genesisConfigOptions, false);
MergeProtocolSchedule.create(genesisConfigOptions, false, badBlockManager);
return new TransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get());
}

@ -690,9 +690,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
@Override
public Optional<Hash> getLatestValidAncestor(final Hash blockHash) {
final var chain = protocolContext.getBlockchain();
final var chainHeadHeader = chain.getChainHeadHeader();
return findValidAncestor(
chain, blockHash, protocolSchedule.getByBlockHeader(chainHeadHeader).getBadBlocksManager());
return findValidAncestor(chain, blockHash);
}
@Override
@ -701,8 +699,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
final var self = chain.getBlockHeader(blockHeader.getHash());
if (self.isEmpty()) {
final var badBlocks = protocolSchedule.getByBlockHeader(blockHeader).getBadBlocksManager();
return findValidAncestor(chain, blockHeader.getParentHash(), badBlocks);
return findValidAncestor(chain, blockHeader.getParentHash());
}
return self.map(BlockHeader::getHash);
}
@ -722,8 +719,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
return miningParameters.isMiningEnabled();
}
private Optional<Hash> findValidAncestor(
final Blockchain chain, final Hash parentHash, final BadBlockManager badBlocks) {
private Optional<Hash> findValidAncestor(final Blockchain chain, final Hash parentHash) {
// check chain first
return chain
@ -740,12 +736,12 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
.map(Optional::of)
.orElseGet(
() ->
badBlocks
protocolContext
.getBadBlockManager()
.getBadBlock(parentHash)
.map(
badParent ->
findValidAncestor(
chain, badParent.getHeader().getParentHash(), badBlocks))
findValidAncestor(chain, badParent.getHeader().getParentHash()))
.orElse(Optional.empty()));
}
@ -786,7 +782,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
final List<Block> badBlockDescendants,
final List<BlockHeader> badBlockHeaderDescendants) {
LOG.trace("Adding bad block {} and all its descendants", badBlock.getHash());
final BadBlockManager badBlockManager = getBadBlockManager();
final BadBlockManager badBlockManager = protocolContext.getBadBlockManager();
final Optional<BlockHeader> parentHeader =
protocolContext.getBlockchain().getBlockHeader(badBlock.getHeader().getParentHash());
@ -841,33 +837,19 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
@Override
public void addBadBlock(final Block block, final Optional<Throwable> maybeCause) {
protocolSchedule
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager()
.addBadBlock(block, maybeCause);
protocolContext.getBadBlockManager().addBadBlock(block, maybeCause);
}
@Override
public boolean isBadBlock(final Hash blockHash) {
final BadBlockManager badBlocksManager = getBadBlockManager();
return badBlocksManager.getBadBlock(blockHash).isPresent()
|| badBlocksManager.getBadHash(blockHash).isPresent();
}
private BadBlockManager getBadBlockManager() {
final BadBlockManager badBlocksManager =
protocolSchedule
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager();
return badBlocksManager;
final BadBlockManager badBlockManager = protocolContext.getBadBlockManager();
return badBlockManager.getBadBlock(blockHash).isPresent()
|| badBlockManager.getBadHash(blockHash).isPresent();
}
@Override
public Optional<Hash> getLatestValidHashOfBadBlock(Hash blockHash) {
return protocolSchedule
.getByBlockHeader(protocolContext.getBlockchain().getChainHeadHeader())
.getBadBlocksManager()
.getLatestValidHash(blockHash);
return protocolContext.getBadBlockManager().getLatestValidHash(blockHash);
}
private boolean isPoSHeader(final BlockHeader header) {

@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor;
@ -44,7 +45,8 @@ public class MergeProtocolScheduleTest {
+ "}";
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSchedule protocolSchedule =
MergeProtocolSchedule.create(config, false, new BadBlockManager());
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1));
final ProtocolSpec londonSpec = protocolSchedule.getByBlockHeader(blockHeader(1559));
@ -58,7 +60,8 @@ public class MergeProtocolScheduleTest {
public void mergeSpecificModificationsAreUnappliedForShanghai() {
final GenesisConfigOptions config = GenesisConfigFile.mainnet().getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSchedule protocolSchedule =
MergeProtocolSchedule.create(config, false, new BadBlockManager());
final long lastParisBlockNumber = 17034869L;
final ProtocolSpec parisSpec =
@ -92,7 +95,8 @@ public class MergeProtocolScheduleTest {
+ "}";
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSchedule protocolSchedule =
MergeProtocolSchedule.create(config, false, new BadBlockManager());
final ProtocolSpec parisSpec =
protocolSchedule.getByBlockHeader(
@ -118,7 +122,8 @@ public class MergeProtocolScheduleTest {
@Test
public void mergeSpecificModificationsAreUnappliedForAllMainnetForksAfterParis() {
final GenesisConfigOptions config = GenesisConfigFile.mainnet().getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSchedule protocolSchedule =
MergeProtocolSchedule.create(config, false, new BadBlockManager());
final long lastParisBlockNumber = 17034869L;
final ProtocolSpec parisSpec =
@ -146,7 +151,8 @@ public class MergeProtocolScheduleTest {
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec london =
MergeProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), false)
MergeProtocolSchedule.create(
GenesisConfigFile.DEFAULT.getConfigOptions(), false, new BadBlockManager())
.getByBlockHeader(blockHeader(0));
assertThat(london.getName()).isEqualTo("Paris");

@ -71,7 +71,6 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolMetrics;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
@ -186,22 +185,10 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
when(mergeContext.as(MergeContext.class)).thenReturn(mergeContext);
when(mergeContext.getTerminalTotalDifficulty())
.thenReturn(genesisState.getBlock().getHeader().getDifficulty().plus(1L));
doAnswer(
getSpecInvocation -> {
ProtocolSpec spec = (ProtocolSpec) spy(getSpecInvocation.callRealMethod());
doAnswer(
getBadBlockInvocation -> {
return badBlockManager;
})
.when(spec)
.getBadBlocksManager();
return spec;
})
.when(protocolSchedule)
.getByBlockHeader(any(BlockHeader.class));
protocolContext =
new ProtocolContext(blockchain, worldStateArchive, mergeContext, Optional.empty());
new ProtocolContext(
blockchain, worldStateArchive, mergeContext, Optional.empty(), badBlockManager);
var mutable = worldStateArchive.getMutable();
genesisState.writeStateTo(mutable);
mutable.persist(null);

@ -20,6 +20,7 @@ import org.hyperledger.besu.config.GenesisAllocation;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import java.io.IOException;
@ -57,6 +58,7 @@ public interface MergeGenesisConfigHelper {
}
default ProtocolSchedule getMergeProtocolSchedule() {
return MergeProtocolSchedule.create(getPosGenesisConfigFile().getConfigOptions(), false);
return MergeProtocolSchedule.create(
getPosGenesisConfigFile().getConfigOptions(), false, new BadBlockManager());
}
}

@ -26,6 +26,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -75,7 +76,8 @@ public class MergeReorgTest implements MergeGenesisConfigHelper {
private final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());
private final EthScheduler ethScheduler = new DeterministicEthScheduler();
private final ProtocolContext protocolContext =
new ProtocolContext(blockchain, worldStateArchive, mergeContext, Optional.empty());
new ProtocolContext(
blockchain, worldStateArchive, mergeContext, Optional.empty(), new BadBlockManager());
private final Address coinbase = genesisAllocations(getPowGenesisConfigFile()).findFirst().get();
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();

@ -81,6 +81,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
@ -420,7 +421,11 @@ public class TestContextBuilder {
final BftProtocolSchedule protocolSchedule =
QbftProtocolScheduleBuilder.create(
genesisConfigOptions, forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
genesisConfigOptions,
forksSchedule,
BFT_EXTRA_DATA_ENCODER,
EvmConfiguration.DEFAULT,
new BadBlockManager());
final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks);
final TransactionSimulator transactionSimulator =
@ -441,7 +446,8 @@ public class TestContextBuilder {
blockChain,
worldStateArchive,
new QbftContext(validatorProvider, epochManager, blockInterface, Optional.empty()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
final TransactionPoolConfiguration poolConf =
ImmutableTransactionPoolConfiguration.builder().txPoolMaxSize(1).build();

@ -43,6 +43,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -130,7 +131,8 @@ public class QbftRoundIntegrationTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), qbftExtraDataEncoder),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test

@ -23,6 +23,7 @@ import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -44,6 +45,7 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
* @param isRevertReasonEnabled the is revert reason enabled
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static BftProtocolSchedule create(
@ -52,7 +54,8 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return new QbftProtocolScheduleBuilder()
.createProtocolSchedule(
config,
@ -60,7 +63,8 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
privacyParameters,
isRevertReasonEnabled,
bftExtraDataCodec,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
/**
@ -70,20 +74,23 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
* @param qbftForksSchedule the qbft forks schedule
* @param bftExtraDataCodec the bft extra data codec
* @param evmConfiguration the evm configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<QbftConfigOptions> qbftForksSchedule,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return create(
config,
qbftForksSchedule,
PrivacyParameters.DEFAULT,
false,
bftExtraDataCodec,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
/**
@ -93,20 +100,23 @@ public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder
* @param qbftForksSchedule the qbft forks schedule
* @param isRevertReasonEnabled the is revert reason enabled
* @param bftExtraDataCodec the bft extra data codec
* @param badBlockManager the cache to use to keep invalid blocks
* @return the protocol schedule
*/
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<QbftConfigOptions> qbftForksSchedule,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec) {
final BftExtraDataCodec bftExtraDataCodec,
final BadBlockManager badBlockManager) {
return create(
config,
qbftForksSchedule,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
bftExtraDataCodec,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
badBlockManager);
}
@Override

@ -25,6 +25,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.Util;
@ -46,7 +47,8 @@ public class QbftBlockHeaderValidationRulesetFactoryTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test

@ -32,6 +32,7 @@ import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -58,7 +59,8 @@ public class QbftProtocolScheduleTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test
@ -134,7 +136,8 @@ public class QbftProtocolScheduleTest {
PrivacyParameters.DEFAULT,
false,
bftExtraDataCodec,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
}
private boolean validateHeader(

@ -24,6 +24,7 @@ import org.hyperledger.besu.consensus.common.bft.Vote;
import org.hyperledger.besu.consensus.qbft.QbftContext;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -47,7 +48,8 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Collections.emptyList());
when(bftExtraData.getVote()).thenReturn(Optional.empty());
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isTrue();
@ -66,7 +68,8 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isTrue();
}
@ -84,7 +87,8 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, validators, bftExtraData),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(validators);
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isFalse();
}
@ -98,7 +102,8 @@ public class QbftValidatorsValidationRuleTest {
null,
null,
setupContextWithBftExtraData(QbftContext.class, Collections.emptyList(), bftExtraData),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(bftExtraData.getValidators()).thenReturn(Collections.emptyList());
when(bftExtraData.getVote()).thenReturn(Optional.of(mock(Vote.class)));
assertThat(qbftValidatorsValidationRule.validate(blockHeader, null, context)).isFalse();

@ -62,6 +62,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -168,7 +169,8 @@ public class QbftBlockHeightManagerTest {
null,
setupContextWithBftExtraDataEncoder(
QbftContext.class, validators, new QbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
final ProtocolScheduleBuilder protocolScheduleBuilder =
new ProtocolScheduleBuilder(
@ -177,7 +179,8 @@ public class QbftBlockHeightManagerTest {
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
ProtocolSchedule protocolSchedule =
new BftProtocolSchedule(

@ -52,6 +52,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -122,7 +123,8 @@ public class QbftRoundTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), new QbftExtraDataCodec()),
Optional.empty());
Optional.empty(),
new BadBlockManager());
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(any())).thenReturn(true);

@ -40,6 +40,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
@ -87,7 +88,8 @@ public class ProposalPayloadValidatorTest {
blockChain,
worldStateArchive,
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), bftExtraDataCodec),
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
@Test
@ -240,7 +242,8 @@ public class ProposalPayloadValidatorTest {
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
final Bytes cms = Bytes.fromHexStringLenient("0x1");
final ProtocolContext protocolContext =
new ProtocolContext(blockChain, worldStateArchive, qbftContext, Optional.empty());
new ProtocolContext(
blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager());
final ProposalPayloadValidator payloadValidator =
new ProposalPayloadValidator(
@ -275,7 +278,8 @@ public class ProposalPayloadValidatorTest {
setupContextWithBftExtraDataEncoder(QbftContext.class, emptyList(), pkiQbftExtraDataCodec);
final Bytes cms = Bytes.fromHexStringLenient("0x1");
final ProtocolContext protocolContext =
new ProtocolContext(blockChain, worldStateArchive, qbftContext, Optional.empty());
new ProtocolContext(
blockChain, worldStateArchive, qbftContext, Optional.empty(), new BadBlockManager());
final ProposalPayloadValidator payloadValidator =
new ProposalPayloadValidator(

@ -42,6 +42,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
@ -103,7 +104,8 @@ public class ProposalValidatorTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), bftExtraDataEncoder),
Optional.empty());
Optional.empty(),
new BadBlockManager());
// typically tests require the blockValidation to be successful
when(blockValidator.validateAndProcessBlock(

@ -41,6 +41,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
@ -85,7 +86,8 @@ public class RoundChangeMessageValidatorTest {
worldStateArchive,
setupContextWithBftExtraDataEncoder(
QbftContext.class, emptyList(), bftExtraDataEncoder),
Optional.empty());
Optional.empty(),
new BadBlockManager());
lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.api.jsonrpc;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
@ -42,7 +43,7 @@ public class BlockchainImporter {
public BlockchainImporter(final URL blocksUrl, final String genesisJson) throws Exception {
protocolSchedule =
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(genesisJson).getConfigOptions());
GenesisConfigFile.fromConfig(genesisJson).getConfigOptions(), new BadBlockManager());
final BlockHeaderFunctions blockHeaderFunctions =
ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
blocks = new ArrayList<>();

@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockImporter;
@ -78,7 +79,9 @@ public class JsonRpcTestMethodsFactory {
this.blockchain = createInMemoryBlockchain(importer.getGenesisBlock());
this.stateArchive = createInMemoryWorldStateArchive();
this.importer.getGenesisState().writeStateTo(stateArchive.getMutable());
this.context = new ProtocolContext(blockchain, stateArchive, null, Optional.empty());
this.context =
new ProtocolContext(
blockchain, stateArchive, null, Optional.empty(), new BadBlockManager());
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
this.synchronizer = mock(Synchronizer.class);

@ -30,6 +30,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResult;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockImporter;
@ -67,7 +68,8 @@ public class EthGetBlockByNumberLatestDesyncIntegrationTest {
InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock());
WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive();
importer.getGenesisState().writeStateTo(state.getMutable());
ProtocolContext context = new ProtocolContext(chain, state, null, Optional.empty());
ProtocolContext context =
new ProtocolContext(chain, state, null, Optional.empty(), new BadBlockManager());
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();

@ -14,30 +14,25 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BadBlockResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import java.util.List;
import java.util.stream.Collectors;
public class DebugGetBadBlocks implements JsonRpcMethod {
private final BlockchainQueries blockchain;
private final ProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
private final BlockResultFactory blockResultFactory;
public DebugGetBadBlocks(
final BlockchainQueries blockchain,
final ProtocolSchedule protocolSchedule,
final BlockResultFactory blockResultFactory) {
this.blockchain = blockchain;
this.protocolSchedule = protocolSchedule;
final ProtocolContext protocolContext, final BlockResultFactory blockResultFactory) {
this.protocolContext = protocolContext;
this.blockResultFactory = blockResultFactory;
}
@ -49,11 +44,7 @@ public class DebugGetBadBlocks implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final List<BadBlockResult> response =
protocolSchedule
.getByBlockHeader(blockchain.headBlockHeader())
.getBadBlocksManager()
.getBadBlocks()
.stream()
protocolContext.getBadBlockManager().getBadBlocks().stream()
.map(block -> BadBlockResult.from(blockResultFactory.transactionComplete(block), block))
.collect(Collectors.toList());
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response);

@ -14,26 +14,22 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
public class DebugResyncWorldstate implements JsonRpcMethod {
private final Synchronizer synchronizer;
private final ProtocolSchedule protocolSchedule;
private final Blockchain blockchain;
private final BadBlockManager badBlockManager;
public DebugResyncWorldstate(
final ProtocolSchedule protocolSchedule,
final Blockchain blockchain,
final Synchronizer synchronizer) {
final ProtocolContext protocolContext, final Synchronizer synchronizer) {
this.synchronizer = synchronizer;
this.protocolSchedule = protocolSchedule;
this.blockchain = blockchain;
this.badBlockManager = protocolContext.getBadBlockManager();
}
@Override
@ -43,10 +39,7 @@ public class DebugResyncWorldstate implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext request) {
protocolSchedule
.getByBlockHeader(blockchain.getChainHeadHeader())
.getBadBlocksManager()
.reset();
badBlockManager.reset();
return new JsonRpcSuccessResponse(
request.getRequest().getId(), synchronizer.resyncWorldState());
}

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams;
@ -25,9 +26,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSucces
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import java.nio.file.Path;
import java.util.Optional;
@ -36,15 +34,15 @@ import java.util.function.Supplier;
public class DebugStandardTraceBadBlockToFile extends DebugStandardTraceBlockToFile
implements JsonRpcMethod {
private final ProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
public DebugStandardTraceBadBlockToFile(
final Supplier<TransactionTracer> transactionTracerSupplier,
final BlockchainQueries blockchainQueries,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final Path dataDir) {
super(transactionTracerSupplier, blockchainQueries, dataDir);
this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext;
}
@Override
@ -58,10 +56,7 @@ public class DebugStandardTraceBadBlockToFile extends DebugStandardTraceBlockToF
final Optional<TransactionTraceParams> transactionTraceParams =
requestContext.getOptionalParameter(1, TransactionTraceParams.class);
final Blockchain blockchain = blockchainQueries.get().getBlockchain();
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader());
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
final BadBlockManager badBlockManager = protocolContext.getBadBlockManager();
return badBlockManager
.getBadBlock(blockHash)

@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalcu
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.Tracer.TraceableState;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -39,9 +40,14 @@ public class BlockReplay {
private final ProtocolSchedule protocolSchedule;
private final Blockchain blockchain;
private final ProtocolContext protocolContext;
public BlockReplay(final ProtocolSchedule protocolSchedule, final Blockchain blockchain) {
public BlockReplay(
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final Blockchain blockchain) {
this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext;
this.blockchain = blockchain;
}
@ -145,7 +151,7 @@ public class BlockReplay {
public <T> Optional<T> performActionWithBlock(final Hash blockHash, final BlockAction<T> action) {
Optional<Block> maybeBlock = getBlock(blockHash);
if (maybeBlock.isEmpty()) {
maybeBlock = getBadBlock(blockHash);
maybeBlock = protocolContext.getBadBlockManager().getBadBlock(blockHash);
}
return maybeBlock.flatMap(
block -> performActionWithBlock(block.getHeader(), block.getBody(), action));
@ -176,12 +182,6 @@ public class BlockReplay {
return Optional.empty();
}
private Optional<Block> getBadBlock(final Hash blockHash) {
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader());
return protocolSpec.getBadBlocksManager().getBadBlock(blockHash);
}
@FunctionalInterface
public interface BlockAction<T> {
Optional<T> perform(

@ -93,14 +93,14 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods {
@Override
protected Map<String, JsonRpcMethod> create() {
final BlockReplay blockReplay =
new BlockReplay(protocolSchedule, blockchainQueries.getBlockchain());
new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain());
return mapOf(
new DebugTraceTransaction(blockchainQueries, new TransactionTracer(blockReplay)),
new DebugAccountRange(blockchainQueries),
new DebugStorageRangeAt(blockchainQueries, blockReplay),
new DebugMetrics(metricsSystem),
new DebugResyncWorldstate(protocolSchedule, protocolContext.getBlockchain(), synchronizer),
new DebugResyncWorldstate(protocolContext, synchronizer),
new DebugTraceBlock(
() -> new BlockTracer(blockReplay),
ScheduleBasedBlockHeaderFunctions.create(protocolSchedule),
@ -110,11 +110,11 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods {
new DebugTraceBlockByNumber(() -> new BlockTracer(blockReplay), blockchainQueries),
new DebugTraceBlockByHash(() -> new BlockTracer(blockReplay), () -> blockchainQueries),
new DebugBatchSendRawTransaction(transactionPool),
new DebugGetBadBlocks(blockchainQueries, protocolSchedule, blockResult),
new DebugGetBadBlocks(protocolContext, blockResult),
new DebugStandardTraceBlockToFile(
() -> new TransactionTracer(blockReplay), blockchainQueries, dataDir),
new DebugStandardTraceBadBlockToFile(
() -> new TransactionTracer(blockReplay), blockchainQueries, protocolSchedule, dataDir),
() -> new TransactionTracer(blockReplay), blockchainQueries, protocolContext, dataDir),
new DebugAccountAt(blockchainQueries, () -> new BlockTracer(blockReplay)),
new DebugGetRawHeader(blockchainQueries),
new DebugGetRawBlock(blockchainQueries),

@ -141,7 +141,8 @@ public class JsonRpcMethodsFactory {
new PrivxJsonRpcMethods(
blockchainQueries, protocolSchedule, transactionPool, privacyParameters),
new Web3JsonRpcMethods(clientVersion),
new TraceJsonRpcMethods(blockchainQueries, protocolSchedule, apiConfiguration),
new TraceJsonRpcMethods(
blockchainQueries, protocolSchedule, protocolContext, apiConfiguration),
new TxPoolJsonRpcMethods(transactionPool),
new PluginsJsonRpcMethods(namedPlugins));

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -39,13 +40,16 @@ public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final ProtocolSchedule protocolSchedule;
private final ApiConfiguration apiConfiguration;
private final ProtocolContext protocolContext;
TraceJsonRpcMethods(
final BlockchainQueries blockchainQueries,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final ApiConfiguration apiConfiguration) {
this.blockchainQueries = blockchainQueries;
this.protocolSchedule = protocolSchedule;
this.protocolContext = protocolContext;
this.apiConfiguration = apiConfiguration;
}
@ -57,7 +61,7 @@ public class TraceJsonRpcMethods extends ApiGroupJsonRpcMethods {
@Override
protected Map<String, JsonRpcMethod> create() {
final BlockReplay blockReplay =
new BlockReplay(protocolSchedule, blockchainQueries.getBlockchain());
new BlockReplay(protocolSchedule, protocolContext, blockchainQueries.getBlockchain());
return mapOf(
new TraceReplayBlockTransactions(protocolSchedule, blockchainQueries),
new TraceFilter(

@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.DefaultSyncStatus;
@ -108,7 +109,11 @@ public abstract class AbstractEthGraphQLHttpServiceTest {
final MutableBlockchain blockchain = blockchainSetupUtil.getBlockchain();
ProtocolContext context =
new ProtocolContext(
blockchain, blockchainSetupUtil.getWorldArchive(), null, Optional.empty());
blockchain,
blockchainSetupUtil.getWorldArchive(),
null,
Optional.empty(),
new BadBlockManager());
final BlockchainQueries blockchainQueries =
new BlockchainQueries(
context.getBlockchain(),

@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -106,7 +107,8 @@ public class JsonRpcHttpServiceHostAllowlistTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -136,7 +137,7 @@ public class JsonRpcHttpServiceLoginTest {
peerDiscoveryMock,
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(genesisConfigOptions),
MainnetProtocolSchedule.fromConfig(genesisConfigOptions, new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethodsFactory;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.ChainHead;
import org.hyperledger.besu.ethereum.core.MiningParameters;
@ -116,7 +117,8 @@ public class JsonRpcHttpServiceTestBase {
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
EvmConfiguration.DEFAULT),
EvmConfiguration.DEFAULT,
new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider;
import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate;
import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -120,7 +121,8 @@ public class JsonRpcHttpServiceTlsClientAuthTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider;
import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate;
import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -108,7 +109,8 @@ class JsonRpcHttpServiceTlsMisconfigurationTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider;
import org.hyperledger.besu.ethereum.api.tls.SelfSignedP12Certificate;
import org.hyperledger.besu.ethereum.api.tls.TlsConfiguration;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -109,7 +110,8 @@ public class JsonRpcHttpServiceTlsTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -16,32 +16,30 @@ 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.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BadBlockResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@SuppressWarnings("unchecked")
@ -49,13 +47,17 @@ public class DebugGetBadBlockTest {
private final TransactionTestFixture transactionTestFixture = new TransactionTestFixture();
private final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class);
private final BlockchainQueries blockchainQueries = mock(BlockchainQueries.class);
private final ProtocolContext protocolContext = mock(ProtocolContext.class);
private final BlockResultFactory blockResult = new BlockResultFactory();
private final BadBlockManager badBlockManager = new BadBlockManager();
private final DebugGetBadBlocks debugGetBadBlocks =
new DebugGetBadBlocks(blockchainQueries, protocolSchedule, blockResult);
new DebugGetBadBlocks(protocolContext, blockResult);
@BeforeEach
public void setup() {
when(protocolContext.getBadBlockManager()).thenReturn(badBlockManager);
}
@Test
public void nameShouldBeDebugTraceBlock() {
@ -95,9 +97,6 @@ public class DebugGetBadBlockTest {
badBlockManager.addBadBlock(badBlockWithTransaction, Optional.empty());
badBlockManager.addBadBlock(badBlockWoTransaction, Optional.empty());
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlock", new Object[] {}));
@ -123,11 +122,6 @@ public class DebugGetBadBlockTest {
@Test
public void shouldReturnCorrectResponseWhenNoInvalidBlockFound() {
final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlock", new Object[] {}));

@ -21,6 +21,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer;
@ -31,11 +32,7 @@ import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
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.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import java.nio.file.Path;
import java.util.ArrayList;
@ -56,16 +53,18 @@ public class DebugStandardTraceBadBlockToFileTest {
private final Blockchain blockchain = mock(Blockchain.class);
private final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
private final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class);
private final ProtocolContext protocolContext = mock(ProtocolContext.class);
private final TransactionTracer transactionTracer = mock(TransactionTracer.class);
private final ProtocolSpec protocolSpec = mock(ProtocolSpec.class);
private final BadBlockManager badBlockManager = new BadBlockManager();
private final DebugStandardTraceBadBlockToFile debugStandardTraceBadBlockToFile =
new DebugStandardTraceBadBlockToFile(
() -> transactionTracer, blockchainQueries, protocolSchedule, folder);
() -> transactionTracer, blockchainQueries, protocolContext, folder);
@BeforeEach
public void setup() {
when(protocolContext.getBadBlockManager()).thenReturn(badBlockManager);
doAnswer(
invocation ->
invocation
@ -100,14 +99,9 @@ public class DebugStandardTraceBadBlockToFileTest {
final List<String> paths = new ArrayList<>();
paths.add("path-1");
final BadBlockManager badBlockManager = new BadBlockManager();
badBlockManager.addBadBlock(block, Optional.empty());
final BlockHeader blockHeader = new BlockHeaderTestFixture().buildHeader();
when(protocolSpec.getBadBlocksManager()).thenReturn(badBlockManager);
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
when(blockchain.getChainHeadHeader()).thenReturn(new BlockHeaderTestFixture().buildHeader());
when(protocolSchedule.getByBlockHeader(blockHeader)).thenReturn(protocolSpec);
when(transactionTracer.traceTransactionToFile(
any(MutableWorldState.class), eq(block.getHash()), any(), any()))
.thenReturn(paths);

@ -142,7 +142,6 @@ public class EthGetTransactionReceiptTest {
null,
GasLimitCalculator.constant(),
FeeMarket.legacy(),
null,
Optional.of(PoWHasher.ETHASH_LIGHT),
null,
Optional.empty(),
@ -172,7 +171,6 @@ public class EthGetTransactionReceiptTest {
null,
GasLimitCalculator.constant(),
FeeMarket.legacy(),
null,
Optional.of(PoWHasher.ETHASH_LIGHT),
null,
Optional.empty(),

@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.ImmutableTransactionTraceParams;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
@ -69,6 +70,7 @@ public class TransactionTracerTest {
@TempDir private Path traceDir;
@Mock private ProtocolSchedule protocolSchedule;
@Mock private ProtocolContext protocolContext;
@Mock private Blockchain blockchain;
@Mock private BlockHeader blockHeader;
@ -91,6 +93,7 @@ public class TransactionTracerTest {
@Mock private MainnetTransactionProcessor transactionProcessor;
private TransactionTracer transactionTracer;
private final BadBlockManager badBlockManager = new BadBlockManager();
private final Hash transactionHash =
Hash.fromHexString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
@ -107,7 +110,8 @@ public class TransactionTracerTest {
@BeforeEach
public void setUp() throws Exception {
transactionTracer = new TransactionTracer(new BlockReplay(protocolSchedule, blockchain));
transactionTracer =
new TransactionTracer(new BlockReplay(protocolSchedule, protocolContext, blockchain));
when(transaction.getHash()).thenReturn(transactionHash);
when(otherTransaction.getHash()).thenReturn(otherTransactionHash);
when(blockHeader.getNumber()).thenReturn(12L);
@ -118,8 +122,8 @@ public class TransactionTracerTest {
when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(BlockHeader::getCoinbase);
when(protocolSpec.getFeeMarket()).thenReturn(FeeMarket.london(0L));
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader);
when(protocolSpec.getBadBlocksManager()).thenReturn(new BadBlockManager());
when(protocolSpec.getGasCalculator()).thenReturn(gasCalculator);
when(protocolContext.getBadBlockManager()).thenReturn(badBlockManager);
lenient().when(gasCalculator.computeExcessBlobGas(anyLong(), anyInt())).thenReturn(0L);
}

@ -42,6 +42,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.methods.WebSocketMeth
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.blockcreation.PoWMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Synchronizer;
@ -172,7 +173,7 @@ public class WebSocketServiceLoginTest {
peerDiscoveryMock,
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(genesisConfigOptions),
MainnetProtocolSchedule.fromConfig(genesisConfigOptions, new BadBlockManager()),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),

@ -41,6 +41,7 @@ import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlobTestFixture;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
@ -362,7 +363,8 @@ abstract class AbstractBlockCreatorTest {
protocolSpecAdapters,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule())
.build();

@ -44,6 +44,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockTransactionSelector;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AllAcceptingTransactionSelector;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
@ -209,7 +210,9 @@ public abstract class AbstractBlockTransactionSelectorTest {
public void emptyPendingTransactionsResultsInEmptyVettingResult() {
final ProtocolSchedule protocolSchedule =
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT);
GenesisConfigFile.development().getConfigOptions(),
EvmConfiguration.DEFAULT,
new BadBlockManager());
final MainnetTransactionProcessor mainnetTransactionProcessor =
protocolSchedule.getByBlockHeader(blockHeader(0)).getTransactionProcessor();

@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -56,7 +57,8 @@ public class BlockMinerTest {
new Block(
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty());
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =
@ -97,7 +99,8 @@ public class BlockMinerTest {
new Block(
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty());
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =
@ -142,7 +145,8 @@ public class BlockMinerTest {
new Block(
headerBuilder.buildHeader(), new BlockBody(Lists.newArrayList(), Lists.newArrayList()));
final ProtocolContext protocolContext = new ProtocolContext(null, null, null, Optional.empty());
final ProtocolContext protocolContext =
new ProtocolContext(null, null, null, Optional.empty(), new BadBlockManager());
final PoWBlockCreator blockCreator = mock(PoWBlockCreator.class);
final Function<BlockHeader, PoWBlockCreator> blockCreatorSupplier =

@ -21,6 +21,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
@ -57,7 +58,8 @@ public class LegacyFeeMarketBlockTransactionSelectorTest
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule();
}

@ -24,6 +24,7 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockTransactionSelector;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
import org.hyperledger.besu.ethereum.core.MiningParameters;
@ -69,7 +70,8 @@ public class LondonFeeMarketBlockTransactionSelectorTest
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule();
}

@ -27,6 +27,7 @@ import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator.BlockCreationResult;
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.Difficulty;
@ -91,7 +92,8 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
ProtocolSpecAdapters.create(0, Function.identity()),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule())
.build();
@ -145,7 +147,8 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
ProtocolSpecAdapters.create(0, Function.identity()),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule())
.build();
@ -189,7 +192,8 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
ProtocolSpecAdapters.create(0, Function.identity()),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule();
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build();
@ -256,7 +260,8 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
ProtocolSpecAdapters.create(0, Function.identity()),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule();
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build();

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -30,6 +31,7 @@ import java.util.Optional;
public class ProtocolContext {
private final MutableBlockchain blockchain;
private final WorldStateArchive worldStateArchive;
private final BadBlockManager badBlockManager;
private final ConsensusContext consensusContext;
private final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory;
@ -38,20 +40,23 @@ public class ProtocolContext {
public ProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ConsensusContext consensusContext) {
this(blockchain, worldStateArchive, consensusContext, Optional.empty());
final ConsensusContext consensusContext,
final BadBlockManager badBlockManager) {
this(blockchain, worldStateArchive, consensusContext, Optional.empty(), badBlockManager);
}
public ProtocolContext(
final MutableBlockchain blockchain,
final WorldStateArchive worldStateArchive,
final ConsensusContext consensusContext,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
this.blockchain = blockchain;
this.worldStateArchive = worldStateArchive;
this.consensusContext = consensusContext;
this.synchronizer = Optional.empty();
this.transactionSelectorFactory = transactionSelectorFactory;
this.badBlockManager = badBlockManager;
}
public static ProtocolContext init(
@ -59,12 +64,14 @@ public class ProtocolContext {
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ConsensusContextFactory consensusContextFactory,
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory) {
final Optional<PluginTransactionSelectorFactory> transactionSelectorFactory,
final BadBlockManager badBlockManager) {
return new ProtocolContext(
blockchain,
worldStateArchive,
consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule),
transactionSelectorFactory);
transactionSelectorFactory,
badBlockManager);
}
public Optional<Synchronizer> getSynchronizer() {
@ -83,6 +90,10 @@ public class ProtocolContext {
return worldStateArchive;
}
public BadBlockManager getBadBlockManager() {
return badBlockManager;
}
public <C extends ConsensusContext> C getConsensusContext(final Class<C> klass) {
return consensusContext.as(klass);
}

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.difficulty.fixed;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
@ -28,7 +29,8 @@ public class FixedDifficultyProtocolSchedule {
final GenesisConfigOptions config,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return new ProtocolScheduleBuilder(
config,
ProtocolSpecAdapters.create(
@ -37,19 +39,28 @@ public class FixedDifficultyProtocolSchedule {
builder.difficultyCalculator(FixedDifficultyCalculators.calculator(config))),
privacyParameters,
isRevertReasonEnabled,
evmConfiguration)
evmConfiguration,
badBlockManager)
.createProtocolSchedule();
}
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
return create(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration);
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return create(
config,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
evmConfiguration,
badBlockManager);
}
public static ProtocolSchedule create(
final GenesisConfigOptions config, final EvmConfiguration evmConfiguration) {
return create(config, PrivacyParameters.DEFAULT, false, evmConfiguration);
final GenesisConfigOptions config,
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return create(config, PrivacyParameters.DEFAULT, false, evmConfiguration, badBlockManager);
}
}

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyCalculators;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule;
@ -36,16 +37,18 @@ public class MainnetProtocolSchedule {
* @param privacyParameters the parameters set for private transactions
* @param isRevertReasonEnabled whether storing the revert reason is for failed transactions
* @param evmConfiguration how to configure the EVMs jumpdest cache
* @param badBlockManager the cache to use to keep invalid blocks
* @return A configured mainnet protocol schedule
*/
public static ProtocolSchedule fromConfig(
final GenesisConfigOptions config,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
if (FixedDifficultyCalculators.isFixedDifficultyInConfig(config)) {
return FixedDifficultyProtocolSchedule.create(
config, privacyParameters, isRevertReasonEnabled, evmConfiguration);
config, privacyParameters, isRevertReasonEnabled, evmConfiguration, badBlockManager);
}
return new ProtocolScheduleBuilder(
config,
@ -53,7 +56,8 @@ public class MainnetProtocolSchedule {
ProtocolSpecAdapters.create(0, Function.identity()),
privacyParameters,
isRevertReasonEnabled,
evmConfiguration)
evmConfiguration,
badBlockManager)
.createProtocolSchedule();
}
@ -64,13 +68,20 @@ public class MainnetProtocolSchedule {
* starting points
* @param isRevertReasonEnabled whether storing the revert reason is for failed transactions
* @param evmConfiguration how to configure the EVMs jumpdest cache
* @param badBlockManager the cache to use to keep invalid blocks
* @return A configured mainnet protocol schedule
*/
public static ProtocolSchedule fromConfig(
final GenesisConfigOptions config,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
return fromConfig(config, PrivacyParameters.DEFAULT, isRevertReasonEnabled, evmConfiguration);
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return fromConfig(
config,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
evmConfiguration,
badBlockManager);
}
/**
@ -79,11 +90,14 @@ public class MainnetProtocolSchedule {
* @param config {@link GenesisConfigOptions} containing the config options for the milestone
* starting points
* @param evmConfiguration size of
* @param badBlockManager the cache to use to keep invalid blocks
* @return A configured mainnet protocol schedule
*/
public static ProtocolSchedule fromConfig(
final GenesisConfigOptions config, final EvmConfiguration evmConfiguration) {
return fromConfig(config, PrivacyParameters.DEFAULT, false, evmConfiguration);
final GenesisConfigOptions config,
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
return fromConfig(config, PrivacyParameters.DEFAULT, false, evmConfiguration, badBlockManager);
}
/**
@ -91,9 +105,12 @@ public class MainnetProtocolSchedule {
*
* @param config {@link GenesisConfigOptions} containing the config options for the milestone
* starting points
* @param badBlockManager the cache to use to keep invalid blocks
* @return A configured mainnet protocol schedule
*/
public static ProtocolSchedule fromConfig(final GenesisConfigOptions config) {
return fromConfig(config, PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT);
public static ProtocolSchedule fromConfig(
final GenesisConfigOptions config, final BadBlockManager badBlockManager) {
return fromConfig(
config, PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT, badBlockManager);
}
}

@ -40,7 +40,7 @@ public class ProtocolScheduleBuilder {
private final PrivacyParameters privacyParameters;
private final boolean isRevertReasonEnabled;
private final EvmConfiguration evmConfiguration;
private final BadBlockManager badBlockManager = new BadBlockManager();
private final BadBlockManager badBlockManager;
private DefaultProtocolSchedule protocolSchedule;
@ -50,14 +50,16 @@ public class ProtocolScheduleBuilder {
final ProtocolSpecAdapters protocolSpecAdapters,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
this(
config,
Optional.of(defaultChainId),
protocolSpecAdapters,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
public ProtocolScheduleBuilder(
@ -65,14 +67,16 @@ public class ProtocolScheduleBuilder {
final ProtocolSpecAdapters protocolSpecAdapters,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
this(
config,
Optional.empty(),
protocolSpecAdapters,
privacyParameters,
isRevertReasonEnabled,
evmConfiguration);
evmConfiguration,
badBlockManager);
}
private ProtocolScheduleBuilder(
@ -81,13 +85,15 @@ public class ProtocolScheduleBuilder {
final ProtocolSpecAdapters protocolSpecAdapters,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration) {
final EvmConfiguration evmConfiguration,
final BadBlockManager badBlockManager) {
this.config = config;
this.protocolSpecAdapters = protocolSpecAdapters;
this.privacyParameters = privacyParameters;
this.isRevertReasonEnabled = isRevertReasonEnabled;
this.evmConfiguration = evmConfiguration;
this.defaultChainId = defaultChainId;
this.badBlockManager = badBlockManager;
}
public ProtocolSchedule createProtocolSchedule() {

@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
@ -72,8 +71,6 @@ public class ProtocolSpec {
private final FeeMarket feeMarket;
private final BadBlockManager badBlockManager;
private final Optional<PoWHasher> powHasher;
private final WithdrawalsValidator withdrawalsValidator;
@ -106,7 +103,6 @@ public class ProtocolSpec {
* @param gasCalculator the gas calculator to use.
* @param gasLimitCalculator the gas limit calculator to use.
* @param feeMarket an {@link Optional} wrapping {@link FeeMarket} class if appropriate.
* @param badBlockManager the cache to use to keep invalid blocks
* @param powHasher the proof-of-work hasher
* @param withdrawalsValidator the withdrawals validator to use
* @param withdrawalsProcessor the Withdrawals processor to use
@ -137,7 +133,6 @@ public class ProtocolSpec {
final GasCalculator gasCalculator,
final GasLimitCalculator gasLimitCalculator,
final FeeMarket feeMarket,
final BadBlockManager badBlockManager,
final Optional<PoWHasher> powHasher,
final WithdrawalsValidator withdrawalsValidator,
final Optional<WithdrawalsProcessor> withdrawalsProcessor,
@ -165,7 +160,6 @@ public class ProtocolSpec {
this.gasCalculator = gasCalculator;
this.gasLimitCalculator = gasLimitCalculator;
this.feeMarket = feeMarket;
this.badBlockManager = badBlockManager;
this.powHasher = powHasher;
this.withdrawalsValidator = withdrawalsValidator;
this.withdrawalsProcessor = withdrawalsProcessor;
@ -354,15 +348,6 @@ public class ProtocolSpec {
return feeMarket;
}
/**
* Returns the bad blocks manager
*
* @return the bad blocks manager
*/
public BadBlockManager getBadBlocksManager() {
return badBlockManager;
}
/**
* Returns the Proof-of-Work hasher
*

@ -380,7 +380,6 @@ public class ProtocolSpecBuilder {
gasCalculator,
gasLimitCalculator,
feeMarket,
badBlockManager,
Optional.ofNullable(powHasher),
withdrawalsValidator,
Optional.ofNullable(withdrawalsProcessor),

@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.ConsensusContext;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
@ -142,7 +143,7 @@ public class BlockchainSetupUtil {
private static ProtocolSchedule mainnetProtocolScheduleProvider(
final GenesisConfigFile genesisConfigFile) {
return MainnetProtocolSchedule.fromConfig(
genesisConfigFile.getConfigOptions(), EvmConfiguration.DEFAULT);
genesisConfigFile.getConfigOptions(), EvmConfiguration.DEFAULT, new BadBlockManager());
}
private static ProtocolContext mainnetProtocolContextProvider(
@ -156,7 +157,8 @@ public class BlockchainSetupUtil {
return null;
}
},
Optional.empty());
Optional.empty(),
new BadBlockManager());
}
private static BlockchainSetupUtil create(

@ -19,6 +19,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
@ -69,7 +70,9 @@ public class ExecutionContextTestFixture {
0);
this.stateArchive = createInMemoryWorldStateArchive();
this.protocolSchedule = protocolSchedule;
this.protocolContext = new ProtocolContext(blockchain, stateArchive, null, Optional.empty());
this.protocolContext =
new ProtocolContext(
blockchain, stateArchive, null, Optional.empty(), new BadBlockManager());
genesisState.writeStateTo(stateArchive.getMutable());
}
@ -138,7 +141,8 @@ public class ExecutionContextTestFixture {
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT)
EvmConfiguration.DEFAULT,
new BadBlockManager())
.createProtocolSchedule();
}
if (blockchainKeyValueStorage == null) {

@ -20,6 +20,7 @@ import static org.hyperledger.besu.config.JsonUtil.normalizeKeys;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.JsonGenesisConfigOptions;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
@ -34,7 +35,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class ProtocolScheduleFixture {
public static final ProtocolSchedule MAINNET =
MainnetProtocolSchedule.fromConfig(
getMainnetConfigOptions(), PrivacyParameters.DEFAULT, false, EvmConfiguration.DEFAULT);
getMainnetConfigOptions(),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
new BadBlockManager());
private static GenesisConfigOptions getMainnetConfigOptions() {
// this method avoids reading all the alloc accounts when all we want is the "config" section

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.difficulty.fixed;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -31,7 +32,9 @@ public class FixedProtocolScheduleTest {
final ProtocolSchedule schedule =
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT);
GenesisConfigFile.development().getConfigOptions(),
EvmConfiguration.DEFAULT,
new BadBlockManager());
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();

@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -58,7 +59,8 @@ public class DefaultProtocolScheduleTest {
ProtocolSpecAdapters.create(FIRST_TIMESTAMP_FORK, modifier),
privacyParameters,
isRevertReasonEnabled,
evmConfiguration);
evmConfiguration,
new BadBlockManager());
}
@Test

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
@ -71,7 +72,9 @@ public class MainnetProtocolScheduleTest {
public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() {
final ProtocolSchedule sched =
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT);
GenesisConfigFile.fromConfig("{}").getConfigOptions(),
EvmConfiguration.DEFAULT,
new BadBlockManager());
Assertions.assertThat(sched.getByBlockHeader(blockHeader(1L)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName())
.isEqualTo("Frontier");
@ -83,7 +86,9 @@ public class MainnetProtocolScheduleTest {
"{\"config\": {\"homesteadBlock\": 2, \"daoForkBlock\": 3, \"eip150Block\": 14, \"eip158Block\": 15, \"byzantiumBlock\": 16, \"constantinopleBlock\": 18, \"petersburgBlock\": 19, \"chainId\":1234}}";
final ProtocolSchedule sched =
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT);
GenesisConfigFile.fromConfig(json).getConfigOptions(),
EvmConfiguration.DEFAULT,
new BadBlockManager());
Assertions.assertThat(sched.getByBlockHeader(blockHeader(1)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(2)).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(3)).getName())
@ -113,7 +118,8 @@ public class MainnetProtocolScheduleTest {
() ->
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(json).getConfigOptions(),
EvmConfiguration.DEFAULT));
EvmConfiguration.DEFAULT,
new BadBlockManager()));
}
@Test
@ -124,7 +130,8 @@ public class MainnetProtocolScheduleTest {
Resources.toString(
this.getClass().getResource("/goerli.json"), StandardCharsets.UTF_8))
.getConfigOptions(),
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
Assertions.assertThat(sched.getByBlockHeader(blockHeader(0L)).getName())
.isEqualTo("Petersburg");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_561_651L)).getName())

@ -22,6 +22,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
@ -57,7 +58,8 @@ class ProtocolScheduleBuilderTest {
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
}
@Test
@ -210,7 +212,8 @@ class ProtocolScheduleBuilderTest {
ProtocolSpecAdapters.create(blockNumber, modifier),
new PrivacyParameters(),
false,
EvmConfiguration.DEFAULT);
EvmConfiguration.DEFAULT,
new BadBlockManager());
return new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule) builder.createProtocolSchedule());

@ -32,6 +32,7 @@ import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.AbstractBlockCreator;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -101,7 +102,8 @@ public abstract class AbstractIsolationTests {
SignatureAlgorithmFactory.getInstance()
.createKeyPair(SECPPrivateKey.create(Bytes32.fromHexString(key), "ECDSA"));
protected final ProtocolSchedule protocolSchedule =
MainnetProtocolSchedule.fromConfig(GenesisConfigFile.development().getConfigOptions());
MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.development().getConfigOptions(), new BadBlockManager());
protected final GenesisState genesisState =
GenesisState.fromConfig(GenesisConfigFile.development(), protocolSchedule);
protected final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());
@ -158,7 +160,8 @@ public abstract class AbstractIsolationTests {
EvmConfiguration.DEFAULT);
var ws = archive.getMutable();
genesisState.writeStateTo(ws);
protocolContext = new ProtocolContext(blockchain, archive, null, Optional.empty());
protocolContext =
new ProtocolContext(blockchain, archive, null, Optional.empty(), new BadBlockManager());
ethContext = mock(EthContext.class, RETURNS_DEEP_STUBS);
when(ethContext.getEthPeers().subscribeConnect(any())).thenReturn(1L);
transactionPool =

@ -609,7 +609,7 @@ public class BlockPropagationManager implements UnverifiedForkchoiceListener {
+ block.toLogString()));
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final BlockHeaderValidator blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
final BadBlockManager badBlockManager = protocolContext.getBadBlockManager();
return ethContext
.getScheduler()
.scheduleSyncWorkerTask(

@ -199,8 +199,7 @@ public class DownloadHeaderSequenceTask extends AbstractRetryingPeerTask<List<Bl
child =
(headerIndex == segmentLength - 1) ? referenceHeader : headers[headerIndex + 1];
}
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(child);
final BadBlockManager badBlockManager = protocolSpec.getBadBlocksManager();
final BadBlockManager badBlockManager = protocolContext.getBadBlockManager();
if (!validateHeader(child, header)) {
// Invalid headers - disconnect from peer

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.eth.messages;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
@ -54,7 +55,10 @@ public final class BlockBodiesMessageTest {
public void setup() {
protocolSchedule =
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(), false, EvmConfiguration.DEFAULT);
GenesisConfigFile.development().getConfigOptions(),
false,
EvmConfiguration.DEFAULT,
new BadBlockManager());
}
@Test

@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.eth.messages;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
@ -63,7 +64,8 @@ public final class BlockHeadersMessageTest {
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(),
false,
EvmConfiguration.DEFAULT));
EvmConfiguration.DEFAULT,
new BadBlockManager()));
for (int i = 0; i < 50; ++i) {
Assertions.assertThat(readHeaders.get(i)).isEqualTo(headers.get(i));

@ -106,7 +106,8 @@ public abstract class AbstractBlockPropagationManagerTest {
blockchain,
tempProtocolContext.getWorldStateArchive(),
tempProtocolContext.getConsensusContext(ConsensusContext.class),
Optional.empty());
Optional.empty(),
new BadBlockManager());
ethProtocolManager =
EthProtocolManagerTestUtil.create(
protocolSchedule,
@ -784,8 +785,7 @@ public abstract class AbstractBlockPropagationManagerTest {
blockchainUtil.importFirstBlocks(2);
final Block firstBlock = blockchainUtil.getBlock(1);
final BadBlockManager badBlocksManager =
protocolSchedule.getByBlockHeader(blockHeader(1)).getBadBlocksManager();
final BadBlockManager badBlocksManager = protocolContext.getBadBlockManager();
final Block badBlock =
new BlockDataGenerator()
.block(

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save