Skip to content

Commit

Permalink
sserver ETH: Avoid repeatedly starting DAG light calculation threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed May 23, 2019
1 parent 0a93fc4 commit 9250057
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/eth/StratumServerEth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ void EthashCalculator::buildDagCache(uint64_t height) {
}

auto buildLightWithLock = [this](uint64_t height, uint64_t epoch) {
{
ScopeLock sl(lock_);
if (buildingLightCaches_.find(epoch) != buildingLightCaches_.end()) {
return;
}
buildingLightCaches_.insert(epoch);
}

LOG(INFO) << "building DAG cache for block height " << height << " (epoch "
<< epoch << ")";
time_t beginTime = time(nullptr);
Expand All @@ -260,6 +268,8 @@ void EthashCalculator::buildDagCache(uint64_t height) {
<< ") built within " << (time(nullptr) - beginTime) << " seconds";

ScopeLock sl(lock_);
buildingLightCaches_.erase(epoch);

if (lightCaches_[epoch] != nullptr) {
// Other threads have added the same light.
ethash_light_delete(light);
Expand Down
1 change: 1 addition & 0 deletions src/eth/StratumServerEth.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class EthashCalculator {

std::mutex lock_;
std::map<uint64_t /*epoch*/, ethash_light_t> lightCaches_;
std::set<uint64_t /*epoch*/> buildingLightCaches_;
std::queue<uint64_t> lightEpochs_;
string cacheFile_;

Expand Down

0 comments on commit 9250057

Please sign in to comment.