Search in sources :

Example 71 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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 72 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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 73 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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 74 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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 75 with RskSystemProperties

use of co.rsk.config.RskSystemProperties 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

RskSystemProperties (co.rsk.config.RskSystemProperties)112 Test (org.junit.Test)81 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)48 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)45 Blockchain (org.ethereum.core.Blockchain)45 Block (org.ethereum.core.Block)41 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)35 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)20 Ignore (org.junit.Ignore)10 Keccak256 (co.rsk.crypto.Keccak256)8 RegTestConfig (org.ethereum.config.blockchain.RegTestConfig)8 Repository (org.ethereum.core.Repository)8 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)8 Channel (org.ethereum.net.server.Channel)7 ChannelManager (org.ethereum.net.server.ChannelManager)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 BlockDifficulty (co.rsk.core.BlockDifficulty)6 RskAddress (co.rsk.core.RskAddress)6 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)6 BeforeClass (org.junit.BeforeClass)6