From a772d388f446c2a6a33090e686be365601c73a0a Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 8 Feb 2017 14:45:58 +1100 Subject: [PATCH 1/2] Unset wbincomplete sooner to minimise duplicate passes through check_incomplete_wbs --- src/stratifier.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 2b35af76..b0515481 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1695,6 +1695,7 @@ static bool rebuild_txns(ckpool_t *ckp, sdata_t *sdata, workbase_t *wb) } if (ret) { + wb->incomplete = false; LOGINFO("Rebuilt txns into workbase with %d transactions", i); /* These two structures are regenerated so free their ram */ json_decref(wb->merkle_array); @@ -1739,10 +1740,9 @@ static void check_incomplete_wbs(ckpool_t *ckp, sdata_t *sdata) HASH_DEL(sdata->remote_workbases, wb); ck_wunlock(&sdata->workbase_lock); - if (rebuild_txns(ckp, sdata, wb)) { + if (rebuild_txns(ckp, sdata, wb)) LOGNOTICE("Rebuilt transactions on previously failed remote workinfo"); - wb->incomplete = false; - } else + else incomplete++; /* Readd it to the hashlist */ From 482a8c7d67cbb319323b8182f7eff005c36b4344 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Wed, 8 Feb 2017 16:03:41 +1100 Subject: [PATCH 2/2] Check for existing transactions from the local bitcoind when adding them to our hashlist and submit them only if they're not known about. --- src/stratifier.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index b0515481..467e03c7 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1135,6 +1135,19 @@ static void broadcast_ping(sdata_t *sdata); #define REFCOUNT_REMOTE 100 #define REFCOUNT_LOCAL 5 +/* Submit the transactions in node/remote mode so the local btcd has all the + * transactions that will go into the next blocksolve. */ +static void submit_transaction(ckpool_t *ckp, const char *hash) +{ + char *buf; + + if (unlikely(!ckp->generator_ready)) + return; + ASPRINTF(&buf, "submittxn:%s", hash); + send_proc(ckp->generator,buf); + free(buf); +} + /* Build a hashlist of all transactions, allowing us to compare with the list of * existing transactions to determine which need to be propagated */ static bool add_txn(ckpool_t *ckp, sdata_t *sdata, txntable_t **txns, const char *hash, @@ -1161,7 +1174,15 @@ static bool add_txn(ckpool_t *ckp, sdata_t *sdata, txntable_t **txns, const char txn = ckzalloc(sizeof(txntable_t)); memcpy(txn->hash, hash, 65); - txn->data = strdup(data); + /* Get the data from our local bitcoind as a way of confirming it + * already knows about this transaction. */ + txn->data = generator_get_txn(ckp, hash); + if (!txn->data) { + /* If our local bitcoind hasn't seen this transaction, + * submit it for mempools to be ~synchronised */ + submit_transaction(ckp, data); + txn->data = strdup(data); + } if (!local || ckp->node) txn->refcount = REFCOUNT_REMOTE; else @@ -1214,19 +1235,6 @@ static void send_node_transactions(ckpool_t *ckp, sdata_t *sdata, const json_t * } } -/* Submit the transactions in node/remote mode so the local btcd has all the - * transactions that will go into the next blocksolve. */ -static void submit_transaction(ckpool_t *ckp, const char *hash) -{ - char *buf; - - if (unlikely(!ckp->generator_ready)) - return; - ASPRINTF(&buf, "submittxn:%s", hash); - send_proc(ckp->generator,buf); - free(buf); -} - static void submit_transaction_array(ckpool_t *ckp, const json_t *arr) { json_t *arr_val; @@ -7146,12 +7154,8 @@ static void add_node_txns(ckpool_t *ckp, sdata_t *sdata, const json_t *val) continue; } - if (!add_txn(ckp, sdata, &txns, hash, data, false)) - continue; - - /* Submit transactions if we haven't seen them before */ - submit_transaction(ckp, data); - added++; + if (add_txn(ckp, sdata, &txns, hash, data, false)) + added++; } if (added)