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()));
}
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()));
}
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()));
}
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()));
}
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()));
}
Aggregations