Search in sources :

Example 1 with AsyncNodeBlockProcessorListener

use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processTwoBlockListsAddingToBlockchainWithFork.

@Test(timeout = WAIT_TIME)
public void processTwoBlockListsAddingToBlockchainWithFork() throws InterruptedException {
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    final Block genesis = blockchain.getBestBlock();
    final BlockGenerator blockGenerator = new BlockGenerator();
    final List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
    final List<Block> blocks2 = blockGenerator.getBlockChain(blocks.get(4), 20);
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
    processor.start();
    BlockProcessResult blockProcessResult = processor.processBlock(null, genesis);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(genesis.getHash());
    }
    Assert.assertEquals(0, store.size());
    Block blockToWait = null;
    for (Block b : blocks) {
        blockProcessResult = processor.processBlock(null, b);
        if (blockProcessResult.isScheduledForProcessing()) {
            blockToWait = b;
        }
    }
    for (Block b : blocks2) {
        blockProcessResult = processor.processBlock(null, b);
        if (blockProcessResult.isScheduledForProcessing()) {
            blockToWait = b;
        }
    }
    if (blockToWait != null) {
        listener.waitForBlock(blockToWait.getHash());
    }
    Assert.assertEquals(25, blockchain.getBestBlock().getNumber());
    Assert.assertEquals(0, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 2 with AsyncNodeBlockProcessorListener

use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processTenBlocksAddingToBlockchain.

@Test(timeout = WAIT_TIME)
public void processTenBlocksAddingToBlockchain() throws InterruptedException {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    final NetBlockStore store = new NetBlockStore();
    final Block genesis = blockchain.getBestBlock();
    final List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
    processor.start();
    BlockProcessResult blockProcessResult = processor.processBlock(null, genesis);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(genesis.getHash());
    }
    Assert.assertEquals(0, store.size());
    Block blockToWait = null;
    for (Block b : blocks) {
        BlockProcessResult result = processor.processBlock(null, b);
        if (result.isScheduledForProcessing()) {
            blockToWait = b;
        }
    }
    if (blockToWait != null) {
        listener.waitForBlock(blockToWait.getHash());
    }
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    Assert.assertEquals(0, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 3 with AsyncNodeBlockProcessorListener

use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processBlockAddingToBlockchainUsingItsParent.

@Test(timeout = WAIT_TIME)
public void processBlockAddingToBlockchainUsingItsParent() throws InterruptedException {
    final NetBlockStore store = new NetBlockStore();
    final BlockGenerator blockGenerator = new BlockGenerator();
    final Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis);
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    final Block parent = blockGenerator.createChildBlock(blockchain.getBlockByNumber(10));
    final Block block = blockGenerator.createChildBlock(parent);
    Assert.assertEquals(11, parent.getNumber());
    Assert.assertEquals(12, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), parent.getParentHash().getBytes());
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
    processor.start();
    BlockProcessResult blockProcessResult = processor.processBlock(null, block);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(block.getHash());
    }
    Assert.assertTrue(store.hasBlock(block));
    Assert.assertNull(blockchain.getBlockByHash(block.getHash().getBytes()));
    blockProcessResult = processor.processBlock(null, parent);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(parent.getHash());
    }
    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());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 4 with AsyncNodeBlockProcessorListener

use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processBlockAddingToBlockchain.

@Test(timeout = WAIT_TIME)
public void processBlockAddingToBlockchain() throws InterruptedException {
    final Blockchain blockchain = new BlockChainBuilder().ofSize(10);
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    final NetBlockStore store = new NetBlockStore();
    final Block genesis = blockchain.getBlockByNumber(0);
    store.saveBlock(genesis);
    final Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
    Assert.assertEquals(11, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
    processor.start();
    BlockProcessResult blockProcessResult = processor.processBlock(null, block);
    if (blockProcessResult.isScheduledForProcessing()) {
        listener.waitForBlock(block.getHash());
    }
    Assert.assertFalse(store.hasBlock(block));
    Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertEquals(1, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) Block(org.ethereum.core.Block) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 5 with AsyncNodeBlockProcessorListener

use of co.rsk.net.utils.AsyncNodeBlockProcessorListener in project rskj by rsksmart.

the class AsyncNodeBlockProcessorTest method processTenBlocksGenesisAtLastAddingToBlockchain.

@Test(timeout = WAIT_TIME)
public void processTenBlocksGenesisAtLastAddingToBlockchain() throws InterruptedException {
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    final Block genesis = blockchain.getBestBlock();
    final List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessorListener listener = new AsyncNodeBlockProcessorListener();
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE, listener);
    processor.start();
    BlockProcessResult blockProcessResult;
    Block blockToWait = null;
    for (Block b : blocks) {
        blockProcessResult = processor.processBlock(null, b);
        if (blockProcessResult.isScheduledForProcessing()) {
            blockToWait = b;
        }
    }
    blockProcessResult = processor.processBlock(null, genesis);
    if (blockProcessResult.isScheduledForProcessing()) {
        blockToWait = genesis;
    }
    if (blockToWait != null) {
        listener.waitForBlock(blockToWait.getHash());
    }
    Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
    Assert.assertEquals(0, store.size());
    processor.stopAndWait(WAIT_TIME);
}
Also used : Blockchain(org.ethereum.core.Blockchain) AsyncNodeBlockProcessorListener(co.rsk.net.utils.AsyncNodeBlockProcessorListener) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

AsyncNodeBlockProcessorListener (co.rsk.net.utils.AsyncNodeBlockProcessorListener)9 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)9 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)8 TestSystemProperties (co.rsk.config.TestSystemProperties)8 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)8 Block (org.ethereum.core.Block)8 Blockchain (org.ethereum.core.Blockchain)8 Test (org.junit.Test)8 Before (org.junit.Before)1