use of org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout 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());
}
use of org.hyperledger.besu.consensus.common.bft.inttest.NetworkLayout 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);
}
Aggregations