Пример #1
0
        public AionJob(string id, AionBlockTemplate blockTemplate, ILogger logger, DaemonClient daemon, IComponentContext ctx, JObject solver)
        {
            Id            = id;
            BlockTemplate = blockTemplate;
            this.logger   = logger;

            var target = blockTemplate.Target;

            if (target.StartsWith("0x"))
            {
                target = target.Substring(2);
            }

            this.daemonClient = daemon;
            Difficulty        = getNetworkDifficulty();
            blockTarget       = new uint256(target.HexToReverseByteArray());
            equihash          = EquihashSolverFactory.GetSolver(ctx, solver);
        }
Пример #2
0
        protected bool UpdateJob(AionBlockTemplate blockTemplate)
        {
            logger.LogInvoke();

            try
            {
                // may happen if daemon is currently not connected to peers
                if (blockTemplate == null || blockTemplate.HeaderHash == null || blockTemplate.HeaderHash?.Length == 0)
                {
                    return(false);
                }

                var job = currentJob;
                // TODO: Is headerHash comparison needed?
                var isNew = currentJob == null ||
                            job.BlockTemplate.HeaderHash != blockTemplate.HeaderHash;

                if (isNew)
                {
                    messageBus.NotifyChainHeight(poolConfig.Id, blockTemplate.Height, poolConfig.Template);

                    var jobId = NextJobId("x8");
                    job = new AionJob(jobId, blockTemplate, logger, daemon, ctx, solver);

                    // logger.Info(() => $"!!! src/Mingingcore/Blockchain/Aion/AionJobManager.cs/UpdateJob jobId '{jobId}' height '{(long)job.BlockTemplate.Height}'");

                    lock (jobLock)
                    {
                        // add jobs
                        validJobs[jobId] = job;

                        // remove old ones
                        var obsoleteKeys = validJobs.Keys
                                           .Where(key => (long)validJobs[key].BlockTemplate.Height < (long)(job.BlockTemplate.Height - MaxBlockBacklog)).ToArray();

                        foreach (var key in obsoleteKeys)
                        {
                            // logger.Info(() => $"!!! src/Mingingcore/Blockchain/Aion/AionJobManager.cs/UpdateJob job-remove key '{key}' height '{(long) validJobs[key].BlockTemplate.Height}' current-height '{(long)job.BlockTemplate.Height}'");
                            validJobs.Remove(key);
                        }
                    }

                    currentJob = job;

                    // update stats
                    BlockchainStats.LastNetworkBlockTime = clock.Now;
                    BlockchainStats.BlockHeight          = currentJob.BlockTemplate.Height;
                    var(networkHashrate, poolHashRate)   = getNetworkAndMinerHashRate();
                    BlockchainStats.NetworkHashrate      = networkHashrate;
                    PoolHashRate = poolHashRate;
                }

                return(isNew);
            }

            catch (Exception ex)
            {
                logger.Error(ex, () => $"Error during {nameof(UpdateJob)}");
            }

            return(false);
        }