use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class NodeMessageHandlerTest method processGetBlockMessageUsingBlockInStore.
@Test
public void processGetBlockMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final BlockStore store = new BlockStore();
store.saveBlock(block);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
final SimpleMessageChannel sender = new SimpleMessageChannel();
handler.processMessage(sender, new GetBlockMessage(block.getHash().getBytes()));
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 co.rsk.net.sync.SyncConfiguration 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 co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class SyncProcessorTest method processBodyResponseRejectsNonSolicitedMessages.
@Test
public void processBodyResponseRejectsNonSolicitedMessages() {
Blockchain blockchain = BlockChainBuilder.ofSize(3);
SimpleMessageChannel sender = new SimpleMessageChannel(new byte[] { 0x01 });
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, new BlockStore(), blockchain, new BlockNodeInformation(), syncConfiguration);
SyncProcessor processor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), getChannelManager(), syncConfiguration, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), DIFFICULTY_CALCULATOR);
processor.setSelectedPeer(sender, StatusUtils.getFakeStatus(), 0);
BodyResponseMessage response = new BodyResponseMessage(new Random().nextLong(), null, null);
processor.registerExpectedMessage(response);
processor.processBodyResponse(sender, response);
Assert.assertTrue(sender.getMessages().isEmpty());
Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class SyncProcessorTest method processBlockHeadersResponseWithEmptyList.
@Test
public void processBlockHeadersResponseWithEmptyList() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
SimpleMessageChannel sender = new SimpleMessageChannel(new byte[] { 0x01 });
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, new BlockStore(), blockchain, new BlockNodeInformation(), syncConfiguration);
SyncProcessor processor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), getChannelManager(), syncConfiguration, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), DIFFICULTY_CALCULATOR);
List<BlockHeader> headers = new ArrayList<>();
processor.setSelectedPeer(sender, StatusUtils.getFakeStatus(), 0);
BlockHeadersResponseMessage response = new BlockHeadersResponseMessage(new Random().nextLong(), headers);
processor.registerExpectedMessage(response);
processor.processBlockHeadersResponse(sender, response);
Assert.assertEquals(0, sender.getMessages().size());
Assert.assertEquals(0, processor.getExpectedResponses().size());
}
use of co.rsk.net.sync.SyncConfiguration in project rskj by rsksmart.
the class SyncProcessorTest method processBlockHeadersResponseWithManyHeadersMissingFirstParent.
@Test
public void processBlockHeadersResponseWithManyHeadersMissingFirstParent() {
Blockchain blockchain = BlockChainBuilder.ofSize(0);
Blockchain otherBlockchain = BlockChainBuilder.ofSize(10, true);
SimpleMessageChannel sender = new SimpleMessageChannel(new byte[] { 0x01 });
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, new BlockStore(), blockchain, new BlockNodeInformation(), syncConfiguration);
SyncProcessor processor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), getChannelManager(), syncConfiguration, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), DIFFICULTY_CALCULATOR);
processor.setSelectedPeer(sender, StatusUtils.getFakeStatus(), 0);
List<BlockHeader> headers = new ArrayList<>();
for (int k = 10; k >= 2; k--) headers.add(otherBlockchain.getBlockByNumber(k).getHeader());
BlockHeadersResponseMessage response = new BlockHeadersResponseMessage(new Random().nextLong(), headers);
processor.registerExpectedMessage(response);
processor.processBlockHeadersResponse(sender, response);
Assert.assertEquals(0, sender.getMessages().size());
Assert.assertEquals(0, processor.getExpectedResponses().size());
}
Aggregations