コード例 #1
0
ファイル: CalculatePower.cs プロジェクト: mangodager/corlas
        static public void Test()
        {
            CalculatePower calculate = new CalculatePower();

            Block blk = new Block();

            blk.prehash = "b6b67d3d8b83f4885620ccd45d1af81d5690a056de2aba8ddf899fba8088b75d";

            double diff_max = 0;

            for (int jj = 0; jj < 100; jj++)
            {
                for (int ii = 0; ii < 1000 * 1000; ii++)
                {
                    string random = RandomHelper.RandUInt64().ToString("x");
                    string hash   = blk.ToHash(random);

                    double diff = Helper.GetDiff(hash);
                    if (diff > diff_max)
                    {
                        diff_max   = diff;
                        blk.hash   = hash;
                        blk.random = random;
                    }
                }

                double value1 = calculate.Power(blk.GetDiff());
                string value2 = CalculatePower.GetPowerCompany(value1);

                Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
            }
        }
コード例 #2
0
        static public void Test()
        {
            //
            {
                Block blk = new Block();
                blk.prehash = "b6b67d3d8b83f4885620ccd45d1af81d5690a056de2aba8ddf899fba8088b75d";
                {
                    blk.hash = "000d24c333b6ba99f18e3c3ca33a1b5a388e562fdd38c1ce0a459f15139e0f5e";
                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);
                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
                {
                    blk.hash = "0e7adeae5ba12d1b14af8a45aaced269e6523621e225e7fd8c6628bdcdbf76db";
                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);
                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
            }
            // 2
            {
                CalculatePower calculate = new CalculatePower();

                Block blk = new Block();
                blk.prehash = "b6b67d3d8b83f4885620ccd45d1af81d5690a056de2aba8ddf899fba8088b75d";

                double diff_max = 0;
                for (int jj = 0; jj < 100; jj++)
                {
                    for (int ii = 0; ii < 1000 * 1000; ii++)
                    {
                        string random = RandomHelper.RandUInt64().ToString("x");
                        string hash   = blk.ToHash(random);

                        double diff = Helper.GetDiff(hash);
                        if (diff > diff_max)
                        {
                            diff_max   = diff;
                            blk.hash   = hash;
                            blk.random = random;
                        }
                    }

                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);

                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
            }
        }
コード例 #3
0
        static public void Test()
        {
            //
            {
                Block blk = new Block();
                blk.prehash = "b6b67d3d8b83f4885620ccd45d1af81d5690a056de2aba8ddf899fba8088b75d";
                {
                    blk.hash = "000000c09983d8950d8d0dce9ab5e9039fade2590d25f361ee0f9c1047832ceb";
                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);
                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
                {
                    blk.hash = "0000003e833bc8b524922d9400e8b489eb1fe753d35efde0d5e2ae5ee430dfbe";
                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);
                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
            }
            // 2
            {
                CalculatePower calculate = new CalculatePower();

                Block blk = new Block();
                blk.prehash = "b6b67d3d8b83f4885620ccd45d1af81d5690a056de2aba8ddf899fba8088b75d";

                double diff_max = 0;
                for (int jj = 0; jj < 100; jj++)
                {
                    for (int ii = 0; ii < 1000 * 1000; ii++)
                    {
                        string random = RandomHelper.RandUInt64().ToString("x");
                        string hash   = blk.ToHash(random);

                        double diff = Helper.GetDiff(hash);
                        if (diff > diff_max)
                        {
                            diff_max   = diff;
                            blk.hash   = hash;
                            blk.random = random;
                        }
                    }

                    double value1 = CalculatePower.Power(blk.GetDiff());
                    string value2 = CalculatePower.GetPowerCompany(value1);

                    Log.Info($"\n PowerCompany {blk.GetDiff()} \n {value2} \n {blk.hash}");
                }
            }
        }
