Search in sources :

Example 1 with BftEventQueue

use of org.hyperledger.besu.consensus.common.bft.BftEventQueue in project besu by hyperledger.

the class QbftBesuControllerBuilder method prepForBuild.

@Override
protected void prepForBuild() {
    qbftConfig = configOptionsSupplier.get().getQbftConfigOptions();
    bftEventQueue = new BftEventQueue(qbftConfig.getMessageQueueLimit());
    qbftForksSchedule = QbftForksSchedulesFactory.create(configOptionsSupplier.get());
}
Also used : BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue)

Example 2 with BftEventQueue

use of org.hyperledger.besu.consensus.common.bft.BftEventQueue in project besu by hyperledger.

the class TestContextBuilder method build.

public TestContext build() {
    final NetworkLayout networkNodes = NetworkLayout.createNetworkLayout(validatorCount, indexOfFirstLocallyProposedBlock);
    final Block genesisBlock = createGenesisBlock(networkNodes.getValidatorAddresses());
    final MutableBlockchain blockChain = createInMemoryBlockchain(genesisBlock, BftBlockHeaderFunctions.forOnchainBlock(IBFT_EXTRA_DATA_ENCODER));
    // Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
    final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();
    final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster, GOSSIPED_HISTORY_LIMIT);
    final Gossiper gossiper = useGossip ? new IbftGossip(uniqueMulticaster) : mock(Gossiper.class);
    final StubbedSynchronizerUpdater synchronizerUpdater = new StubbedSynchronizerUpdater();
    final ControllerAndState controllerAndState = createControllerAndFinalState(blockChain, multicaster, networkNodes.getLocalNode().getNodeKey(), clock, bftEventQueue, gossiper, synchronizerUpdater, bftForks);
    // Add each networkNode to the Multicaster (such that each can receive msgs from local node).
    // NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine
    // the proposer order which must be managed in test).
    final Map<Address, ValidatorPeer> remotePeers = networkNodes.getRemotePeers().stream().collect(Collectors.toMap(NodeParams::getAddress, nodeParams -> new ValidatorPeer(nodeParams, new MessageFactory(nodeParams.getNodeKey()), controllerAndState.getEventMultiplexer()), (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    final List<DefaultValidatorPeer> peerCollection = new ArrayList<>(remotePeers.values());
    multicaster.addNetworkPeers(peerCollection);
    synchronizerUpdater.addNetworkPeers(peerCollection);
    return new TestContext(remotePeers, blockChain, controllerAndState.getIbftExecutors(), controllerAndState.getEventHandler(), controllerAndState.getFinalState(), controllerAndState.getEventMultiplexer(), controllerAndState.getMessageFactory());
}
Also used : BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) Subscribers(org.hyperledger.besu.util.Subscribers) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) IbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightManagerFactory) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) MessageValidatorFactory(org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory) Map(java.util.Map) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) Block(org.hyperledger.besu.ethereum.core.Block) BftFork(org.hyperledger.besu.config.BftFork) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) Set(java.util.Set) Instant(java.time.Instant) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) IbftController(org.hyperledger.besu.consensus.ibft.statemachine.IbftController) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) Mockito.mock(org.mockito.Mockito.mock) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) IbftProtocolSchedule(org.hyperledger.besu.consensus.ibft.IbftProtocolSchedule) Iterables(com.google.common.collect.Iterables) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) BftBlockCreatorFactory(org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory) IbftRoundFactory(org.hyperledger.besu.consensus.ibft.statemachine.IbftRoundFactory) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) ArrayList(java.util.ArrayList) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LinkedHashMap(java.util.LinkedHashMap) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) IbftGossip(org.hyperledger.besu.consensus.ibft.IbftGossip) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) Wei(org.hyperledger.besu.datatypes.Wei) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) UTF_8(java.nio.charset.StandardCharsets.UTF_8) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) IbftForksSchedulesFactory(org.hyperledger.besu.consensus.ibft.IbftForksSchedulesFactory) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) AddressHelpers(org.hyperledger.besu.ethereum.core.AddressHelpers) TestTransitions(org.hyperledger.besu.consensus.common.bft.inttest.TestTransitions) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) IbftExtraDataCodec(org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) Clock(java.time.Clock) BftHelpers(org.hyperledger.besu.consensus.common.bft.BftHelpers) SynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.SynchronizerUpdater) Collections(java.util.Collections) TestClock(org.hyperledger.besu.testutil.TestClock) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) Address(org.hyperledger.besu.datatypes.Address) MessageFactory(org.hyperledger.besu.consensus.ibft.payload.MessageFactory) ArrayList(java.util.ArrayList) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) IbftGossip(org.hyperledger.besu.consensus.ibft.IbftGossip)

