void BeginBlock() { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Getting {0} block", mMiningTarget.mName)); WorkBlock work = mUpstream.GetWorkBlock(); if (work != null) { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Got {0} block: {1}", mMiningTarget.mName, work.ToString())); // Put the current block in the previous list if (mBlock != null) { mPrevBlocks[mPrevBlockIndex++] = mBlock; if (mPrevBlockIndex >= mPrevBlocks.Length) { mPrevBlockIndex = 0; } } mBlock = work; mBlock.mAlgorithm = mMiningTarget.mPOWAlgorithm; } else { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("GetWork failed")); } }
public override WorkBlock GetWorkBlock() { WorkBlock work = null; JObject obj = null; try { // Get block from bitcoin BitnetClient bc = new BitnetClient("http://" + mURL + ":" + mPort); bc.Credentials = new NetworkCredential(mUser, mPass); mBlockCount = bc.GetBlockCount(); obj = bc.GetWork(); mNewBlockReady = false; } catch (Exception e) { Console.WriteLine("Failed to get work!"); Console.WriteLine(e.Message); } if (obj != null) { work = new WorkBlock(obj); } return(work); }
public override WorkBlock GetWorkBlock() { WorkBlock work = null; JObject obj = null; try { // Get block from bitcoin BitnetClient bc = new BitnetClient("http://" + mURL + ":" + mPort); bc.Credentials = new NetworkCredential(mUser, mPass); mBlockCount = bc.GetBlockCount(); obj = bc.GetWork(); mNewBlockReady = false; } catch (Exception e) { Console.WriteLine("Failed to get work!"); Console.WriteLine(e.Message); } if (obj != null) { work = new WorkBlock(obj); } return work; }
public override bool SubmitWork(WorkBlock work, uint solution) { JobInfo ji = (JobInfo)work; // {"params": ["slush.miner1", "bf", "00000001", "504e86ed", "b2957c02"], "id": 4, "method": "mining.submit"} // Values in particular order: worker_name (previously authorized!), job_id, extranonce2, ntime, nonce. string[] parms = new string[5]; parms[0] = mUser; parms[1] = ji.mJobID; parms[2] = ji.mExtraNonce2; parms[3] = ji.mTimeStr; parms[4] = Utils.UIntToHexString(solution); mSubmitString = String.Format("Submit Job({0}), Time({1}), Solution({2})", parms[1], parms[3], parms[4]) + "\n" + ji.strData + "\n" + ji.strTarget; Console.WriteLine(mSubmitString); mLog.WriteLine(mSubmitString); mAwaitingSubmitResult = true; SendRPC("mining.submit", parms); while (mAwaitingSubmitResult) { Thread.Sleep(50); } return(mSubmitResult); }
public Client(TcpClient tcp, ClientManager manager) { mTheMan = manager; mClient = tcp; mClient.NoDelay = true; mState = State.New; mType = Type.Unknown; mHashesDone = 0; mTotalHashesDone = 0; mCurrentBlock = null; mHashrate = 0; mLastSeen = DateTime.Now; }
public Client(TcpClient tcp, ClientManager manager) { mTheMan = manager; mClient = tcp; mClient.NoDelay = true; mState = State.New; mType = Type.Unknown; mHashesDone = 0; mTotalHashesDone = 0; mCurrentBlock = null; mHashrate = 0; mLastSeen = DateTime.Now; }
public void WorkComplete(Client solver, bool solutionFound, uint solution) { mEventLog.RecordClientWork(solver); WorkBlock block = solver.mCurrentBlock; block.mHashMan.FinishBlock(solver.mHashBlock); solver.mHashBlock = null; if (solutionFound && mBlock == block) { mBlocksSubmitted++; bool success = mUpstream.SubmitWork(block, solution); //if (!success) // success = mUpstream.SubmitWork(block, (uint)IPAddress.HostToNetworkOrder((int)solution)); // Start a new block if (success) { // Send email notification about this found solution /* * TimeSpan span = DateTime.Now - block.mHashMan.mStartTime; * string hashrate = string.Format("{0:N}", block.mHashMan.mHashesDone / span.TotalSeconds); * string body = "Found solution for " + block.mCurrency + " block: \n" + block.ToString() + "\n\n"; * body += "Solution string: " + data + "\n"; * body += "Block Accepted: " + success.ToString() + "\n"; * body += "Hashes Done: " + block.mHashMan.mHashesDone + "\n"; * body += "Time Spent: " + span.ToString() + "\n"; * body += "Hashrate: " + hashrate + "\n"; * body += "Clients: " + mClients.Count + "\n"; * body += "\n\n"; * //mMailer.SendEmail(body); */ //mMailer.SendEmail("Block Accepted"); string data = block.GetSolutionString(solution); mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Work accepted! solution: {0}, dataString: {1}", solution, data)); BeginBlock(); mBlocksAccepted++; } else { string data = block.GetSolutionString(solution); mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Work not accepted. solution: {0}, dataString: {1}", solution, data)); } } }
public override bool SubmitWork(WorkBlock work, uint solution) { // Submit this solution to bitcoin string data = work.GetSolutionString(solution); Console.WriteLine("Trying solution: " + data); BitnetClient bc = new BitnetClient("http://" + mURL + ":" + mPort); bc.Credentials = new NetworkCredential(mUser, mPass); bool success = bc.GetWork(data); if (!success) { data = work.GetSolutionString((uint)IPAddress.HostToNetworkOrder((int)solution)); success = bc.GetWork(data); } return success; }
public override bool SubmitWork(WorkBlock work, uint solution) { // Submit this solution to bitcoin string data = work.GetSolutionString(solution); Console.WriteLine("Trying solution: " + data); BitnetClient bc = new BitnetClient("http://" + mURL + ":" + mPort); bc.Credentials = new NetworkCredential(mUser, mPass); bool success = bc.GetWork(data); if (!success) { data = work.GetSolutionString((uint)IPAddress.HostToNetworkOrder((int)solution)); success = bc.GetWork(data); } return(success); }
public void SendWork(HashManager.HashBlock hashBlock, WorkBlock block) { mHashBlock = hashBlock; MemoryStream stream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(stream); bw.Write((byte)3); bw.Write(hashBlock.Start); bw.Write(hashBlock.Count); bw.Write((int)block.mAlgorithm); bw.Write(block.target); bw.Write(block.data); SendPacket(stream.ToArray()); bw.Close(); mCurrentBlock = block; mState = State.Busy; mWorkSent = DateTime.Now; }
public abstract bool SubmitWork(WorkBlock work, uint solution);
public override bool SubmitWork(WorkBlock work, uint solution) { JobInfo ji = (JobInfo)work; // {"params": ["slush.miner1", "bf", "00000001", "504e86ed", "b2957c02"], "id": 4, "method": "mining.submit"} // Values in particular order: worker_name (previously authorized!), job_id, extranonce2, ntime, nonce. string[] parms = new string[5]; parms[0] = mUser; parms[1] = ji.mJobID; parms[2] = ji.mExtraNonce2; parms[3] = ji.mTimeStr; parms[4] = Utils.UIntToHexString(solution); mSubmitString = String.Format("Submit Job({0}), Time({1}), Solution({2})", parms[1], parms[3], parms[4]) + "\n" + ji.strData + "\n" + ji.strTarget; Console.WriteLine(mSubmitString); mLog.WriteLine(mSubmitString); mAwaitingSubmitResult = true; SendRPC("mining.submit", parms); while (mAwaitingSubmitResult) { Thread.Sleep(50); } return mSubmitResult; }
public void SendWork(HashManager.HashBlock hashBlock, WorkBlock block) { mHashBlock = hashBlock; MemoryStream stream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(stream); bw.Write((byte)3); bw.Write(hashBlock.Start); bw.Write(hashBlock.Count); bw.Write((int)block.mAlgorithm); bw.Write(block.target); bw.Write(block.data); SendPacket(stream.ToArray()); bw.Close(); mCurrentBlock = block; mState = State.Busy; mWorkSent = DateTime.Now; }
abstract public bool SubmitWork(WorkBlock work, uint solution);
void BeginBlock() { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Getting {0} block", mMiningTarget.mName)); WorkBlock work = mUpstream.GetWorkBlock(); if (work != null) { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("Got {0} block: {1}", mMiningTarget.mName, work.ToString())); // Put the current block in the previous list if (mBlock != null) { mPrevBlocks[mPrevBlockIndex++] = mBlock; if (mPrevBlockIndex >= mPrevBlocks.Length) mPrevBlockIndex = 0; } mBlock = work; mBlock.mAlgorithm = mMiningTarget.mPOWAlgorithm; } else { mEventLog.RecordEvent(EventLog.EventType.Upstream, string.Format("GetWork failed")); } }