Search in sources :

Example 71 with Blockchain

use of org.ethereum.core.Blockchain 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 72 with Blockchain

use of org.ethereum.core.Blockchain 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 73 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithTwoPeers.

@Test
public void synchronizeNewNodeWithTwoPeers() {
    Blockchain b1 = BlockChainBuilder.ofSize(30, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 43, 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(73, 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.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(30, node3.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
    node2.sendFullStatusTo(node3);
    // sync setup
    node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(73, 30, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 43 new blocks from node 2
    node3.waitExactlyNTasksWithTimeout(43);
    Assert.assertEquals(node2.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(73, 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()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) Test(org.junit.Test)

Example 74 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class ThreeAsyncNodeUsingSyncProcessorTest method dontSynchronizeNodeWithShorterChainAndThenSynchronizeWithNewPeer.

@Test
public void dontSynchronizeNodeWithShorterChainAndThenSynchronizeWithNewPeer() throws InterruptedException {
    Blockchain b1 = BlockChainBuilder.ofSize(30, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 43, true);
    Blockchain b3 = BlockChainBuilder.copyAndExtend(b2, 7, true);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b3, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, node3.getBestBlock().getNumber());
    node1.sendFullStatusTo(node2);
    // receive status, do nothing
    node2.waitExactlyNTasksWithTimeout(1);
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(73, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, node3.getBestBlock().getNumber());
    node3.sendFullStatusTo(node2);
    // sync setup
    node2.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(80, 73, SyncConfiguration.IMMEDIATE_FOR_TESTING));
    // synchronize 7 new blocks from node 3
    node2.waitExactlyNTasksWithTimeout(7);
    Assert.assertEquals(30, node1.getBestBlock().getNumber());
    Assert.assertEquals(80, node2.getBestBlock().getNumber());
    Assert.assertEquals(80, 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) Test(org.junit.Test)

Example 75 with Blockchain

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

Aggregations

Blockchain (org.ethereum.core.Blockchain)86 Test (org.junit.Test)75 Block (org.ethereum.core.Block)51 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)47 RskSystemProperties (co.rsk.config.RskSystemProperties)45 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)38 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)25 World (co.rsk.test.World)19 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)14 Keccak256 (co.rsk.crypto.Keccak256)7 Ignore (org.junit.Ignore)7 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)5 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)2 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)2 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)2 Repository (org.ethereum.core.Repository)2 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1