Search in sources :

Example 1 with SimpleChannelManager

use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.

the class NodeMessageHandlerTest method processTooMuchGasTransactionMessage.

@Test
public void processTooMuchGasTransactionMessage() throws UnknownHostException {
    PeerScoringManager scoring = createPeerScoringManager();
    final SimpleChannelManager channelManager = new SimpleChannelManager();
    final World world = new World();
    final Blockchain blockchain = world.getBlockChain();
    TransactionPool state = mock(TransactionPool.class);
    BlockProcessor blockProcessor = mock(BlockProcessor.class);
    Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
    TxHandler txHandler = new TxHandlerImpl(config, mock(CompositeEthereumListener.class), mock(RepositoryImpl.class), blockchain);
    final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, state, txHandler, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    final List<Transaction> txs = new ArrayList<>();
    BigInteger value = BigInteger.ONE;
    BigInteger nonce = BigInteger.ZERO;
    BigInteger gasPrice = BigInteger.ONE;
    BigInteger gasLimit = BigDecimal.valueOf(Math.pow(2, 60)).add(BigDecimal.ONE).toBigInteger();
    txs.add(TransactionUtils.createTransaction(TransactionUtils.getPrivateKeyBytes(), TransactionUtils.getAddress(), value, nonce, gasPrice, gasLimit));
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Assert.assertNotNull(channelManager.getTransactions());
    Assert.assertEquals(0, channelManager.getTransactions().size());
    Assert.assertFalse(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    // besides this
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_TRANSACTION));
}
Also used : SimpleTransactionPool(co.rsk.net.simples.SimpleTransactionPool) TxHandler(co.rsk.net.handler.TxHandler) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) World(co.rsk.test.World) TxHandlerImpl(co.rsk.net.handler.TxHandlerImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) RepositoryImpl(co.rsk.db.RepositoryImpl) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 2 with SimpleChannelManager

use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.

the class NodeMessageHandlerTest method processTransactionsMessageUsingTransactionPool.

@Test
public void processTransactionsMessageUsingTransactionPool() throws UnknownHostException {
    final SimpleTransactionPool transactionPool = new SimpleTransactionPool();
    final SimpleChannelManager channelManager = new SimpleChannelManager();
    TxHandler txmock = mock(TxHandler.class);
    BlockProcessor blockProcessor = mock(BlockProcessor.class);
    Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
    final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, transactionPool, txmock, RskMockFactory.getPeerScoringManager(), new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    sender.setPeerNodeID(new NodeID(new byte[] { 1 }));
    final SimpleMessageChannel sender2 = new SimpleMessageChannel();
    sender2.setPeerNodeID(new NodeID(new byte[] { 2 }));
    final List<Transaction> txs = TransactionUtils.getTransactions(10);
    Mockito.when(txmock.retrieveValidTxs(any(List.class))).thenReturn(txs);
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Assert.assertNotNull(channelManager.getTransactions());
    Assert.assertEquals(10, channelManager.getTransactions().size());
    for (int k = 0; k < 10; k++) Assert.assertSame(txs.get(k), channelManager.getTransactions().get(k));
    Assert.assertNotNull(channelManager.getLastSkip());
    Assert.assertEquals(1, channelManager.getLastSkip().size());
    Assert.assertTrue(channelManager.getLastSkip().contains(sender.getPeerNodeID()));
    channelManager.setLastSkip(null);
    handler.processMessage(sender2, message);
    Assert.assertNull(channelManager.getLastSkip());
}
Also used : TxHandler(co.rsk.net.handler.TxHandler) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) SimpleTransactionPool(co.rsk.net.simples.SimpleTransactionPool) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) Test(org.junit.Test)

Example 3 with SimpleChannelManager

use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.

the class NodeMessageHandlerTest method processRejectedTransactionsMessage.

@Test
public void processRejectedTransactionsMessage() throws UnknownHostException {
    PeerScoringManager scoring = createPeerScoringManager();
    final SimpleChannelManager channelManager = new SimpleChannelManager();
    TxHandler txmock = mock(TxHandler.class);
    TransactionPool state = mock(TransactionPool.class);
    BlockProcessor blockProcessor = mock(BlockProcessor.class);
    Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
    final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, state, txmock, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    final List<Transaction> txs = TransactionUtils.getTransactions(0);
    Mockito.when(txmock.retrieveValidTxs(any(List.class))).thenReturn(txs);
    final TransactionsMessage message = new TransactionsMessage(txs);
    handler.processMessage(sender, message);
    Assert.assertNotNull(channelManager.getTransactions());
    Assert.assertEquals(0, channelManager.getTransactions().size());
    Assert.assertTrue(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertTrue(pscoring.isEmpty());
    Assert.assertEquals(0, pscoring.getTotalEventCounter());
    Assert.assertEquals(0, pscoring.getEventCounter(EventType.INVALID_TRANSACTION));
}
Also used : SimpleTransactionPool(co.rsk.net.simples.SimpleTransactionPool) TxHandler(co.rsk.net.handler.TxHandler) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) Test(org.junit.Test)

Example 4 with SimpleChannelManager

use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.

the class NodeMessageHandlerUtil method createHandler.

public static NodeMessageHandler createHandler(BlockValidationRule validationRule) {
    final World world = new World();
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = world.getBlockChain();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), RskMockFactory.getChannelManager(), syncConfiguration, new DummyBlockValidationRule(), DIFFICULTY_CALCULATOR);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    return new NodeMessageHandler(config, processor, syncProcessor, new SimpleChannelManager(), null, null, RskMockFactory.getPeerScoringManager(), validationRule);
}
Also used : SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 5 with SimpleChannelManager

use of org.ethereum.rpc.Simples.SimpleChannelManager in project rskj by rsksmart.

the class SimpleAsyncNode method createNode.

public static SimpleAsyncNode createNode(Blockchain blockchain, SyncConfiguration syncConfiguration) {
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, peerScoringManager, channelManager, syncConfiguration, blockValidationRule, new DifficultyCalculator(config));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, peerScoringManager, blockValidationRule);
    return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule)

Aggregations

SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)7 TxHandler (co.rsk.net.handler.TxHandler)4 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)4 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)4 SimpleTransactionPool (co.rsk.net.simples.SimpleTransactionPool)4 PeerScoringManager (co.rsk.scoring.PeerScoringManager)4 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)4 Test (org.junit.Test)4 PeerScoring (co.rsk.scoring.PeerScoring)3 World (co.rsk.test.World)3 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)2 Blockchain (org.ethereum.core.Blockchain)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 TxHandlerImpl (co.rsk.net.handler.TxHandlerImpl)1 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)1 BigInteger (java.math.BigInteger)1 CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)1