示例#1
0
        public async Task StopAsync()
        {
            if (_logger.IsInfo)
            {
                _logger.Info("Shutting down...");
            }
            _runnerCancellation.Cancel();

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping rlpx peer...");
            }
            var rlpxPeerTask = _rlpxPeer?.Shutdown() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping sesison monitor...");
            }
            _sessionMonitor?.Stop();

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping peer manager...");
            }
            var peerManagerTask = _peerManager?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping synchronizer...");
            }
            var synchronizerTask = (_synchronizer?.StopAsync() ?? Task.CompletedTask)
                                   .ContinueWith(t => _synchronizer?.Dispose());

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping sync peer pool...");
            }
            var peerPoolTask = _syncPeerPool?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping block producer...");
            }
            var blockProducerTask = _blockProducer?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping blockchain processor...");
            }
            var blockchainProcessorTask = (_blockchainProcessor?.StopAsync() ?? Task.CompletedTask);

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping discovery app...");
            }
            var discoveryStopTask = _discoveryApp?.StopAsync() ?? Task.CompletedTask;

            await Task.WhenAll(discoveryStopTask, rlpxPeerTask, peerManagerTask, synchronizerTask, peerPoolTask, blockchainProcessorTask, blockProducerTask);

            if (_logger.IsInfo)
            {
                _logger.Info("Closing DBs...");
            }
            _dbProvider.Dispose();
            if (_logger.IsInfo)
            {
                _logger.Info("Ethereum shutdown complete... please wait for all components to close");
            }
        }