Browse Source

Hold lock only as necessary in add_node_txns, preventing one recursive lock in submit_transaction.

master
Con Kolivas 8 years ago
parent
commit
e307bd584a
  1. 11
      src/stratifier.c

11
src/stratifier.c

@ -6823,7 +6823,6 @@ static void add_node_txns(ckpool_t *ckp, sdata_t *sdata, const json_t *val)
txn_array = json_object_get(val, "transaction"); txn_array = json_object_get(val, "transaction");
arr_size = json_array_size(txn_array); arr_size = json_array_size(txn_array);
ck_wlock(&sdata->workbase_lock);
for (i = 0; i < arr_size; i++) { for (i = 0; i < arr_size; i++) {
const char *hash, *data; const char *hash, *data;
@ -6836,11 +6835,16 @@ static void add_node_txns(ckpool_t *ckp, sdata_t *sdata, const json_t *val)
LOGERR("Failed to get hash/data in add_node_txns"); LOGERR("Failed to get hash/data in add_node_txns");
continue; continue;
} }
ck_rlock(&sdata->workbase_lock);
HASH_FIND_STR(sdata->txns, hash, txn); HASH_FIND_STR(sdata->txns, hash, txn);
if (txn) { if (txn) {
txn->refcount = 100; txn->refcount = 100;
ck_runlock(&sdata->workbase_lock);
continue; continue;
} }
ck_runlock(&sdata->workbase_lock);
submit_transaction(ckp, data); submit_transaction(ckp, data);
txn = ckzalloc(sizeof(txntable_t)); txn = ckzalloc(sizeof(txntable_t));
memcpy(txn->hash, hash, 65); memcpy(txn->hash, hash, 65);
@ -6849,10 +6853,13 @@ static void add_node_txns(ckpool_t *ckp, sdata_t *sdata, const json_t *val)
* upstream pool to ensure we never age them faster than the * upstream pool to ensure we never age them faster than the
* pool does. */ * pool does. */
txn->refcount = 100; txn->refcount = 100;
ck_wlock(&sdata->workbase_lock);
HASH_ADD_STR(sdata->txns, hash, txn); HASH_ADD_STR(sdata->txns, hash, txn);
ck_wunlock(&sdata->workbase_lock);
added++; added++;
} }
ck_wunlock(&sdata->workbase_lock);
if (added) if (added)
LOGINFO("Stratifier added %d remote transactions", added); LOGINFO("Stratifier added %d remote transactions", added);

Loading…
Cancel
Save