From de5d84097e1352a322bd71225b8efbaf61a6fa61 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 15 Mar 2018 15:00:39 +1030 Subject: [PATCH] lightningd: remove ltmp context now we have tmpctx. Signed-off-by: Rusty Russell --- lightningd/chaintopology.c | 6 +++--- lightningd/lightningd.c | 4 ++-- lightningd/log.c | 11 ----------- lightningd/log.h | 4 ---- lightningd/netaddress.c | 4 ++-- lightningd/onchain_control.c | 2 +- lightningd/opening_control.c | 4 ++-- lightningd/pay.c | 4 ++-- lightningd/watch.c | 6 +++--- wallet/test/run-wallet.c | 1 - wallet/wallet.c | 2 +- 11 files changed, 16 insertions(+), 32 deletions(-) diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 385675142..be3e4d64e 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -254,7 +254,7 @@ void broadcast_tx(struct chain_topology *topo, tal_add_destructor2(channel, clear_otx_channel, otx); log_add(topo->log, " (tx %s)", - type_to_string(ltmp, struct bitcoin_txid, &otx->txid)); + type_to_string(tmpctx, struct bitcoin_txid, &otx->txid)); bitcoind_sendrawtx(topo->bitcoind, otx->hextx, broadcast_done, otx); } @@ -407,7 +407,7 @@ static struct block *new_block(struct chain_topology *topo, sha256_double(&b->blkid.shad, &blk->hdr, sizeof(blk->hdr)); log_debug(topo->log, "Adding block %u: %s", height, - type_to_string(ltmp, struct bitcoin_blkid, &b->blkid)); + type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); assert(!block_map_get(&topo->block_map, &b->blkid)); b->next = NULL; b->prev = NULL; @@ -433,7 +433,7 @@ static void remove_tip(struct chain_topology *topo) if (!topo->tip) fatal("Initial block %u (%s) reorganized out!", b->height, - type_to_string(ltmp, struct bitcoin_blkid, &b->blkid)); + type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid)); /* Notify that txs are kicked out. */ for (i = 0; i < n; i++) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 6e9a1854a..a84d2fa80 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -390,8 +390,8 @@ int main(int argc, char *argv[]) /* Mark ourselves live. */ log_info(ld->log, "Server started with public key %s, alias %s (color #%s) and lightningd %s", - type_to_string(ltmp, struct pubkey, &ld->id), - ld->alias, tal_hex(ltmp, ld->rgb), version()); + type_to_string(tmpctx, struct pubkey, &ld->id), + ld->alias, tal_hex(tmpctx, ld->rgb), version()); /* Start the peers. */ activate_peers(ld); diff --git a/lightningd/log.c b/lightningd/log.c index e259dbc7c..75aeb4d1e 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -137,10 +137,6 @@ struct log_book *new_log_book(size_t max_mem, lr->init_time = time_now(); list_head_init(&lr->log); - /* In case ltmp not initialized, do so now (parent is lightningd log) */ - if (!ltmp) - ltmp = notleak(tal(lr, char)); - return lr; } @@ -225,13 +221,6 @@ static void add_entry(struct log *log, struct log_entry *l) log_debug(log, "Log pruned %zu entries (mem %zu -> %zu)", deleted, old_mem, log->lr->mem_used); } - - /* Free up temporaries now if any */ - if (tal_first(ltmp)) { - void *parent = tal_parent(ltmp); - tal_free(ltmp); - ltmp = notleak(tal(parent, char)); - } } static struct log_entry *new_log_entry(struct log *log, enum log_level level) diff --git a/lightningd/log.h b/lightningd/log.h index d7b8035be..c7395b07e 100644 --- a/lightningd/log.h +++ b/lightningd/log.h @@ -93,10 +93,6 @@ void crashlog_activate(const char *argv0, struct log *log); char *arg_log_to_file(const char *arg, struct lightningd *ld); -/* Convenience parent for temporary allocations (eg. type_to_string) - * during log calls; freed after every log_*() */ -const tal_t *ltmp; - /* Before the crashlog is activated, just prints to stderr. */ void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...); diff --git a/lightningd/netaddress.c b/lightningd/netaddress.c index 58845d1bd..4231a6977 100644 --- a/lightningd/netaddress.c +++ b/lightningd/netaddress.c @@ -272,12 +272,12 @@ static bool guess_one_address(struct lightningd *ld, if (!IsRoutable(addr)) { log_debug(ld->log, "Address %s is not routable", - type_to_string(ltmp, struct wireaddr, addr)); + type_to_string(tmpctx, struct wireaddr, addr)); return false; } log_debug(ld->log, "Public address %s", - type_to_string(ltmp, struct wireaddr, addr)); + type_to_string(tmpctx, struct wireaddr, addr)); return true; } diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 30926a316..de176e0cf 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -148,7 +148,7 @@ static void handle_onchain_unwatch_tx(struct channel *channel, const u8 *msg) txw = find_txwatch(channel->peer->ld->topology, &txid, channel); if (!txw) log_unusual(channel->log, "Can't unwatch txid %s", - type_to_string(ltmp, struct bitcoin_txid, &txid)); + type_to_string(tmpctx, struct bitcoin_txid, &txid)); tal_free(txw); } diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 79c8af92d..19d202bfb 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -275,7 +275,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, goto failed; } log_debug(ld->log, - "%s", type_to_string(ltmp, struct pubkey, + "%s", type_to_string(tmpctx, struct pubkey, &channel_info.remote_per_commit)); /* Generate the funding tx. */ @@ -301,7 +301,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, log_debug(fc->uc->log, "%zi: %"PRIu64" satoshi (%s) %s\n", i, fc->utxomap[i]->amount, fc->utxomap[i]->is_p2sh ? "P2SH" : "SEGWIT", - type_to_string(ltmp, struct bitcoin_txid, + type_to_string(tmpctx, struct bitcoin_txid, &fundingtx->input[i].txid)); } diff --git a/lightningd/pay.c b/lightningd/pay.c index e32bd0573..20e137b1f 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -434,7 +434,7 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, log_unusual(hout->key.channel->log, "No route_channels for htlc %s:" " was this an old database?", - type_to_string(ltmp, struct sha256, + type_to_string(tmpctx, struct sha256, &hout->payment_hash)); wallet_payment_set_status(ld->wallet, &hout->payment_hash, PAYMENT_FAILED, NULL); @@ -463,7 +463,7 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, log_info(hout->key.channel->log, "htlc %"PRIu64" failed with bad reply (%s)", hout->key.id, - tal_hex(ltmp, hout->failuremsg)); + tal_hex(tmpctx, hout->failuremsg)); /* Cannot report failure. */ fail = NULL; failcode = WIRE_PERMANENT_NODE_FAILURE; diff --git a/lightningd/watch.c b/lightningd/watch.c index e83772f78..73a2dc164 100644 --- a/lightningd/watch.c +++ b/lightningd/watch.c @@ -216,7 +216,7 @@ static bool txw_fire(struct txwatch *txw, log_debug(txw->channel->log, "Got depth change %u->%u for %s", txw->depth, depth, - type_to_string(ltmp, struct bitcoin_txid, &txw->txid)); + type_to_string(tmpctx, struct bitcoin_txid, &txw->txid)); txw->depth = depth; r = txw->cb(txw->channel, tx, txw->depth); switch (r) { @@ -254,9 +254,9 @@ void txowatch_fire(const struct txowatch *txow, bitcoin_txid(tx, &txid); log_debug(txow->channel->log, "Got UTXO spend for %s:%u: %s", - type_to_string(ltmp, struct bitcoin_txid, &txow->out.txid), + type_to_string(tmpctx, struct bitcoin_txid, &txow->out.txid), txow->out.index, - type_to_string(ltmp, struct bitcoin_txid, &txid)); + type_to_string(tmpctx, struct bitcoin_txid, &txid)); r = txow->cb(txow->channel, tx, input_num, block); switch (r) { diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index c02c30bfc..476ca5224 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -469,7 +469,6 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx w->db = db_open(w, filename); - ltmp = tal_tmpctx(ctx); list_head_init(&w->unstored_payments); w->ld = ld; ld->wallet = w; diff --git a/wallet/wallet.c b/wallet/wallet.c index ccd2ca763..fc09c6bbf 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1073,7 +1073,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx, log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s", output, tx->output[output].amount, is_p2sh ? "P2SH" : "SEGWIT", - type_to_string(ltmp, struct bitcoin_txid, + type_to_string(tmpctx, struct bitcoin_txid, &utxo->txid)); if (!wallet_add_utxo(w, utxo, is_p2sh ? p2sh_wpkh : our_change)) {