Example #1
0
        private async Task DetectChainAsync()
        {
            var commands = new[]
            {
                new DaemonCmd(EC.GetNetVersion),
                new DaemonCmd(EC.ParityChain),
            };

            var results = await daemon.ExecuteBatchAnyAsync(commands);

            if (results.Any(x => x.Error != null))
            {
                var errors = results.Where(x => x.Error != null)
                             .ToArray();

                if (errors.Any())
                {
                    throw new Exception($"Chain detection failed: {string.Join(", ", errors.Select(y => y.Error.Message))}");
                }
            }

            var netVersion  = results[0].Response.ToObject <string>();
            var parityChain = results[1].Response.ToObject <string>();

            EthereumUtils.DetectNetworkAndChain(netVersion, parityChain, out networkType, out chainType);
        }
        protected override async Task PostStartInitAsync(CancellationToken ct)
        {
            var commands = new[]
            {
                new DaemonCmd(EC.GetNetVersion),
                new DaemonCmd(EC.GetAccounts),
                new DaemonCmd(EC.GetCoinbase),
                new DaemonCmd(EC.ParityVersion),
                new DaemonCmd(EC.ParityChain),
            };

            var results = await daemon.ExecuteBatchAnyAsync(commands);

            if (results.Any(x => x.Error != null))
            {
                if (results[4].Error != null)
                {
                    logger.ThrowLogPoolStartupException($"Looks like you are NOT running 'Parity' as daemon which is not supported - https://parity.io/", LogCat);
                }

                var errors = results.Where(x => x.Error != null)
                             .ToArray();

                if (errors.Any())
                {
                    logger.ThrowLogPoolStartupException($"Init RPC failed: {string.Join(", ", errors.Select(y => y.Error.Message))}", LogCat);
                }
            }


            var netVersion    = results[0].Response.ToObject <string>();
            var accounts      = results[1].Response.ToObject <string[]>();
            var coinbase      = results[2].Response.ToObject <string>();
            var parityVersion = results[3].Response.ToObject <JObject>();
            var parityChain   = results[4].Response.ToObject <string>();


            EthereumUtils.DetectNetworkAndChain(netVersion, parityChain, out networkType, out chainType);



            BlockchainStats.RewardType  = "POW";
            BlockchainStats.NetworkType = $"{chainType}-{networkType}";

            await UpdateNetworkStatsAsync();

            // Periodically update network stats
            Observable.Interval(TimeSpan.FromMinutes(10))
            .Select(via => Observable.FromAsync(UpdateNetworkStatsAsync))
            .Concat()
            .Subscribe();

            if (poolConfig.EnableInternalStratum == true)
            {
                while (true)
                {
                    var blockTemplate = await GetBlockTemplateAsync();

                    if (blockTemplate != null)
                    {
                        logger.Info(() => $"[{LogCat}] Loading current DAG ...");

                        await ethash.GetDagAsync(blockTemplate.Height, logger);

                        logger.Info(() => $"[{LogCat}] Loaded current DAG");
                        break;
                    }

                    logger.Info(() => $"[{LogCat}] Waiting for first valid block template");
                    await Task.Delay(TimeSpan.FromSeconds(5), ct);
                }

                SetupJobUpdates();
            }
        }