Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //mikefdm 2013
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace ShelvedShares
- {
- class Program
- {
- //входные параметры
- static int TestDays = 90; //дней в одном тесте (сначала майнинг, потом ожидание выплат)
- static int MiningDays = 30; //дней майнинга в одном тесте
- static int TestCount = 1000; //кол-во тестов
- static double MyGH = 1500.0; //своя мощность в GH/s
- static double PoolGH = 24140.2; //мощность пула в GH/s
- static double PoolShelvedSharesCost = 1000; //стоимость отложенных шар - "долг"
- static double Diff = 267731249.482421; //сложность
- static int TestSec;
- static int MiningSec;
- static double DiffGH;
- const double Eps = 1e-8;
- const int MaxStackDepth = 1000;
- const double GHPerShare = 4.294967296;
- static double[] StackPoolSharesCount = new double[MaxStackDepth];
- static double[] StackMySharesCount = new double[MaxStackDepth];
- static double[] StackShareCost = new double[MaxStackDepth];
- static bool ParseArgs(string[] args)
- {
- if (args.Count() != 7) return false;
- bool res =
- int.TryParse(args[0], out TestDays) |
- int.TryParse(args[1], out MiningDays) |
- int.TryParse(args[2], out TestCount) |
- double.TryParse(args[3], out MyGH) |
- double.TryParse(args[4], out PoolGH) |
- double.TryParse(args[5], out PoolShelvedSharesCost) |
- double.TryParse(args[6], out Diff);
- return res;
- }
- static int Main(string[] args)
- {
- if (args.Count() > 0)
- {
- if (!ParseArgs(args))
- {
- Console.WriteLine("Usage: ShelvedShares.exe TestDays MiningDays TestCount MyGH PoolGH PoolShelvedSharesCost Diff");
- return 1;
- }
- }
- else
- {
- Console.WriteLine("Usage: ShelvedShares.exe TestDays MiningDays TestCount MyGH PoolGH PoolShelvedSharesCost Diff");
- Console.WriteLine("Using defaults");
- }
- TestSec = TestDays * 24 * 60 * 60;
- MiningSec = MiningDays * 24 * 60 * 60;
- DiffGH = Diff * GHPerShare / 600.0;
- int seed = 0;//3737661;
- double PercAll = 0.0;
- double ShelvedSharesCostAll = 0.0;
- double MyShelvedSharesCostAll = 0.0;
- double LuckAll = 0.0;
- double PercAvg = 0.0;
- double ShelvedSharesCostAvg;
- double MyShelvedSharesCostAvg;
- double LuckAvg;
- for (int CurTest = 1; CurTest <= TestCount; ++CurTest)
- {
- double ShelvedSharesCost;
- double MyShelvedSharesCost;
- double Luck;
- double CurPerc = RunTest(seed, out ShelvedSharesCost, out MyShelvedSharesCost, out Luck);
- PercAll += CurPerc;
- ShelvedSharesCostAll += ShelvedSharesCost;
- MyShelvedSharesCostAll += MyShelvedSharesCost;
- LuckAll += Luck;
- PercAvg = PercAll / CurTest;
- ShelvedSharesCostAvg = ShelvedSharesCostAll / CurTest;
- MyShelvedSharesCostAvg = MyShelvedSharesCostAll / CurTest;
- LuckAvg = LuckAll / CurTest;
- Console.WriteLine("Test #{0} Tot: {1:f3}% Shelved My/Pool: {2:f3}/{3:f3} Luck: {4:f3}%", CurTest,
- PercAvg * 100.0, MyShelvedSharesCostAvg, ShelvedSharesCostAvg, LuckAvg * 100.0);
- if (seed != 0) ++seed;
- }
- bool ok = false;
- for (int i = 0; i < 100; ++i)
- {
- try
- {
- StreamWriter sw = new StreamWriter("results.txt", true);
- sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",
- TestDays, MiningDays, TestCount, MyGH, PoolGH, PoolShelvedSharesCost, Diff, PercAvg);
- sw.Close();
- ok = true;
- break;
- }
- catch (Exception) { }
- System.Threading.Thread.Sleep(100);
- }
- if (!ok)
- {
- Console.WriteLine("Saving failed");
- return 1;
- }
- return 0;
- }
- static double RunTest(int seed, out double ShelvedSharesCost, out double MyShelvedSharesCost, out double Luck)
- {
- Random Rand;
- if (seed == 0)
- Rand = new Random();
- else
- Rand = new Random(seed);
- double ProbFindBlockPerSec = PoolGH / DiffGH / 10.0 / 60.0;
- double CurShareCost = 25.0 / 600.0 / (DiffGH / GHPerShare);
- int StackDepth = 1;
- StackPoolSharesCount[0] = 1;
- StackMySharesCount[0] = 0;
- StackShareCost[0] = PoolShelvedSharesCost;
- double MySharesCount = 0.0;
- double PoolSharesCount = 0.0;
- double Sec = 0;
- double BlockTimeAvg = 0;
- double BlockCount = 0;
- double PoolAvailBTC = 0.0;
- double POutPool = 0.0;
- double POutPPS = 0.0;
- double MySharesPerSec = MyGH / GHPerShare;
- double PoolSharesPerSec = PoolGH / GHPerShare;
- double POutPPSPerSec = MyGH / GHPerShare * CurShareCost;
- for (int i = 0; i < TestSec; ++i)
- {
- ++Sec;
- if (i < MiningSec)
- {
- POutPPS += POutPPSPerSec;
- MySharesCount += MySharesPerSec;
- }
- PoolSharesCount += PoolSharesPerSec;
- bool Found = Rand.NextDouble() < ProbFindBlockPerSec;
- if (Found || i == TestSec - 1)
- {
- if (StackDepth == MaxStackDepth)
- {
- throw new Exception("MaxStackDepth");
- }
- StackPoolSharesCount[StackDepth] = PoolSharesCount;
- StackMySharesCount[StackDepth] = MySharesCount;
- StackShareCost[StackDepth] = CurShareCost;
- ++StackDepth;
- PoolSharesCount = 0;
- MySharesCount = 0;
- if (Found)
- {
- ++BlockCount;
- PoolAvailBTC += 25.0;
- }
- while (PoolAvailBTC > Eps && StackDepth > 0)
- {
- double AllSharesCost = StackPoolSharesCount[StackDepth - 1] * StackShareCost[StackDepth - 1];
- double PercToPay = PoolAvailBTC / AllSharesCost;
- if (PercToPay > 1.0)
- PercToPay = 1.0;
- PoolAvailBTC -= AllSharesCost * PercToPay;
- POutPool += StackMySharesCount[StackDepth - 1] * PercToPay * StackShareCost[StackDepth - 1];
- StackMySharesCount[StackDepth - 1] *= (1.0 - PercToPay);
- StackPoolSharesCount[StackDepth - 1] *= (1.0 - PercToPay);
- if (PercToPay >= 1.0 - Eps)
- --StackDepth;
- }
- }
- }
- ShelvedSharesCost = -PoolAvailBTC;
- MyShelvedSharesCost = 0;
- for (int i = 0; i < StackDepth; ++i)
- {
- ShelvedSharesCost += StackPoolSharesCount[i] * StackShareCost[i];
- MyShelvedSharesCost += StackMySharesCount[i] * StackShareCost[i];
- }
- if (BlockCount == 0)
- Luck = 0.0;
- else
- {
- BlockTimeAvg = Sec / BlockCount;
- Luck = (1.0 / ProbFindBlockPerSec) / BlockTimeAvg;
- }
- return POutPool / POutPPS;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement