Search in sources :

Example 26 with SimpleAsyncNode

use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.

the class TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainWithUnclesAndSynchronize.

@Test
public void buildBlockchainWithUnclesAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(10, true, true);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    node1.sendFullStatusTo(node2);
    // find connection point
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(10, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // get blocks
    node2.waitExactlyNTasksWithTimeout(10);
    node2.sendFullStatusTo(node1);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, 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()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Test(org.junit.Test)

Example 27 with SimpleAsyncNode

use of co.rsk.net.simples.SimpleAsyncNode in project rskj by rsksmart.

the class TwoAsyncNodeUsingSyncProcessorTest method buildBlockchainPartialAndSynchronize.

@Test
public void buildBlockchainPartialAndSynchronize() throws InterruptedException {
    SimpleAsyncNode node1 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNodeWithWorldBlockChain(0, false, true);
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10, 0, false, true, null);
    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);
        }
    }
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(5, node2.getBestBlock().getNumber());
    node1.sendFullStatusTo(node2);
    // find connection point
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(10, 5, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // get blocks
    node2.waitExactlyNTasksWithTimeout(5);
    // drain node 1 for next test
    node1.clearQueue();
    node2.sendFullStatusTo(node1);
    // receive status, do nothing
    node1.waitExactlyNTasksWithTimeout(1);
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, 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()));
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)27 Test (org.junit.Test)24 Blockchain (org.ethereum.core.Blockchain)14 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)6 Block (org.ethereum.core.Block)6 BlockMessage (co.rsk.net.messages.BlockMessage)4 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)3 World (co.rsk.test.World)3 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)3 Ignore (org.junit.Ignore)3 RskSystemProperties (co.rsk.config.RskSystemProperties)1 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 BodyResponseMessage (co.rsk.net.messages.BodyResponseMessage)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)1