Esempio n. 1
0
        private void OverClock(INTMinerContext ntminerContext, IGpuProfile data)
        {
#if DEBUG
            NTStopwatch.Start();
#endif
            if (ntminerContext.GpuSet.TryGetGpu(data.Index, out IGpu gpu))
            {
                ntminerContext.GpuSet.OverClock.OverClock(gpuIndex: data.Index, OverClockValue.Create(data));
                if (data.Index == NTMinerContext.GpuAllId)
                {
                    NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}");
                }
                else
                {
                    NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}");
                }
                2.SecondsDelay().ContinueWith(t => {
                    ntminerContext.GpuSet.OverClock.RefreshGpuState(data.Index);
                });
            }
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(OverClock)}");
            }
#endif
        }
Esempio n. 2
0
        private void Init(INTMinerContext root)
        {
            var minerProfileRepository = root.ServerContext.CreateLocalRepository <MinerProfileData>();

            _data = minerProfileRepository.GetAll().FirstOrDefault();
            var mineWorkRepository = root.ServerContext.CreateLocalRepository <MineWorkData>();

            MineWork = mineWorkRepository.GetAll().FirstOrDefault();
            if (_data == null)
            {
                Guid  coinId = Guid.Empty;
                ICoin coin   = root.ServerContext.CoinSet.AsEnumerable().OrderBy(a => a.Code).FirstOrDefault();
                if (coin != null)
                {
                    coinId = coin.GetId();
                }
                _data = MinerProfileData.CreateDefaultData(coinId);
            }
            else
            {
                // 交换到注册表以供守护进程访问
                if (ClientAppType.IsMinerClient && !NTMinerContext.IsJsonLocal)
                {
                    SetIsOuterUserEnabled(_data.IsOuterUserEnabled);
                    SetOuterUserId(_data.OuterUserId);
                }
            }
            if (_coinProfileSet == null)
            {
                _coinProfileSet = new CoinProfileSet(root);
            }
            else
            {
                _coinProfileSet.Refresh();
            }
            if (_coinKernelProfileSet == null)
            {
                _coinKernelProfileSet = new CoinKernelProfileSet(root);
            }
            else
            {
                _coinKernelProfileSet.Refresh();
            }
            if (_poolProfileSet == null)
            {
                _poolProfileSet = new PoolProfileSet(root);
            }
            else
            {
                _poolProfileSet.Refresh();
            }
            if (_walletSet == null)
            {
                _walletSet = new WalletSet(root);
            }
            else
            {
                _walletSet.Refresh();
            }
        }
Esempio n. 3
0
        private void OverClock(INTMinerContext root, IGpuProfile data)
        {
#if DEBUG
            NTStopwatch.Start();
#endif
            if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu))
            {
                // fanSpeed == -1表示开源自动温控
                int fanSpeed = data.IsAutoFanSpeed ? -1 : data.Cool;
                root.GpuSet.OverClock.OverClock(data.Index, data.CoreClockDelta, data.CoreVoltage, data.MemoryClockDelta,
                                                data.MemoryVoltage, data.PowerCapacity, data.TempLimit, fanSpeed);
                if (data.Index == NTMinerContext.GpuAllId)
                {
                    NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}");
                }
                else
                {
                    NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}");
                }
                2.SecondsDelay().ContinueWith(t => {
                    root.GpuSet.OverClock.RefreshGpuState(data.Index);
                });
            }
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(OverClock)}");
            }
