Browse Source

Dramatically simplify the setting of enonce1 to just an LE encoded 64 bit

master
ckolivas 10 years ago
parent
commit
0a4ce58b3f
  1. 72
      src/stratifier.c

72
src/stratifier.c

@ -291,14 +291,6 @@ struct share {
typedef struct share share_t; typedef struct share share_t;
/* Variable length enonce1 always refers back to a u64 */
typedef union {
uint64_t u64;
uint32_t u32;
uint16_t u16;
uint8_t u8;
} enonce1_t;
struct proxy_base { struct proxy_base {
UT_hash_handle hh; UT_hash_handle hh;
UT_hash_handle sh; /* For subproxy hashlist */ UT_hash_handle sh; /* For subproxy hashlist */
@ -347,7 +339,7 @@ struct stratifier_data {
bool ckdb_offline; bool ckdb_offline;
bool verbose; bool verbose;
enonce1_t enonce1u; uint64_t enonce1_64;
/* For protecting the hashtable data */ /* For protecting the hashtable data */
cklock_t workbase_lock; cklock_t workbase_lock;
@ -2452,9 +2444,7 @@ static void __fill_enonce1data(const workbase_t *wb, stratum_instance_t *client)
static bool new_enonce1(ckpool_t *ckp, sdata_t *ckp_sdata, sdata_t *sdata, stratum_instance_t *client) static bool new_enonce1(ckpool_t *ckp, sdata_t *ckp_sdata, sdata_t *sdata, stratum_instance_t *client)
{ {
proxy_t *proxy = NULL; proxy_t *proxy = NULL;
enonce1_t *enonce1u; uint64_t enonce1;
int enonce1varlen;
bool ret = false;
if (ckp->proxy) { if (ckp->proxy) {
if (!ckp_sdata->proxy) if (!ckp_sdata->proxy)
@ -2471,64 +2461,27 @@ static bool new_enonce1(ckpool_t *ckp, sdata_t *ckp_sdata, sdata_t *sdata, strat
return false; return false;
} }
} }
enonce1u = &ckp_sdata->enonce1u;
/* Extract the enonce1varlen from the current workbase which may be
* a different workbase to when we __fill_enonce1data but the value
* will not change and this avoids grabbing recursive locks */
ck_rlock(&sdata->workbase_lock);
enonce1varlen = sdata->current_workbase->enonce1varlen;
ck_runlock(&sdata->workbase_lock);
/* instance_lock protects enonce1u. Recruiting extra proxies should /* instance_lock protects enonce1_64. Incrementing a little endian 64bit
* prevent these ever running out.*/ * number ensures that no matter how many of the bits we take from the
* left depending on nonce2 length, we'll always get a changing value
* for every next client.*/
ck_wlock(&ckp_sdata->instance_lock); ck_wlock(&ckp_sdata->instance_lock);
switch(enonce1varlen) { enonce1 = htole64(ckp_sdata->enonce1_64);
case 8: enonce1++;
enonce1u->u64++; client->enonce1_64 = ckp_sdata->enonce1_64 = le64toh(enonce1);
ret = true;
break;
case 7:
case 6:
case 5:
case 4:
enonce1u->u32++;
ret = true;
break;
case 3:
case 2:
enonce1u->u16++;
ret = true;
break;
case 1:
enonce1u->u8++;
ret = true;
break;
case 0:
/* Only one client/enonce1 used on this proxy */
ret = true;
break;
default:
quit(0, "Invalid enonce1varlen %d", enonce1varlen);
}
if (ret) {
if (proxy) { if (proxy) {
client->proxy = proxy; client->proxy = proxy;
proxy->clients++; proxy->clients++;
proxy->bound_clients++; proxy->bound_clients++;
} }
client->enonce1_64 = enonce1u->u64;
}
ck_wunlock(&ckp_sdata->instance_lock); ck_wunlock(&ckp_sdata->instance_lock);
ck_rlock(&sdata->workbase_lock); ck_rlock(&sdata->workbase_lock);
__fill_enonce1data(sdata->current_workbase, client); __fill_enonce1data(sdata->current_workbase, client);
ck_runlock(&sdata->workbase_lock); ck_runlock(&sdata->workbase_lock);
if (unlikely(!ret)) return true;
LOGWARNING("Enonce1 space exhausted! Proxy rejecting clients");
return ret;
} }
static void stratum_send_message(sdata_t *sdata, const stratum_instance_t *client, const char *msg); static void stratum_send_message(sdata_t *sdata, const stratum_instance_t *client, const char *msg);
@ -5041,12 +4994,13 @@ int stratifier(proc_instance_t *pi)
} }
} }
randomiser = ((int64_t)time(NULL)) << 32; randomiser = time(NULL);
sdata->enonce1_64 = htole64(randomiser);
/* Set the initial id to time as high bits so as to not send the same /* Set the initial id to time as high bits so as to not send the same
* id on restarts */ * id on restarts */
randomiser <<= 32;
if (!ckp->proxy) if (!ckp->proxy)
sdata->blockchange_id = sdata->workbase_id = randomiser; sdata->blockchange_id = sdata->workbase_id = randomiser;
sdata->enonce1u.u64 = htobe64(randomiser);
if (!ckp->serverurls) { if (!ckp->serverurls) {
ckp->serverurl[0] = "127.0.0.1"; ckp->serverurl[0] = "127.0.0.1";

Loading…
Cancel
Save