Example 3 with BftEventQueue

use of org.hyperledger.besu.consensus.common.bft.BftEventQueue in project besu by hyperledger.

the class TransitionsTest method transitionsBlockPeriod.

@Test
public void transitionsBlockPeriod() throws InterruptedException {
    final TestClock clock = new TestClock(Instant.EPOCH);
    final List<BftFork> bftForks = List.of(new BftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.BLOCK_PERIOD_SECONDS_KEY, 10))), new BftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 2, BftFork.BLOCK_PERIOD_SECONDS_KEY, 20))));
    final BftEventQueue bftEventQueue = new BftEventQueue(TestContextBuilder.MESSAGE_QUEUE_LIMIT);
    final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).validatorCount(1).clock(clock).bftForks(bftForks).eventQueue(bftEventQueue).buildAndStart();
    clock.stepMillis(10_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
    clock.stepMillis(20_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
    final BlockHeader blockHeader1 = context.getBlockchain().getBlockHeader(1).get();
    final BlockHeader blockHeader2 = context.getBlockchain().getBlockHeader(2).get();
    assertThat(blockHeader1.getTimestamp()).isEqualTo(genesisBlock.getTimestamp() + 10);
    assertThat(blockHeader2.getTimestamp()).isEqualTo(blockHeader1.getTimestamp() + 20);
}
Also used : TestClock(org.hyperledger.besu.testutil.TestClock) TestContext(org.hyperledger.besu.consensus.ibft.support.TestContext) TestContextBuilder(org.hyperledger.besu.consensus.ibft.support.TestContextBuilder) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) BftFork(org.hyperledger.besu.config.BftFork) Test(org.junit.jupiter.api.Test)

Example 4 with BftEventQueue

use of org.hyperledger.besu.consensus.common.bft.BftEventQueue in project besu by hyperledger.

the class TestContextBuilder method build.

