From a48cc6626061947edeb38c703e88c4b2fd0dda03 Mon Sep 17 00:00:00 2001 From: Intel Date: Wed, 7 May 2014 08:17:34 -0400 Subject: [PATCH 1/2] Improved duplicate share registry performance --- src/server/poolserver/Stratum/Client.cpp | 10 +++++++--- src/server/poolserver/Stratum/Job.h | 9 ++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/server/poolserver/Stratum/Client.cpp b/src/server/poolserver/Stratum/Client.cpp index 4bf1906..e4a7f97 100644 --- a/src/server/poolserver/Stratum/Client.cpp +++ b/src/server/poolserver/Stratum/Client.cpp @@ -166,9 +166,13 @@ namespace Stratum return; } - ByteBuffer share; - share << extranonce2 << timebuf << noncebuf; - if (!job.SubmitShare(share.Binary())) { + // Pack two 32bit ints into 64bit + ByteBuffer sharebuf; + sharebuf << noncebuf << extranonce2; + uint64 share; + sharebuf >> share; + sLog.Debug(LOG_STRATUM, "Job::SubmitShare: Nonce: %s, Extranonse: %s, Share: %u", Util::BinToASCII(noncebuf.Binary()).c_str(), Util::BinToASCII(extranonce2).c_str(), share); + if (!job.SubmitShare(share)) { sLog.Error(LOG_STRATUM, "%s: Duplicate share", username.c_str()); DataMgr::Instance()->Push(Share(_ip, username, false, "Duplicate share", Util::Date(), job.diff)); _shareLimiter.LogBad(); diff --git a/src/server/poolserver/Stratum/Job.h b/src/server/poolserver/Stratum/Job.h index e6d8e41..1e03223 100644 --- a/src/server/poolserver/Stratum/Job.h +++ b/src/server/poolserver/Stratum/Job.h @@ -16,18 +16,17 @@ namespace Stratum Bitcoin::BlockPtr block; BinaryData coinbase1; BinaryData coinbase2; - std::set shares; + std::set shares; BigInt blockCriteria; BigInt target; // Submits share to a job // Returns false if the same share already exists - bool SubmitShare(BinaryData share) + bool SubmitShare(uint64 share) { - std::string sharestr = Util::BinToASCII(Crypto::SHA256(share)); - std::set::iterator it = shares.find(sharestr); + std::set::iterator it = shares.find(share); if (it == shares.end()) { - shares.insert(sharestr); + shares.insert(share); return true; } else return false; From 1bb85e8d5dc0cc24f093fc4477314d232adbd179 Mon Sep 17 00:00:00 2001 From: Intel Date: Wed, 7 May 2014 14:24:28 -0400 Subject: [PATCH 2/2] Better variable naming --- src/server/poolserver/Stratum/Client.cpp | 9 ++++----- src/server/poolserver/Stratum/Job.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/server/poolserver/Stratum/Client.cpp b/src/server/poolserver/Stratum/Client.cpp index e4a7f97..fde4a79 100644 --- a/src/server/poolserver/Stratum/Client.cpp +++ b/src/server/poolserver/Stratum/Client.cpp @@ -213,7 +213,7 @@ namespace Stratum BigInt target(Util::BinToASCII(Util::Reverse(hash)), 16); // Check if difficulty meets job diff - if (target > job.target) { + if (target > job.jobTarget) { sLog.Error(LOG_STRATUM, "%s: Share above target", username.c_str()); DataMgr::Instance()->Push(Share(_ip, username, false, "Share above target", Util::Date(), job.diff)); _shareLimiter.LogBad(); @@ -229,7 +229,7 @@ namespace Stratum } // Check if block meets criteria - if (target <= job.blockCriteria) { + if (target <= job.blockTarget) { sLog.Info(LOG_SERVER, "We have found a block candidate!"); if (_server->SubmitBlock(block)) { @@ -321,7 +321,8 @@ namespace Stratum Job job; job.block = _server->GetWork(); job.diff = _diff; - job.target = Bitcoin::DiffToTarget(job.diff); + job.jobTarget = Bitcoin::DiffToTarget(job.diff); + job.blockTarget = Bitcoin::TargetFromBits(job.block->bits); // Serialize transaction ByteBuffer coinbasebuf; @@ -338,8 +339,6 @@ namespace Stratum job.coinbase1 = BinaryData(coinbase.begin(), coinbase.begin() + cbsplit); job.coinbase2 = BinaryData(coinbase.begin() + cbsplit + 8, coinbase.end()); // plus extranonce size - job.blockCriteria = Bitcoin::TargetFromBits(job.block->bits); - return job; } diff --git a/src/server/poolserver/Stratum/Job.h b/src/server/poolserver/Stratum/Job.h index 1e03223..26aba4b 100644 --- a/src/server/poolserver/Stratum/Job.h +++ b/src/server/poolserver/Stratum/Job.h @@ -17,8 +17,8 @@ namespace Stratum BinaryData coinbase1; BinaryData coinbase2; std::set shares; - BigInt blockCriteria; - BigInt target; + BigInt blockTarget; + BigInt jobTarget; // Submits share to a job // Returns false if the same share already exists