Search in sources :

Example 61 with SyncConfiguration

use of co.rsk.net.sync.SyncConfiguration 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()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 62 with SyncConfiguration

use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers200Different.

@Test
public void synchronizeNewNodeWithTwoPeers200Different() {
    Blockchain b1 = BlockChainBuilder.ofSize(193, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 7);
    Blockchain b3 = BlockChainBuilder.ofSize(0, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b2);
    SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 1, 1, 20, 192);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b3, syncConfiguration);
    Assert.assertEquals(193, 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);
    node3.waitUntilNTasksWithTimeout(setupRequests);
    // synchronize 200 new blocks (extra tasks are from old sync protocol messages)
    node3.waitExactlyNTasksWithTimeout(192 + setupRequests - 2);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(200, node3.getBestBlock().getNumber());
    Assert.assertEquals(node2.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()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 63 with SyncConfiguration

use of co.rsk.net.sync.SyncConfiguration 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()));
}
Also used : BodyResponseMessage(co.rsk.net.messages.BodyResponseMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Random(java.util.Random) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 64 with SyncConfiguration

use of co.rsk.net.sync.SyncConfiguration 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);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 65 with SyncConfiguration

use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.

the class TwoNodeTest method createNode.

private static SimpleNode 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;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    NodeMessageHandler handler = new NodeMessageHandler(new RskSystemProperties(), processor, null, null, null, null, null, new DummyBlockValidationRule());
    return new SimpleNode(handler);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Aggregations

SyncConfiguration (co.rsk.net.sync.SyncConfiguration)65 Test (org.junit.Test)59 RskSystemProperties (co.rsk.config.RskSystemProperties)48 Blockchain (org.ethereum.core.Blockchain)47 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)42 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)36 Block (org.ethereum.core.Block)36 World (co.rsk.test.World)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 Ignore (org.junit.Ignore)10 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)9 Keccak256 (co.rsk.crypto.Keccak256)8 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)8 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)4 BlockDifficulty (co.rsk.core.BlockDifficulty)3 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 Nonnull (javax.annotation.Nonnull)2 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 TxHandler (co.rsk.net.handler.TxHandler)1