Search in sources :

Example 26 with SyncConfiguration

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 27 with SyncConfiguration

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);
}
Also used : SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 28 with SyncConfiguration

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) RskSystemProperties(co.rsk.config.RskSystemProperties) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 29 with SyncConfiguration

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 30 with SyncConfiguration

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

SyncConfiguration (co.rsk.net.sync.SyncConfiguration)65 Test (org.junit.Test)59 RskSystemProperties (co.rsk.config.RskSystemProperties)48 Blockchain (org.ethereum.core.Blockchain)47 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)42 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)36 Block (org.ethereum.core.Block)36 World (co.rsk.test.World)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 Ignore (org.junit.Ignore)10 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)9 Keccak256 (co.rsk.crypto.Keccak256)8 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)8 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)4 BlockDifficulty (co.rsk.core.BlockDifficulty)3 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 Nonnull (javax.annotation.Nonnull)2 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 TxHandler (co.rsk.net.handler.TxHandler)1