예제 #1
0
        protected bool UpdateJob(AionBlockTemplate blockTemplate)
        {
            logger.LogInvoke(LogCat);

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

                var job   = currentJob;
                var isNew = currentJob == null || job.BlockTemplate.HeaderHash != blockTemplate.HeaderHash;

                if (isNew)
                {
                    var jobId = NextJobId("x8");
                    job = new AionJob(jobId, blockTemplate, logger, daemon);
                    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)
                        {
                            validJobs.Remove(key);
                        }
                    }

                    currentJob = job;

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

                return(isNew);
            }

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

            return(false);
        }
예제 #2
0
        public AionJob(string id, AionBlockTemplate blockTemplate, ILogger logger, DaemonClient daemon)
        {
            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.HexToByteArray().ReverseArray());
        }