Ejemplo n.º 1
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HelloMessageSerializer)));

            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Ecdsa(), _nodeKey, _logManager);

            var networkConfig = _configProvider.GetConfig <INetworkConfig>();

            _sessionMonitor = new SessionMonitor(networkConfig, _logManager);
            _rlpxPeer       = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _sessionMonitor);

            await _rlpxPeer.Init();

            var peerStorage = new NetworkStorage(PeersDbPath, networkConfig, _logManager, _perfService);

            ProtocolValidator protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, _logManager);

            _protocolsManager = new ProtocolsManager(_syncPeerPool, _syncServer, _txPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);
            PeerLoader peerLoader = new PeerLoader(networkConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager);
            _peerManager.Init();
        }
 public void RegisterDiscoverySerializers()
 {
     _messageSerializationService.Register(_pingMessageSerializer);
     _messageSerializationService.Register(_pongMessageSerializer);
     _messageSerializationService.Register(_findNodeMessageSerializer);
     _messageSerializationService.Register(_neighborsMessageSerializer);
 }
            public Context()
            {
                _channel = Substitute.For <IChannel>();
                _channelHandlerContext = Substitute.For <IChannelHandlerContext>();
                _pipeline = Substitute.For <IChannelPipeline>();
                _channelHandlerContext.Channel.Returns(_channel);
                _channel.Pipeline.Returns(_pipeline);
                _pipeline.Get <ZeroPacketSplitter>().Returns(new ZeroPacketSplitter(LimboLogs.Instance));
                _packetSender = Substitute.For <IPacketSender>();
                _syncServer   = Substitute.For <ISyncServer>();
                _syncServer   = Substitute.For <ISyncServer>();
                _syncServer.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header);
                _syncServer.Head.Returns(Build.A.BlockHeader.TestObject);
                _txPool             = Substitute.For <ITxPool>();
                _pooledTxsRequestor = Substitute.For <IPooledTxsRequestor>();
                _discoveryApp       = Substitute.For <IDiscoveryApp>();
                _serializer         = new MessageSerializationService();
                _rlpxHost           = Substitute.For <IRlpxHost>();
                _rlpxHost.LocalPort.Returns(_localPort);
                _rlpxHost.LocalNodeId.Returns(TestItem.PublicKeyA);
                ITimerFactory timerFactory = Substitute.For <ITimerFactory>();

                _nodeStatsManager = new NodeStatsManager(timerFactory, LimboLogs.Instance);
                _blockTree        = Substitute.For <IBlockTree>();
                _blockTree.ChainId.Returns(1ul);
                _blockTree.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header);
                _protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, LimboLogs.Instance);
                _peerStorage       = Substitute.For <INetworkStorage>();
                _syncPeerPool      = Substitute.For <ISyncPeerPool>();
                _gossipPolicy      = Substitute.For <IGossipPolicy>();
                _manager           = new ProtocolsManager(
                    _syncPeerPool,
                    _syncServer,
                    _txPool,
                    _pooledTxsRequestor,
                    _discoveryApp,
                    _serializer,
                    _rlpxHost,
                    _nodeStatsManager,
                    _protocolValidator,
                    _peerStorage,
                    MainnetSpecProvider.Instance,
                    _gossipPolicy,
                    LimboLogs.Instance);

                _serializer.Register(new HelloMessageSerializer());
                _serializer.Register(new StatusMessageSerializer());
                _serializer.Register(new DisconnectMessageSerializer());
            }
