Search in sources :

Example 1 with PeersInformation

use of co.rsk.net.sync.PeersInformation in project rskj by rsksmart.

the class NodeMessageHandlerUtil method createHandlerWithSyncProcessor.

public static NodeMessageHandler createHandlerWithSyncProcessor(Blockchain blockchain, SyncConfiguration syncConfiguration, ChannelManager channelManager, BlockStore blockStore) {
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    ProofOfWorkRule blockValidationRule = new ProofOfWorkRule(config);
    PeerScoringManager peerScoringManager = mock(PeerScoringManager.class);
    Mockito.when(peerScoringManager.hasGoodReputation(isA(NodeID.class))).thenReturn(true);
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, blockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, blockValidationRule, new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(channelManager, syncConfiguration, blockchain, peerScoringManager), mock(Genesis.class), mock(EthereumListener.class));
    return new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, mock(StatusResolver.class));
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) PeerScoringManager(co.rsk.scoring.PeerScoringManager) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis)

Example 2 with PeersInformation

use of co.rsk.net.sync.PeersInformation in project rskj by rsksmart.

the class NodeMessageHandlerUtil method createHandler.

public static NodeMessageHandler createHandler(Blockchain blockchain) {
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    return new NodeMessageHandler(config, processor, syncProcessor, new SimpleChannelManager(), null, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 3 with PeersInformation

use of co.rsk.net.sync.PeersInformation in project rskj by rsksmart.

the class SimpleAsyncNode method createNode.

public static SimpleAsyncNode createNode(Blockchain blockchain, SyncConfiguration syncConfiguration, org.ethereum.db.BlockStore indexedBlockStore) {
    NetBlockStore blockStore = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, blockStore, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(blockStore, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    SimpleChannelManager channelManager = new SimpleChannelManager();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, indexedBlockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, blockValidationRule, new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, peerScoringManager), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, peerScoringManager, mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis)

Example 4 with PeersInformation

use of co.rsk.net.sync.PeersInformation in project rskj by rsksmart.

the class NodeMessageHandlerTest method processStatusMessageWithKnownBestBlock.

@Test
public void processStatusMessageWithKnownBestBlock() {
    final World world = new World();
    final Blockchain blockchain = world.getBlockChain();
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    final SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), null, new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    final NodeMessageHandler handler = new NodeMessageHandler(config, bp, syncProcessor, null, null, null, mock(StatusResolver.class));
    BlockGenerator blockGenerator = new BlockGenerator();
    final Block block = blockGenerator.createChildBlock(blockGenerator.getGenesisBlock());
    final Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), blockchain.getTotalDifficulty());
    final Message message = new StatusMessage(status);
    store.saveBlock(block);
    handler.processMessage(sender, message);
    Assert.assertNotNull(sender.getMessages());
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) BlockStore(org.ethereum.db.BlockStore) SimplePeer(co.rsk.net.simples.SimplePeer) PeersInformation(co.rsk.net.sync.PeersInformation) Test(org.junit.Test)

Example 5 with PeersInformation

use of co.rsk.net.sync.PeersInformation in project rskj by rsksmart.

the class OneAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode() {
    final World world = new World();
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = world.getBlockChain();
    TestSystemProperties config = new TestSystemProperties();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, new BlockFactory(config.getActivationConfig()), new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis) TestSystemProperties(co.rsk.config.TestSystemProperties)

Aggregations

ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)5 PeersInformation (co.rsk.net.sync.PeersInformation)5 EthereumListener (org.ethereum.listener.EthereumListener)5 Genesis (org.ethereum.core.Genesis)4 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)3 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 PeerScoringManager (co.rsk.scoring.PeerScoringManager)2 World (co.rsk.test.World)2 BlockFactory (org.ethereum.core.BlockFactory)2 BlockStore (org.ethereum.db.BlockStore)2 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)1 SimplePeer (co.rsk.net.simples.SimplePeer)1 Blockchain (org.ethereum.core.Blockchain)1 Test (org.junit.Test)1