#endif
        }
                public static CoinProfile Create(INTMinerContext root, Guid coinId)
                {
                    if (root.ServerContext.CoinSet.TryGetCoin(coinId, out ICoin coin))
                    {
                        var data = GetCoinProfileData(coin.GetId());
                        if (data == null)
                        {
                            Guid  poolId = Guid.Empty;
                            IPool pool   = root.ServerContext.PoolSet.AsEnumerable().OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId);
                            if (pool != null)
                            {
                                poolId = pool.GetId();
                            }
                            string wallet       = coin.TestWallet;
                            Guid   coinKernelId = GetDefaultCoinKernelId(coin);
                            data = CoinProfileData.CreateDefaultData(coinId, poolId, wallet, coinKernelId);
                        }
                        else
                        {
                            if (!root.ServerContext.CoinKernelSet.TryGetCoinKernel(data.CoinKernelId, out ICoinKernel coinKernel))
                            {
                                data.CoinKernelId = GetDefaultCoinKernelId(coin);
                            }
                        }
                        CoinProfile coinProfile = new CoinProfile(data);

                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
Esempio n. 5
0
 public GpuProfileSet(INTMinerContext ntminerContext)
 {
     VirtualRoot.BuildCmdPath <AddOrUpdateGpuProfileCommand>(path: message => {
         GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index);
         if (data != null)
         {
             data.Update(message.Input);
             Save();
         }
         else
         {
             data = new GpuProfileData().Update(message.Input);
             _data.GpuProfiles.Add(data);
             Save();
         }
         VirtualRoot.RaiseEvent(new GpuProfileAddedOrUpdatedEvent(message.MessageId, data));
     }, location: this.GetType());
     // 注意:这个命令处理程序不能放在展示层注册。修复通过群控超频不生效的BUG:这是一个难以发现的老BUG,以前的版本也存
     // 在这个BUG,BUG具体表现是当没有点击过挖矿端主界面上的算力Tab页时通过群控超频无效。感谢矿友发现问题,已经修复。
     VirtualRoot.BuildCmdPath <CoinOverClockCommand>(path: message => {
         Task.Factory.StartNew(() => {
             CoinOverClock(ntminerContext, message.CoinId);
             VirtualRoot.RaiseEvent(new CoinOverClockDoneEvent(targetPathId: message.MessageId));
         });
     }, location: this.GetType());
 }
Esempio n. 6
0
        private static void PicGotOneIncorrectShare(INTMinerContext context, IMineContext mineContext, string line, string preline, IKernelOutput kernelOutput)
        {
            string pattern = kernelOutput.GpuGotOneIncorrectShare;

            if (string.IsNullOrEmpty(pattern))
            {
                return;
            }
            if (pattern.Contains("\n"))
            {
                line = preline + "\n" + line;
            }
            Regex regex = VirtualRoot.GetRegex(pattern);
            var   match = regex.Match(line);

            if (match.Success)
            {
                string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (IsMapGpuIndex(context, mineContext, kernelOutput) && gpuIndex < mineContext.UseDevices.Length)
                        {
                            gpuIndex = mineContext.UseDevices[gpuIndex];
                        }
                        context.GpusSpeed.IncreaseIncorrectShare(gpuIndex);
                    }
                }
            }
        }
Esempio n. 7
0
 private void CoinOverClock(INTMinerContext root, Guid coinId)
 {
     try {
         if (IsOverClockGpuAll(coinId))
         {
             GpuProfileData overClockData = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == coinId && a.Index == NTMinerContext.GpuAllId);
             if (overClockData != null)
             {
                 OverClock(root, overClockData);
             }
         }
         else
         {
             foreach (var overClockData in _data.GpuProfiles.Where(a => a.CoinId == coinId))
             {
                 if (overClockData.Index != NTMinerContext.GpuAllId)
                 {
                     OverClock(root, overClockData);
                 }
             }
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
Esempio n. 8
0
        public LocalJsonDb(INTMinerContext ntminerContext, MineWorkData mineWorkData)
        {
            var                    minerProfile    = ntminerContext.MinerProfile;
            CoinProfileData        mainCoinProfile = new CoinProfileData().Update(minerProfile.GetCoinProfile(minerProfile.CoinId));
            List <CoinProfileData> coinProfiles    = new List <CoinProfileData> {
                mainCoinProfile
            };
            List <PoolProfileData> poolProfiles        = new List <PoolProfileData>();
            CoinKernelProfileData  coinKernelProfile   = new CoinKernelProfileData().Update(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId));
            PoolProfileData        mainCoinPoolProfile = new PoolProfileData().Update(minerProfile.GetPoolProfile(mainCoinProfile.PoolId));

            poolProfiles.Add(mainCoinPoolProfile);
            if (mainCoinProfile.PoolId1 != Guid.Empty)
            {
                mainCoinPoolProfile = new PoolProfileData().Update(minerProfile.GetPoolProfile(mainCoinProfile.PoolId1));
                poolProfiles.Add(mainCoinPoolProfile);
            }
            if (coinKernelProfile.IsDualCoinEnabled)
            {
                CoinProfileData dualCoinProfile = new CoinProfileData().Update(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId));
                coinProfiles.Add(dualCoinProfile);
                PoolProfileData dualCoinPoolProfile = new PoolProfileData().Update(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId));
                poolProfiles.Add(dualCoinPoolProfile);
            }

            MinerProfile           = new MinerProfileData().Update(minerProfile);
            MinerProfile.MinerName = NTKeyword.MinerNameParameterName;
            MineWork           = mineWorkData;
            CoinProfiles       = coinProfiles.ToArray();
            CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile };
            PoolProfiles       = poolProfiles.ToArray();
            Pools     = ntminerContext.ServerContext.PoolSet.AsEnumerable().Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData().Update(a)).ToArray();
            Wallets   = minerProfile.GetWallets().Select(a => new WalletData().Update(a)).ToArray();
            TimeStamp = Timestamp.GetTimestamp();
        }