public TestContext build() {
    final NetworkLayout networkNodes;
    if (nodeParams.isEmpty()) {
        networkNodes = NetworkLayout.createNetworkLayout(validatorCount, indexOfFirstLocallyProposedBlock);
    } else {
        final TreeMap<Address, NodeParams> addressKeyMap = new TreeMap<>();
        for (NodeParams params : nodeParams) {
            addressKeyMap.put(params.getAddress(), params);
        }
        final NodeParams localNode = Iterables.get(addressKeyMap.values(), indexOfFirstLocallyProposedBlock);
        networkNodes = new NetworkLayout(localNode, addressKeyMap);
    }
    final MutableBlockchain blockChain;
    final DefaultWorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
    if (genesisFile.isPresent()) {
        try {
            final GenesisState genesisState = createGenesisBlock(genesisFile.get());
            blockChain = createInMemoryBlockchain(genesisState.getBlock(), BftBlockHeaderFunctions.forOnchainBlock(BFT_EXTRA_DATA_ENCODER));
            genesisState.writeStateTo(worldStateArchive.getMutable());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    } else {
        final Block genesisBlock = createGenesisBlock(networkNodes.getValidatorAddresses());
        blockChain = createInMemoryBlockchain(genesisBlock, BftBlockHeaderFunctions.forOnchainBlock(BFT_EXTRA_DATA_ENCODER));
    }
    // Use a stubbed version of the multicaster, to prevent creating PeerConnections etc.
    final StubValidatorMulticaster multicaster = new StubValidatorMulticaster();
    final UniqueMessageMulticaster uniqueMulticaster = new UniqueMessageMulticaster(multicaster, GOSSIPED_HISTORY_LIMIT);
    final Gossiper gossiper = useGossip ? new QbftGossip(uniqueMulticaster, BFT_EXTRA_DATA_ENCODER) : mock(Gossiper.class);
    final StubbedSynchronizerUpdater synchronizerUpdater = new StubbedSynchronizerUpdater();
    final ControllerAndState controllerAndState = createControllerAndFinalState(blockChain, worldStateArchive, multicaster, networkNodes.getLocalNode().getNodeKey(), clock, bftEventQueue, gossiper, synchronizerUpdater, useValidatorContract, qbftForks);
    // Add each networkNode to the Multicaster (such that each can receive msgs from local node).
    // NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine
    // the proposer order which must be managed in test).
    final Map<Address, ValidatorPeer> remotePeers = networkNodes.getRemotePeers().stream().collect(Collectors.toMap(NodeParams::getAddress, nodeParams -> new ValidatorPeer(nodeParams, new MessageFactory(nodeParams.getNodeKey()), controllerAndState.getEventMultiplexer()), (u, v) -> {
        throw new IllegalStateException(String.format("Duplicate key %s", u));
    }, LinkedHashMap::new));
    final List<DefaultValidatorPeer> peerCollection = new ArrayList<>(remotePeers.values());
    multicaster.addNetworkPeers(peerCollection);
    synchronizerUpdater.addNetworkPeers(peerCollection);
    return new TestContext(remotePeers, blockChain, controllerAndState.getBftExecutors(), controllerAndState.getEventHandler(), controllerAndState.getFinalState(), controllerAndState.getEventMultiplexer(), controllerAndState.getMessageFactory(), controllerAndState.getValidatorProvider(), BFT_EXTRA_DATA_ENCODER);
}
Also used : BftFinalState(org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState) QbftFork(org.hyperledger.besu.config.QbftFork) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) Subscribers(org.hyperledger.besu.util.Subscribers) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProposerSelector(org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) MessageValidatorFactory(org.hyperledger.besu.consensus.qbft.validation.MessageValidatorFactory) Map(java.util.Map) BlockTimer(org.hyperledger.besu.consensus.common.bft.BlockTimer) Block(org.hyperledger.besu.ethereum.core.Block) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Path(java.nio.file.Path) RoundTimer(org.hyperledger.besu.consensus.common.bft.RoundTimer) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) BftEventHandler(org.hyperledger.besu.consensus.common.bft.statemachine.BftEventHandler) QbftRoundFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftRoundFactory) Set(java.util.Set) JsonUtil(org.hyperledger.besu.config.JsonUtil) EventMultiplexer(org.hyperledger.besu.consensus.common.bft.EventMultiplexer) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) ZoneId(java.time.ZoneId) BftExecutors(org.hyperledger.besu.consensus.common.bft.BftExecutors) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) ProtocolScheduleFixture(org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture) ValidatorContractController(org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController) ForkingValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) MinedBlockObserver(org.hyperledger.besu.ethereum.chain.MinedBlockObserver) Iterables(com.google.common.collect.Iterables) BftValidatorOverrides(org.hyperledger.besu.consensus.common.BftValidatorOverrides) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) BftBlockCreatorFactory(org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory) Bytes(org.apache.tuweni.bytes.Bytes) ArrayList(java.util.ArrayList) QbftController(org.hyperledger.besu.consensus.qbft.statemachine.QbftController) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LinkedHashMap(java.util.LinkedHashMap) FutureMessageBuffer(org.hyperledger.besu.consensus.common.bft.statemachine.FutureMessageBuffer) QbftProtocolSchedule(org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) Wei(org.hyperledger.besu.datatypes.Wei) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) QbftContext(org.hyperledger.besu.consensus.qbft.QbftContext) Files(java.nio.file.Files) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) AddressHelpers(org.hyperledger.besu.ethereum.core.AddressHelpers) IOException(java.io.IOException) MutableQbftConfigOptions(org.hyperledger.besu.consensus.qbft.MutableQbftConfigOptions) ValidatorModeTransitionLogger(org.hyperledger.besu.consensus.qbft.validator.ValidatorModeTransitionLogger) TestTransitions(org.hyperledger.besu.consensus.common.bft.inttest.TestTransitions) QbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec) QbftBlockCreatorFactory(org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory) TreeMap(java.util.TreeMap) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) SynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.SynchronizerUpdater) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip) TestClock(org.hyperledger.besu.testutil.TestClock) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) BftFork(org.hyperledger.besu.config.BftFork) MessageTracker(org.hyperledger.besu.consensus.common.bft.MessageTracker) Instant(java.time.Instant) QbftConfigOptions(org.hyperledger.besu.config.QbftConfigOptions) BlockValidatorProvider(org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidatorProvider) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) Collectors(java.util.stream.Collectors) JsonQbftConfigOptions(org.hyperledger.besu.config.JsonQbftConfigOptions) List(java.util.List) TransactionValidatorProvider(org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) NodeKey(org.hyperledger.besu.crypto.NodeKey) HashMap(java.util.HashMap) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) InMemoryKeyValueStorageProvider.createInMemoryBlockchain(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) QbftForksSchedulesFactory(org.hyperledger.besu.consensus.qbft.QbftForksSchedulesFactory) EpochManager(org.hyperledger.besu.consensus.common.EpochManager) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) StubGenesisConfigOptions(org.hyperledger.besu.config.StubGenesisConfigOptions) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) QbftBlockHeightManagerFactory(org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Clock(java.time.Clock) BftHelpers(org.hyperledger.besu.consensus.common.bft.BftHelpers) Collections(java.util.Collections) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) Address(org.hyperledger.besu.datatypes.Address) ArrayList(java.util.ArrayList) UniqueMessageMulticaster(org.hyperledger.besu.consensus.common.bft.UniqueMessageMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) StubbedSynchronizerUpdater(org.hyperledger.besu.consensus.common.bft.inttest.StubbedSynchronizerUpdater) StubValidatorMulticaster(org.hyperledger.besu.consensus.common.bft.inttest.StubValidatorMulticaster) DefaultValidatorPeer(org.hyperledger.besu.consensus.common.bft.inttest.DefaultValidatorPeer) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) MessageFactory(org.hyperledger.besu.consensus.qbft.payload.MessageFactory) NetworkLayout(org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout) IOException(java.io.IOException) TreeMap(java.util.TreeMap) NodeParams(org.hyperledger.besu.consensus.common.bft.inttest.NodeParams) Gossiper(org.hyperledger.besu.consensus.common.bft.Gossiper) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) QbftGossip(org.hyperledger.besu.consensus.qbft.QbftGossip)

