mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-08 23:08:15 -05:00
Simplify ProtocolContext creation (#7792)
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
This commit is contained in:
@@ -52,6 +52,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration;
|
||||
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues;
|
||||
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
|
||||
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
|
||||
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
|
||||
@@ -99,18 +100,6 @@ public class CliqueBlockCreatorTest {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
protocolSchedule =
|
||||
CliqueProtocolSchedule.create(
|
||||
GenesisConfigFile.DEFAULT.getConfigOptions(),
|
||||
new ForksSchedule<>(List.of()),
|
||||
proposerNodeKey,
|
||||
false,
|
||||
EvmConfiguration.DEFAULT,
|
||||
MiningConfiguration.MINING_DISABLED,
|
||||
new BadBlockManager(),
|
||||
false,
|
||||
new NoOpMetricsSystem());
|
||||
|
||||
final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey());
|
||||
validatorList.add(otherAddress);
|
||||
|
||||
@@ -118,6 +107,20 @@ public class CliqueBlockCreatorTest {
|
||||
voteProvider = mock(VoteProvider.class);
|
||||
when(validatorProvider.getVoteProviderAtHead()).thenReturn(Optional.of(voteProvider));
|
||||
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);
|
||||
|
||||
protocolSchedule =
|
||||
CliqueProtocolSchedule.create(
|
||||
GenesisConfigFile.DEFAULT.getConfigOptions(),
|
||||
new ForksSchedule<>(List.of()),
|
||||
proposerNodeKey,
|
||||
PrivacyParameters.DEFAULT,
|
||||
false,
|
||||
EvmConfiguration.DEFAULT,
|
||||
MiningConfiguration.MINING_DISABLED,
|
||||
new BadBlockManager(),
|
||||
false,
|
||||
new NoOpMetricsSystem());
|
||||
|
||||
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
|
||||
|
||||
final Block genesis =
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
|
||||
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration;
|
||||
import org.hyperledger.besu.ethereum.core.ImmutableMiningConfiguration.MutableInitValues;
|
||||
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
|
||||
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
|
||||
import org.hyperledger.besu.ethereum.core.Util;
|
||||
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
|
||||
import org.hyperledger.besu.ethereum.eth.manager.EthScheduler;
|
||||
@@ -103,6 +104,7 @@ public class CliqueMinerExecutorTest {
|
||||
GENESIS_CONFIG_OPTIONS,
|
||||
new ForksSchedule<>(List.of()),
|
||||
proposerNodeKey,
|
||||
PrivacyParameters.DEFAULT,
|
||||
false,
|
||||
EvmConfiguration.DEFAULT,
|
||||
MiningConfiguration.MINING_DISABLED,
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.hyperledger.besu.consensus.common;
|
||||
import org.hyperledger.besu.ethereum.ConsensusContext;
|
||||
|
||||
/** The Migrating context. */
|
||||
public class MigratingContext implements ConsensusContext {
|
||||
public class MigratingConsensusContext implements ConsensusContext {
|
||||
|
||||
private final ForksSchedule<ConsensusContext> consensusContextSchedule;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MigratingContext implements ConsensusContext {
|
||||
*
|
||||
* @param consensusContextSchedule the consensus context schedule
|
||||
*/
|
||||
public MigratingContext(final ForksSchedule<ConsensusContext> consensusContextSchedule) {
|
||||
public MigratingConsensusContext(final ForksSchedule<ConsensusContext> consensusContextSchedule) {
|
||||
this.consensusContextSchedule = consensusContextSchedule;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
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;
|
||||
|
||||
/** The Migrating protocol context. */
|
||||
@@ -32,42 +30,16 @@ public class MigratingProtocolContext extends ProtocolContext {
|
||||
*
|
||||
* @param blockchain the blockchain
|
||||
* @param worldStateArchive the world state archive
|
||||
* @param consensusContextSchedule the consensus context schedule
|
||||
* @param migratingConsensusContext the consensus context
|
||||
* @param badBlockManager the cache to use to keep invalid blocks
|
||||
*/
|
||||
public MigratingProtocolContext(
|
||||
final MutableBlockchain blockchain,
|
||||
final WorldStateArchive worldStateArchive,
|
||||
final ForksSchedule<ConsensusContext> consensusContextSchedule,
|
||||
final MigratingConsensusContext migratingConsensusContext,
|
||||
final BadBlockManager badBlockManager) {
|
||||
super(blockchain, worldStateArchive, null, badBlockManager);
|
||||
this.consensusContextSchedule = consensusContextSchedule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init protocol context.
|
||||
*
|
||||
* @param blockchain the blockchain
|
||||
* @param worldStateArchive the world state archive
|
||||
* @param protocolSchedule the protocol schedule
|
||||
* @param consensusContextFactory the consensus context factory
|
||||
* @param badBlockManager the cache to use to keep invalid blocks
|
||||
* @return the protocol context
|
||||
*/
|
||||
public static ProtocolContext init(
|
||||
final MutableBlockchain blockchain,
|
||||
final WorldStateArchive worldStateArchive,
|
||||
final ProtocolSchedule protocolSchedule,
|
||||
final ConsensusContextFactory consensusContextFactory,
|
||||
final BadBlockManager badBlockManager) {
|
||||
final ConsensusContext consensusContext =
|
||||
consensusContextFactory.create(blockchain, worldStateArchive, protocolSchedule);
|
||||
final MigratingContext migratingContext = consensusContext.as(MigratingContext.class);
|
||||
return new MigratingProtocolContext(
|
||||
blockchain,
|
||||
worldStateArchive,
|
||||
migratingContext.getConsensusContextSchedule(),
|
||||
badBlockManager);
|
||||
super(blockchain, worldStateArchive, migratingConsensusContext, badBlockManager);
|
||||
this.consensusContextSchedule = migratingConsensusContext.getConsensusContextSchedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,9 +43,13 @@ public class MigratingProtocolContextTest {
|
||||
|
||||
final ForksSchedule<ConsensusContext> contextSchedule =
|
||||
new ForksSchedule<>(List.of(new ForkSpec<>(0L, context1), new ForkSpec<>(10L, context2)));
|
||||
|
||||
final MigratingProtocolContext migratingProtocolContext =
|
||||
new MigratingProtocolContext(
|
||||
blockchain, worldStateArchive, contextSchedule, new BadBlockManager());
|
||||
blockchain,
|
||||
worldStateArchive,
|
||||
new MigratingConsensusContext(contextSchedule),
|
||||
new BadBlockManager());
|
||||
|
||||
assertThat(migratingProtocolContext.getConsensusContext(ConsensusContext.class))
|
||||
.isSameAs(context1);
|
||||
|
||||
Reference in New Issue
Block a user