Search in sources :

Example 1 with PeerScoring

use of co.rsk.scoring.PeerScoring 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 PeerScoring

use of co.rsk.scoring.PeerScoring in project rskj by rsksmart.

the class NodeMessageHandlerTest method skipProcessGenesisBlock.

@Test
public void skipProcessGenesisBlock() throws UnknownHostException {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new DummyBlockValidationRule());
    Block block = new BlockGenerator().getGenesisBlock();
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(0, sbp.getBlocks().size());
    Assert.assertTrue(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertTrue(pscoring.isEmpty());
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 3 with PeerScoring

use of co.rsk.scoring.PeerScoring in project rskj by rsksmart.

the class NodeMessageHandlerTest method skipAdvancedBlock.

@Test
public void skipAdvancedBlock() throws UnknownHostException {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    sbp.setBlockGap(100000);
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new DummyBlockValidationRule());
    Block block = new BlockGenerator().createBlock(200000, 0);
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(0, sbp.getBlocks().size());
    Assert.assertTrue(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertTrue(pscoring.isEmpty());
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 4 with PeerScoring

use of co.rsk.scoring.PeerScoring 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 5 with PeerScoring

use of co.rsk.scoring.PeerScoring in project rskj by rsksmart.

the class RskMockFactory method getPeerScoringManager.

public static PeerScoringManager getPeerScoringManager() {
    PeerScoringManager peerScoringManager = mock(PeerScoringManager.class);
    when(peerScoringManager.hasGoodReputation(isA(NodeID.class))).thenReturn(true);
    when(peerScoringManager.getPeerScoring(isA(NodeID.class))).thenReturn(new PeerScoring());
    return peerScoringManager;
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) NodeID(co.rsk.net.NodeID)

Aggregations

PeerScoring (co.rsk.scoring.PeerScoring)10 PeerScoringManager (co.rsk.scoring.PeerScoringManager)10 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)9 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)9 Test (org.junit.Test)8 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 TxHandler (co.rsk.net.handler.TxHandler)3 SimpleTransactionPool (co.rsk.net.simples.SimpleTransactionPool)3 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)3 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)3 RepositoryImpl (co.rsk.db.RepositoryImpl)1 NodeID (co.rsk.net.NodeID)1 TxHandlerImpl (co.rsk.net.handler.TxHandlerImpl)1 World (co.rsk.test.World)1 BigInteger (java.math.BigInteger)1 CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)1 Ignore (org.junit.Ignore)1