public void Dig(object sender, DoWorkEventArgs e) { Job ThisJob = (Job)((object[])e.Argument)[0]; Ztratum ztratum = (Ztratum)((object[])e.Argument)[1]; main = (frmMain)((object[])e.Argument)[2]; main.WriteLog("Starting " + threads.Length + " threads for new job..."); byte[] databyte = new byte[76]; uint targetbyte = 0; if (GV.Bench) { //200000007c6e5530a551ca1496969d0909412315cdefd569e0c64db09207663680af4278c303fb0ff0ad69b0dea42307b075b246822f444ee444450af3b786f7beb377256094edac1d0f1d61 //for (byte n = 0; n < 74; n++) // databyte[n] = n; //databyte[17] = BitConverter.GetBytes(1619664393)[0]; //databyte[18] = BitConverter.GetBytes(1619664393)[1]; //databyte[19] = BitConverter.GetBytes(1619664393)[2]; //databyte[20] = BitConverter.GetBytes(1619664393)[3]; //databyte[20] = BitConverter.GetBytes(0x80000000)[0]; //databyte[21] = BitConverter.GetBytes(0x80000000)[1]; //databyte[22] = BitConverter.GetBytes(0x80000000)[2]; //databyte[23] = BitConverter.GetBytes(0x80000000)[3]; //databyte[31] = BitConverter.GetBytes(0x00000280)[0]; //databyte[32] = BitConverter.GetBytes(0x00000280)[1]; //databyte[33] = BitConverter.GetBytes(0x00000280)[2]; //databyte[34] = BitConverter.GetBytes(0x00000280)[3]; databyte = Utilities.ReverseByteArrayByFours(Utilities.HexStringToByteArray("200000007c6e5530a551ca1496969d0909412315cdefd569e0c64db09207663680af4278c303fb0ff0ad69b0dea42307b075b246822f444ee444450af3b786f7beb377256094edac1d0f1d61")); } else { databyte = Utilities.ReverseByteArrayByFours(Utilities.HexStringToByteArray(ThisJob.Data)); targetbyte = Convert.ToUInt32(ThisJob.Target); } if (main.statsReset) { main.statsReset = false; main.totalHashFoundList = new int[threads.Length]; main.totalShareSubmited = 0; main.totalShareAccepted = 0; main.totalShareRejected = 0; main.workStartTime = DateTime.Now; } done = false; hashCountList = new int[threads.Length]; hashStartList = new DateTime[threads.Length]; hashStatList = new List <double>(); if (main.submitList.Count == 0) { GV.lastNonceList = new uint[threads.Length]; } submitQList = new List <Submit>(); hModule = LoadLibrary("Ghostrider.dll"); stopQ = false; Thread thz = new Thread(new ParameterizedThreadStart(submitQ)); thz.IsBackground = false; thz.Priority = ThreadPriority.BelowNormal; thz.Start(ztratum); uint workSize = (uint)(uint.MaxValue / threads.Length); int start = 0; string starts = ""; Random rnd = new Random(); for (int i = 0; i < threads.Length; i++) { start = rnd.Next(0, (int)(workSize / 2)); start += 100000; ArrayList args = new ArrayList(); args.Add(ThisJob); args.Add(ztratum); args.Add(i); args.Add(databyte); args.Add(targetbyte); args.Add((uint)((i * workSize) + start)); starts += ((uint)((i * workSize) + start)).ToString() + "\r\n"; args.Add((uint)((i + 1) * workSize)); threads[i] = new Thread(new ParameterizedThreadStart(doGR)); threads[i].IsBackground = false; threads[i].Priority = ThreadPriority.BelowNormal; threads[i].Start(args); } for (int i = 0; i < threads.Length; i++) { threads[i].Join(); } stopQ = true; while (thz.ThreadState == System.Threading.ThreadState.Running) { Thread.Sleep(10); } e.Result = null; main.WriteLog("Current Hashrate: " + hashStatList.Sum().ToString("0.00") + " Hash/s"); UpdateStats(hashStatList.Sum().ToString("0.00")); FreeLibrary(hModule); }
public void doGR(object o) { IntPtr processHandle = Process.GetCurrentProcess().Handle; Action a; ArrayList args = (ArrayList)o; Job ThisJob = (Job)args[0]; Ztratum ztratum = (Ztratum)args[1]; int threadId = (int)args[2]; byte[] Tempdata = (byte[])args[3]; uint Target = (uint)args[4]; uint Nonce = (uint)args[5]; uint MaxNonce = (uint)args[6]; IntPtr intPtr_GhostriderInit; GhostriderInit _GhostriderInit; IntPtr intPtr_GhostriderWork; GhostriderWork _GhostriderWork; intPtr_GhostriderInit = UnsafeNativeMethods.GetProcAddress(hModule, "GhostriderInit"); _GhostriderInit = (GhostriderInit)Marshal.GetDelegateForFunctionPointer(intPtr_GhostriderInit, typeof(GhostriderInit)); intPtr_GhostriderWork = GetProcAddress(hModule, "GhostriderWork"); _GhostriderWork = (GhostriderWork)Marshal.GetDelegateForFunctionPointer(intPtr_GhostriderWork, typeof(GhostriderWork)); IntPtr hp_state = new IntPtr(); int memSize = (int)(GV.largePageMinimum * 2); bool usinglargeMem = false; thLock.AcquireWriterLock(Timeout.Infinite); try { if (GV.largeMemAccess) { hp_state = VirtualAllocEx(processHandle, IntPtr.Zero, new IntPtr(memSize), AllocationType.Commit | AllocationType.Reserve | AllocationType.LargePages, MemoryProtection.ReadWrite); if (hp_state == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); main.WriteLog("Thread" + threadId.ToString() + ": " + "LP Error=" + error.ToString() + " - LP OFF"); hp_state = Marshal.AllocHGlobal(memSize); usinglargeMem = false; } else { usinglargeMem = true; } } else { hp_state = Marshal.AllocHGlobal(memSize); usinglargeMem = false; } } catch { } thLock.ReleaseLock(); _GhostriderInit(hp_state); if (GV.Bench) { Target = 0x00ff; } int Hashcount = 0; byte[] input = new byte[80]; Array.Copy(Tempdata, input, 76); byte[] n = be32enc(Nonce); Array.Copy(n, 0, input, 76, 4); byte[] output = new byte[32]; DateTime StartTime = DateTime.Now; DateTime reportTimeStart = DateTime.Now; hashStartList[threadId] = StartTime; try { while (!done) { if (GV.StopMining) { break; } n = be32enc(Nonce); Array.Copy(n, 0, input, 76, 4); _GhostriderWork(input, output); uint ou = BitConverter.ToUInt32(output, 28); Hashcount++; main.totalHashFoundList[threadId]++; hashCountList[threadId] = Hashcount; if (ou <= GV.CurrentTarget) { if (!GV.Bench) { if (!main.submitList.Contains(Nonce)) { if (main.lastJob == ThisJob.JobID) { main.submitList.Add(Nonce); main.submitListThread.Add(Nonce.ToString() + "_" + threadId.ToString() + "_" + ThisJob.JobID.ToString()); submitQList.Add(new Submit(ThisJob.JobID, ThisJob.Data.Substring(68 * 2, 8), Nonce, GV.CurrentDifficulty)); //ztratum.SendSUBMIT(ThisJob.JobID, ThisJob.Data.Substring(68 * 2, 8), Nonce, GV.CurrentDifficulty); a = () => main.pictureBox1.Image = GV.eyeDown; main.pictureBox1.Invoke(a); } else { done = true; } } } List <double> hashStatListSub = new List <double>(); for (int i = 0; i < hashStartList.Length; i++) { double ElapsedtimeSub = (DateTime.Now - hashStartList[i]).TotalSeconds; hashStatListSub.Add(hashCountList[i] / ElapsedtimeSub); } main.WriteLog("Current Hashrate: " + hashStatListSub.Sum().ToString("0.00") + " Hash/s"); UpdateStats(hashStatListSub.Sum().ToString("0.00")); } if ((threadId == 0) && (Nonce > 1) && ((DateTime.Now - reportTimeStart).TotalSeconds > 10)) { reportTimeStart = DateTime.Now; List <double> hashStatListSub = new List <double>(); for (int i = 0; i < hashStartList.Length; i++) { double ElapsedtimeSub = (DateTime.Now - hashStartList[i]).TotalSeconds; hashStatListSub.Add(hashCountList[i] / ElapsedtimeSub); } main.WriteLog("Current Hashrate: " + hashStatListSub.Sum().ToString("0.00") + " Hash/s"); UpdateStats(hashStatListSub.Sum().ToString("0.00")); } Nonce++; GV.lastNonceList[threadId] = Nonce; if (Nonce >= MaxNonce) { break; } } } catch (Exception ex) { main.WriteLog(ex.Message); done = true; } thLock.AcquireWriterLock(Timeout.Infinite); try { if (usinglargeMem) { VirtualFreeEx(processHandle, hp_state, 0, FreeType.Release); } else { Marshal.FreeHGlobal(hp_state); } } catch { } thLock.ReleaseLock(); double Elapsedtime = (DateTime.Now - StartTime).TotalSeconds; string largeMemMsg = ""; if (usinglargeMem) { largeMemMsg = "LP ON"; } else { largeMemMsg = "LP OFF"; } main.WriteLog("Thread finished - " + Hashcount.ToString() + " hashes in " + Elapsedtime.ToString("0.00") + " s. Speed: " + (Hashcount / Elapsedtime).ToString("0.00") + " Hash/s" + " - " + largeMemMsg); hashStatList.Add(Hashcount / Elapsedtime); }
public void ConnectToServer(string DigServer, int DigPort, string DigUser, string DdigPassword) { try { ID = 1; Server = DigServer; Port = DigPort; Username = DigUser; Password = DdigPassword; tcpClient = new TcpClient(); tcpClient.BeginConnect(Server, Port, new AsyncCallback(ConnectCallback), tcpClient); } catch (Exception ex) { if (!GV.StopMining) { main.WriteLog("Socket error:" + ex.Message); } } }