Browse Source

Merge branch 'master' of bitbucket.org:ckolivas/ckpool

master
Con Kolivas 9 years ago
parent
commit
799822c537
  1. 22
      src/bitcoin.c
  2. 2
      src/bitcoin.h
  3. 30
      src/stratifier.c

22
src/bitcoin.c

@ -89,18 +89,18 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
dealloc(gbt->txn_data); dealloc(gbt->txn_data);
dealloc(gbt->txn_hashes); dealloc(gbt->txn_hashes);
gbt->transactions = 0; gbt->txns = 0;
gbt->merkles = 0; gbt->merkles = 0;
gbt->transactions = json_array_size(transaction_arr); gbt->txns = json_array_size(transaction_arr);
binlen = gbt->transactions * 32 + 32; binlen = gbt->txns * 32 + 32;
hashbin = alloca(binlen + 32); hashbin = alloca(binlen + 32);
memset(hashbin, 0, 32); memset(hashbin, 0, 32);
binleft = binlen / 32; binleft = binlen / 32;
if (gbt->transactions) { if (gbt->txns) {
int len = 1, ofs = 0; int len = 1, ofs = 0;
const char *txn; const char *txn;
for (i = 0; i < gbt->transactions; i++) { for (i = 0; i < gbt->txns; i++) {
arr_val = json_array_get(transaction_arr, i); arr_val = json_array_get(transaction_arr, i);
txn = json_string_value(json_object_get(arr_val, "data")); txn = json_string_value(json_object_get(arr_val, "data"));
if (!txn) { if (!txn) {
@ -111,10 +111,10 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
} }
gbt->txn_data = ckzalloc(len + 1); gbt->txn_data = ckzalloc(len + 1);
gbt->txn_hashes = ckzalloc(gbt->transactions * 65 + 1); gbt->txn_hashes = ckzalloc(gbt->txns * 65 + 1);
memset(gbt->txn_hashes, 0x20, gbt->transactions * 65); // Spaces memset(gbt->txn_hashes, 0x20, gbt->txns * 65); // Spaces
for (i = 0; i < gbt->transactions; i++) { for (i = 0; i < gbt->txns; i++) {
char binswap[32]; char binswap[32];
const char *hash; const char *hash;
@ -168,7 +168,7 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
binlen = binleft * 32; binlen = binleft * 32;
} }
} }
LOGINFO("Stored %d transactions", gbt->transactions); LOGINFO("Stored %d transactions", gbt->txns);
return true; return true;
} }
@ -259,8 +259,8 @@ bool gen_gbtbase(connsock_t *cs, gbtbase_t *gbt)
json_object_set_new_nocheck(gbt->json, "flags", json_string_nocheck(gbt->flags)); json_object_set_new_nocheck(gbt->json, "flags", json_string_nocheck(gbt->flags));
gbt_merkle_bins(gbt, transaction_arr); gbt_merkle_bins(gbt, transaction_arr);
json_object_set_new_nocheck(gbt->json, "transactions", json_integer(gbt->transactions)); json_object_set_new_nocheck(gbt->json, "txns", json_integer(gbt->txns));
if (gbt->transactions) { if (gbt->txns) {
json_object_set_new_nocheck(gbt->json, "txn_data", json_string_nocheck(gbt->txn_data)); json_object_set_new_nocheck(gbt->json, "txn_data", json_string_nocheck(gbt->txn_data));
json_object_set_new_nocheck(gbt->json, "txn_hashes", json_string_nocheck(gbt->txn_hashes)); json_object_set_new_nocheck(gbt->json, "txn_hashes", json_string_nocheck(gbt->txn_hashes));
} }

2
src/bitcoin.h

