예제 #1
0
        private MiningParameters GetMiningParameters()
        {
            Program.Print(string.Format("[INFO] Checking latest parameters from master URL: {0}", SubmitURL));

            var getChallenge  = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetChallenge);
            var getDifficulty = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetDifficulty);
            var getTarget     = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetTarget);
            var getPause      = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetPause);

            var success   = true;
            var startTime = DateTime.Now;

            try
            {
                return(MiningParameters.GetMiningParameters(SubmitURL,
                                                            getChallenge: getChallenge,
                                                            getDifficulty: getDifficulty,
                                                            getTarget: getTarget,
                                                            getPause: getPause));
            }
            catch (Exception ex)
            {
                HandleException(ex);
                success = false;
            }
            finally
            {
                if (success)
                {
                    Latency = (int)(DateTime.Now - startTime).TotalMilliseconds;
                }
            }
            return(null);
        }
        public MiningParameters GetMiningParameters()
        {
            Program.Print("[INFO] Checking latest parameters from network...");

            m_cacheParameters = MiningParameters.GetSoloMiningParameters(m_contract, m_minerAddress);

            return(m_cacheParameters);
        }
예제 #3
0
        private void m_updateMinerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var miningParameters = GetMiningParameters();
                if (miningParameters == null)
                {
                    OnGetMiningParameterStatusEvent(this, false, null);
                    return;
                }

                var address = miningParameters.EthAddress;
                var target  = miningParameters.MiningTargetByte32String;
                CurrentChallenge = miningParameters.ChallengeNumberByte32String;
                DifficultyHex    = miningParameters.MiningDifficulty.HexValue;

                if (m_lastParameters == null || miningParameters.ChallengeNumber.Value != m_lastParameters.ChallengeNumber.Value)
                {
                    Program.Print(string.Format("[INFO] New challenge detected {0}...", CurrentChallenge));
                    OnNewMessagePrefixEvent(this, CurrentChallenge + address.Replace("0x", string.Empty));
                }

                if (m_lastParameters == null || miningParameters.MiningTarget.Value != m_lastParameters.MiningTarget.Value)
                {
                    Program.Print(string.Format("[INFO] New target detected {0}...", target));
                    OnNewTargetEvent(this, target);
                }

                if (m_lastParameters == null || miningParameters.MiningDifficulty.Value != m_lastParameters.MiningDifficulty.Value)
                {
                    Program.Print(string.Format("[INFO] New difficulity detected ({0})...", miningParameters.MiningDifficulty.Value));
                    Difficulty = Convert.ToUInt64(miningParameters.MiningDifficulty.Value.ToString());

                    // Actual difficulty should have decimals
                    var calculatedDifficulty = Math.Exp(BigInteger.Log(m_maxTarget.Value) - BigInteger.Log(miningParameters.MiningTarget.Value));

                    if ((ulong)calculatedDifficulty != Difficulty) // Only replace if the integer portion is different
                    {
                        Difficulty = (ulong)calculatedDifficulty;

                        var expValue = BitConverter.GetBytes(decimal.GetBits((decimal)calculatedDifficulty)[3])[2];

                        var calculatedTarget = m_maxTarget.Value * (ulong)Math.Pow(10, expValue) / (ulong)(calculatedDifficulty * Math.Pow(10, expValue));

                        Program.Print(string.Format("[INFO] Update target {0}...", Utils.Numerics.BigIntegerToByte32HexString(calculatedTarget)));
                        OnNewTargetEvent(this, Utils.Numerics.BigIntegerToByte32HexString(calculatedTarget));
                    }
                }

                m_lastParameters = miningParameters;
                OnGetMiningParameterStatusEvent(this, true, miningParameters);
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("[ERROR] {0}", ex.Message));
            }
        }
