diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index b3f0fc75c..e8364af4a 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -53,7 +53,7 @@ static void next_topology_timer(struct chain_topology *topo) static bool we_broadcast(const struct chain_topology *topo, const struct bitcoin_txid *txid) { - return outgoing_tx_map_get(&topo->outgoing_txs, txid) != NULL; + return outgoing_tx_map_get(topo->outgoing_txs, txid) != NULL; } static void filter_block_txs(struct chain_topology *topo, struct block *b) @@ -75,7 +75,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b) bitcoin_tx_input_get_txid(tx, j, &out.txid); out.n = tx->wtx->inputs[j].index; - txo = txowatch_hash_get(&topo->txowatches, &out); + txo = txowatch_hash_get(topo->txowatches, &out); if (txo) { wallet_transaction_add(topo->ld->wallet, tx->wtx, b->height, i); @@ -162,8 +162,8 @@ static void rebroadcast_txs(struct chain_topology *topo) /* Put any txs we want to broadcast in ->txs. */ txs->txs = tal_arr(txs, const char *, 0); - for (otx = outgoing_tx_map_first(&topo->outgoing_txs, &it); otx; - otx = outgoing_tx_map_next(&topo->outgoing_txs, &it)) { + for (otx = outgoing_tx_map_first(topo->outgoing_txs, &it); otx; + otx = outgoing_tx_map_next(topo->outgoing_txs, &it)) { if (wallet_transaction_height(topo->ld->wallet, &otx->txid)) continue; @@ -179,7 +179,7 @@ static void rebroadcast_txs(struct chain_topology *topo) static void destroy_outgoing_tx(struct outgoing_tx *otx, struct chain_topology *topo) { - outgoing_tx_map_del(&topo->outgoing_txs, otx); + outgoing_tx_map_del(topo->outgoing_txs, otx); } static void clear_otx_channel(struct channel *channel, struct outgoing_tx *otx) @@ -215,7 +215,7 @@ static void broadcast_done(struct bitcoind *bitcoind, } else { /* For continual rebroadcasting, until channel freed. */ tal_steal(otx->channel, otx); - outgoing_tx_map_add(&bitcoind->ld->topology->outgoing_txs, notleak(otx)); + outgoing_tx_map_add(bitcoind->ld->topology->outgoing_txs, notleak(otx)); tal_add_destructor2(otx, destroy_outgoing_tx, bitcoind->ld->topology); } } @@ -731,7 +731,7 @@ static void add_tip(struct chain_topology *topo, struct block *b) /* Only keep the transactions we care about. */ filter_block_txs(topo, b); - block_map_add(&topo->block_map, b); + block_map_add(topo->block_map, b); topo->max_blockheight = b->height; } @@ -745,7 +745,7 @@ static struct block *new_block(struct chain_topology *topo, log_debug(topo->log, "Adding block %u: %s", height, type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); - assert(!block_map_get(&topo->block_map, &b->blkid)); + assert(!block_map_get(topo->block_map, &b->blkid)); b->next = NULL; b->prev = NULL; @@ -792,7 +792,7 @@ static void remove_tip(struct chain_topology *topo) /* This may have unconfirmed txs: reconfirm as we add blocks. */ watch_for_utxo_reconfirmation(topo, topo->ld->wallet); - block_map_del(&topo->block_map, b); + block_map_del(topo->block_map, b); /* These no longer exist, so gossipd drops any reference to them just * as if they were spent. */ @@ -845,7 +845,7 @@ static void init_topo(struct bitcoind *bitcoind UNUSED, struct chain_topology *topo) { topo->root = new_block(topo, blk, topo->max_blockheight); - block_map_add(&topo->block_map, topo->root); + block_map_add(topo->block_map, topo->root); topo->tip = topo->root; topo->prev_tip = topo->tip->blkid; @@ -939,17 +939,11 @@ static void destroy_chain_topology(struct chain_topology *topo) { struct outgoing_tx *otx; struct outgoing_tx_map_iter it; - for (otx = outgoing_tx_map_first(&topo->outgoing_txs, &it); otx; - otx = outgoing_tx_map_next(&topo->outgoing_txs, &it)) { + for (otx = outgoing_tx_map_first(topo->outgoing_txs, &it); otx; + otx = outgoing_tx_map_next(topo->outgoing_txs, &it)) { tal_del_destructor2(otx, destroy_outgoing_tx, topo); tal_free(otx); } - - /* htable uses malloc, so it would leak here */ - txwatch_hash_clear(&topo->txwatches); - txowatch_hash_clear(&topo->txowatches); - outgoing_tx_map_clear(&topo->outgoing_txs); - block_map_clear(&topo->block_map); } struct chain_topology *new_topology(struct lightningd *ld, struct log *log) @@ -957,10 +951,14 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log) struct chain_topology *topo = tal(ld, struct chain_topology); topo->ld = ld; - block_map_init(&topo->block_map); - outgoing_tx_map_init(&topo->outgoing_txs); - txwatch_hash_init(&topo->txwatches); - txowatch_hash_init(&topo->txowatches); + topo->block_map = tal(topo, struct block_map); + block_map_init(topo->block_map); + topo->outgoing_txs = tal(topo, struct outgoing_tx_map); + outgoing_tx_map_init(topo->outgoing_txs); + topo->txwatches = tal(topo, struct txwatch_hash); + txwatch_hash_init(topo->txwatches); + topo->txowatches = tal(topo, struct txowatch_hash); + txowatch_hash_init(topo->txowatches); topo->log = log; memset(topo->feerate, 0, sizeof(topo->feerate)); topo->bitcoind = new_bitcoind(topo, ld, log); diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index 08076e8f4..4ba6687eb 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -90,7 +90,7 @@ struct chain_topology { struct block *root; struct block *tip; struct bitcoin_blkid prev_tip; - struct block_map block_map; + struct block_map *block_map; u32 feerate[NUM_FEERATES]; bool feerate_uninitialized; u32 feehistory[NUM_FEERATES][FEE_HISTORY_NUM]; @@ -116,11 +116,11 @@ struct chain_topology { struct oneshot *extend_timer, *updatefee_timer; /* Bitcoin transactions we're broadcasting */ - struct outgoing_tx_map outgoing_txs; + struct outgoing_tx_map *outgoing_txs; /* Transactions/txos we are watching. */ - struct txwatch_hash txwatches; - struct txowatch_hash txowatches; + struct txwatch_hash *txwatches; + struct txowatch_hash *txowatches; /* The number of headers known to the bitcoin backend at startup. Not * updated after the initial check. */ diff --git a/lightningd/memdump.c b/lightningd/memdump.c index 4c3884c9e..8fb65f56c 100644 --- a/lightningd/memdump.c +++ b/lightningd/memdump.c @@ -150,8 +150,8 @@ static void finish_report(const struct leak_detect *leaks) memleak_ignore_children(memtable, cmd); /* First delete known false positives. */ - memleak_scan_htable(memtable, &ld->topology->txwatches.raw); - memleak_scan_htable(memtable, &ld->topology->txowatches.raw); + memleak_scan_htable(memtable, &ld->topology->txwatches->raw); + memleak_scan_htable(memtable, &ld->topology->txowatches->raw); memleak_scan_htable(memtable, &ld->htlcs_in.raw); memleak_scan_htable(memtable, &ld->htlcs_out.raw); memleak_scan_htable(memtable, &ld->htlc_sets.raw); diff --git a/lightningd/watch.c b/lightningd/watch.c index 05a54c651..a0e502aae 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -94,7 +94,7 @@ bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out) static void destroy_txowatch(struct txowatch *w) { - txowatch_hash_del(&w->topo->txowatches, w); + txowatch_hash_del(w->topo->txowatches, w); } const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w) @@ -115,7 +115,7 @@ bool txwatch_eq(const struct txwatch *w, const struct bitcoin_txid *txid) static void destroy_txwatch(struct txwatch *w) { - txwatch_hash_del(&w->topo->txwatches, w); + txwatch_hash_del(w->topo->txwatches, w); } struct txwatch *watch_txid(const tal_t *ctx, @@ -138,7 +138,7 @@ struct txwatch *watch_txid(const tal_t *ctx, w->channel = channel; w->cb = cb; - txwatch_hash_add(&w->topo->txwatches, w); + txwatch_hash_add(w->topo->txwatches, w); tal_add_destructor(w, destroy_txwatch); return w; @@ -153,9 +153,9 @@ struct txwatch *find_txwatch(struct chain_topology *topo, /* We could have more than one channel watching same txid, though we * don't for onchaind. */ - for (w = txwatch_hash_getfirst(&topo->txwatches, txid, &i); + for (w = txwatch_hash_getfirst(topo->txwatches, txid, &i); w; - w = txwatch_hash_getnext(&topo->txwatches, txid, &i)) { + w = txwatch_hash_getnext(topo->txwatches, txid, &i)) { if (w->channel == channel) break; } @@ -165,7 +165,7 @@ struct txwatch *find_txwatch(struct chain_topology *topo, bool watching_txid(const struct chain_topology *topo, const struct bitcoin_txid *txid) { - return txwatch_hash_get(&topo->txwatches, txid) != NULL; + return txwatch_hash_get(topo->txwatches, txid) != NULL; } struct txwatch *watch_tx(const tal_t *ctx, @@ -201,7 +201,7 @@ struct txowatch *watch_txo(const tal_t *ctx, w->channel = channel; w->cb = cb; - txowatch_hash_add(&w->topo->txowatches, w); + txowatch_hash_add(w->topo->txowatches, w); tal_add_destructor(w, destroy_txowatch); return w; @@ -247,7 +247,7 @@ void txwatch_fire(struct chain_topology *topo, { struct txwatch *txw; - txw = txwatch_hash_get(&topo->txwatches, txid); + txw = txwatch_hash_get(topo->txwatches, txid); if (txw) txw_fire(txw, txid, depth); @@ -287,9 +287,9 @@ void watch_topology_changed(struct chain_topology *topo) do { /* Iterating a htable during deletes is safe, but might skip entries. */ needs_rerun = false; - for (w = txwatch_hash_first(&topo->txwatches, &i); + for (w = txwatch_hash_first(topo->txwatches, &i); w; - w = txwatch_hash_next(&topo->txwatches, &i)) { + w = txwatch_hash_next(topo->txwatches, &i)) { u32 depth; depth = get_tx_depth(topo, &w->txid); @@ -309,7 +309,7 @@ void txwatch_inform(const struct chain_topology *topo, { struct txwatch *txw; - txw = txwatch_hash_get(&topo->txwatches, txid); + txw = txwatch_hash_get(topo->txwatches, txid); if (txw && !txw->tx) txw->tx = tal_steal(txw, tx_may_steal);