From e119e13fb14e8fc0a9c87b414f43eee1ea440e75 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 29 Apr 2014 13:08:22 +1000 Subject: [PATCH] Add share hashtable purging on new blocks --- src/stratifier.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index 4f13c43e..a84b8ccd 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -288,6 +288,24 @@ static void clear_workbase(workbase_t *wb) free(wb); } +static void purge_share_hashtable(int wb_id) +{ + share_t *share, *tmp; + int purged = 0; + + ck_wlock(&share_lock); + HASH_ITER(hh, shares, share, tmp) { + if (share->workbase_id < wb_id) { + HASH_DEL(shares, share); + free(share); + purged++; + } + } + ck_wunlock(&share_lock); + + LOGINFO("Cleared %d shares from share hashtable", purged); +} + /* This function assumes it will only receive a valid json gbt base template * since checking should have been done earlier, and creates the base template * for generating work templates. */ @@ -365,6 +383,9 @@ static void update_base(ckpool_t *ckp) current_workbase = wb; ck_wunlock(&workbase_lock); + if (new_block) + purge_share_hashtable(wb->id); + stratum_broadcast_update(new_block); } @@ -996,7 +1017,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, } sdiff = submission_diff(client, wb, nonce2, ntime32, nonce, hash); out_unlock: - wb_id = workbase_id; + wb_id = wb->id; ck_runlock(&workbase_lock); /* Accept the lower of new and old diffs until the next update */