예제 #4
0
        public MiningParameters GetMiningParameters()
        {
            Program.Print("[INFO] Checking latest parameters from pool...");

            var getPoolEthAddress             = GetPoolParameter("getPoolEthAddress");
            var getPoolChallengeNumber        = GetPoolParameter("getChallengeNumber");
            var getPoolMinimumShareDifficulty = GetPoolParameter("getMinimumShareDifficulty", s_MinerAddress);
            var getPoolMinimumShareTarget     = GetPoolParameter("getMinimumShareTarget", s_MinerAddress);

            bool success = true;

            try
            {
                m_cacheParameters = MiningParameters.GetPoolMiningParameters(s_PoolURL, getPoolEthAddress, getPoolChallengeNumber,
                                                                             getPoolMinimumShareDifficulty, getPoolMinimumShareTarget);

                return(m_cacheParameters);
            }
            catch (AggregateException ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                foreach (var iEx in ex.InnerExceptions)
                {
                    errorMsg += ("\n " + iEx.Message);
                }

                Program.Print("[ERROR] " + errorMsg);
            }
            catch (Exception ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMsg += ("\n " + ex.InnerException.Message);
                }
                Program.Print("[ERROR] " + errorMsg);
            }

            if (!success && SecondaryPool != null && m_retryCount >= m_maxScanRetry)
            {
                m_runFailover = true;
                Program.Print("[INFO] Checking mining parameters from secondary pool...");
                return(SecondaryPool.GetMiningParameters());
            }

            return(null);
        }
        private void m_updateMinerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var miningParameters = GetMiningParameters();
                if (miningParameters == null)
                {
                    OnGetMiningParameterStatusEvent(this, false, null);
                    return;
                }

                var address   = miningParameters.EthAddress;
                var challenge = miningParameters.ChallengeNumberByte32String;
                var target    = miningParameters.MiningTargetByte32String;
                DifficultyHex = miningParameters.MiningDifficulty.HexValue;

                if (m_lastParameters == null || miningParameters.ChallengeNumber.Value != m_lastParameters.ChallengeNumber.Value)
                {
                    Program.Print(string.Format("[INFO] New challenge detected {0}...", challenge));
                    OnNewMessagePrefixEvent(this, challenge + address.Replace("0x", string.Empty));
                }

                if (m_lastParameters == null || miningParameters.MiningTarget.Value != m_lastParameters.MiningTarget.Value)
                {
                    Program.Print(string.Format("[INFO] New target detected {0}...", target));
                    OnNewTargetEvent(this, target);
                }

                if (m_lastParameters == null || miningParameters.MiningDifficulty.Value != m_lastParameters.MiningDifficulty.Value)
                {
                    Program.Print(string.Format("[INFO] New difficulity detected ({0})...", miningParameters.MiningDifficulty.Value));
                    Difficulty = Convert.ToUInt64(miningParameters.MiningDifficulty.Value.ToString());

                    var calculatedTarget = m_maxTarget.Value / Difficulty;
                    if (calculatedTarget != miningParameters.MiningTarget.Value)
                    {
                        var newTarget = calculatedTarget.ToString();
                        Program.Print(string.Format("[INFO] Update target {0}...", newTarget));
                        OnNewTargetEvent(this, newTarget);
                    }
                }

                m_lastParameters = miningParameters;
                OnGetMiningParameterStatusEvent(this, true, miningParameters);
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("[ERROR] {0}", ex.Message));
            }
        }
