forked from tpruvot/ccminer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stratum: handle a small cache of submitted jobs
Prevent to send duplicated shares on some pools like hashharder.. This cache keeps submitted job/nounces of the last 15 minutes so, remove exit on repeated duplicate shares, the submitted cache now handles this problem. Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
- Loading branch information
Showing
7 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <inttypes.h> | ||
#include <stdlib.h> | ||
#include <map> | ||
|
||
#include "miner.h" | ||
|
||
static std::map<uint64_t, uint32_t> tlastshares; | ||
|
||
/** | ||
* Purge entries after 15 minutes | ||
*/ | ||
#define LOG_PURGE_TIMEOUT 15*60 | ||
|
||
/** | ||
* Store submitted nounces of a job | ||
*/ | ||
extern "C" void hashlog_remember_submit(char* jobid, uint32_t nounce) | ||
{ | ||
char *ptr; | ||
uint64_t njobid = (uint64_t) strtoul(jobid, &ptr, 16); | ||
uint64_t key = (njobid << 32) + nounce; | ||
tlastshares[key] = (uint32_t) time(NULL); | ||
} | ||
|
||
/** | ||
* @return time of submission | ||
*/ | ||
extern "C" uint32_t hashlog_already_submittted(char* jobid, uint32_t nounce) | ||
{ | ||
char *ptr; | ||
uint32_t ret = 0; | ||
uint64_t njobid = (uint64_t) strtoul(jobid, &ptr, 16); | ||
uint64_t key = (njobid << 32) + nounce; | ||
std::map<uint64_t, uint32_t>::iterator i = tlastshares.find(key); | ||
if (i != tlastshares.end()) | ||
ret = (uint32_t) tlastshares[key]; | ||
return ret; | ||
} | ||
|
||
/** | ||
* Remove entries of a job... not used yet | ||
*/ | ||
extern "C" void hashlog_purge_job(char* jobid) | ||
{ | ||
char *ptr; | ||
uint64_t njobid = strtoul(jobid, &ptr, 16); | ||
uint64_t keypfx = (njobid << 32); | ||
std::map<uint64_t, uint32_t>::iterator i = tlastshares.begin(); | ||
while (i != tlastshares.end()) { | ||
if ((keypfx & i->first) != 0) | ||
tlastshares.erase(i); | ||
i++; | ||
} | ||
} | ||
|
||
/** | ||
* Remove old entries to reduce memory usage | ||
*/ | ||
extern "C" void hashlog_purge_old(void) | ||
{ | ||
int deleted = 0; | ||
uint32_t now = (uint32_t) time(NULL); | ||
std::map<uint64_t, uint32_t>::iterator i = tlastshares.begin(); | ||
while (i != tlastshares.end()) { | ||
if ((now - i->second) > LOG_PURGE_TIMEOUT) { | ||
deleted++; | ||
tlastshares.erase(i); | ||
} | ||
i++; | ||
} | ||
if (opt_debug && deleted) { | ||
applog(LOG_DEBUG, "hashlog: %d/%d purged", | ||
deleted, tlastshares.size()); | ||
} | ||
} | ||
|
||
/** | ||
* Reset the submitted nounce cache | ||
*/ | ||
extern "C" void hashlog_purge_all(void) | ||
{ | ||
tlastshares.clear(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters