diff --git a/src/generator.c b/src/generator.c index 52f9c605..fba8ac23 100644 --- a/src/generator.c +++ b/src/generator.c @@ -858,6 +858,29 @@ out: return ret; } +bool generator_checkaddr(ckpool_t *ckp, const char *addr) +{ + gdata_t *gdata = ckp->gdata; + server_instance_t *si; + int ret = false; + connsock_t *cs; + + /* Use temporary variables to prevent deref while accessing */ + si = gdata->current_si; + if (unlikely(!si)) { + LOGWARNING("No live current server in generator_checkaddr"); + goto out; + } + cs = &si->cs; + if (unlikely(!cs)) { + LOGWARNING("No live connsock for current server in generator_checkaddr"); + goto out; + } + ret = validate_address(cs, addr); +out: + return ret; +} + static bool parse_notify(ckpool_t *ckp, proxy_instance_t *proxi, json_t *val) { const char *prev_hash, *bbversion, *nbit, *ntime; diff --git a/src/generator.h b/src/generator.h index b5c25f6a..c9811c02 100644 --- a/src/generator.h +++ b/src/generator.h @@ -19,6 +19,7 @@ void generator_add_send(ckpool_t *ckp, json_t *val); json_t *generator_genbase(ckpool_t *ckp); int generator_getbest(ckpool_t *ckp, char *hash); +bool generator_checkaddr(ckpool_t *ckp, const char *addr); void *generator(void *arg); #endif /* GENERATOR_H */ diff --git a/src/stratifier.c b/src/stratifier.c index 11be7963..83b716af 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1120,29 +1120,6 @@ static void add_base(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, bool *new_bl } } -/* Mandatory send_recv to the generator which sets the message priority if this - * message is higher priority. Races galore on gen_priority mean this might - * read the wrong priority but occasional wrong values are harmless. */ -static char *__send_recv_generator(ckpool_t *ckp, const char *msg, const int prio) -{ - sdata_t *sdata = ckp->sdata; - char *buf = NULL; - bool set; - - if (prio > sdata->gen_priority) { - sdata->gen_priority = prio; - set = true; - } else - set = false; - buf = _send_recv_proc(&ckp->generator, msg, UNIX_WRITE_TIMEOUT, RPC_TIMEOUT, __FILE__, __func__, __LINE__); - if (unlikely(!buf)) - buf = strdup("failed"); - if (set) - sdata->gen_priority = 0; - - return buf; -} - static void send_generator(ckpool_t *ckp, const char *msg, const int prio) { sdata_t *sdata = ckp->sdata; @@ -4718,22 +4695,6 @@ static json_t *parse_subscribe(stratum_instance_t *client, const int64_t client_ return ret; } -static bool test_address(ckpool_t *ckp, const char *address) -{ - bool ret = false; - char *buf, *msg; - - ASPRINTF(&msg, "checkaddr:%s", address); - /* Must wait for a response here */ - buf = __send_recv_generator(ckp, msg, GEN_LAX); - dealloc(msg); - if (!buf) - return ret; - ret = cmdmatch(buf, "true"); - dealloc(buf); - return ret; -} - static double dsps_from_key(json_t *val, const char *key) { char *string, *endptr; @@ -5030,7 +4991,7 @@ static user_instance_t *generate_user(ckpool_t *ckp, stratum_instance_t *client, /* Is this a btc address based username? */ if (!ckp->proxy && (new_user || !user->btcaddress) && (len > 26 && len < 35)) - user->btcaddress = test_address(ckp, username); + user->btcaddress = generator_checkaddr(ckp, username); if (new_user) { LOGNOTICE("Added new user %s%s", username, user->btcaddress ? " as address based registration" : ""); @@ -6459,7 +6420,7 @@ static user_instance_t *generate_remote_user(ckpool_t *ckp, const char *workerna /* Is this a btc address based username? */ if (!ckp->proxy && (new_user || !user->btcaddress) && (len > 26 && len < 35)) - user->btcaddress = test_address(ckp, username); + user->btcaddress = generator_checkaddr(ckp, username); if (new_user) { LOGNOTICE("Added new remote user %s%s", username, user->btcaddress ? " as address based registration" : ""); @@ -8098,7 +8059,7 @@ void *stratifier(void *arg) dealloc(buf); if (!ckp->proxy) { - if (!test_address(ckp, ckp->btcaddress)) { + if (!generator_checkaddr(ckp, ckp->btcaddress)) { LOGEMERG("Fatal: btcaddress invalid according to bitcoind"); goto out; } @@ -8113,7 +8074,7 @@ void *stratifier(void *arg) sdata->pubkeytxnlen = 25; } - if (test_address(ckp, ckp->donaddress)) { + if (generator_checkaddr(ckp, ckp->donaddress)) { ckp->donvalid = true; if (script_address(ckp->donaddress)) { sdata->donkeytxnlen = 23;