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