use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.
the class TwoAsyncNodeTest method createNode.
private static SimpleAsyncNode createNode(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);
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 TwoAsyncNodeUsingSyncProcessorTest method syncInMultipleStepsWithLongBlockchain.
@Test
public void syncInMultipleStepsWithLongBlockchain() {
Blockchain b1 = BlockChainBuilder.ofSize(300, false);
Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 4000, false);
SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
Assert.assertEquals(300, node1.getBestBlock().getNumber());
Assert.assertEquals(4300, node2.getBestBlock().getNumber());
for (int i = 0; i < 5; i++) {
int skippedChunks = 300 / 192;
int expectedBestBlockNumber = Math.min(4300, 192 * skippedChunks + 192 * 6 * (i + 1));
long currentBestBlock = node1.getBestBlock().getNumber();
// at the beginning and the end we might have different number of blocks to download
int blocksToDownload = Math.toIntExact(expectedBestBlockNumber - currentBestBlock);
node2.sendFullStatusTo(node1);
node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(4300, currentBestBlock, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// request bodies
node1.waitExactlyNTasksWithTimeout(blocksToDownload);
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(expectedBestBlockNumber, node1.getBestBlock().getNumber());
Assert.assertEquals(4300, node2.getBestBlock().getNumber());
// this prevents node2's queue to get full
node2.clearQueue();
}
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 TwoAsyncNodeUsingSyncProcessorTest method sendNewBlock.
@Test
public void sendNewBlock() throws InterruptedException {
SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(1, false, true);
SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
node2.receiveMessageFrom(node1, new NewBlockHashMessage(node1.getBestBlock().getHash().getBytes()));
// process new block hash
node2.waitUntilNTasksWithTimeout(1);
// process block response
node2.waitExactlyNTasksWithTimeout(1);
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertEquals(1, node1.getBestBlock().getNumber());
Assert.assertEquals(1, node2.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
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 TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainAndSynchronize400Blocks.
@Test
public void buildBlockchainAndSynchronize400Blocks() throws InterruptedException {
SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(400, false, true);
SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
node1.sendFullStatusTo(node2);
// sync setup
node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(400, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// get blocks
node2.waitExactlyNTasksWithTimeout(400);
node1.joinWithTimeout();
node2.joinWithTimeout();
Assert.assertEquals(400, node1.getBestBlock().getNumber());
Assert.assertEquals(400, node2.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
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 TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainAndSynchronize.
@Test
public void buildBlockchainAndSynchronize() throws InterruptedException {
SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(100, false, true);
SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
node1.sendFullStatusTo(node2);
// sync setup
node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(100, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// 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());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Aggregations