Esempio n. 9
0
        private static void PickTotalShare(INTMinerContext context, string line, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string totalSharePattern = kernelOutput.TotalSharePattern;

            if (isDual)
            {
                totalSharePattern = kernelOutput.DualTotalSharePattern;
            }
            if (string.IsNullOrEmpty(totalSharePattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(totalSharePattern);
            var   match = regex.Match(line);

            if (match.Success)
            {
                string totalShareText = match.Groups[NTKeyword.TotalShareGroupName].Value;
                if (int.TryParse(totalShareText, out int totalShare))
                {
                    ICoinShare share = context.CoinShareSet.GetOrCreate(coin.GetId());
                    context.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: totalShare - share.RejectShareCount, rejectShareCount: null, now: DateTime.Now);
                }
            }
        }
Esempio n. 10
0
 public ServerJsonDb(INTMinerContext root)
 {
     Coins = root.ServerContext.CoinSet.AsEnumerable().Cast <CoinData>().ToArray();
     // json向后兼容
     foreach (var coin in Coins)
     {
         if (root.ServerContext.SysDicItemSet.TryGetDicItem(coin.AlgoId, out ISysDicItem dicItem))
         {
             coin.Algo = dicItem.Value;
         }
     }
     Groups                  = root.ServerContext.GroupSet.AsEnumerable().Cast <GroupData>().ToArray();
     CoinGroups              = root.ServerContext.CoinGroupSet.AsEnumerable().Cast <CoinGroupData>().ToArray();
     KernelInputs            = root.ServerContext.KernelInputSet.AsEnumerable().Cast <KernelInputData>().ToArray();
     KernelOutputs           = root.ServerContext.KernelOutputSet.AsEnumerable().Cast <KernelOutputData>().ToArray();
     KernelOutputTranslaters = root.ServerContext.KernelOutputTranslaterSet.AsEnumerable().Cast <KernelOutputTranslaterData>().ToArray();
     Kernels                 = root.ServerContext.KernelSet.AsEnumerable().Cast <KernelData>().ToList();
     Packages                = root.ServerContext.PackageSet.AsEnumerable().Cast <PackageData>().ToList();
     CoinKernels             = root.ServerContext.CoinKernelSet.AsEnumerable().Cast <CoinKernelData>().ToList();
     FileWriters             = root.ServerContext.FileWriterSet.AsEnumerable().Cast <FileWriterData>().ToList();
     FragmentWriters         = root.ServerContext.FragmentWriterSet.AsEnumerable().Cast <FragmentWriterData>().ToList();
     PoolKernels             = root.ServerContext.PoolKernelSet.AsEnumerable().Cast <PoolKernelData>().Where(a => !string.IsNullOrEmpty(a.Args)).ToList();
     Pools          = root.ServerContext.PoolSet.AsEnumerable().Cast <PoolData>().ToList();
     SysDicItems    = root.ServerContext.SysDicItemSet.AsEnumerable().Cast <SysDicItemData>().ToArray();
     SysDics        = root.ServerContext.SysDicSet.AsEnumerable().Cast <SysDicData>().ToArray();
     this.TimeStamp = Timestamp.GetTimestamp();
 }
Esempio n. 11
0
        private static void PicGotOneIncorrectShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput)
        {
            string pattern = kernelOutput.GpuGotOneIncorrectShare;

            if (string.IsNullOrEmpty(pattern))
            {
                return;
            }
            if (pattern.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(pattern);
            var   match = regex.Match(input);

            if (match.Success)
            {
                string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                        {
                            if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                            {
                                gpuIndex = mineContext.UseDevices[gpuIndex];
                            }
                        }
                        root.GpusSpeed.IncreaseIncorrectShare(gpuIndex);
                    }
                }
            }
        }