예제 #6
0
        public SlaveInterface(string masterURL, int updateInterval, int hashratePrintInterval)
            : base(updateInterval, hashratePrintInterval)
        {
            m_isGetMiningParameters = false;
            SubmitURL = masterURL;

            Program.Print(string.Format("[INFO] Waiting for master instance ({0}) to start...", SubmitURL));

            var getMasterAddress = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetMinerAddress);
            var getMaximumTarget = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetMaximumTarget);
            var getKingAddress   = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetKingAddress);
            var getPoolMining    = Miner.MasterInterface.GetMasterParameter(Miner.MasterInterface.RequestMethods.GetPoolMining);

            var retryCount = 0;

            while (true)
            {
                try
                {
                    var parameters = MiningParameters.GetMiningParameters(SubmitURL,
                                                                          getEthAddress: getMasterAddress,
                                                                          getMaximumTarget: getMaximumTarget,
                                                                          getKingAddress: getKingAddress,
                                                                          getPoolMining: getPoolMining);
                    m_isPool               = parameters.IsPoolMining;
                    MinerAddress           = parameters.EthAddress;
                    MaxTarget              = parameters.MaximumTarget;
                    Miner.Work.KingAddress = parameters.KingAddressByte20;
                    break;
                }
                catch (Exception ex)
                {
                    retryCount++;
                    if (retryCount > 3)
                    {
                        HandleException(ex);
                    }

                    Task.Delay(1000).Wait();
                }
            }

            if (hashratePrintInterval > 0)
            {
                m_hashPrintTimer          = new Timer(hashratePrintInterval);
                m_hashPrintTimer.Elapsed += HashPrintTimer_Elapsed;
                m_hashPrintTimer.Start();
            }
        }
