Browse Source

Update transactions after sending out stratum updates.

master
Con Kolivas 8 years ago
parent
commit
700d3accac
  1. 26
      src/stratifier.c

26
src/stratifier.c

@ -1322,8 +1322,8 @@ static void update_txns(ckpool_t *ckp, sdata_t *sdata, txntable_t *txns, bool lo
/* Distill down a set of transactions into an efficient tree arrangement for /* Distill down a set of transactions into an efficient tree arrangement for
* stratum messages and fast work assembly. */ * stratum messages and fast work assembly. */
static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t *txn_array, static txntable_t *wb_merkle_bin_txns(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb,
bool local) json_t *txn_array, bool local)
{ {
int i, j, binleft, binlen; int i, j, binleft, binlen;
txntable_t *txns = NULL; txntable_t *txns = NULL;
@ -1345,7 +1345,7 @@ static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t
txn = json_string_value(json_object_get(arr_val, "data")); txn = json_string_value(json_object_get(arr_val, "data"));
if (!txn) { if (!txn) {
LOGWARNING("json_string_value fail - cannot find transaction data"); LOGWARNING("json_string_value fail - cannot find transaction data");
return; goto out;
} }
len += strlen(txn); len += strlen(txn);
} }
@ -1367,7 +1367,7 @@ static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t
txid = hash; txid = hash;
if (unlikely(!txid)) { if (unlikely(!txid)) {
LOGERR("Missing txid for transaction in wb_merkle_bins"); LOGERR("Missing txid for transaction in wb_merkle_bins");
return; goto out;
} }
txn = json_string_value(json_object_get(arr_val, "data")); txn = json_string_value(json_object_get(arr_val, "data"));
add_txn(ckp, sdata, &txns, hash, txn, local); add_txn(ckp, sdata, &txns, hash, txn, local);
@ -1376,7 +1376,7 @@ static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t
ofs += len; ofs += len;
if (!hex2bin(binswap, txid, 32)) { if (!hex2bin(binswap, txid, 32)) {
LOGERR("Failed to hex2bin hash in gbt_merkle_bins"); LOGERR("Failed to hex2bin hash in gbt_merkle_bins");
return; goto out;
} }
memcpy(wb->txn_hashes + i * 65, txid, 64); memcpy(wb->txn_hashes + i * 65, txid, 64);
bswap_256(hashbin + 32 + 32 * i, binswap); bswap_256(hashbin + 32 + 32 * i, binswap);
@ -1406,8 +1406,8 @@ static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t
} }
LOGNOTICE("Stored %s workbase with %d transactions", local ? "local" : "remote", LOGNOTICE("Stored %s workbase with %d transactions", local ? "local" : "remote",
wb->txns); wb->txns);
out:
update_txns(ckp, sdata, txns, true); return txns;
} }
static const unsigned char witness_nonce[32] = {0}; static const unsigned char witness_nonce[32] = {0};
@ -1474,6 +1474,7 @@ static void block_update(ckpool_t *ckp, int *prio)
bool new_block = false; bool new_block = false;
int i, retries = 0; int i, retries = 0;
bool ret = false; bool ret = false;
txntable_t *txns;
workbase_t *wb; workbase_t *wb;
time_t now_t; time_t now_t;
@ -1506,7 +1507,7 @@ retry:
json_intcpy(&wb->height, val, "height"); json_intcpy(&wb->height, val, "height");
json_strdup(&wb->flags, val, "flags"); json_strdup(&wb->flags, val, "flags");
txn_array = json_object_get(val, "transactions"); txn_array = json_object_get(val, "transactions");
wb_merkle_bins(ckp, sdata, wb, txn_array, true); txns = wb_merkle_bin_txns(ckp, sdata, wb, txn_array, true);
wb->insert_witness = false; wb->insert_witness = false;
memset(wb->witnessdata, 0, sizeof(wb->witnessdata)); memset(wb->witnessdata, 0, sizeof(wb->witnessdata));
@ -1548,6 +1549,10 @@ retry:
stratum_broadcast_update(sdata, wb, new_block); stratum_broadcast_update(sdata, wb, new_block);
ret = true; ret = true;
LOGINFO("Broadcast updated stratum base"); LOGINFO("Broadcast updated stratum base");
/* Update transactions after stratum broadcast to not delay
* propagation. */
if (likely(txns))
update_txns(ckp, sdata, txns, true);
out: out:
cksem_post(&sdata->update_sem); cksem_post(&sdata->update_sem);
@ -1631,6 +1636,7 @@ static bool rebuild_txns(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb)
json_t *txn_array, *missing_txns; json_t *txn_array, *missing_txns;
char hash[68] = {}; char hash[68] = {};
bool ret = false; bool ret = false;
txntable_t *txns;
int i, len = 0; int i, len = 0;
/* We'll only see this on testnet now */ /* We'll only see this on testnet now */
@ -1706,7 +1712,9 @@ static bool rebuild_txns(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb)
/* These two structures are regenerated so free their ram */ /* These two structures are regenerated so free their ram */
json_decref(wb->merkle_array); json_decref(wb->merkle_array);
dealloc(wb->txn_hashes); dealloc(wb->txn_hashes);
wb_merkle_bins(ckp, sdata, wb, txn_array, false); txns = wb_merkle_bin_txns(ckp, sdata, wb, txn_array, false);
if (likely(txns))
update_txns(ckp, sdata, txns, true);
} else { } else {
if (!sdata->wbincomplete) { if (!sdata->wbincomplete) {
sdata->wbincomplete = true; sdata->wbincomplete = true;

Loading…
Cancel
Save