Search in sources :

Example 16 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers200Different.

@Test
public void synchronizeNewNodeWithTwoPeers200Different() {
    Blockchain b1 = BlockChainBuilder.ofSize(193, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 7);
    Blockchain b3 = BlockChainBuilder.ofSize(0, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b2);
    SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 1, 1, 20, 192);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b3, syncConfiguration);
    Assert.assertEquals(193, 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);
    node3.waitUntilNTasksWithTimeout(setupRequests);
    // synchronize 200 new blocks (extra tasks are from old sync protocol messages)
    node3.waitExactlyNTasksWithTimeout(192 + setupRequests - 2);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(200, node3.getBestBlock().getNumber());
    Assert.assertEquals(node2.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 17 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithBestChain.

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

Example 18 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers.

@Test
public void synchronizeNewNodeWithTwoPeers() {
    Blockchain b1 = BlockChainBuilder.ofSize(30, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 43, 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(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(0, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(30, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 30 new blocks from node 1
    node3.waitExactlyNTasksWithTimeout(30);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(30, node3.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
    node2.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(73, 30, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 43 new blocks from node 2
    node3.waitExactlyNTasksWithTimeout(43);
    Assert.assertEquals(node2.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(73, 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) Test(org.junit.Test)

Example 19 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method dontSynchronizeNodeWithShorterChainAndThenSynchronizeWithNewPeer.

@Test
public void dontSynchronizeNodeWithShorterChainAndThenSynchronizeWithNewPeer() throws InterruptedException {
    Blockchain b1 = BlockChainBuilder.ofSize(30, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 43, true);
    Blockchain b3 = BlockChainBuilder.copyAndExtend(b2, 7, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b3, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node2);
    // receive status, do nothing
    node2.waitExactlyNTasksWithTimeout(1);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, node3.getBestBlock().getNumber());
    node3.sendFullStatusTo(node2);
    // sync setup
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(80, 73, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 7 new blocks from node 3
    node2.waitExactlyNTasksWithTimeout(7);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(80, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, node3.getBestBlock().getNumber());
    Assert.assertEquals(node2.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) Test(org.junit.Test)

Example 20 with SimpleAsyncNode

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

the class ThreeAsyncNodeUsingSyncProcessorTest method acceptNewBlockHashWhenNotSyncing.

@Test
public void acceptNewBlockHashWhenNotSyncing() {
    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);
    // 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());
    // receive the hash of a better block than node1's best
    // after syncing with node1
    node3.receiveMessageFrom(node2, new NewBlockHashMessage(node2.getBestBlock().getHash().getBytes()));
    // receive block hash, then receive block
    node3.waitExactlyNTasksWithTimeout(2);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(31, node2.getBestBlock().getNumber());
    Assert.assertEquals(31, 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)

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