예제 #7
0
        public MiningParameters GetMiningParameters()
        {
            Program.Print("[INFO] Checking latest parameters from network...");
            bool success   = true;
            var  startTime = DateTime.Now;

            try
            {
                return(MiningParameters.GetSoloMiningParameters(MinerAddress, m_getMiningDifficulty, m_getMiningTarget, m_getChallengeNumber));
            }
            catch (Exception ex)
            {
                success = false;
                throw ex;
            }
            finally
            {
                if (success)
                {
                    var tempLatency = (int)(DateTime.Now - startTime).TotalMilliseconds;
                    try
                    {
                        using (var ping = new Ping())
                        {
                            var submitUrl = SubmitURL.Contains("://") ? SubmitURL.Split("://")[1] : SubmitURL;
                            try
                            {
                                var response = ping.Send(submitUrl);
                                if (response.RoundtripTime > 0)
                                {
                                    tempLatency = (int)response.RoundtripTime;
                                }
                            }
                            catch
                            {
                                try
                                {
                                    submitUrl = submitUrl.Split('/').First();
                                    var response = ping.Send(submitUrl);
                                    if (response.RoundtripTime > 0)
                                    {
                                        tempLatency = (int)response.RoundtripTime;
                                    }
                                }
                                catch
                                {
                                    try
                                    {
                                        submitUrl = submitUrl.Split(':').First();
                                        var response = ping.Send(submitUrl);
                                        if (response.RoundtripTime > 0)
                                        {
                                            tempLatency = (int)response.RoundtripTime;
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                    catch { }
                    Latency = tempLatency;
                }
            }
        }
예제 #8
0
        private void m_updateMinerTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (m_isGetMiningParameters)
            {
                return;
            }
            try
            {
                m_isGetMiningParameters = true;
                var miningParameters = GetMiningParameters();
                if (miningParameters == null)
                {
                    OnGetMiningParameterStatus(this, false, null);
                    return;
                }

                var address = miningParameters.EthAddress;
                var target  = miningParameters.MiningTargetByte32String;
                CurrentChallenge = miningParameters.ChallengeNumberByte32String;

                if (m_lastParameters == null || miningParameters.ChallengeNumber.Value != m_lastParameters.ChallengeNumber.Value)
                {
                    Program.Print(string.Format("[INFO] New challenge detected {0}...", CurrentChallenge));
                    OnNewMessagePrefix(this, CurrentChallenge + address.Replace("0x", string.Empty));
                    if (m_challengeReceiveDateTime == DateTime.MinValue)
                    {
                        m_challengeReceiveDateTime = DateTime.Now;
                    }
                }

                if (m_customDifficulity == 0)
                {
                    DifficultyHex = miningParameters.MiningDifficulty.HexValue;

                    if (m_lastParameters == null || miningParameters.MiningTarget.Value != m_lastParameters.MiningTarget.Value)
                    {
                        Program.Print(string.Format("[INFO] New target detected {0}...", target));
                        OnNewTarget(this, target);
                    }

                    if (m_lastParameters == null || miningParameters.MiningDifficulty.Value != m_lastParameters.MiningDifficulty.Value)
                    {
                        Program.Print(string.Format("[INFO] New difficulity detected ({0})...", miningParameters.MiningDifficulty.Value));
                        Difficulty = Convert.ToUInt64(miningParameters.MiningDifficulty.Value.ToString());

                        var calculatedTarget = m_maxTarget.Value / Difficulty;
                        if (calculatedTarget != miningParameters.MiningTarget.Value)
                        {
                            var newTarget = calculatedTarget.ToString();
                            Program.Print(string.Format("[INFO] Update target {0}...", newTarget));
                            OnNewTarget(this, newTarget);
                        }
                    }
                }
                else
                {
                    Difficulty = m_customDifficulity;
                    var calculatedTarget = m_maxTarget.Value / m_customDifficulity;
                    var newTarget        = new HexBigInteger(new BigInteger(m_customDifficulity)).HexValue;

                    OnNewTarget(this, newTarget);
                }

                m_lastParameters = miningParameters;
                OnGetMiningParameterStatus(this, true, miningParameters);
            }
            catch (Exception ex)
            {
                Program.Print(string.Format("[ERROR] {0}", ex.Message));
            }
            finally { m_isGetMiningParameters = false; }
        }
예제 #9
0
        public MiningParameters GetMiningParameters()
        {
            Program.Print(string.Format("[INFO] Checking latest parameters from {0} pool...", IsSecondaryPool ? "secondary" : "primary"));

            var getPoolEthAddress             = GetPoolParameter("getPoolEthAddress");
            var getPoolChallengeNumber        = GetPoolParameter("getChallengeNumber");
            var getPoolMinimumShareDifficulty = GetPoolParameter("getMinimumShareDifficulty", MinerAddress);
            var getPoolMinimumShareTarget     = GetPoolParameter("getMinimumShareTarget", MinerAddress);

            bool success   = true;
            var  startTime = DateTime.Now;

            try
            {
                return(MiningParameters.GetPoolMiningParameters(s_PoolURL, getPoolEthAddress, getPoolChallengeNumber,
                                                                getPoolMinimumShareDifficulty, getPoolMinimumShareTarget));
            }
            catch (AggregateException ex)
            {
                success = false;
                m_retryCount++;

                Program.Print("[ERROR] " + ex.Message);
            }
            catch (Exception ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMsg += ("\n " + ex.InnerException.Message);
                }
                Program.Print("[ERROR] " + errorMsg);
            }
            finally
            {
                if (success)
                {
                    m_runFailover = false;
                    var tempLatency = (int)(DateTime.Now - startTime).TotalMilliseconds;
                    try
                    {
                        using (var ping = new Ping())
                        {
                            var poolURL = s_PoolURL.Contains("://") ? s_PoolURL.Split("://")[1] : s_PoolURL;
                            try
                            {
                                var response = ping.Send(poolURL);
                                if (response.RoundtripTime > 0)
                                {
                                    tempLatency = (int)response.RoundtripTime;
                                }
                            }
                            catch
                            {
                                try
                                {
                                    poolURL = poolURL.Split('/').First();
                                    var response = ping.Send(poolURL);
                                    if (response.RoundtripTime > 0)
                                    {
                                        tempLatency = (int)response.RoundtripTime;
                                    }
                                }
                                catch
                                {
                                    try
                                    {
                                        poolURL = poolURL.Split(':').First();
                                        var response = ping.Send(poolURL);
                                        if (response.RoundtripTime > 0)
                                        {
                                            tempLatency = (int)response.RoundtripTime;
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                    catch { }
                    Latency = tempLatency;
                }
            }

            var runFailover = (!success && SecondaryPool != null && m_maxScanRetry > -1 && m_retryCount >= m_maxScanRetry);

            try
            {
                if (runFailover)
                {
                    return(SecondaryPool.GetMiningParameters());
                }
            }
            finally { m_runFailover = runFailover; }

            return(null);
        }