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));
}
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));
}
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);
}
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());
}
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);
}
Aggregations