use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockMessageUsingBlockInStore.
@Test
public void processGetBlockMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final Keccak256 blockHash = block.getHash();
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();
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());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeBlockProcessorTest method processGetBlockHeaderMessageUsingBlockInBlockchain.
@Test
public void processGetBlockHeaderMessageUsingBlockInBlockchain() throws UnknownHostException {
final Blockchain blockchain = BlockChainBuilder.ofSize(10);
final Block block = blockchain.getBlockByNumber(5);
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, 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());
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeMessageHandlerUtil method createHandler.
public static NodeMessageHandler createHandler(BlockValidationRule validationRule) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), RskMockFactory.getChannelManager(), syncConfiguration, new DummyBlockValidationRule(), DIFFICULTY_CALCULATOR);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
return new NodeMessageHandler(config, processor, syncProcessor, new SimpleChannelManager(), null, null, RskMockFactory.getPeerScoringManager(), validationRule);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class NodeMessageHandlerUtil method createHandlerWithSyncProcessor.
public static NodeMessageHandler createHandlerWithSyncProcessor(SyncConfiguration syncConfiguration, ChannelManager channelManager) {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
return createHandlerWithSyncProcessor(blockchain, syncConfiguration, channelManager);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class ThreeAsyncNodeUsingSyncProcessorTest method ignoreNewBlockHashesWhenSyncing.
@Test
public void ignoreNewBlockHashesWhenSyncing() {
Blockchain b1 = BlockChainBuilder.ofSize(30, true);
Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 1, true);
SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
SimpleAsyncNode node3 = SimpleAsyncNode.createNodeWithBlockChainBuilder(0);
Assert.assertEquals(30, node1.getBestBlock().getNumber());
Assert.assertEquals(31, node2.getBestBlock().getNumber());
Assert.assertEquals(0, node3.getBestBlock().getNumber());
node1.sendFullStatusTo(node3);
// receive the hash of a better block than node1's best
// while it's syncing with node1
node3.receiveMessageFrom(node2, new NewBlockHashMessage(node2.getBestBlock().getHash().getBytes()));
// receive and ignore NewBlockHashMessage
node3.waitUntilNTasksWithTimeout(1);
// sync setup
node3.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(30, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING));
// synchronize 30 new blocks from node 1
node3.waitExactlyNTasksWithTimeout(30);
Assert.assertEquals(30, node1.getBestBlock().getNumber());
Assert.assertEquals(31, node2.getBestBlock().getNumber());
Assert.assertEquals(30, node3.getBestBlock().getNumber());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
node1.joinWithTimeout();
node2.joinWithTimeout();
node3.joinWithTimeout();
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
}
Aggregations