use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class TwoAsyncNodeUsingSyncProcessorTest method stopSyncingAfter5SkeletonChunks.
@Test
public void stopSyncingAfter5SkeletonChunks() {
Blockchain b1 = BlockChainBuilder.ofSize(30, false);
Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 2000, false);
SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(30, node1.getBestBlock().getNumber());
Assert.assertEquals(2030, node2.getBestBlock().getNumber());
node2.sendFullStatusTo(node1);
// sync setup
node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(2030, 30, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// request bodies
node1.waitExactlyNTasksWithTimeout(1122);
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(1152, node1.getBestBlock().getNumber());
Assert.assertEquals(2030, node2.getBestBlock().getNumber());
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class OneAsyncNodeTest method createNode.
private static SimpleAsyncNode createNode() {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
RskSystemProperties config = new RskSystemProperties();
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);
SimpleChannelManager channelManager = new SimpleChannelManager();
SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), channelManager, syncConfiguration, new DummyBlockValidationRule(), new DifficultyCalculator(config));
NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, RskMockFactory.getPeerScoringManager(), new DummyBlockValidationRule());
return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class OneAsyncNodeTest method buildBlockchain.
@Test
public void buildBlockchain() throws InterruptedException {
SimpleAsyncNode node = createNode();
List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
for (Block block : blocks) 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());
}
use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeersDefault.
@Test
public void synchronizeNewNodeWithTwoPeersDefault() {
Blockchain b1 = BlockChainBuilder.ofSize(50, true);
Blockchain b2 = BlockChainBuilder.ofSize(0, true);
SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b1);
SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 1, 1, 20, 192);
SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b2, syncConfiguration);
Assert.assertEquals(50, node1.getBestBlock().getNumber());
Assert.assertEquals(50, node2.getBestBlock().getNumber());
Assert.assertEquals(0, node3.getBestBlock().getNumber());
node1.sendFullStatusTo(node3);
node2.sendFullStatusTo(node3);
// sync setup
node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(50, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// synchronize 50 new blocks from node 1
node3.waitExactlyNTasksWithTimeout(50 + 2);
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(50, 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 ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers200Default.
@Test
public void synchronizeNewNodeWithTwoPeers200Default() {
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, 1, 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.waitExactlyNTasksWithTimeout(200 + setupRequests - 10);
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()));
}
Aggregations