diff --git a/src/stratifier.c b/src/stratifier.c index 74bdd869..997a8487 100644 --- a/src/stratifier.c +++ b/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 * stratum messages and fast work assembly. */ -static void wb_merkle_bins(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, json_t *txn_array, - bool local) +static txntable_t *wb_merkle_bin_txns(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb, + json_t *txn_array, bool local) { int i, j, binleft, binlen; 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")); if (!txn) { LOGWARNING("json_string_value fail - cannot find transaction data"); - return; + goto out; } 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; if (unlikely(!txid)) { LOGERR("Missing txid for transaction in wb_merkle_bins"); - return; + goto out; } txn = json_string_value(json_object_get(arr_val, "data")); 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; if (!hex2bin(binswap, txid, 32)) { LOGERR("Failed to hex2bin hash in gbt_merkle_bins"); - return; + goto out; } memcpy(wb->txn_hashes + i * 65, txid, 64); 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", wb->txns); - - update_txns(ckp, sdata, txns, true); +out: + return txns; } 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; int i, retries = 0; bool ret = false; + txntable_t *txns; workbase_t *wb; time_t now_t; @@ -1506,7 +1507,7 @@ retry: json_intcpy(&wb->height, val, "height"); json_strdup(&wb->flags, val, "flags"); 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; memset(wb->witnessdata, 0, sizeof(wb->witnessdata)); @@ -1548,6 +1549,10 @@ retry: stratum_broadcast_update(sdata, wb, new_block); ret = true; LOGINFO("Broadcast updated stratum base"); + /* Update transactions after stratum broadcast to not delay + * propagation. */ + if (likely(txns)) + update_txns(ckp, sdata, txns, true); out: 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; char hash[68] = {}; bool ret = false; + txntable_t *txns; int i, len = 0; /* 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 */ json_decref(wb->merkle_array); 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 { if (!sdata->wbincomplete) { sdata->wbincomplete = true;