コード例 #4
0
ファイル: Pool.cs プロジェクト: mangodager/smartx-dotnet
        public MinerView GetMinerTop(long minerIndex, long minerColumn)
        {
            minerColumn = Math.Min(minerColumn, 100);

            var minerView = new MinerView();

            if (httpPool != null)
            {
                Dictionary <string, MinerTask> miners = httpPool.GetMinerRewardMin(out long miningHeight);
                if (miners != null)
                {
                    var minerList = miners.Values.OrderByDescending((x) => { double.TryParse(x.power_average, out double power_average); return(power_average); }).ToList();
                    for (var ii = 0; ii < minerColumn; ii++)
                    {
                        if ((minerIndex + ii) >= minerList.Count)
                        {
                            break;
                        }
                        var miner = minerList[(int)minerIndex + ii];

                        if (string.IsNullOrEmpty(miner.power_cur))
                        {
                            miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                        }

                        var minerdata = new MinerViewData();
                        minerdata.number    = $"{miner.address}_{ miner.number}";
                        minerdata.lasttime  = miner.time;
                        minerdata.power_cur = miner.power_cur;

                        double.TryParse(miner.power_average, out double power_average);
                        minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                        minerView.miners.Add(minerdata);
                    }
                }
            }

            return(minerView);
        }
コード例 #5
0
ファイル: Pool.cs プロジェクト: mangodager/smartx-dotnet
        public MinerView GetMinerViewAbstract(string address)
        {
            if (minerViewAbstractTimePass.IsPassSet())
            {
                minerViewAbstractCache.Clear();
            }
            if (minerViewAbstractCache.TryGetValue(address, out MinerView minerViewLast))
            {
                return(minerViewLast);
            }

            var minerView = new MinerView();
            // pool name
            var httpPoolRelay = Entity.Root.GetComponent <HttpPoolRelay>();

            if (httpPoolRelay != null)
            {
                minerView.address = httpPoolRelay.number;
            }
            else
            {
                minerView.address = "Ruler";
            }

            Dictionary <string, BlockSub> minerTransferCache = null;

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                var str = snapshot.Get($"Pool_Cache_MinerReward");
                if (!string.IsNullOrEmpty(str))
                {
                    minerTransferCache = JsonHelper.FromJson <Dictionary <string, BlockSub> >(str);
                }
            }

            var transfers_cur = minerTransferCache?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
                minerView.share      = transfers_cur.type;
            }

            // 当前总算力
            var    miners     = httpPool.GetMinerRewardMin(out long miningHeight);
            var    minerList  = miners?.Values.Where((x) => x.address == address).ToList();
            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                for (var ii = 0; ii < minerList.Count; ii++)
                {
                    var miner = minerList[ii];
                    if (double.TryParse(miner.power_average, out double power_average))
                    {
                        totalPower += power_average;
                    }
                }
                minerView.totalMiners = minerList.Count;
            }
            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            minerViewAbstractCache.Add(address, minerView);
            return(minerView);
        }
コード例 #6
0
ファイル: Pool.cs プロジェクト: mangodager/smartx-dotnet
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            if (getMinerViewTimePass.IsPassSet())
            {
                getMinerViewCache.Clear();
            }
            if (getMinerViewCache.TryGetValue($"{address}_{transferIndex}_{transferColumn}_{minerIndex}_{minerColumn}", out MinerView minerViewLast))
            {
                return(minerViewLast);
            }

            transferColumn = Math.Min(transferColumn, 100);
            minerColumn    = Math.Min(minerColumn, 100);

            var minerView = new MinerView();

            minerView.address = address;

            Dictionary <string, BlockSub> minerTransferCache = null;

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                var str = snapshot.Get($"Pool_Cache_MinerReward");
                if (!string.IsNullOrEmpty(str))
                {
                    minerTransferCache = JsonHelper.FromJson <Dictionary <string, BlockSub> >(str);
                }
            }

            var transfers_cur = minerTransferCache?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
                minerView.share      = transfers_cur.type;
            }

            // 交易确认
            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                int TopIndex = snapshot.Queue.GetTopIndex($"Pool_MT_{address}");
                for (int ii = 1; ii <= (int)transferColumn; ii++)
                {
                    var value = snapshot.Queue.Get($"Pool_MT_{address}", TopIndex - (int)transferIndex - ii);
                    if (!string.IsNullOrEmpty(value))
                    {
                        var transfer = JsonHelper.FromJson <BlockSub>(value);
                        if (transfer != null)
                        {
                            minerView.transfers.Add(transfer);
                        }
                    }
                }

                foreach (var transfer in minerView.transfers)
                {
                    // 节点使用自己的地址挖矿
                    if (transfer.addressIn == transfer.addressOut)
                    {
                        transfer.hash = transfer.addressIn;
                    }
                    else
                    {
                        transfer.hash = TransferProcess.GetMinerTansfer(snapshot, transfer.data);
                    }
                }
            }

            var    miners     = httpPool.GetMinerRewardMin(out long miningHeight);
            var    minerList  = miners?.Values.Where((x) => x.address == address).ToList();
            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                // 当前页矿机算力
                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);
                }

                // 当前总算力
                for (var ii = 0; ii < minerList.Count; ii++)
                {
                    var miner = minerList[ii];
                    if (double.TryParse(miner.power_average, out double power_average))
                    {
                        totalPower += power_average;
                    }
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            getMinerViewCache.Add($"{address}_{transferIndex}_{transferColumn}_{minerIndex}_{minerColumn}", minerView);
            return(minerView);
        }