Ejemplo n.º 4
0
            public Context()
            {
                _channel = Substitute.For <IChannel>();
                _channelHandlerContext = Substitute.For <IChannelHandlerContext>();
                _pipeline = Substitute.For <IChannelPipeline>();
                _channelHandlerContext.Channel.Returns(_channel);
                _channel.Pipeline.Returns(_pipeline);
                _pipeline.Get <ZeroPacketSplitter>().Returns(new ZeroPacketSplitter(LimboLogs.Instance));
                _packetSender = Substitute.For <IPacketSender>();
                _syncServer   = Substitute.For <ISyncServer>();
                _syncServer   = Substitute.For <ISyncServer>();
                _syncServer.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header);
                _syncServer.Head.Returns(Build.A.BlockHeader.TestObject);
                _txPool       = Substitute.For <ITxPool>();
                _discoveryApp = Substitute.For <IDiscoveryApp>();
                _serializer   = new MessageSerializationService();
                _localPeer    = Substitute.For <IRlpxPeer>();
                _localPeer.LocalPort.Returns(_localPort);
                _localPeer.LocalNodeId.Returns(TestItem.PublicKeyA);
                _nodeStatsManager = new NodeStatsManager(new StatsConfig(), LimboLogs.Instance);
                _blockTree        = Substitute.For <IBlockTree>();
                _blockTree.ChainId.Returns(1);
                _blockTree.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header);
                _protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, LimboLogs.Instance);
                _peerStorage       = Substitute.For <INetworkStorage>();
                _perfService       = new PerfService(LimboLogs.Instance);
                _syncPeerPool      = Substitute.For <IEthSyncPeerPool>();
                _manager           = new ProtocolsManager(
                    _syncPeerPool,
                    _syncServer,
                    _txPool,
                    _discoveryApp,
                    _serializer,
                    _localPeer,
                    _nodeStatsManager,
                    _protocolValidator,
                    _peerStorage,
                    _perfService,
                    LimboLogs.Instance);

                _serializer.Register(new HelloMessageSerializer());
                _serializer.Register(new StatusMessageSerializer());
                _serializer.Register(new DisconnectMessageSerializer());
            }
        public Task InitNetworkProtocol()
        {
            if (_accountAbstractionConfig.Enabled)
            {
                if (_nethermindApi is null)
                {
                    throw new ArgumentNullException(nameof(_nethermindApi));
                }

                // init all relevant objects if not already initialized
                foreach (Address entryPoint in _entryPointContractAddresses)
                {
                    UserOperationPool(entryPoint);
                    UserOperationSimulator(entryPoint);
                    UserOperationTxBuilder(entryPoint);
                }

                if (_userOperationPools.Count == 0)
                {
                    throw new ArgumentNullException(nameof(UserOperationPool));
                }

                IProtocolsManager protocolsManager = _nethermindApi.ProtocolsManager ??
                                                     throw new ArgumentNullException(
                                                               nameof(_nethermindApi.ProtocolsManager));
                IMessageSerializationService serializer = _nethermindApi.MessageSerializationService ??
                                                          throw new ArgumentNullException(
                                                                    nameof(_nethermindApi.MessageSerializationService));
                INodeStatsManager stats = _nethermindApi.NodeStatsManager ??
                                          throw new ArgumentNullException(nameof(_nethermindApi.NodeStatsManager));
                ILogManager logManager = _nethermindApi.LogManager ??
                                         throw new ArgumentNullException(nameof(_nethermindApi.LogManager));

                AccountAbstractionPeerManager peerManager = new(_userOperationPools, UserOperationBroadcaster, _accountAbstractionConfig.AaPriorityPeersMaxCount, _logger);

                serializer.Register(new UserOperationsMessageSerializer());
                protocolsManager.AddProtocol(Protocol.AA,
                                             session => new AaProtocolHandler(session, serializer, stats, _userOperationPools, peerManager, logManager));
                protocolsManager.AddSupportedCapability(new Capability(Protocol.AA, 0));

                if (_logger.IsInfo)
                {
                    _logger.Info("Initialized Account Abstraction network protocol");
                }
            }
            else
            {
                if (_logger.IsInfo)
                {
                    _logger.Info("Skipping Account Abstraction network protocol");
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
 public void RegisterDiscoverySerializers()
 {
     _msgSerializationService.Register(_pingMsgSerializer);
     _msgSerializationService.Register(_pongMsgSerializer);
     _msgSerializationService.Register(_findNodeMsgSerializer);
     _msgSerializationService.Register(_neighborsMsgSerializer);
     _msgSerializationService.Register(_enrRequestMsgSerializer);
     _msgSerializationService.Register(_enrResponseMsgSerializer);
 }
        public Task InitNetworkProtocol()
        {
            if (_accountAbstractionConfig.Enabled)
            {
                if (_nethermindApi is null)
                {
                    throw new ArgumentNullException(nameof(_nethermindApi));
                }
                if (UserOperationPool is null)
                {
                    throw new ArgumentNullException(nameof(UserOperationPool));
                }

                IProtocolsManager protocolsManager = _nethermindApi.ProtocolsManager ??
                                                     throw new ArgumentNullException(
                                                               nameof(_nethermindApi.ProtocolsManager));
                IMessageSerializationService serializer = _nethermindApi.MessageSerializationService ??
                                                          throw new ArgumentNullException(
                                                                    nameof(_nethermindApi.MessageSerializationService));
                INodeStatsManager stats = _nethermindApi.NodeStatsManager ??
                                          throw new ArgumentNullException(nameof(_nethermindApi.NodeStatsManager));
                ILogManager logManager = _nethermindApi.LogManager ??
                                         throw new ArgumentNullException(nameof(_nethermindApi.LogManager));

                serializer.Register(new UserOperationsMessageSerializer());
                protocolsManager.AddProtocol(Protocol.AA,
                                             session => new AaProtocolHandler(session, serializer, stats, UserOperationPool, logManager));
                protocolsManager.AddSupportedCapability(new Capability(Protocol.AA, 0));

                if (_logger.IsInfo)
                {
                    _logger.Info("Initialized Account Abstraction network protocol");
                }
            }
            else
            {
                if (_logger.IsInfo)
                {
                    _logger.Info("Skipping Account Abstraction network protocol");
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 8
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Ecdsa(), _nodeKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth62 */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            /* eth63 */
            _messageSerializationService.Register(new GetNodeDataMessageSerializer());
            _messageSerializationService.Register(new NodeDataMessageSerializer());
            _messageSerializationService.Register(new GetReceiptsMessageSerializer());
            _messageSerializationService.Register(new ReceiptsMessageSerializer());

            var networkConfig = _configProvider.GetConfig <INetworkConfig>();

            _sessionMonitor = new SessionMonitor(networkConfig, _logManager);
            _rlpxPeer       = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _sessionMonitor);

            await _rlpxPeer.Init();

            var peerStorage = new NetworkStorage(PeersDbPath, networkConfig, _logManager, _perfService);

            ProtocolValidator protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, _logManager);

            _protocolsManager = new ProtocolsManager(_syncManager, _transactionPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);
            PeerLoader peerLoader = new PeerLoader(networkConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager);
            _peerManager.Init();
        }
Ejemplo n.º 9
0
        private async Task InitNet(int listenPort)
        {
            /* tools */
            _messageSerializationService = new MessageSerializationService();
            _cryptoRandom = new CryptoRandom();
            _signer       = new Signer();

            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher, _cryptoRandom, _signer, _privateKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            _logger.Info("Initializing server...");
            _localPeer = new RlpxPeer(new NodeId(_privateKey.PublicKey), listenPort, encryptionHandshakeServiceA, _messageSerializationService, _syncManager, _logManager);
            await _localPeer.Init();

            var localIp = _networkHelper.GetLocalIp();

            _logger.Info($"Node is up and listening on {localIp}:{listenPort}... press ENTER to exit");
            _logger.Info($"enode://{_privateKey.PublicKey}@{localIp}:{listenPort}");
        }
Ejemplo n.º 10
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HelloMessageSerializer)));

            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Ecdsa(), _nodeKey, _logManager);

            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HiMessageSerializer)));

            var networkConfig   = _configProvider.GetConfig <INetworkConfig>();
            var discoveryConfig = _configProvider.GetConfig <IDiscoveryConfig>();

            _sessionMonitor = new SessionMonitor(networkConfig, _logManager);
            _rlpxPeer       = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _sessionMonitor);

            await _rlpxPeer.Init();

            _staticNodesManager = new StaticNodesManager(_initConfig.StaticNodesPath, _logManager);
            await _staticNodesManager.InitAsync();

            var peersDb     = new SimpleFilePublicKeyDb(Path.Combine(_initConfig.BaseDbPath, PeersDbPath), _logManager);
            var peerStorage = new NetworkStorage(peersDb, _logManager);

            ProtocolValidator protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, _logManager);

            _protocolsManager = new ProtocolsManager(_syncPeerPool, _syncServer, _txPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);

            if (!(_ndmInitializer is null))
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Initializing NDM...");
                }
                var capabilityConnector = await _ndmInitializer.InitAsync(_configProvider, _dbProvider,
                                                                          _initConfig.BaseDbPath, _blockProcessor, _blockTree, _txPool, _txPoolInfoProvider, _specProvider,
                                                                          _receiptStorage, _wallet, _timestamp, _ethereumEcdsa, _rpcModuleProvider, _keyStore, _jsonSerializer,
                                                                          _cryptoRandom, _enode, _ndmConsumerChannelManager, _ndmDataPublisher, _grpcService,
                                                                          _nodeStatsManager, _protocolsManager, protocolValidator, _messageSerializationService,
                                                                          _initConfig.EnableUnsecuredDevWallet, _logManager);

                capabilityConnector.Init();
                if (_logger.IsInfo)
                {
                    _logger.Info($"NDM initialized.");
                }
            }

            PeerLoader peerLoader = new PeerLoader(networkConfig, discoveryConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager, _staticNodesManager);
            _peerManager.Init();
        }
Ejemplo n.º 11
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Signer(), _privateKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            _rlpxPeer = new RlpxPeer(new NodeId(_privateKey.PublicKey), _initConfig.P2PPort,
                                     _syncManager,
                                     _messageSerializationService,
                                     encryptionHandshakeServiceA,
                                     _nodeStatsProvider,
                                     _logManager, _perfService);

            await _rlpxPeer.Init();

            var peerStorage = new NetworkStorage(PeersDbPath, _configProvider.GetConfig <INetworkConfig>(), _logManager, _perfService);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryManager, _syncManager, _nodeStatsProvider, peerStorage,
                                           _nodeFactory, _configProvider, _perfService, _logManager);
            _peerManager.Init(_initConfig.DiscoveryEnabled);
        }