Esempio n. 12
0
        private static void PickRejectPattern(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectSharePattern = kernelOutput.RejectSharePattern;

            if (isDual)
            {
                rejectSharePattern = kernelOutput.DualRejectSharePattern;
            }
            if (string.IsNullOrEmpty(rejectSharePattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(rejectSharePattern);
            var   match = regex.Match(input);

            if (match.Success)
            {
                string rejectShareText = match.Groups[NTKeyword.RejectShareGroupName].Value;

                if (int.TryParse(rejectShareText, out int rejectShare))
                {
                    root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: rejectShare, now: DateTime.Now);
                }
            }
        }
Esempio n. 13
0
 public void ReInit(INTMinerContext root)
 {
     Init(root);
     // 本地数据集已刷新,此时刷新本地数据集的视图模型集
     VirtualRoot.RaiseEvent(new LocalContextReInitedEvent());
     // 本地数据集的视图模型已刷新,此时刷新本地数据集的视图界面
     VirtualRoot.RaiseEvent(new LocalContextReInitedEventHandledEvent());
 }
Esempio n. 14
0
        private static void PickTotalSpeed(INTMinerContext root, string input, IKernelOutput kernelOutput, bool isDual)
        {
            string totalSpeedPattern = kernelOutput.TotalSpeedPattern;

            if (isDual)
            {
                totalSpeedPattern = kernelOutput.DualTotalSpeedPattern;
            }
            if (string.IsNullOrEmpty(totalSpeedPattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(totalSpeedPattern);
            Match match = regex.Match(input);

            if (match.Success)
            {
                string totalSpeedText = match.Groups[NTKeyword.TotalSpeedGroupName].Value;
                string totalSpeedUnit = match.Groups[NTKeyword.TotalSpeedUnitGroupName].Value;
                if (string.IsNullOrEmpty(totalSpeedUnit))
                {
                    if (isDual)
                    {
                        totalSpeedUnit = kernelOutput.DualSpeedUnit;
                    }
                    else
                    {
                        totalSpeedUnit = kernelOutput.SpeedUnit;
                    }
                }
                if (double.TryParse(totalSpeedText, out double totalSpeed))
                {
                    double     totalSpeedL = totalSpeed.FromUnitSpeed(totalSpeedUnit);
                    var        now         = DateTime.Now;
                    IGpusSpeed gpuSpeeds   = NTMinerContext.Instance.GpusSpeed;
                    gpuSpeeds.SetCurrentSpeed(NTMinerContext.GpuAllId, totalSpeedL, isDual, now);
                    string gpuSpeedPattern = kernelOutput.GpuSpeedPattern;
                    if (isDual)
                    {
                        gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern;
                    }
                    if (string.IsNullOrEmpty(gpuSpeedPattern) && root.GpuSet.Count != 0)
                    {
                        // 平分总算力
                        double gpuSpeedL = totalSpeedL / root.GpuSet.Count;
                        foreach (var item in gpuSpeeds.AsEnumerable())
                        {
                            if (item.Gpu.Index != NTMinerContext.GpuAllId)
                            {
                                gpuSpeeds.SetCurrentSpeed(item.Gpu.Index, gpuSpeedL, isDual, now);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 15
0
 public CalcConfigSet(INTMinerContext root)
 {
     _root = root;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.AddOnecePath <HasBoot20SecondEvent>("启动一定时间后初始化收益计算器", LogEnum.DevConsole,
                                                         action: message => {
             Init(forceRefresh: true);
         }, location: this.GetType(), pathId: PathId.Empty);
     }
 }
Esempio n. 16
0
 public CalcConfigSet(INTMinerContext ntminerContext)
 {
     _ntminerContext = ntminerContext;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.BuildOnecePath <HasBoot20SecondEvent>("初始化收益计算器", LogEnum.DevConsole, pathId: PathId.Empty, location: this.GetType(), PathPriority.Normal,
                                                           path: message => {
             Init();
         });
     }
 }
Esempio n. 17
0
 public CalcConfigSet(INTMinerContext root)
 {
     _root = root;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.BuildOnecePath <HasBoot20SecondEvent>("初始化收益计算器", LogEnum.DevConsole,
                                                           path: message => {
             Init();
         }, location: this.GetType(), pathId: PathId.Empty);
     }
 }
Esempio n. 18
0
 public CalcConfigSet(INTMinerContext ntminerContext)
 {
     _ntminerContext = ntminerContext;
     if (ClientAppType.IsMinerClient)
     {
         VirtualRoot.BuildEventPath <MineStartedEvent>("开始挖矿时加载收益计算器数据", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                       path: message => {
             Init();
         });
     }
 }
                // 获取默认双挖权重
                private static double GetDualCoinWeight(INTMinerContext ntminerContext, Guid kernelId)
                {
                    double dualCoinWeight = 0;

                    if (ntminerContext.ServerContext.KernelSet.TryGetKernel(kernelId, out IKernel kernel))
                    {
                        if (ntminerContext.ServerContext.KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput))
                        {
                            dualCoinWeight = (kernelInput.DualWeightMin + kernelInput.DualWeightMax) / 2;
                        }
                    }
                    return(dualCoinWeight);
                }
Esempio n. 20
0
        public NVIDIAGpuSet(INTMinerContext ntminerContext)
        {
            this.OverClock  = new GpuOverClock(_nvapiHelper);
            this.Properties = new List <GpuSetProperty>();
            var gpus = _nvmlHelper.GetGpus();

            if (gpus.Count > 0)
            {
                foreach (var item in gpus)
                {
                    var gpu = Gpu.Create(GpuType.NVIDIA, item.GpuIndex, item.BusId.ToString(), item.Name);
                    gpu.TotalMemory = item.TotalMemory;
                    _gpus.Add(item.GpuIndex, gpu);
                }
                _nvmlHelper.GetVersion(out _driverVersionRaw, out string nvmlVersion);
                Version.TryParse(_driverVersionRaw, out _driverVersion);
                this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", _driverVersion));
                try {
                    var item = ntminerContext.ServerContext.SysDicItemSet.GetSysDicItems(NTKeyword.CudaVersionSysDicCode)
                               .Select(a => new { Version = double.Parse(a.Value), a })
                               .OrderByDescending(a => a.Version)
                               .FirstOrDefault(a => _driverVersion.Major >= a.Version);
                    if (item != null)
                    {
                        this.Properties.Add(new GpuSetProperty(NTKeyword.CudaVersionSysDicCode, "Cuda版本", item.a.Code));
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                this.Properties.Add(new GpuSetProperty("NVMLVersion", "NVML版本", nvmlVersion));
                Dictionary <string, string> kvs = new Dictionary <string, string> {
                    ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
                };
                foreach (var kv in kvs)
                {
                    var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value);
                    this.Properties.Add(property);
                }
                Task.Factory.StartNew(() => {
                    OverClock.RefreshGpuState(NTMinerContext.GpuAllId);
                    // 这里会耗时5秒
                    foreach (var kv in kvs)
                    {
                        Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                    }
                });
            }
        }
Esempio n. 21
0
 public MinerProfile(INTMinerContext ntminerContext)
 {
     _ntminerContext = ntminerContext;
     VirtualRoot.BuildCmdPath <RefreshAutoBootStartCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => {
         var minerProfileRepository = ntminerContext.ServerContext.CreateLocalRepository <MinerProfileData>();
         var data = minerProfileRepository.GetAll().FirstOrDefault();
         if (data != null && _data != null)
         {
             _data.IsAutoBoot  = data.IsAutoBoot;
             _data.IsAutoStart = data.IsAutoStart;
             VirtualRoot.RaiseEvent(new AutoBootStartRefreshedEvent());
         }
     });
     Init(ntminerContext);
 }
                private static PoolProfileData GetPoolProfileData(INTMinerContext root, Guid poolId)
                {
                    var repository = root.ServerContext.CreateLocalRepository <PoolProfileData>();
                    var result     = repository.GetByKey(poolId);

                    if (result == null)
                    {
                        if (root.ServerContext.PoolSet.TryGetPool(poolId, out IPool pool))
                        {
                            // 如果本地未设置用户名密码则使用默认的测试用户名密码
                            result = PoolProfileData.CreateDefaultData(pool);
                        }
                    }
                    return(result);
                }
Esempio n. 23
0
        private static string GetDevicesArgs(IKernelInput kernelInput)
        {
            INTMinerContext ntminerContext = NTMinerContext.Instance;
            var             gpuSet         = ntminerContext.GpuSet;
            string          devicesArgs    = string.Empty;

            if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg))
            {
                int[] useDevices = gpuSet.GetUseDevices();
                if ((useDevices.Length != 0 && useDevices.Length != gpuSet.Count) || kernelInput.IsDeviceAllNotEqualsNone)
                {
                    string separator = kernelInput.DevicesSeparator;
                    // 因为空格在界面上不易被人读取所以以关键字代替空格
                    if (kernelInput.DevicesSeparator == NTKeyword.SpaceKeyword)
                    {
                        separator = " ";
                    }
                    List <string> gpuIndexes = new List <string>();
                    foreach (var index in useDevices)
                    {
                        int i = index;
                        if (kernelInput.DeviceBaseIndex != 0)
                        {
                            i = index + kernelInput.DeviceBaseIndex;
                        }
                        string nText = NTKeyword.GetIndexChar(i, separator);
                        gpuIndexes.Add(nText);
                    }
                    switch (gpuSet.GpuType)
                    {
                    case GpuType.Empty:
                        break;

                    case GpuType.NVIDIA:
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes.Select(a => $"{kernelInput.NDevicePrefix}{a}{kernelInput.NDevicePostfix}"))}";
                        break;

                    case GpuType.AMD:
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes.Select(a => $"{kernelInput.ADevicePrefix}{a}{kernelInput.ADevicePostfix}"))}";
                        break;

                    default:
                        break;
                    }
                }
            }
            return(devicesArgs);
        }
