Search in sources :

Example 21 with Blockchain

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

the class NodeBlockProcessorTest method syncingWithEmptyBlockchainAndHighBestBlock.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingWithEmptyBlockchainAndHighBestBlock() {
    BlockStore store = new BlockStore();
    Block block = new BlockGenerator().createBlock(30, 0);
    Blockchain blockchain = BlockChainBuilder.ofSize(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);
    Assert.assertFalse(processor.hasBetterBlockToSync());
    // Status status = new Status(block.getNumber(), block.getHash());
    // processor.processStatus(new SimpleNodeChannel(null, null), status);
    Assert.assertTrue(processor.hasBetterBlockToSync());
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with Blockchain

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

the class NodeBlockProcessorTest method processGetBlockMessageUsingBlockInBlockchain.

@Test
public void processGetBlockMessageUsingBlockInBlockchain() throws UnknownHostException {
    final Blockchain blockchain = BlockChainBuilder.ofSize(10);
    final Block block = blockchain.getBlockByNumber(5);
    final Keccak256 blockHash = block.getHash();
    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();
    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
    processor.processGetBlock(sender, block.getHash().getBytes());
    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.BLOCK_MESSAGE, message.getMessageType());
    final BlockMessage bMessage = (BlockMessage) message;
    Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 23 with Blockchain

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

the class NodeBlockProcessorTest method processStatusHavingBestBlockInBlockchainStore.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusHavingBestBlockInBlockchainStore() throws UnknownHostException {
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = BlockChainBuilder.ofSize(2);
    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();
    final Block block = blockchain.getBlockByNumber(1);
    final Keccak256 blockHash = block.getHash();
    store.saveBlock(block);
    // final Status status = new Status(block.getNumber(), block.getHash());
    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
    // processor.processStatus(sender, status);
    Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).contains(blockHash));
    Assert.assertEquals(0, sender.getGetBlockMessages().size());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with Blockchain

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

the class NodeBlockProcessorTest method syncingThenNoSyncing.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void syncingThenNoSyncing() {
    BlockStore store = new BlockStore();
    Block block = new BlockGenerator().createBlock(30, 0);
    Blockchain blockchain = BlockChainBuilder.ofSize(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);
    Assert.assertFalse(processor.hasBetterBlockToSync());
    // Status status = new Status(block.getNumber(), block.getHash());
    // processor.processStatus(new SimpleNodeChannel(null, null), status);
    Assert.assertTrue(processor.hasBetterBlockToSync());
    Assert.assertTrue(processor.hasBetterBlockToSync());
    blockchain.setBestBlock(block);
    blockchain.setTotalDifficulty(new BlockDifficulty(BigInteger.valueOf(30)));
    Assert.assertFalse(processor.hasBetterBlockToSync());
    Assert.assertFalse(processor.hasBetterBlockToSync());
    Block block2 = new BlockGenerator().createBlock(60, 0);
    // Status status2 = new Status(block2.getNumber(), block2.getHash());
    // processor.processStatus(new SimpleNodeChannel(null, null), status2);
    Assert.assertTrue(processor.hasBetterBlockToSync());
    Assert.assertFalse(processor.hasBetterBlockToSync());
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with Blockchain

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

the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInStore.

@Test
public void processGetBlockHeaderMessageUsingBlockInStore() throws UnknownHostException {
    final Block block = new BlockGenerator().getBlock(3);
    final BlockStore store = new BlockStore();
    store.saveBlock(block);
    final Blockchain blockchain = BlockChainBuilder.ofSize(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);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
    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 bMessage = (BlockHeadersResponseMessage) message;
    Assert.assertEquals(block.getHeader().getHash(), bMessage.getBlockHeaders().get(0).getHash());
}
Also used : 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)

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