Search in sources :

Example 21 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodesInAChain.

@Test
public void synchronizeNewNodesInAChain() throws InterruptedException {
    SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(100, false, true);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    Assert.assertEquals(100, node1.getBestBlock().getNumber());
    Assert.assertEquals(0, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node2);
    // sync setup
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(100, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 100 new blocks from node 1
    node2.waitExactlyNTasksWithTimeout(100);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(100, node1.getBestBlock().getNumber());
    Assert.assertEquals(100, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node2.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(100, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 100 new blocks from node 2
    node3.waitExactlyNTasksWithTimeout(100);
    Assert.assertEquals(100, node1.getBestBlock().getNumber());
    Assert.assertEquals(100, node2.getBestBlock().getNumber());
    Assert.assertEquals(100, node3.getBestBlock().getNumber());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
    Assert.assertEquals(node2.getBestBlock().getHash(), node3.getBestBlock().getHash());
    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(node3.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Test(org.junit.Test)

Example 22 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeWithTwoPeers200AndOneFails.

@Test
public void synchronizeWithTwoPeers200AndOneFails() {
    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, 0, 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.waitUntilNTasksWithTimeout(5);
    // synchronize 200 (extra tasks are from old sync protocol messages)
    BodyResponseMessage response = new BodyResponseMessage(new Random().nextLong(), null, null);
    node3.getSyncProcessor().registerExpectedMessage(response);
    node3.getSyncProcessor().processBodyResponse(node1.getMessageChannel(node3), response);
    node3.waitExactlyNTasksWithTimeout(200 + setupRequests - 15);
    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 : BodyResponseMessage(co.rsk.net.messages.BodyResponseMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Random(java.util.Random) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 23 with SimpleAsyncNode

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

the class TwoAsyncNodeTest method buildBlockchainPartialAndSynchronize.

@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = createNode(0);
    SimpleAsyncNode node2 = createNode(0);
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    for (Block block : blocks) {
        BlockMessage message = new BlockMessage(block);
        node1.receiveMessageFrom(null, message);
        node1.waitExactlyNTasksWithTimeout(1);
        if (block.getNumber() <= 5) {
            node2.receiveMessageFrom(null, message);
            node2.waitExactlyNTasksWithTimeout(1);
        }
    }
    node1.sendStatusTo(node2);
    node2.waitUntilNTasksWithTimeout(1);
    node1.waitExactlyNTasksWithTimeout(5);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with SimpleAsyncNode

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

the class TwoAsyncNodeTest method createNodeWithUncles.

private static SimpleAsyncNode createNodeWithUncles(int size) {
    final World world = new World();
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = world.getBlockChain();
    List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size, 0, true);
    for (Block b : blocks) blockchain.tryToConnect(b);
    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);
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, null, null, null, null, null, new DummyBlockValidationRule());
    return new SimpleAsyncNode(handler);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 25 with SimpleAsyncNode

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

the class TwoAsyncNodeTest method buildBlockchainWithUnclesAndSynchronize.

@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void buildBlockchainWithUnclesAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = createNodeWithUncles(10);
    SimpleAsyncNode node2 = createNode(0);
    node1.sendStatusTo(node2);
    // status
    node2.waitUntilNTasksWithTimeout(1);
    // get blocks
    node2.waitExactlyNTasksWithTimeout(10);
    node2.sendStatusTo(node1);
    // status
    node1.waitUntilNTasksWithTimeout(1);
    // get blocks
    node1.waitExactlyNTasksWithTimeout(10);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Ignore(org.junit.Ignore) 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