use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method advancedBlock.
@Test
public void advancedBlock() throws UnknownHostException {
final BlockStore store = new BlockStore();
final MessageChannel sender = new SimpleMessageChannel();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final Blockchain blockchain = BlockChainBuilder.ofSize(0);
final long advancedBlockNumber = syncConfiguration.getChunkSize() * syncConfiguration.getMaxSkeletonChunks() + blockchain.getBestBlock().getNumber() + 1;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertTrue(processor.isAdvancedBlock(advancedBlockNumber));
Assert.assertFalse(processor.isAdvancedBlock(advancedBlockNumber - 1));
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockHashRequestMessageUsingOutOfBoundsHeight.
@Test
public void processBlockHashRequestMessageUsingOutOfBoundsHeight() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(10);
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.processBlockHashRequest(sender, 100, 99999);
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTwoBlockListsAddingToBlockchainWithFork.
@Test
public void processTwoBlockListsAddingToBlockchainWithFork() {
BlockStore store = new BlockStore();
Blockchain blockchain = BlockChainBuilder.ofSize(0);
Block genesis = blockchain.getBestBlock();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getBlockChain(genesis, 10);
List<Block> blocks2 = blockGenerator.getBlockChain(blocks.get(4), 20);
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, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
for (Block b : blocks2) processor.processBlock(null, b);
Assert.assertEquals(25, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingEmptyStore.
@Test
public void processGetBlockHeaderMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final BlockStore store = new BlockStore();
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();
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
processor.processBlockHeadersRequest(sender, 1, block.getHash().getBytes(), 1);
Assert.assertTrue(nodeInformation.getBlocksByNode(sender.getPeerNodeID()).isEmpty());
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksAddingToBlockchain.
@Test
public void processTenBlocksAddingToBlockchain() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
BlockStore store = new BlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
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, genesis);
Assert.assertEquals(0, store.size());
for (Block b : blocks) processor.processBlock(null, b);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
Aggregations