use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class NodeMessageHandlerTest method processTransactionsMessageDoesNothingBecauseNodeIsSyncing.
@Test
public void processTransactionsMessageDoesNothingBecauseNodeIsSyncing() {
ChannelManager channelManager = mock(ChannelManager.class);
TxHandler txHandler = mock(TxHandler.class);
BlockProcessor blockProcessor = mock(BlockProcessor.class);
Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(true);
final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, null, txHandler, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
Message message = mock(Message.class);
Mockito.when(message.getMessageType()).thenReturn(MessageType.TRANSACTIONS);
handler.processMessage(null, message);
verify(channelManager, never()).broadcastTransactionMessage(any(), any());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(Ethereum eth, Blockchain blockchain, TransactionPool transactionPool, BlockStore blockStore, BlockProcessor nodeBlockProcessor, ConfigCapabilities configCapabilities, ReceiptStore receiptStore) {
wallet = WalletFactory.createWallet();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
ReversibleTransactionExecutor executor = Mockito.mock(ReversibleTransactionExecutor.class);
ProgramResult res = new ProgramResult();
res.setHReturn(TypeConverter.stringHexToByteArray("0x0000000000000000000000000000000000000000000000000000000064617665"));
Mockito.when(executor.executeTransaction(Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any(), Matchers.any())).thenReturn(res);
EthModule ethModule = new EthModule(config, blockchain, executor, new ExecutionBlockRetriever(blockchain, null, null), new EthModuleSolidityDisabled(), new EthModuleWalletEnabled(config, eth, wallet, transactionPool));
TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, transactionPool, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, txPoolModule, channelManager, Web3Mocks.getMockRepository(), null, null, blockStore, receiptStore, null, nodeBlockProcessor, null, configCapabilities);
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class SyncProcessorTest method sendSkeletonRequest.
@Test
public void sendSkeletonRequest() {
Blockchain blockchain = new BlockChainBuilder().ofSize(100);
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
final ChannelManager channelManager = mock(ChannelManager.class);
Peer channel = mock(Peer.class);
when(channel.getPeerNodeID()).thenReturn(sender.getPeerNodeID());
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(channel));
SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), null, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), 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));
processor.sendSkeletonRequest(sender, 0);
Assert.assertFalse(sender.getMessages().isEmpty());
Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.SKELETON_REQUEST_MESSAGE, message.getMessageType());
SkeletonRequestMessage request = (SkeletonRequestMessage) message;
Assert.assertNotEquals(0, request.getId());
Assert.assertEquals(0, request.getStartNumber());
Assert.assertEquals(1, processor.getExpectedResponses().size());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class SyncProcessorTest method syncWithAdvancedPeerAfterTimeoutWaitingPeers.
@Test
public void syncWithAdvancedPeerAfterTimeoutWaitingPeers() {
final NetBlockStore store = new NetBlockStore();
BlockChainBuilder builder = new BlockChainBuilder();
Blockchain blockchain = builder.ofSize(0);
BlockStore blockStore = builder.getBlockStore();
byte[] hash = HashUtil.randomHash();
byte[] parentHash = HashUtil.randomHash();
Status status = new Status(100, hash, parentHash, blockchain.getTotalDifficulty().add(new BlockDifficulty(BigInteger.TEN)));
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
final ChannelManager channelManager = mock(ChannelManager.class);
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(sender));
SyncProcessor processor = new SyncProcessor(blockchain, blockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(channelManager, syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
processor.processStatus(sender, status);
Assert.assertEquals(1, processor.getPeersCount());
Assert.assertEquals(1, processor.getNoAdvancedPeers());
Set<NodeID> ids = processor.getKnownPeersNodeIDs();
Assert.assertFalse(ids.isEmpty());
Assert.assertTrue(ids.contains(sender.getPeerNodeID()));
List<Message> messages = sender.getMessages();
Assert.assertTrue(messages.isEmpty());
processor.onTimePassed(syncConfiguration.getTimeoutWaitingPeers().dividedBy(2));
Assert.assertTrue(messages.isEmpty());
processor.onTimePassed(syncConfiguration.getTimeoutWaitingPeers().dividedBy(2));
Assert.assertFalse(messages.isEmpty());
Assert.assertEquals(1, messages.size());
Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_REQUEST_MESSAGE, message.getMessageType());
BlockHeadersRequestMessage request = (BlockHeadersRequestMessage) message;
Assert.assertEquals(status.getBestBlockHash(), request.getHash());
}
use of org.ethereum.net.server.ChannelManager in project rskj by rsksmart.
the class SyncProcessorTest method processSkeletonResponseWithTenBlockIdentifiers.
@Test
public void processSkeletonResponseWithTenBlockIdentifiers() {
final NetBlockStore store = new NetBlockStore();
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
final ChannelManager channelManager = mock(ChannelManager.class);
Peer channel = mock(Peer.class);
when(channel.getPeerNodeID()).thenReturn(sender.getPeerNodeID());
when(channelManager.getActivePeers()).thenReturn(Collections.singletonList(channel));
SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), 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));
int connectionPoint = 0;
int step = 10;
int linkCount = 9;
processor.startDownloadingSkeleton(connectionPoint, sender);
List<BlockIdentifier> blockIdentifiers = buildSkeleton(blockchain, connectionPoint, step, linkCount);
SkeletonResponseMessage response = new SkeletonResponseMessage(new Random().nextLong(), blockIdentifiers);
processor.registerExpectedMessage(response);
processor.processSkeletonResponse(sender, response);
Assert.assertFalse(sender.getMessages().isEmpty());
Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_HEADERS_REQUEST_MESSAGE, message.getMessageType());
BlockHeadersRequestMessage request = (BlockHeadersRequestMessage) message;
Assert.assertArrayEquals(blockIdentifiers.get(1).getHash(), request.getHash());
Assert.assertEquals(10, request.getCount());
DownloadingHeadersSyncState syncState = (DownloadingHeadersSyncState) processor.getSyncState();
List<BlockIdentifier> skeleton = syncState.getSkeleton();
Assert.assertEquals(10, skeleton.size());
Assert.assertEquals(1, processor.getExpectedResponses().size());
}
Aggregations