コード例 #7
0
ファイル: Miner.cs プロジェクト: mangodager/smartx-dotnet
        public async void Run()
        {
            SetTitle($" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}, version:{version}");

            Log.Info($"start mining...");

            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

            //创建后台工作线程
            ThreadDataList = new ThreadData[thread];
            for (int ii = 0; ii < thread; ii++)
            {
                ThreadDataList[ii]            = new ThreadData();
                ThreadDataList[ii].miner      = this;
                ThreadDataList[ii].index      = ii;
                ThreadDataList[ii].diff_max   = 0;
                ThreadDataList[ii].random     = "";
                ThreadDataList[ii].hashmining = "";

                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Mining));
                thread.IsBackground = true;//设置为后台线程
                thread.Priority     = System.Threading.ThreadPriority.Normal;
                thread.Start(ThreadDataList[ii]);
            }

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                try
                {
                    if (timePassInfo.IsPassSet())
                    {
                        Get_Random_diff_max();
                        string hash     = BlockDag.ToHash(height, hashmining_last, random);
                        var    sharePer = Math.Round(effectiveShare * 100 / submitCount, 2);
                        var    power    = CalculatePower.GetPowerCompany(calculatePower.GetPowerDouble());

                        Log.Info($"\n height:{height}, taskid:{taskid},random:{random}, diff:{diff_max_last}, share:{sharePer}%, power:{power} hash:{hash}");
                    }

                    long time = (GetNodeTime() / 1000) % pooltime;
                    if (string.IsNullOrEmpty(hashmining) && time >= 1 && time < broadcasttime && timePass1.IsPassSet())
                    {
                        Get_Random_diff_max();
                        await Submit(quest);

                        //Log.Info("Task New");
                    }

                    if (!string.IsNullOrEmpty(hashmining) && time > broadcasttime - 3 && time <= broadcasttime && timePass2.IsPassSet())
                    {
                        Get_Random_diff_max();
                        if (diff_max > diff_max_lastSubmit)
                        {
                            diff_max_last       = diff_max;
                            diff_max_lastSubmit = diff_max;
                            await Submit(quest);

                            //Log.Info($"Task Submit {height}");
                        }
                    }

                    if (!string.IsNullOrEmpty(hashmining) && time > broadcasttime)
                    {
                        hashmining = null;
                        changeCallback?.Invoke();
                    }
                }
                catch (Exception)
                {
                    await Task.Delay(15000);
                }
                await Task.Delay(10);
            }
        }
コード例 #8
0
ファイル: Pool.cs プロジェクト: Gabbe-x/smartx-dotnet
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            transferColumn = Math.Min(transferColumn, 100);
            minerColumn    = Math.Min(minerColumn, 100);

            var minerView = new MinerView();

            minerView.address = address;

            var transfers_cur = MinerReward_PPLNS(false)?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
            }

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                int TopIndex = snapshot.Queue.GetTopIndex($"Pool_MT_{address}");
                for (int ii = 1; ii <= (int)transferColumn; ii++)
                {
                    var value = snapshot.Queue.Get($"Pool_MT_{address}", TopIndex - (int)transferIndex - ii);
                    if (!string.IsNullOrEmpty(value))
                    {
                        var transfer = JsonHelper.FromJson <BlockSub>(value);
                        if (transfer != null)
                        {
                            minerView.transfers.Add(transfer);
                        }
                    }
                }

                foreach (var transfer in minerView.transfers)
                {
                    // 节点使用自己的地址挖矿
                    if (transfer.addressIn == transfer.addressOut)
                    {
                        transfer.hash = transfer.addressIn;
                    }
                    else
                    {
                        transfer.hash = transferProcess.GetMinerTansfer(snapshot, transfer.data);
                    }
                }
            }

            var miners    = httpPool.GetMinerReward(out long miningHeight);
            var minerList = miners?.Values.Where((x) => x.address == address).ToList();

            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);

                    totalPower += power_average;
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            return(minerView);
        }
