Search in sources :

Example 86 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method processBlockMessageUsingProcessor.

@Test
public void processBlockMessageUsingProcessor() {
    SimplePeer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(1, sbp.getBlocks().size());
    Assert.assertSame(block, sbp.getBlocks().get(0));
    Assert.assertFalse(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
    pscoring = scoring.getPeerScoring(sender.getAddress());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 87 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method processStatusMessageWithKnownBestBlock.

@Test
public void processStatusMessageWithKnownBestBlock() {
    final World world = new World();
    final Blockchain blockchain = world.getBlockChain();
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    final SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), null, new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    final NodeMessageHandler handler = new NodeMessageHandler(config, bp, syncProcessor, null, null, null, mock(StatusResolver.class));
    BlockGenerator blockGenerator = new BlockGenerator();
    final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
    final Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), blockchain.getTotalDifficulty());
    final Message message = new StatusMessage(status);
    store.saveBlock(block);
    handler.processMessage(sender, message);
    Assert.assertNotNull(sender.getMessages());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) BlockStore(org.ethereum.db.BlockStore) SimplePeer(co.rsk.net.simples.SimplePeer) PeersInformation(co.rsk.net.sync.PeersInformation) Test(org.junit.Test)

Example 88 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method postBlockMessageTwice.

@Test
public void postBlockMessageTwice() throws InterruptedException, UnknownHostException {
    Peer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    processor.postMessage(sender, message);
    processor.postMessage(sender, message);
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.REPEATED_MESSAGE));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimplePeer(co.rsk.net.simples.SimplePeer) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 89 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method processStatusMessageUsingNodeBlockProcessor.

@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void processStatusMessageUsingNodeBlockProcessor() throws UnknownHostException {
    final World world = new World();
    final Blockchain blockchain = world.getBlockChain();
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, mock(StatusResolver.class));
    BlockGenerator blockGenerator = new BlockGenerator();
    final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
    final Status status = new Status(block.getNumber(), block.getHash().getBytes());
    final Message message = new StatusMessage(status);
    handler.processMessage(sender, message);
    Assert.assertNotNull(sender.getGetBlockMessages());
    Assert.assertEquals(1, sender.getGetBlockMessages().size());
    final Message msg = sender.getGetBlockMessages().get(0);
    Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, msg.getMessageType());
    final GetBlockMessage gbMessage = (GetBlockMessage) msg;
    Assert.assertArrayEquals(block.getHash().getBytes(), gbMessage.getBlockHash());
}
Also used : World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 90 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processBlockRequestMessageUsingBlockInStore.

@Test
public void processBlockRequestMessageUsingBlockInStore() {
    final Block block = new BlockGenerator().getBlock(3);
    final Keccak256 blockHash = block.getHash();
    final NetBlockStore store = new NetBlockStore();
    store.saveBlock(block);
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final SimplePeer sender = new SimplePeer();
    Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
    processor.processBlockRequest(sender, 100, block.getHash().getBytes());
    Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).contains(sender.getPeerNodeID()));
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.BLOCK_RESPONSE_MESSAGE, message.getMessageType());
    final BlockResponseMessage bMessage = (BlockResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

SimplePeer (co.rsk.net.simples.SimplePeer)109 Test (org.junit.Test)108 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)81 TestSystemProperties (co.rsk.config.TestSystemProperties)68 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)54 Blockchain (org.ethereum.core.Blockchain)49 Block (org.ethereum.core.Block)46 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)41 BlockStore (org.ethereum.db.BlockStore)28 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)26 EthereumListener (org.ethereum.listener.EthereumListener)26 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)19 PeerScoringManager (co.rsk.scoring.PeerScoringManager)16 Keccak256 (co.rsk.crypto.Keccak256)13 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)13 ChannelManager (org.ethereum.net.server.ChannelManager)11 PeerScoring (co.rsk.scoring.PeerScoring)10 World (co.rsk.test.World)8 Ignore (org.junit.Ignore)7 BlockBuilder (co.rsk.test.builders.BlockBuilder)6