Esempio n. 24
0
        private static void PickAcceptOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string acceptOneShare = kernelOutput.AcceptOneShare;

            if (isDual)
            {
                acceptOneShare = kernelOutput.DualAcceptOneShare;
            }
            if (string.IsNullOrEmpty(acceptOneShare))
            {
                return;
            }
            if (acceptOneShare.Contains("\n"))
            {
                input = preline + "\n" + input;
            }
            Regex regex = VirtualRoot.GetRegex(acceptOneShare);
            var   match = regex.Match(input);

            if (match.Success)
            {
                if (!isDual)
                {
                    // 决定不支持双挖的单卡份额统计
                    string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                    if (!string.IsNullOrEmpty(gpuText))
                    {
                        if (int.TryParse(gpuText, out int gpuIndex))
                        {
                            if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg))
                            {
                                if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length)
                                {
                                    gpuIndex = mineContext.UseDevices[gpuIndex];
                                }
                            }
                            if (string.IsNullOrEmpty(kernelOutput.FoundOneShare))
                            {
                                root.GpusSpeed.IncreaseFoundShare(gpuIndex);
                            }
                            root.GpusSpeed.IncreaseAcceptShare(gpuIndex);
                        }
                    }
                }
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: share.AcceptShareCount + 1, rejectShareCount: null, now: DateTime.Now);
            }
        }
