Search in sources :

Example 41 with SyncConfiguration

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

the class NodeBlockProcessorTest method processBlockHeadersRequestMessageUsingBlockInBlockchain.

@Test
public void processBlockHeadersRequestMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(100);
    final Block block = blockchain.getBlockByNumber(60);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    processor.processBlockHeadersRequest(sender, 100, block.getHash().getBytes(), 20);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.BLOCK_HEADERS_RESPONSE_MESSAGE, message.getMessageType());
    final BlockHeadersResponseMessage response = (BlockHeadersResponseMessage) message;
    Assert.assertEquals(100, response.getId());
    Assert.assertNotNull(response.getBlockHeaders());
    Assert.assertEquals(20, response.getBlockHeaders().size());
    for (int k = 0; k < 20; k++) Assert.assertEquals(blockchain.getBlockByNumber(60 - k).getHash(), response.getBlockHeaders().get(k).getHash());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 42 with SyncConfiguration

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

the class NodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.

@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() throws UnknownHostException {
    int skeletonStep = 192;
    final Blockchain blockchain = BlockChainBuilder.ofSize(skeletonStep / 2);
    final Block blockStart = blockchain.getBlockByNumber(5);
    final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    processor.processSkeletonRequest(sender, 100, 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block genesis = blockchain.getBlockByNumber(0);
    Block bestBlock = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(genesis.getHash().getBytes(), genesis.getNumber()), new BlockIdentifier(bestBlock.getHash().getBytes(), bestBlock.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 43 with SyncConfiguration

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

the class NodeBlockProcessorTest method processBlockAddingToBlockchainUsingItsParent.

@Test
public void processBlockAddingToBlockchainUsingItsParent() {
    BlockStore store = new BlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis);
    Blockchain blockchain = BlockChainBuilder.ofSize(10);
    Block parent = blockGenerator.createChildBlock(blockchain.getBlockByNumber(10));
    Block block = blockGenerator.createChildBlock(parent);
    Assert.assertEquals(11, parent.getNumber());
    Assert.assertEquals(12, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), parent.getParentHash().getBytes());
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    processor.processBlock(null, block);
    Assert.assertTrue(store.hasBlock(block));
    Assert.assertNull(blockchain.getBlockByHash(block.getHash().getBytes()));
    processor.processBlock(null, parent);
    Assert.assertFalse(store.hasBlock(block));
    Assert.assertFalse(store.hasBlock(parent));
    Assert.assertEquals(12, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertEquals(1, store.size());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 44 with SyncConfiguration

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

the class NodeBlockProcessorTest method processBlockWithTooMuchHeight.

@Test
public void processBlockWithTooMuchHeight() throws UnknownHostException {
    final BlockStore store = new BlockStore();
    final MessageChannel sender = new SimpleMessageChannel();
    final Blockchain blockchain = BlockChainBuilder.ofSize(0);
    final Block orphan = new BlockGenerator().createBlock(1000, 0);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    processor.processBlock(sender, orphan);
    Assert.assertFalse(processor.getNodeInformation().getNodesByBlock(orphan.getHash().getBytes()).size() == 1);
    Assert.assertFalse(store.hasBlock(orphan));
    Assert.assertEquals(0, store.size());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 45 with SyncConfiguration

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

the class NodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.

@Test
public void processSkeletonRequestNotIncludingGenesis() throws UnknownHostException {
    int skeletonStep = 192;
    final Blockchain blockchain = BlockChainBuilder.ofSize(400);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    processor.processSkeletonRequest(sender, 100, skeletonStep + 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block b1 = blockchain.getBlockByNumber(skeletonStep);
    Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
    Block b3 = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

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