Search in sources :

Example 1 with SimpleAsyncNode

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

the class OneAsyncNodeTest method buildBlockchainInReverse.

@Test
public void buildBlockchainInReverse() throws InterruptedException {
    SimpleAsyncNode node = createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    List<Block> reverse = new ArrayList<>();
    for (Block block : blocks) reverse.add(0, block);
    for (Block block : reverse) 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) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 2 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method ignoreNewBlockHashesWhenSyncing.

@Test
public void ignoreNewBlockHashesWhenSyncing() {
    Blockchain b1 = BlockChainBuilder.ofSize(30, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 1, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNodeWithBlockChainBuilder(0);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(31, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node3);
    // receive the hash of a better block than node1's best
    // while it's syncing with node1
    node3.receiveMessageFrom(node2, new NewBlockHashMessage(node2.getBestBlock().getHash().getBytes()));
    // receive and ignore NewBlockHashMessage
    node3.waitUntilNTasksWithTimeout(1);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(30, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 30 new blocks from node 1
    node3.waitExactlyNTasksWithTimeout(30);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(31, node2.getBestBlock().getNumber());
    Assert.assertEquals(30, node3.getBestBlock().getNumber());
    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) NewBlockHashMessage(co.rsk.net.messages.NewBlockHashMessage) Test(org.junit.Test)

Example 3 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method dontSynchronizeNodeWithShorterChain.

@Test
public void dontSynchronizeNodeWithShorterChain() throws InterruptedException {
    SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(50, false, true);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(30, false, true);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    Assert.assertEquals(50, node1.getBestBlock().getNumber());
    Assert.assertEquals(30, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(50, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 50 new blocks from node 1
    node3.waitExactlyNTasksWithTimeout(50);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(50, node1.getBestBlock().getNumber());
    Assert.assertEquals(30, node2.getBestBlock().getNumber());
    Assert.assertEquals(50, node3.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
    node2.sendFullStatusTo(node3);
    // receive status, do nothing
    node3.waitExactlyNTasksWithTimeout(1);
    Assert.assertEquals(50, node1.getBestBlock().getNumber());
    Assert.assertEquals(30, node2.getBestBlock().getNumber());
    Assert.assertEquals(50, node3.getBestBlock().getNumber());
    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) Test(org.junit.Test)

Example 4 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithThreePeers400Different.

@Test
public void synchronizeNewNodeWithThreePeers400Different() {
    Blockchain b1 = BlockChainBuilder.ofSize(0, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 200);
    Blockchain b3 = BlockChainBuilder.copyAndExtend(b2, 200);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b2);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b2);
    SimpleAsyncNode node3 = SimpleAsyncNode.createDefaultNode(b3);
    SyncConfiguration syncConfiguration = new SyncConfiguration(3, 1, 10, 100, 20, 192);
    SimpleAsyncNode node4 = SimpleAsyncNode.createNode(b1, syncConfiguration);
    Assert.assertEquals(200, node1.getBestBlock().getNumber());
    Assert.assertEquals(200, node2.getBestBlock().getNumber());
    Assert.assertEquals(400, node3.getBestBlock().getNumber());
    Assert.assertEquals(0, node4.getBestBlock().getNumber());
    node1.sendFullStatusTo(node4);
    node2.sendFullStatusTo(node4);
    node3.sendFullStatusTo(node4);
    // sync setup
    int setupRequests = SyncUtils.syncSetupRequests(400, 0, syncConfiguration);
    node4.waitUntilNTasksWithTimeout(setupRequests);
    // synchronize 50 new blocks from node 1
    node4.waitExactlyNTasksWithTimeout(400 + setupRequests - 10);
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(400, node4.getBestBlock().getNumber());
    Assert.assertEquals(node4.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    node3.joinWithTimeout();
    node4.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
    Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node4.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 5 with SimpleAsyncNode

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

the class TwoAsyncNodeTest method buildBlockchainAndSynchronize.

@Test
@Ignore("This should be reviewed with sync processor or deleted")
public void buildBlockchainAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = createNode(100);
    SimpleAsyncNode node2 = createNode(0);
    node1.sendStatusTo(node2);
    // status
    node2.waitUntilNTasksWithTimeout(1);
    // get blocks
    node2.waitExactlyNTasksWithTimeout(100);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(100, node1.getBestBlock().getNumber());
    Assert.assertEquals(100, 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