Check that we'll get 1 shares' worth of work time by rolling before saying we should roll the work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/cgminer.c b/cgminer.c
index 7b1bbae..059fc81 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2289,9 +2289,27 @@ static bool stale_work(struct work *work, bool share);
static inline bool should_roll(struct work *work)
{
- if (work->pool == current_pool() || pool_strategy == POOL_LOADBALANCE)
- return true;
- return false;
+ struct timeval now;
+ double share_time;
+ time_t expiry;
+
+ if (work->pool != current_pool() && pool_strategy != POOL_LOADBALANCE)
+ return false;
+
+ share_time = total_secs * mining_threads / (total_accepted + 1);
+ if (work->rolltime > opt_scantime)
+ expiry = work->rolltime;
+ else
+ expiry = opt_scantime;
+ expiry -= share_time;
+
+ /* We shouldn't roll if we're unlikely to get one shares' duration
+ * work out of doing so */
+ gettimeofday(&now, NULL);
+ if (now.tv_sec - work->tv_staged.tv_sec > expiry)
+ return false;
+
+ return true;
}
/* Limit rolls to 7000 to not beyond 2 hours in the future where bitcoind will
@@ -2467,21 +2485,13 @@ static bool stale_work(struct work *work, bool share)
struct pool *pool;
int getwork_delay;
- if (share) {
- /* Technically the rolltime should be correct but some pools
- * advertise a broken expire= that is lower than a meaningful
- * scantime */
- if (work->rolltime > opt_scantime)
- work_expiry = work->rolltime;
- else
- work_expiry = opt_expiry;
- } else {
- /* Don't keep rolling work right up to the expiration */
- if (work->rolltime > opt_scantime)
- work_expiry = (work->rolltime - opt_scantime) * 2 / 3 + opt_scantime;
- else /* Shouldn't happen unless someone increases scantime */
- work_expiry = opt_scantime;
- }
+ /* Technically the rolltime should be correct but some pools
+ * advertise a broken expire= that is lower than a meaningful
+ * scantime */
+ if (work->rolltime > opt_scantime)
+ work_expiry = work->rolltime;
+ else
+ work_expiry = opt_expiry;
pool = work->pool;
/* Factor in the average getwork delay of this pool, rounding it up to