From 381c56f811782bbd9b700ff94318a425621fd422 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 16 Aug 2012 09:53:36 +1000 Subject: [PATCH] Check that we'll get 1 shares' worth of work time by rolling before saying we should roll the work. --- cgminer.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/cgminer.c b/cgminer.c index 7b1bbaee..059fc813 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