Example 5 with BftEventQueue

use of org.hyperledger.besu.consensus.common.bft.BftEventQueue in project besu by hyperledger.

the class TransitionsTest method transitionsBlockPeriod.

@Test
public void transitionsBlockPeriod() throws InterruptedException {
    final TestClock clock = new TestClock(Instant.EPOCH);
    final List<QbftFork> qbftForks = List.of(new QbftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.BLOCK_PERIOD_SECONDS_KEY, 10))), new QbftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 2, BftFork.BLOCK_PERIOD_SECONDS_KEY, 20))));
    final BftEventQueue bftEventQueue = new BftEventQueue(TestContextBuilder.MESSAGE_QUEUE_LIMIT);
    final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).validatorCount(1).clock(clock).qbftForks(qbftForks).eventQueue(bftEventQueue).buildAndStart();
    clock.stepMillis(10_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
    clock.stepMillis(20_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
    final BlockHeader blockHeader1 = context.getBlockchain().getBlockHeader(1).get();
    final BlockHeader blockHeader2 = context.getBlockchain().getBlockHeader(2).get();
    assertThat(blockHeader1.getTimestamp()).isEqualTo(genesisBlock.getTimestamp() + 10);
    assertThat(blockHeader2.getTimestamp()).isEqualTo(blockHeader1.getTimestamp() + 20);
}
Also used : TestClock(org.hyperledger.besu.testutil.TestClock) QbftFork(org.hyperledger.besu.config.QbftFork) TestContext(org.hyperledger.besu.consensus.qbft.support.TestContext) TestContextBuilder(org.hyperledger.besu.consensus.qbft.support.TestContextBuilder) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) Test(org.junit.jupiter.api.Test)

Aggregations

BftEventQueue (org.hyperledger.besu.consensus.common.bft.BftEventQueue)6 BftFork (org.hyperledger.besu.config.BftFork)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 TestClock (org.hyperledger.besu.testutil.TestClock)3 Iterables (com.google.common.collect.Iterables)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Clock (java.time.Clock)2 Instant (java.time.Instant)2 ZoneId (java.time.ZoneId)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Bytes (org.apache.tuweni.bytes.Bytes)2 QbftFork (org.hyperledger.besu.config.QbftFork)2 StubGenesisConfigOptions (org.hyperledger.besu.config.StubGenesisConfigOptions)2