use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class SyncProcessorTest method findConnectionPointBlockchainWith30BlocksVsBlockchainWith100Blocks.
@Test
public void findConnectionPointBlockchainWith30BlocksVsBlockchainWith100Blocks() {
BlockChainBuilder builder = new BlockChainBuilder();
Blockchain blockchain = builder.ofSize(30);
org.ethereum.db.BlockStore blockStore = builder.getBlockStore();
Blockchain advancedBlockchain = BlockChainBuilder.copyAndExtend(blockchain, 70);
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
final ChannelManager channelManager = mock(ChannelManager.class);
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(sender));
NetBlockStore store = new NetBlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SyncProcessor processor = new SyncProcessor(blockchain, blockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(channelManager, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
Status status = StatusUtils.fromBlockchain(advancedBlockchain);
processor.processStatus(sender, status);
List<Message> messages = sender.getMessages();
BlockHeadersRequestMessage requestMessage = (BlockHeadersRequestMessage) messages.get(0);
processor.processBlockHeadersResponse(sender, new BlockHeadersResponseMessage(requestMessage.getId(), Collections.singletonList(advancedBlockchain.getBestBlock().getHeader())));
long[] binarySearchHeights = new long[] { 50, 25, 37, 31, 28, 29, 30, 30 };
for (int k = 0; k < binarySearchHeights.length; k++) {
Assert.assertEquals(k + 2, messages.size());
Message message = messages.get(k + 1);
Assert.assertEquals(MessageType.BLOCK_HASH_REQUEST_MESSAGE, message.getMessageType());
BlockHashRequestMessage request = (BlockHashRequestMessage) message;
long requestId = request.getId();
Assert.assertEquals(binarySearchHeights[k], request.getHeight());
Block block = advancedBlockchain.getBlockByNumber(binarySearchHeights[k]);
processor.processBlockHashResponse(sender, new BlockHashResponseMessage(requestId, block.getHash().getBytes()));
}
Assert.assertEquals(binarySearchHeights.length + 2, messages.size());
Message message = messages.get(messages.size() - 1);
Assert.assertEquals(MessageType.SKELETON_REQUEST_MESSAGE, message.getMessageType());
SkeletonRequestMessage request = (SkeletonRequestMessage) message;
Assert.assertEquals(30, request.getStartNumber());
Assert.assertEquals(1, processor.getExpectedResponses().size());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(Ethereum eth, Blockchain blockchain, RepositoryLocator repositoryLocator, TransactionPool transactionPool, BlockStore blockStore, BlockProcessor nodeBlockProcessor, ConfigCapabilities configCapabilities, ReceiptStore receiptStore) {
MiningMainchainView miningMainchainViewMock = mock(MiningMainchainView.class);
ExecutionBlockRetriever executionBlockRetriever = mock(ExecutionBlockRetriever.class);
wallet = WalletFactory.createWallet();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
ReversibleTransactionExecutor executor = new ReversibleTransactionExecutor(repositoryLocator, buildTransactionExecutorFactory(blockStore, null));
Web3InformationRetriever retriever = new Web3InformationRetriever(transactionPool, blockchain, repositoryLocator, executionBlockRetriever);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, executor, new ExecutionBlockRetriever(miningMainchainViewMock, blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet), new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, transactionGateway), new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
RskModule rskModule = new RskModuleImpl(blockchain, blockStore, receiptStore, retriever);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, rskModule, channelManager, null, null, blockStore, receiptStore, null, nodeBlockProcessor, null, configCapabilities, new BuildInfo("test", "test"), null, retriever, syncProcessor);
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class DecidingSyncStateTest method startsSyncingWith5NonRepeatedPeers.
@Test
public void startsSyncingWith5NonRepeatedPeers() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation();
ChannelManager channelManager = RskMockFactory.getChannelManager();
PeersInformation knownPeers = new PeersInformation(syncInformation, channelManager, syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Collection<Channel> peers = new ArrayList<>();
NodeID peerToRepeat = new NodeID(HashUtil.randomPeerId());
Channel channel = mock(Channel.class);
when(channel.getNodeId()).thenReturn(peerToRepeat);
peers.add(channel);
for (int i = 0; i < 10; i++) {
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
knownPeers.registerPeer(peerToRepeat).setStatus(StatusUtils.getFakeStatus());
syncState.newPeerStatus();
}
for (int i = 0; i < 4; i++) {
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
NodeID nodeID = new NodeID(HashUtil.randomPeerId());
knownPeers.registerPeer(nodeID).setStatus(StatusUtils.getFakeStatus());
channel = mock(Channel.class);
when(channel.getNodeId()).thenReturn(nodeID);
peers.add(channel);
when(channelManager.getActivePeers()).thenReturn(peers);
syncState.newPeerStatus();
}
Assert.assertTrue(syncEventsHandler.startSyncingWasCalled());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(SimpleEthereum eth, PeerServer peerServer) {
wallet = WalletFactory.createWallet();
Blockchain blockchain = Web3Mocks.getMockBlockchain();
BlockStore blockStore = Web3Mocks.getMockBlockStore();
MiningMainchainView mainchainView = new MiningMainchainViewImpl(blockStore, 449);
TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, null);
EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, null, new ExecutionBlockRetriever(mainchainView, blockchain, null, null), null, new EthModuleWalletEnabled(wallet), null, new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule txPoolModule = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, null, channelManager, null, null, null, null, peerServer, null, null, null, null, null, new Web3InformationRetriever(transactionPool, blockchain, mock(RepositoryLocator.class), mock(ExecutionBlockRetriever.class)), null);
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class Web3ImplTest method createWeb3CallNoReturn.
private Web3Impl createWeb3CallNoReturn(Ethereum eth, Blockchain blockchain, RepositoryLocator repositoryLocator, TransactionPool transactionPool, BlockStore blockStore, BlockProcessor nodeBlockProcessor, ConfigCapabilities configCapabilities, ReceiptStore receiptStore) {
MiningMainchainView miningMainchainViewMock = mock(MiningMainchainView.class);
ExecutionBlockRetriever executionBlockRetriever = mock(ExecutionBlockRetriever.class);
wallet = WalletFactory.createWallet();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
ProgramResult res = new ProgramResult();
res.setHReturn(new byte[0]);
when(executor.executeTransaction(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(res);
Web3InformationRetriever retriever = new Web3InformationRetriever(transactionPool, blockchain, repositoryLocator, executionBlockRetriever);
EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, executor, new ExecutionBlockRetriever(miningMainchainViewMock, blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet), new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, null), new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
RskModule rskModule = new RskModuleImpl(blockchain, blockStore, receiptStore, retriever);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, rskModule, channelManager, null, null, blockStore, receiptStore, null, nodeBlockProcessor, null, configCapabilities, new BuildInfo("test", "test"), null, retriever, null);
}
Aggregations