Search in sources :

Example 11 with SimpleAsyncNode

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

the class TwoAsyncNodeUsingSyncProcessorTest method stopSyncingAfter5SkeletonChunks.

@Test
public void stopSyncingAfter5SkeletonChunks() {
    Blockchain b1 = BlockChainBuilder.ofSize(30, false);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 2000, false);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(2030, node2.getBestBlock().getNumber());
    node2.sendFullStatusTo(node1);
    // sync setup
    node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(2030, 30, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // request bodies
    node1.waitExactlyNTasksWithTimeout(1122);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(1152, node1.getBestBlock().getNumber());
    Assert.assertEquals(2030, node2.getBestBlock().getNumber());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) Test(org.junit.Test)

Example 12 with SimpleAsyncNode

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

the class OneAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode() {
    final World world = new World();
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = world.getBlockChain();
    RskSystemProperties config = new RskSystemProperties();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), channelManager, syncConfiguration, new DummyBlockValidationRule(), new DifficultyCalculator(config));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, RskMockFactory.getPeerScoringManager(), new DummyBlockValidationRule());
    return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 13 with SimpleAsyncNode

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

the class OneAsyncNodeTest method buildBlockchain.

@Test
public void buildBlockchain() throws InterruptedException {
    SimpleAsyncNode node = createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    for (Block block : blocks) node.receiveMessageFrom(null, new BlockMessage(block));
    node.waitExactlyNTasksWithTimeout(10);
    node.joinWithTimeout();
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 14 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeersDefault.

@Test
public void synchronizeNewNodeWithTwoPeersDefault() {
    Blockchain b1 = BlockChainBuilder.ofSize(50, true);
    Blockchain b2 = BlockChainBuilder.ofSize(0, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b1);
    SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 1, 1, 20, 192);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b2, syncConfiguration);
    Assert.assertEquals(50, node1.getBestBlock().getNumber());
    Assert.assertEquals(50, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node3);
    node2.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(50, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 50 new blocks from node 1
    node3.waitExactlyNTasksWithTimeout(50 + 2);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(50, node3.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    node3.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
    Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 15 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers200Default.

@Test
public void synchronizeNewNodeWithTwoPeers200Default() {
    Blockchain b1 = BlockChainBuilder.ofSize(200, true);
    Blockchain b2 = BlockChainBuilder.ofSize(0, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b1);
    SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 1, 1, 20, 192);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b2, syncConfiguration);
    Assert.assertEquals(200, node1.getBestBlock().getNumber());
    Assert.assertEquals(200, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node3);
    node2.sendFullStatusTo(node3);
    // sync setup
    int setupRequests = SyncUtils.syncSetupRequests(200, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    node3.waitUntilNTasksWithTimeout(setupRequests);
    node3.waitExactlyNTasksWithTimeout(200 + setupRequests - 10);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(200, node3.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    node3.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
    Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)27 Test (org.junit.Test)24 Blockchain (org.ethereum.core.Blockchain)14 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)6 Block (org.ethereum.core.Block)6 BlockMessage (co.rsk.net.messages.BlockMessage)4 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)3 World (co.rsk.test.World)3 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)3 Ignore (org.junit.Ignore)3 RskSystemProperties (co.rsk.config.RskSystemProperties)1 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 BodyResponseMessage (co.rsk.net.messages.BodyResponseMessage)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)1