use of co.rsk.net.messages.NewBlockHashMessage in project rskj by rsksmart.
the class ThreeAsyncNodeUsingSyncProcessorTest method ignoreNewBlockHashesWhenSyncing.
@Test
public void ignoreNewBlockHashesWhenSyncing() {
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);
// receive the hash of a better block than node1's best
// while it's syncing with node1
node3.receiveMessageFrom(node2, new NewBlockHashMessage(node2.getBestBlock().getHash().getBytes()));
// receive and ignore NewBlockHashMessage
node3.waitUntilNTasksWithTimeout(1);
// 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());
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.messages.NewBlockHashMessage 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.messages.NewBlockHashMessage 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