private static async Task Start() { // start share recorder shareRecorder = container.Resolve <ShareRecorder>(); shareRecorder.Start(clusterConfig); // start API if (clusterConfig.Api == null || clusterConfig.Api.Enabled) { apiServer = container.Resolve <ApiServer>(); apiServer.Start(clusterConfig); } // start payment processor if (clusterConfig.PaymentProcessing?.Enabled == true && clusterConfig.Pools.Any(x => x.PaymentProcessing?.Enabled == true)) { payoutManager = container.Resolve <PayoutManager>(); payoutManager.Configure(clusterConfig); payoutManager.Start(); } else { logger.Info("Payment processing is not enabled"); } // start pool stats updater statsRecorder = container.Resolve <StatsRecorder>(); statsRecorder.Configure(clusterConfig); statsRecorder.Start(); // start pools await Task.WhenAll(clusterConfig.Pools.Where(x => x.Enabled).Select(async poolConfig => { // resolve pool implementation var poolImpl = container.Resolve <IEnumerable <Meta <Lazy <IMiningPool, CoinMetadataAttribute> > > >() .First(x => x.Value.Metadata.SupportedCoins.Contains(poolConfig.Coin.Type)).Value; // create and configure var pool = poolImpl.Value; pool.Configure(poolConfig, clusterConfig); // pre-start attachments shareRecorder.AttachPool(pool); statsRecorder.AttachPool(pool); await pool.StartAsync(); // post-start attachments apiServer.AttachPool(pool); })); // keep running await Observable.Never <Unit>().ToTask(); }
private static async Task Start() { var coinTemplates = LoadCoinTemplates(); logger.Info($"{coinTemplates.Keys.Count} coins loaded from {string.Join(", ", clusterConfig.CoinTemplates)}"); // Populate pool configs with corresponding template foreach (var poolConfig in clusterConfig.Pools.Where(x => x.Enabled)) { // Lookup coin definition if (!coinTemplates.TryGetValue(poolConfig.Coin, out var template)) { logger.ThrowLogPoolStartupException($"Pool {poolConfig.Id} references undefined coin '{poolConfig.Coin}'"); } poolConfig.Template = template; } // Notifications notificationService = container.Resolve <NotificationService>(); // start btStream receiver btStreamReceiver = container.Resolve <BtStreamReceiver>(); btStreamReceiver.Start(clusterConfig); if (clusterConfig.ShareRelay == null) { // start share recorder shareRecorder = container.Resolve <ShareRecorder>(); shareRecorder.Start(clusterConfig); // start share receiver (for external shares) shareReceiver = container.Resolve <ShareReceiver>(); shareReceiver.Start(clusterConfig); } else { // start share relay shareRelay = container.Resolve <ShareRelay>(); shareRelay.Start(clusterConfig); } // start API if (clusterConfig.Api == null || clusterConfig.Api.Enabled) { StartApi(); metricsPublisher = container.Resolve <MetricsPublisher>(); } // start payment processor if (clusterConfig.PaymentProcessing?.Enabled == true && clusterConfig.Pools.Any(x => x.PaymentProcessing?.Enabled == true)) { payoutManager = container.Resolve <PayoutManager>(); payoutManager.Configure(clusterConfig); payoutManager.Start(); } else { logger.Info("Payment processing is not enabled"); } if (clusterConfig.ShareRelay == null) { // start pool stats updater statsRecorder = container.Resolve <StatsRecorder>(); statsRecorder.Configure(clusterConfig); statsRecorder.Start(); } // start pools await Task.WhenAll(clusterConfig.Pools.Where(x => x.Enabled).Select(async poolConfig => { // resolve pool implementation var poolImpl = container.Resolve <IEnumerable <Meta <Lazy <IMiningPool, CoinFamilyAttribute> > > >() .First(x => x.Value.Metadata.SupportedFamilies.Contains(poolConfig.Template.Family)).Value; // create and configure var pool = poolImpl.Value; pool.Configure(poolConfig, clusterConfig); pools[poolConfig.Id] = pool; // pre-start attachments shareReceiver?.AttachPool(pool); statsRecorder?.AttachPool(pool); //apiServer?.AttachPool(pool); await pool.StartAsync(cts.Token); })); // keep running await Observable.Never <Unit>().ToTask(cts.Token); }