Skip to content

Commit

Permalink
Teach longpoll logic about multiple mining goals
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Oct 29, 2014
1 parent db0d472 commit adf7671
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
root = api_add_string(root, "Current Block Hash", fullhash, true);
cg_runlock(&ch_lock);

root = api_add_bool(root, "LP", &have_longpoll, false);
root = api_add_bool(root, "LP", &goal->have_longpoll, false);
root = api_add_diff(root, "Network Difficulty", &goal->current_diff, true);

root = print_data(root, buf, isjson, precom);
Expand Down
28 changes: 17 additions & 11 deletions miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ char *request_target_str;
float request_pdiff = 1.0;
double request_bdiff;
static bool want_stratum = true;
bool have_longpoll;
int opt_skip_checks;
bool want_per_device_stats;
bool use_syslog;
Expand Down Expand Up @@ -4469,7 +4468,7 @@ static void curses_print_status(const int ts)
lowdiff_pool->diff,
(lowdiff == highdiff) ? "" : "-",
(lowdiff == highdiff) ? "" : highdiff_pool->diff,
have_longpoll ? '+' : '-',
pool->goal->have_longpoll ? '+' : '-',
oldest_work_restart_pool->work_restart_timestamp);
}
else
Expand All @@ -4495,7 +4494,7 @@ one_workable_pool: ;
}
cg_mvwprintw(statuswin, 2, 0, " Pool%2u: %s Diff:%s %c%s LU:%s User:%s",
pool->pool_no, pooladdr, pool->diff,
have_longpoll ? '+' : '-', pool_proto_str(pool),
pool->goal->have_longpoll ? '+' : '-', pool_proto_str(pool),
pool->work_restart_timestamp,
pool->rpc_user);
}
Expand Down Expand Up @@ -6164,6 +6163,8 @@ bool stale_work(struct work *work, bool share)

block_id = ((uint32_t*)work->data)[1];
pool = work->pool;
struct mining_goal_info * const goal = pool->goal;
struct blockchain_info * const blkchain = goal->blkchain;

/* Technically the rolltime should be correct but some pools
* advertise a broken expire= that is lower than a meaningful
Expand All @@ -6173,7 +6174,7 @@ bool stale_work(struct work *work, bool share)
else
work_expiry = opt_expiry;

unsigned max_expiry = (have_longpoll ? opt_expiry_lp : opt_expiry);
unsigned max_expiry = (goal->have_longpoll ? opt_expiry_lp : opt_expiry);
if (work_expiry > max_expiry)
work_expiry = max_expiry;

Expand All @@ -6193,9 +6194,6 @@ bool stale_work(struct work *work, bool share)
return true;
}
} else {
struct mining_goal_info * const goal = pool->goal;
struct blockchain_info * const blkchain = goal->blkchain;

/* If this work isn't for the latest Bitcoin block, it's stale */
/* But only care about the current pool if failover-only */
if (enabled_pools <= 1 || opt_fail_only) {
Expand Down Expand Up @@ -7158,7 +7156,7 @@ static bool test_work_current(struct work *work)
pool->pool_no);
}
else
if (have_longpoll)
if (goal->have_longpoll)
applog(LOG_NOTICE, "New block detected on network before longpoll");
else
applog(LOG_NOTICE, "New block detected on network");
Expand Down Expand Up @@ -9256,7 +9254,8 @@ static void *stratum_thread(void *userdata)

static void init_stratum_thread(struct pool *pool)
{
have_longpoll = true;
struct mining_goal_info * const goal = pool->goal;
goal->have_longpoll = true;

if (unlikely(pthread_create(&pool->stratum_thread, NULL, stratum_thread, (void *)pool)))
quit(1, "Failed to create stratum thread");
Expand Down Expand Up @@ -10603,6 +10602,8 @@ struct pool *_select_longpoll_pool(struct pool *cp, bool(*func)(struct pool *))
return cp;
for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i];
if (cp->goal != pool->goal)
continue;

if (func(pool))
return pool;
Expand Down Expand Up @@ -10674,7 +10675,7 @@ static void *longpoll_thread(void *userdata)
}

/* Any longpoll from any pool is enough for this to be true */
have_longpoll = true;
pool->goal->have_longpoll = true;

wait_lpcurrent(cp);

Expand Down Expand Up @@ -10780,7 +10781,12 @@ static void stop_longpoll(void)
pool->lp_started = false;
pthread_cancel(pool->longpoll_thread);
}
have_longpoll = false;

struct mining_goal_info *goal, *tmpgoal;
HASH_ITER(hh, mining_goals, goal, tmpgoal)
{
goal->have_longpoll = false;
}
}

static void start_longpoll(void)
Expand Down
3 changes: 2 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ extern bool opt_protocol;
extern bool opt_dev_protocol;
extern char *opt_coinbase_sig;
extern char *request_target_str;
extern bool have_longpoll;
extern int opt_skip_checks;
extern char *opt_kernel_path;
extern char *opt_socks_proxy;
Expand Down Expand Up @@ -1156,6 +1155,8 @@ struct mining_goal_info {

double diff_accepted;

bool have_longpoll;

UT_hash_handle hh;
};

Expand Down

0 comments on commit adf7671

Please sign in to comment.