Esempio n. 25
0
        public ServerJsonDb(INTMinerContext ntminerContext, LocalJsonDb localJsonObj) : this()
        {
            var minerProfile    = ntminerContext.MinerProfile;
            var mainCoinProfile = minerProfile.GetCoinProfile(minerProfile.CoinId);

            ntminerContext.ServerContext.CoinKernelSet.TryGetCoinKernel(mainCoinProfile.CoinKernelId, out ICoinKernel coinKernel);
            if (coinKernel == null)
            {
                return;
            }
            ntminerContext.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel);
            if (kernel == null)
            {
                return;
            }
            var coins      = ntminerContext.ServerContext.CoinSet.AsEnumerable().Cast <CoinData>().Where(a => localJsonObj.CoinProfiles.Any(b => b.CoinId == a.Id)).ToArray();
            var coinGroups = ntminerContext.ServerContext.CoinGroupSet.AsEnumerable().Cast <CoinGroupData>().Where(a => coins.Any(b => b.Id == a.CoinId)).ToArray();
            var pools      = ntminerContext.ServerContext.PoolSet.AsEnumerable().Cast <PoolData>().Where(a => localJsonObj.PoolProfiles.Any(b => b.PoolId == a.Id)).ToList();

            Coins = coins;
            // json向后兼容
            foreach (var coin in Coins)
            {
                if (ntminerContext.ServerContext.SysDicItemSet.TryGetDicItem(coin.AlgoId, out ISysDicItem dicItem))
                {
                    coin.Algo = dicItem.Value;
                }
            }
            CoinGroups              = coinGroups;
            Pools                   = pools;
            Groups                  = ntminerContext.ServerContext.GroupSet.AsEnumerable().Cast <GroupData>().Where(a => coinGroups.Any(b => b.GroupId == a.Id)).ToArray();
            KernelInputs            = ntminerContext.ServerContext.KernelInputSet.AsEnumerable().Cast <KernelInputData>().Where(a => a.Id == kernel.KernelInputId).ToArray();
            KernelOutputs           = ntminerContext.ServerContext.KernelOutputSet.AsEnumerable().Cast <KernelOutputData>().Where(a => a.Id == kernel.KernelOutputId).ToArray();
            KernelOutputTranslaters = ntminerContext.ServerContext.KernelOutputTranslaterSet.AsEnumerable().Cast <KernelOutputTranslaterData>().Where(a => a.KernelOutputId == kernel.KernelOutputId).ToArray();
            Kernels                 = new List <KernelData> {
                (KernelData)kernel
            };
            Packages        = ntminerContext.ServerContext.PackageSet.AsEnumerable().Cast <PackageData>().Where(a => a.Name == kernel.Package).ToList();
            CoinKernels     = ntminerContext.ServerContext.CoinKernelSet.AsEnumerable().Cast <CoinKernelData>().Where(a => localJsonObj.CoinKernelProfiles.Any(b => b.CoinKernelId == a.Id)).ToList();
            FileWriters     = ntminerContext.ServerContext.FileWriterSet.AsEnumerable().Cast <FileWriterData>().ToList();         // 这个数据没几条就不精简了
            FragmentWriters = ntminerContext.ServerContext.FragmentWriterSet.AsEnumerable().Cast <FragmentWriterData>().ToList(); // 这个数据没几条就不精简了
            PoolKernels     = ntminerContext.ServerContext.PoolKernelSet.AsEnumerable().Cast <PoolKernelData>().Where(a => !string.IsNullOrEmpty(a.Args) && pools.Any(b => b.Id == a.PoolId)).ToList();
            SysDicItems     = ntminerContext.ServerContext.SysDicItemSet.AsEnumerable().Cast <SysDicItemData>().ToArray();
            SysDics         = ntminerContext.ServerContext.SysDicSet.AsEnumerable().Cast <SysDicData>().ToArray();
            TimeStamp       = NTMinerContext.ServerJsonDb.TimeStamp;
        }
                public static PoolProfile Create(INTMinerContext root, Guid poolIdId)
                {
                    if (root.ServerContext.PoolSet.TryGetPool(poolIdId, out IPool pool))
                    {
                        var data = GetPoolProfileData(root, pool.GetId());
                        if (data == null)
                        {
                            data = PoolProfileData.CreateDefaultData(pool);
                        }
                        PoolProfile coinProfile = new PoolProfile(data);

                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
Esempio n. 27
0
        public GpusSpeed(INTMinerContext root)
        {
            _root = root;
            VirtualRoot.BuildEventPath <Per10MinuteEvent>("周期清除过期的历史算力", LogEnum.DevConsole,
                                                          path: message => {
                ClearOutOfDateHistory();
            }, location: this.GetType());

            VirtualRoot.BuildEventPath <MineStopedEvent>("停止挖矿后产生一次0算力", LogEnum.DevConsole,
                                                         path: message => {
                var now = DateTime.Now;
                foreach (var gpu in _root.GpuSet.AsEnumerable())
                {
                    SetCurrentSpeed(gpuIndex: gpu.Index, speed: 0.0, isDual: false, now: now);
                    if (message.MineContext is IDualMineContext dualMineContext)
                    {
                        SetCurrentSpeed(gpuIndex: gpu.Index, speed: 0.0, isDual: true, now: now);
                    }
                }
            }, location: this.GetType());

            VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始时产生一次0算力0份额", LogEnum.DevConsole,
                                                          path: message => {
                var now = DateTime.Now;
                _root.CoinShareSet.UpdateShare(message.MineContext.MainCoin.GetId(), 0, 0, now);
                _root.GpusSpeed.ResetShare();
                foreach (var gpu in _root.GpuSet.AsEnumerable())
                {
                    SetCurrentSpeed(gpuIndex: gpu.Index, speed: 0.0, isDual: false, now: now);
                }
                if (message.MineContext is IDualMineContext dualMineContext)
                {
                    _root.CoinShareSet.UpdateShare(dualMineContext.DualCoin.GetId(), 0, 0, now);
                    foreach (var gpu in _root.GpuSet.AsEnumerable())
                    {
                        SetCurrentSpeed(gpuIndex: gpu.Index, speed: 0.0, isDual: true, now: now);
                    }
                }
            }, location: this.GetType());
        }
Esempio n. 28
0
        private static void PickRejectPercent(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual)
        {
            string rejectPercentPattern = kernelOutput.RejectPercentPattern;

            if (isDual)
            {
                rejectPercentPattern = kernelOutput.DualRejectPercentPattern;
            }
            if (string.IsNullOrEmpty(rejectPercentPattern))
            {
                return;
            }
            Regex  regex             = VirtualRoot.GetRegex(rejectPercentPattern);
            var    match             = regex.Match(input);
            string rejectPercentText = match.Groups[NTKeyword.RejectPercentGroupName].Value;

            if (double.TryParse(rejectPercentText, out double rejectPercent))
            {
                ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId());
                root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: (int)(share.TotalShareCount * rejectPercent), now: DateTime.Now);
            }
        }