@ -22,7 +22,7 @@ struct gbtbase {
uint64_t coinbasevalue; uint64_t coinbasevalue;
int height; int height;
char *flags; char *flags;
int transactions; int txns;
char *txn_data; char *txn_data;
char *txn_hashes; char *txn_hashes;
int merkles; int merkles;

30
src/stratifier.c

@ -106,7 +106,7 @@ struct workbase {
uint64_t coinbasevalue; uint64_t coinbasevalue;
int height; int height;
char *flags; char *flags;
int transactions; int txns;
char *txn_data; char *txn_data;
char *txn_hashes; char *txn_hashes;
int merkles; int merkles;
@ -877,8 +877,8 @@ static void send_node_workinfo(sdata_t *sdata, const workbase_t *wb)
json_set_int(wb_val, "coinbasevalue", wb->coinbasevalue); json_set_int(wb_val, "coinbasevalue", wb->coinbasevalue);
json_set_int(wb_val, "height", wb->height); json_set_int(wb_val, "height", wb->height);
json_set_string(wb_val, "flags", wb->flags); json_set_string(wb_val, "flags", wb->flags);
json_set_int(wb_val, "transactions", wb->transactions); json_set_int(wb_val, "txns", wb->txns);
if (likely(wb->transactions)) if (likely(wb->txns))
json_set_string(wb_val, "txn_data", wb->txn_data); json_set_string(wb_val, "txn_data", wb->txn_data);
/* We don't need txn_hashes */ /* We don't need txn_hashes */
json_set_int(wb_val, "merkles", wb->merkles); json_set_int(wb_val, "merkles", wb->merkles);
@ -1158,8 +1158,8 @@ retry:
json_uint64cpy(&wb->coinbasevalue, val, "coinbasevalue"); json_uint64cpy(&wb->coinbasevalue, val, "coinbasevalue");
json_intcpy(&wb->height, val, "height"); json_intcpy(&wb->height, val, "height");
json_strdup(&wb->flags, val, "flags"); json_strdup(&wb->flags, val, "flags");
json_intcpy(&wb->transactions, val, "transactions"); json_intcpy(&wb->txns, val, "txns");
if (wb->transactions) { if (wb->txns) {
json_strdup(&wb->txn_data, val, "txn_data"); json_strdup(&wb->txn_data, val, "txn_data");
json_strdup(&wb->txn_hashes, val, "txn_hashes"); json_strdup(&wb->txn_hashes, val, "txn_hashes");
} else } else
@ -1230,8 +1230,8 @@ static void add_node_base(ckpool_t *ckp, json_t *val)
json_uint64cpy(&wb->coinbasevalue, val, "coinbasevalue"); json_uint64cpy(&wb->coinbasevalue, val, "coinbasevalue");
json_intcpy(&wb->height, val, "height"); json_intcpy(&wb->height, val, "height");
json_strdup(&wb->flags, val, "flags"); json_strdup(&wb->flags, val, "flags");
json_intcpy(&wb->transactions, val, "transactions"); json_intcpy(&wb->txns, val, "txns");
if (wb->transactions) if (wb->txns)
json_strdup(&wb->txn_data, val, "txn_data"); json_strdup(&wb->txn_data, val, "txn_data");
json_intcpy(&wb->merkles, val, "merkles"); json_intcpy(&wb->merkles, val, "merkles");
wb->merkle_array = json_object_dup(val, "merklehash"); wb->merkle_array = json_object_dup(val, "merklehash");
@ -1433,7 +1433,7 @@ static void
process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const int cblen, process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const int cblen,
const uchar *data, const uchar *hash, uchar *swap32, char *blockhash) const uchar *data, const uchar *hash, uchar *swap32, char *blockhash)
{ {
int transactions = wb->transactions + 1; int txns = wb->txns + 1;
char *gbt_block, varint[12]; char *gbt_block, varint[12];
char hexcoinbase[1024]; char hexcoinbase[1024];
@ -1444,17 +1444,17 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i
/* Message format: "submitblock:hash,data" */ /* Message format: "submitblock:hash,data" */
sprintf(gbt_block, "submitblock:%s,", blockhash); sprintf(gbt_block, "submitblock:%s,", blockhash);
__bin2hex(gbt_block + 12 + 64 + 1, data, 80); __bin2hex(gbt_block + 12 + 64 + 1, data, 80);
if (transactions < 0xfd) { if (txns < 0xfd) {
uint8_t val8 = transactions; uint8_t val8 = txns;
__bin2hex(varint, (const unsigned char *)&val8, 1); __bin2hex(varint, (const unsigned char *)&val8, 1);
} else if (transactions <= 0xffff) { } else if (txns <= 0xffff) {
uint16_t val16 = htole16(transactions); uint16_t val16 = htole16(txns);
strcat(gbt_block, "fd"); strcat(gbt_block, "fd");
__bin2hex(varint, (const unsigned char *)&val16, 2); __bin2hex(varint, (const unsigned char *)&val16, 2);
} else { } else {
uint32_t val32 = htole32(transactions); uint32_t val32 = htole32(txns);
strcat(gbt_block, "fe"); strcat(gbt_block, "fe");
__bin2hex(varint, (const unsigned char *)&val32, 4); __bin2hex(varint, (const unsigned char *)&val32, 4);
@ -1462,7 +1462,7 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i
strcat(gbt_block, varint); strcat(gbt_block, varint);
__bin2hex(hexcoinbase, coinbase, cblen); __bin2hex(hexcoinbase, coinbase, cblen);
strcat(gbt_block, hexcoinbase); strcat(gbt_block, hexcoinbase);
if (wb->transactions) if (wb->txns)
realloc_strcat(&gbt_block, wb->txn_data); realloc_strcat(&gbt_block, wb->txn_data);
send_generator(ckp, gbt_block, GEN_PRIORITY); send_generator(ckp, gbt_block, GEN_PRIORITY);
if (ckp->remote) if (ckp->remote)
@ -6474,7 +6474,7 @@ static int transactions_by_jobid(sdata_t *sdata, const int64_t id)
ck_rlock(&sdata->workbase_lock); ck_rlock(&sdata->workbase_lock);
HASH_FIND_I64(sdata->workbases, &id, wb); HASH_FIND_I64(sdata->workbases, &id, wb);
if (wb) if (wb)
ret = wb->transactions; ret = wb->txns;
ck_runlock(&sdata->workbase_lock); ck_runlock(&sdata->workbase_lock);
return ret; return ret;

Loading…
Cancel
Save