コード例 #9
0
        public MinerView GetMinerView(string address, long transferIndex, long transferColumn, long minerIndex, long minerColumn)
        {
            var minerView = new MinerView();

            minerView.address = address;

            var transfers_cur = MinerReward_PPLNS(false)?.Values.FirstOrDefault(c => c.addressOut == address);

            if (transfers_cur != null)
            {
                minerView.amount_cur = transfers_cur.amount;
            }

            long counted = 0;

            using (DbSnapshot snapshot = PoolDBStore.GetSnapshot())
            {
                string str_Counted = snapshot.Get("Pool_Counted");
                if (long.TryParse(str_Counted, out counted))
                {
                    counted = counted - transferIndex;
                    for (int i = 0; i < transferColumn; i++)
                    {
                        string str_MT = snapshot.Get($"Pool_MT_{counted-i}");
                        Dictionary <string, BlockSub> minerTransfer = null;
                        if (!string.IsNullOrEmpty(str_MT))
                        {
                            minerTransfer = JsonHelper.FromJson <Dictionary <string, BlockSub> >(str_MT);
                            if (minerTransfer != null)
                            {
                                var transfer = minerTransfer?.Values.FirstOrDefault(c => c.addressOut == address);
                                if (transfer != null)
                                {
                                    string        str_MR          = snapshot.Get($"Pool_MR_{counted - i}");
                                    MinerRewardDB minerRewardLast = null;
                                    if (!string.IsNullOrEmpty(str_MR))
                                    {
                                        minerRewardLast = JsonHelper.FromJson <MinerRewardDB>(str_MR);
                                    }

                                    long.TryParse(minerRewardLast.time, out long time);
                                    transfer.depend = new DateTime(time).ToString("yyyy-MM-dd HH:mm:ss");
                                    minerView.transfers.Add(transfer);
                                }
                            }
                        }
                    }
                }
            }

            // Is the query successful
            using (var dbSnapshot = PoolDBStore.GetSnapshot(0))
            {
                foreach (var transfer in minerView.transfers)
                {
                    transfer.hash = transferProcess.GetMinerTansfer(dbSnapshot, transfer.data);
                }
            }

            var miners    = httpPool.GetMinerReward(out long miningHeight);
            var minerList = miners?.Values.Where((x) => x.address == address).ToList();

            double totalPower = 0L;

            if (minerList != null)
            {
                minerList.Sort((MinerTask a, MinerTask b) => {
                    return(a.number.CompareTo(b.number));
                });

                for (var ii = 0; ii < minerColumn; ii++)
                {
                    if ((minerIndex + ii) >= minerList.Count)
                    {
                        break;
                    }
                    var miner = minerList[(int)minerIndex + ii];

                    if (string.IsNullOrEmpty(miner.power_cur))
                    {
                        miner.power_cur = CalculatePower.GetPowerCompany(CalculatePower.Power(miner.diff));
                    }

                    var minerdata = new MinerViewData();
                    minerdata.number    = miner.number;
                    minerdata.lasttime  = miner.time;
                    minerdata.power_cur = miner.power_cur;

                    double.TryParse(miner.power_average, out double power_average);
                    minerdata.power_average = CalculatePower.GetPowerCompany(power_average);
                    minerView.miners.Add(minerdata);

                    totalPower += power_average;
                }
                minerView.totalMiners = minerList.Count;
            }

            minerView.totalPower = CalculatePower.GetPowerCompany(totalPower);

            return(minerView);
        }