Esempio n. 29
0
        private static void PicGpuRejectShare(INTMinerContext context, IMineContext mineContext, string line, IKernelOutput kernelOutput, bool isDual)
        {
            string gpuRejectSharePattern = kernelOutput.GpuRejectShare;

            if (isDual)
            {
                return;
            }
            if (string.IsNullOrEmpty(gpuRejectSharePattern))
            {
                return;
            }
            Regex regex = VirtualRoot.GetRegex(gpuRejectSharePattern);
            Match match = regex.Match(line);

            if (match.Success)
            {
                string gpuText         = match.Groups[NTKeyword.GpuIndexGroupName].Value;
                string rejectShareText = match.Groups[NTKeyword.RejectShareGroupName].Value;
                if (!string.IsNullOrEmpty(gpuText))
                {
                    if (int.TryParse(gpuText, out int gpuIndex))
                    {
                        if (IsMapGpuIndex(context, mineContext, kernelOutput) && gpuIndex < mineContext.UseDevices.Length)
                        {
                            gpuIndex = mineContext.UseDevices[gpuIndex];
                        }
                        if (!string.IsNullOrEmpty(rejectShareText))
                        {
                            if (int.TryParse(rejectShareText, out int rejectShare))
                            {
                                context.GpusSpeed.SetRejectShare(gpuIndex, rejectShare);
                                // TODO:如果gpuTotal的拒绝份额为0,求和拒绝份额
                            }
                        }
                    }
                }
            }
        }
Esempio n. 30
0
        private void OverClock(INTMinerContext root, IGpuProfile data)
        {
#if DEBUG
            NTStopwatch.Start();
#endif
            if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu))
            {
                IOverClock overClock = root.GpuSet.OverClock;
                if (!data.IsAutoFanSpeed)
                {
                    overClock.SetFanSpeed(data.Index, data.Cool);
                }
                overClock.SetCoreClock(data.Index, data.CoreClockDelta, data.CoreVoltage);
                overClock.SetMemoryClock(data.Index, data.MemoryClockDelta, data.MemoryVoltage);
                overClock.SetPowerLimit(data.Index, data.PowerCapacity);
                overClock.SetTempLimit(data.Index, data.TempLimit);
                if (data.Index == NTMinerContext.GpuAllId)
                {
                    NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}");
                }
                else
                {
                    NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}");
                }
                1.SecondsDelay().ContinueWith(t => {
                    overClock.RefreshGpuState(data.Index);
                });
            }
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.OverClock");
            }
#endif
        }