Browse Source

utils: remove tal_tmpctx altogether, use global.

In particular, we now only free tmpctx at the end of main().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
0a6e3d1e13
  1. 38
      channeld/channel.c
  2. 2
      channeld/commit_tx.c
  3. 39
      channeld/full_channel.c
  4. 18
      channeld/test/run-full_channel.c
  5. 11
      common/bolt11.c
  6. 2
      common/initial_commit_tx.c
  7. 11
      common/sphinx.c
  8. 12
      common/test/run-bolt11.c
  9. 35
      common/test/run-ip_port_parsing.c
  10. 7
      common/test/run-sphinx.c
  11. 2
      common/timeout.c
  12. 3
      common/utils.h
  13. 4
      common/wireaddr.c
  14. 13
      gossipd/gossip.c
  15. 36
      gossipd/routing.c
  16. 2
      gossipd/routing.h
  17. 10
      gossipd/test/run-bench-find_route.c
  18. 10
      gossipd/test/run-find_route-specific.c
  19. 26
      gossipd/test/run-find_route.c
  20. 10
      gossipd/test/run-initiator-success.c
  21. 11
      gossipd/test/run-responder-success.c
  22. 12
      hsmd/hsm.c
  23. 3
      lightningd/channel_control.c
  24. 4
      lightningd/closing_control.c
  25. 2
      lightningd/gossip_control.c
  26. 3
      lightningd/hsm_control.c
  27. 2
      lightningd/jsonrpc.c
  28. 15
      lightningd/lightningd.c
  29. 5
      lightningd/onchain_control.c
  30. 2
      lightningd/opening_control.c
  31. 22
      lightningd/pay.c
  32. 4
      lightningd/payalgo.c
  33. 3
      lightningd/peer_control.c
  34. 7
      lightningd/peer_htlcs.c
  35. 9
      lightningd/subd.c
  36. 15
      lightningd/test/run-commit_tx.c
  37. 10
      lightningd/test/run-cryptomsg.c
  38. 6
      lightningd/test/run-find_my_path.c
  39. 5
      lightningd/test/run-funding_tx.c
  40. 16
      onchaind/onchain.c
  41. 13
      wallet/invoices.c
  42. 6
      wallet/test/run-wallet.c
  43. 3
      wallet/txfilter.c
  44. 19
      wallet/wallet.c
  45. 2
      wire/towire.c

38
channeld/channel.c

@ -174,7 +174,6 @@ static void start_commit_timer(struct peer *peer);
static void billboard_update(const struct peer *peer)
{
const tal_t *tmpctx = tal_tmpctx(peer);
const char *funding_status, *announce_status, *shutdown_status;
if (peer->funding_locked[LOCAL] && peer->funding_locked[REMOTE])
@ -338,7 +337,6 @@ static void gossip_in(struct peer *peer, const u8 *msg)
* our own outgoing payments */
static void send_temporary_announcement(struct peer *peer)
{
tal_t *tmpctx;
u8 *msg;
/* If we are supposed to send a real announcement, don't do a
@ -347,23 +345,18 @@ static void send_temporary_announcement(struct peer *peer)
!peer->funding_locked[REMOTE])
return;
tmpctx = tal_tmpctx(peer);
msg = towire_gossip_local_add_channel(
tmpctx, &peer->short_channel_ids[LOCAL], &peer->chain_hash,
&peer->node_ids[REMOTE], peer->cltv_delta,
peer->conf[REMOTE].htlc_minimum_msat, peer->fee_base,
peer->fee_per_satoshi);
wire_sync_write(GOSSIP_FD, take(msg));
tal_free(tmpctx);
}
static void send_announcement_signatures(struct peer *peer)
{
/* First 2 + 256 byte are the signatures and msg type, skip them */
size_t offset = 258;
const tal_t *tmpctx;
struct sha256_double hash;
u8 *msg, *ca, *req;
@ -378,7 +371,6 @@ static void send_announcement_signatures(struct peer *peer)
!peer->funding_locked[REMOTE])
return;
tmpctx = tal_tmpctx(peer);
status_trace("Exchanging announcement signatures.");
ca = create_channel_announcement(tmpctx, peer);
req = towire_hsm_cannouncement_sig_req(
@ -421,13 +413,11 @@ static void send_announcement_signatures(struct peer *peer)
&peer->announcement_node_sigs[LOCAL],
&peer->announcement_bitcoin_sigs[LOCAL]);
enqueue_peer_msg(peer, take(msg));
tal_free(tmpctx);
}
static u8 *create_channel_update(const tal_t *ctx,
struct peer *peer, bool disabled)
{
tal_t *tmpctx = tal_tmpctx(ctx);
u32 timestamp = time_now().ts.tv_sec;
u16 flags;
u8 *cupdate, *msg;
@ -460,7 +450,6 @@ static u8 *create_channel_update(const tal_t *ctx,
status_failed(STATUS_FAIL_HSM_IO,
"Reading cupdate_sig_req: %s",
strerror(errno));
tal_free(tmpctx);
return cupdate;
}
@ -557,7 +546,6 @@ static void check_short_ids_match(struct peer *peer)
static void announce_channel(struct peer *peer)
{
tal_t *tmpctx = tal_tmpctx(peer);
u8 *cannounce, *cupdate;
check_short_ids_match(peer);
@ -567,8 +555,6 @@ static void announce_channel(struct peer *peer)
wire_sync_write(GOSSIP_FD, cannounce);
wire_sync_write(GOSSIP_FD, cupdate);
tal_free(tmpctx);
}
static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg)
@ -606,7 +592,6 @@ static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg
static bool get_shared_secret(const struct htlc *htlc,
struct secret *shared_secret)
{
tal_t *tmpctx = tal_tmpctx(htlc);
struct pubkey ephemeral;
struct onionpacket *op;
u8 *msg;
@ -616,7 +601,6 @@ static bool get_shared_secret(const struct htlc *htlc,
if (!op) {
/* Return an invalid shared secret. */
memset(shared_secret, 0, sizeof(*shared_secret));
tal_free(tmpctx);
return false;
}
@ -629,7 +613,6 @@ static bool get_shared_secret(const struct htlc *htlc,
/* Gives all-zero shares_secret if it was invalid. */
if (!msg || !fromwire_hsm_ecdh_resp(msg, shared_secret))
status_failed(STATUS_FAIL_HSM_IO, "Reading ecdh response");
tal_free(tmpctx);
return !memeqzero(shared_secret, sizeof(*shared_secret));
}
@ -745,7 +728,6 @@ static u8 *sending_commitsig_msg(const tal_t *ctx,
const secp256k1_ecdsa_signature *commit_sig,
const secp256k1_ecdsa_signature *htlc_sigs)
{
const tal_t *tmpctx = tal_tmpctx(ctx);
struct changed_htlc *changed;
u8 *msg;
@ -755,7 +737,6 @@ static u8 *sending_commitsig_msg(const tal_t *ctx,
msg = towire_channel_sending_commitsig(ctx, remote_commit_index,
remote_feerate,
changed, commit_sig, htlc_sigs);
tal_free(tmpctx);
return msg;
}
@ -852,7 +833,6 @@ static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
const struct peer *peer,
u64 commit_index)
{
const tal_t *tmpctx = tal_tmpctx(ctx);
size_t i;
struct bitcoin_tx **txs;
const u8 **wscripts;
@ -929,13 +909,11 @@ static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
&commit_sigs->htlc_sigs[i]));
}
tal_free(tmpctx);
return commit_sigs;
}
static void send_commit(struct peer *peer)
{
tal_t *tmpctx = tal_tmpctx(peer);
u8 *msg;
const struct htlc **changed_htlcs;
@ -943,7 +921,6 @@ static void send_commit(struct peer *peer)
/* Hack to suppress all commit sends if dev_disconnect says to */
if (dev_suppress_commit) {
peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}
#endif
@ -963,7 +940,6 @@ static void send_commit(struct peer *peer)
/* Mark this as done and try again. */
peer->commit_timer = NULL;
start_commit_timer(peer);
tal_free(tmpctx);
return;
}
@ -976,7 +952,6 @@ static void send_commit(struct peer *peer)
status_trace("Can't send commit: final shutdown phase");
peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}
@ -1016,7 +991,6 @@ static void send_commit(struct peer *peer)
maybe_send_shutdown(peer);
peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}
@ -1050,7 +1024,6 @@ static void send_commit(struct peer *peer)
/* Timer now considered expired, you can add a new one. */
peer->commit_timer = NULL;
start_commit_timer(peer);
tal_free(tmpctx);
}
static void start_commit_timer(struct peer *peer)
@ -1124,7 +1097,6 @@ static u8 *got_commitsig_msg(const tal_t *ctx,
const struct htlc **changed_htlcs,
const struct bitcoin_tx *committx)
{
const tal_t *tmpctx = tal_tmpctx(ctx);
struct changed_htlc *changed;
struct fulfilled_htlc *fulfilled;
const struct failed_htlc **failed;
@ -1187,13 +1159,11 @@ static u8 *got_commitsig_msg(const tal_t *ctx,
failed,
changed,
committx);
tal_free(tmpctx);
return msg;
}
static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
{
const tal_t *tmpctx = tal_tmpctx(peer);
struct channel_id channel_id;
secp256k1_ecdsa_signature commit_sig, *htlc_sigs;
struct pubkey remote_htlckey, point;
@ -1312,7 +1282,6 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
master_wait_sync_reply(tmpctx, peer, take(msg),
WIRE_CHANNEL_GOT_COMMITSIG_REPLY);
tal_free(tmpctx);
return send_revocation(peer);
}
@ -1321,7 +1290,6 @@ static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
const struct pubkey *next_per_commit_point,
const struct htlc **changed_htlcs)
{
tal_t *tmpctx = tal_tmpctx(ctx);
u8 *msg;
struct changed_htlc *changed = tal_arr(tmpctx, struct changed_htlc, 0);
@ -1339,7 +1307,6 @@ static u8 *got_revoke_msg(const tal_t *ctx, u64 revoke_num,
msg = towire_channel_got_revoke(ctx, revoke_num, per_commitment_secret,
next_per_commit_point, changed);
tal_free(tmpctx);
return msg;
}
@ -1349,7 +1316,6 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
struct privkey privkey;
struct channel_id channel_id;
struct pubkey per_commit_point, next_per_commit;
tal_t *tmpctx = tal_tmpctx(msg);
const struct htlc **changed_htlcs = tal_arr(msg, const struct htlc *, 0);
if (!fromwire_revoke_and_ack(msg, &channel_id, &old_commit_secret,
@ -1416,8 +1382,6 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
&peer->old_remote_per_commit));
start_commit_timer(peer);
tal_free(tmpctx);
}
static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
@ -2201,7 +2165,6 @@ static u8 *foreign_channel_update(const tal_t *ctx,
struct peer *peer,
const struct short_channel_id *scid)
{
tal_t *tmpctx = tal_tmpctx(ctx);
u8 *msg, *update;
msg = towire_gossip_get_update(tmpctx, scid);
@ -2210,7 +2173,6 @@ static u8 *foreign_channel_update(const tal_t *ctx,
if (!fromwire_gossip_get_update_reply(ctx, msg, &update))
status_failed(STATUS_FAIL_GOSSIP_IO,
"Invalid update reply");
tal_free(tmpctx);
return update;
}

2
channeld/commit_tx.c

@ -101,7 +101,6 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
u64 obscured_commitment_number,
enum side side)
{
const tal_t *tmpctx = tal_tmpctx(ctx);
u64 base_fee_msat;
struct bitcoin_tx *tx;
size_t i, n, untrimmed;
@ -287,6 +286,5 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* Input amount needed for signature code. */
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
tal_free(tmpctx);
return tx;
}

39
channeld/full_channel.c

@ -293,12 +293,10 @@ static enum channel_add_err add_htlc(struct channel *channel,
struct htlc **htlcp,
bool enforce_aggregate_limits)
{
const tal_t *tmpctx = tal_tmpctx(channel);
struct htlc *htlc, *old;
s64 msat_in_htlcs, fee_msat, balance_msat;
enum side sender = htlc_state_owner(state), recipient = !sender;
const struct htlc **committed, **adding, **removing;
enum channel_add_err e;
const struct channel_view *view;
size_t i;
@ -317,8 +315,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
* `cltv_expiry` to greater or equal to 500000000.
*/
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) {
e = CHANNEL_ERR_INVALID_EXPIRY;
goto out;
return CHANNEL_ERR_INVALID_EXPIRY;
}
htlc->rhash = *payment_hash;
@ -333,10 +330,9 @@ static enum channel_add_err add_htlc(struct channel *channel,
|| old->msatoshi != htlc->msatoshi
|| old->expiry.locktime != htlc->expiry.locktime
|| !structeq(&old->rhash, &htlc->rhash))
e = CHANNEL_ERR_DUPLICATE_ID_DIFFERENT;
return CHANNEL_ERR_DUPLICATE_ID_DIFFERENT;
else
e = CHANNEL_ERR_DUPLICATE;
goto out;
return CHANNEL_ERR_DUPLICATE;
}
/* We're always considering the recipient's view of the channel here */
@ -349,12 +345,10 @@ static enum channel_add_err add_htlc(struct channel *channel,
* or...
*/
if (htlc->msatoshi == 0) {
e = CHANNEL_ERR_HTLC_BELOW_MINIMUM;
goto out;
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
}
if (htlc->msatoshi < htlc_minimum_msat(channel, recipient)) {
e = CHANNEL_ERR_HTLC_BELOW_MINIMUM;
goto out;
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
}
/* BOLT #2:
@ -364,8 +358,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
* `amount_msat` to zero.
*/
if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) {
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
goto out;
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
}
/* Figure out what receiver will already be committed to. */
@ -380,8 +373,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
if (enforce_aggregate_limits
&& tal_count(committed) - tal_count(removing) + tal_count(adding)
> max_accepted_htlcs(channel, recipient)) {
e = CHANNEL_ERR_TOO_MANY_HTLCS;
goto out;
return CHANNEL_ERR_TOO_MANY_HTLCS;
}
msat_in_htlcs = total_offered_msatoshis(committed, htlc_owner(htlc))
@ -395,8 +387,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
* HTLCs to its local commitment transaction */
if (enforce_aggregate_limits
&& msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
goto out;
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
}
/* BOLT #2:
@ -446,13 +437,11 @@ static enum channel_add_err add_htlc(struct channel *channel,
", reserve is %"PRIu64,
balance_msat, fee_msat,
channel_reserve_msat(channel, sender));
e = CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
goto out;
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
}
dump_htlc(htlc, "NEW:");
htlc_map_add(channel->htlcs, tal_steal(channel, htlc));
e = CHANNEL_ERR_ADD_OK;
if (htlcp)
*htlcp = htlc;
@ -463,9 +452,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
if (htlc_state_flags(htlc->state) & HTLC_REMOTE_F_PENDING)
channel->changes_pending[REMOTE] = true;
out:
tal_free(tmpctx);
return e;
return CHANNEL_ERR_ADD_OK;
}
enum channel_add_err channel_add_htlc(struct channel *channel,
@ -694,14 +681,12 @@ u32 approx_max_feerate(const struct channel *channel)
size_t num;
u64 weight;
const struct htlc **committed, **adding, **removing;
const tal_t *tmpctx = tal_tmpctx(channel);
gather_htlcs(tmpctx, channel, !channel->funder,
&committed, &removing, &adding);
/* Assume none are trimmed; this gives lower bound on feerate. */
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
tal_free(tmpctx);
weight = 724 + 172 * num;
@ -714,8 +699,6 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw
u64 fee_msat, dust = dust_limit_satoshis(channel, !channel->funder);
size_t untrimmed;
const struct htlc **committed, **adding, **removing;
const tal_t *tmpctx = tal_tmpctx(channel);
gather_htlcs(tmpctx, channel, !channel->funder,
&committed, &removing, &adding);
@ -728,8 +711,6 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw
fee_msat = commit_tx_base_fee(feerate_per_kw, untrimmed);
tal_free(tmpctx);
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the sender cannot afford

18
channeld/test/run-full_channel.c

@ -24,8 +24,6 @@ void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
va_end(ap);
}
const void *trc;
/* bitcoind loves its backwards txids! */
static struct bitcoin_txid txid_from_hex(const char *hex)
{
@ -183,7 +181,6 @@ static struct pubkey pubkey_from_hex(const char *hex)
static void tx_must_be_eq(const struct bitcoin_tx *a,
const struct bitcoin_tx *b)
{
tal_t *tmpctx = tal_tmpctx(NULL);
u8 *lina, *linb;
size_t i;
@ -211,7 +208,6 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
"%s",
tal_hex(tmpctx, lina),
tal_hex(tmpctx, linb));
tal_free(tmpctx);
}
static void txs_must_be_eq(struct bitcoin_tx **a, struct bitcoin_tx **b)
@ -321,21 +317,19 @@ static void update_feerate(struct channel *channel, u32 feerate)
int main(void)
{
tal_t *tmpctx = tal_tmpctx(NULL);
struct bitcoin_txid funding_txid;
/* We test from both sides. */
struct channel *lchannel, *rchannel;
u64 funding_amount_satoshi;
u32 *feerate_per_kw = tal_arr(tmpctx, u32, NUM_SIDES);
u32 *feerate_per_kw;
unsigned int funding_output_index;
struct keyset keyset;
struct pubkey local_funding_pubkey, remote_funding_pubkey;
struct pubkey local_per_commitment_point;
struct basepoints localbase, remotebase;
struct pubkey *unknown = tal(tmpctx, struct pubkey);
struct pubkey *unknown;
struct bitcoin_tx *raw_tx, **txs, **txs2;
struct channel_config *local_config = tal(tmpctx, struct channel_config);
struct channel_config *remote_config = tal(tmpctx, struct channel_config);
struct channel_config *local_config, *remote_config;
u64 to_local_msat, to_remote_msat;
const struct htlc **htlc_map, **htlcs;
const u8 *funding_wscript, **wscripts;
@ -343,8 +337,12 @@ int main(void)
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
trc = tmpctx;
feerate_per_kw = tal_arr(tmpctx, u32, NUM_SIDES);
unknown = tal(tmpctx, struct pubkey);
local_config = tal(tmpctx, struct channel_config);
remote_config = tal(tmpctx, struct channel_config);
/* BOLT #3:
*

11
common/bolt11.c

@ -410,7 +410,6 @@ static char *decode_r(struct bolt11 *b11,
u5 **data, size_t *data_len,
size_t data_length)
{
tal_t *tmpctx = tal_tmpctx(b11);
size_t rlen = data_length * 5 / 8;
u8 *r8 = tal_arr(tmpctx, u8, rlen);
size_t n = 0;
@ -423,7 +422,6 @@ static char *decode_r(struct bolt11 *b11,
do {
tal_resize(&r, n+1);
if (!fromwire_route_info(&cursor, &rlen, &r[n])) {
tal_free(tmpctx);
return tal_fmt(b11, "r: hop %zu truncated", n);
}
n++;
@ -434,7 +432,6 @@ static char *decode_r(struct bolt11 *b11,
tal_resize(&b11->routes, n+1);
b11->routes[n] = tal_steal(b11, r);
tal_free(tmpctx);
return NULL;
}
@ -464,7 +461,6 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
u5 *data;
size_t data_len;
struct bolt11 *b11 = new_bolt11(ctx, NULL);
tal_t *tmpctx = tal_tmpctx(b11);
u8 sig_and_recid[65];
secp256k1_ecdsa_recoverable_signature sig;
struct hash_u5 hu5;
@ -701,7 +697,6 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
return decode_fail(b11, fail, "invalid signature");
}
tal_free(tmpctx);
return b11;
}
@ -893,7 +888,6 @@ char *bolt11_encode_(const tal_t *ctx,
void *arg),
void *arg)
{
tal_t *tmpctx = tal_tmpctx(ctx);
u5 *data = tal_arr(tmpctx, u5, 0);
char *hrp, *output;
char postfix;
@ -971,12 +965,12 @@ char *bolt11_encode_(const tal_t *ctx,
/* FIXME: towire_ should check this? */
if (tal_len(data) > 65535)
return tal_free(tmpctx);
return NULL;
/* Need exact length here */
hrpu8 = tal_dup_arr(tmpctx, u8, (const u8 *)hrp, strlen(hrp), 0);
if (!sign(data, hrpu8, &rsig, arg))
return tal_free(tmpctx);
return NULL;
secp256k1_ecdsa_recoverable_signature_serialize_compact(
secp256k1_ctx,
@ -991,7 +985,6 @@ char *bolt11_encode_(const tal_t *ctx,
if (!bech32_encode(output, hrp, data, tal_count(data), (size_t)-1))
output = tal_free(output);
tal_free(tmpctx);
return output;
}

2
common/initial_commit_tx.c

@ -68,7 +68,6 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
u64 obscured_commitment_number,
enum side side)
{
const tal_t *tmpctx = tal_tmpctx(ctx);
u64 base_fee_msat;
struct bitcoin_tx *tx;
size_t n, untrimmed;
@ -195,6 +194,5 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
/* Input amount needed for signature code. */
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
tal_free(tmpctx);
return tx;
}

11
common/sphinx.c

@ -530,7 +530,6 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
const struct secret *shared_secrets,
const int numhops, const u8 *reply)
{
tal_t *tmpctx = tal_tmpctx(ctx);
struct onionreply *oreply = tal(tmpctx, struct onionreply);
u8 *msg = tal_arr(oreply, u8, tal_len(reply));
u8 key[KEY_LEN], hmac[HMAC_SIZE];
@ -539,7 +538,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
u16 msglen;
if (tal_len(reply) != ONION_REPLY_SIZE + sizeof(hmac) + 4) {
goto fail;
return NULL;
}
memcpy(msg, reply, tal_len(reply));
@ -561,7 +560,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
}
}
if (oreply->origin_index == -1) {
goto fail;
return NULL;
}
cursor = msg + sizeof(hmac);
@ -569,15 +568,13 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
msglen = fromwire_u16(&cursor, &max);
if (msglen > ONION_REPLY_SIZE) {
goto fail;
return NULL;
}
oreply->msg = tal_arr(oreply, u8, msglen);
fromwire(&cursor, &max, oreply->msg, msglen);
tal_steal(ctx, oreply);
tal_free(tmpctx);
return oreply;
fail:
return tal_free(tmpctx);
}

12
common/test/run-bolt11.c

@ -68,7 +68,6 @@ static void test_b11(const char *b11str,
const char *hashed_desc)
{
struct bolt11 *b11;
const void *tmpctx = tal_tmpctx(NULL);
char *fail;
char *reproduce;
@ -111,7 +110,6 @@ static void test_b11(const char *b11str,
abort();
}
assert(streq(reproduce, b11str));
tal_free(tmpctx);
}
int main(void)
@ -119,10 +117,10 @@ int main(void)
struct bolt11 *b11;
struct pubkey node;
u64 msatoshi;
const void *ctx = tal_tmpctx(NULL);
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
/* BOLT #11:
*
@ -159,7 +157,7 @@ int main(void)
* * `8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcq`: signature
* * `ca784w`: Bech32 checksum
*/
b11 = new_bolt11(ctx, NULL);
b11 = new_bolt11(tmpctx, NULL);
b11->chain = chainparams_for_network("bitcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
@ -193,7 +191,7 @@ int main(void)
* * `fj9srp`: Bech32 checksum
*/
msatoshi = 2500 * (1000ULL * 100000000) / 1000000;
b11 = new_bolt11(ctx, &msatoshi);
b11 = new_bolt11(tmpctx, &msatoshi);
b11->chain = chainparams_for_network("bitcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
@ -225,7 +223,7 @@ int main(void)
* * `2yxxz7`: Bech32 checksum
*/
msatoshi = 20 * (1000ULL * 100000000) / 1000;
b11 = new_bolt11(ctx, &msatoshi);
b11 = new_bolt11(tmpctx, &msatoshi);
b11->chain = chainparams_for_network("bitcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
@ -239,6 +237,6 @@ int main(void)
/* FIXME: Test the others! */
secp256k1_context_destroy(secp256k1_ctx);
tal_free(ctx);
tal_free(tmpctx);
return 0;
}

35
common/test/run-ip_port_parsing.c

@ -28,48 +28,49 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
int main(void)
{
struct wireaddr addr;
tal_t *ctx = tal_tmpctx(NULL);
char *ip;
u16 port;
setup_tmpctx();
/* Grossly invalid. */
assert(!separate_address_and_port(ctx, "[", &ip, &port));
assert(!separate_address_and_port(ctx, "[123", &ip, &port));
assert(!separate_address_and_port(ctx, "[::1]:8f", &ip, &port));
assert(!separate_address_and_port(ctx, "127.0.0.1:8f", &ip, &port));
assert(!separate_address_and_port(ctx, "127.0.0.1:0", &ip, &port));
assert(!separate_address_and_port(ctx, "127.0.0.1:ff", &ip, &port));
assert(!separate_address_and_port(tmpctx, "[", &ip, &port));
assert(!separate_address_and_port(tmpctx, "[123", &ip, &port));
assert(!separate_address_and_port(tmpctx, "[::1]:8f", &ip, &port));
assert(!separate_address_and_port(tmpctx, "127.0.0.1:8f", &ip, &port));
assert(!separate_address_and_port(tmpctx, "127.0.0.1:0", &ip, &port));
assert(!separate_address_and_port(tmpctx, "127.0.0.1:ff", &ip, &port));
/* ret = getaddrinfo("[::1]:80", NULL, NULL, &res); */
assert(separate_address_and_port(ctx, "[::1]:80", &ip, &port));
assert(separate_address_and_port(tmpctx, "[::1]:80", &ip, &port));
assert(streq(ip, "::1"));
assert(port == 80);
port = 0;
assert(separate_address_and_port(ctx, "ip6-localhost", &ip, &port));
assert(separate_address_and_port(tmpctx, "ip6-localhost", &ip, &port));
assert(streq(ip, "ip6-localhost"));
assert(port == 0);
assert(separate_address_and_port(ctx, "::1", &ip, &port));
assert(separate_address_and_port(tmpctx, "::1", &ip, &port));
assert(streq(ip, "::1"));
assert(port == 0);
assert(separate_address_and_port(ctx, "192.168.1.1:8000", &ip, &port));
assert(separate_address_and_port(tmpctx, "192.168.1.1:8000", &ip, &port));
assert(streq(ip, "192.168.1.1"));
assert(port == 8000);
port = 0;
assert(separate_address_and_port(ctx, "192.168.2.255", &ip, &port));
assert(separate_address_and_port(tmpctx, "192.168.2.255", &ip, &port));
assert(streq(ip, "192.168.2.255"));
assert(port == 0);
// unusual but possibly valid case
assert(separate_address_and_port(ctx, "[::1]", &ip, &port));
assert(separate_address_and_port(tmpctx, "[::1]", &ip, &port));
assert(streq(ip, "::1"));
assert(port == 0);
// service names not supported yet
assert(!separate_address_and_port(ctx, "[::1]:http", &ip, &port));
assert(!separate_address_and_port(tmpctx, "[::1]:http", &ip, &port));
// localhost hostnames for backward compat
parse_wireaddr("localhost", &addr, 200, NULL);
@ -78,18 +79,18 @@ int main(void)
// string should win the port battle
parse_wireaddr("[::1]:9735", &addr, 500, NULL);
assert(addr.port == 9735);
ip = fmt_wireaddr(ctx, &addr);
ip = fmt_wireaddr(tmpctx, &addr);
assert(streq(ip, "[::1]:9735"));
// should use argument if we have no port in string
parse_wireaddr("2001:db8:85a3::8a2e:370:7334", &addr, 9777, NULL);
assert(addr.port == 9777);
ip = fmt_wireaddr(ctx, &addr);
ip = fmt_wireaddr(tmpctx, &addr);
assert(streq(ip, "[2001:db8:85a3::8a2e:370:7334]:9777"));
assert(parse_wireaddr("[::ffff:127.0.0.1]:49150", &addr, 1, NULL));
assert(addr.port == 49150);
tal_free(ctx);
tal_free(tmpctx);
return 0;
}

7
common/test/run-sphinx.c

@ -72,7 +72,6 @@ static struct secret secret_from_hex(const char *hex)
* we match the test vectors and that we can also unwrap it. */
static void run_unit_tests(void)
{
tal_t *tmpctx = tal_tmpctx(NULL);
struct onionreply *oreply;
u8 *reply;
u8 *raw = tal_hexdata(tmpctx, "2002", 4);
@ -155,19 +154,17 @@ static void run_unit_tests(void)
oreply = unwrap_onionreply(tmpctx, ss, 5, reply);
printf("unwrapped %s\n", tal_hex(tmpctx, oreply->msg));
assert(memcmp(raw, oreply->msg, tal_len(raw)) == 0);
tal_free(tmpctx);
}
int main(int argc, char **argv)
{
bool generate = false, decode = false, unit = false;
const tal_t *ctx = talz(NULL, tal_t);
u8 assocdata[32];
memset(assocdata, 'B', sizeof(assocdata));
secp256k1_ctx = secp256k1_context_create(
SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
opt_register_noarg("--help|-h", opt_usage_and_exit,
"--generate <pubkey1> <pubkey2>... OR\n"
@ -194,6 +191,6 @@ int main(int argc, char **argv)
}
secp256k1_context_destroy(secp256k1_ctx);
opt_free_table();
tal_free(ctx);
tal_free(tmpctx);
return 0;
}

2
common/timeout.c

@ -33,10 +33,8 @@ struct oneshot *new_reltimer_(struct timers *timers,
void timer_expired(tal_t *ctx, struct timer *timer)
{
struct oneshot *t = container_of(timer, struct oneshot, timer);
const tal_t *tmpctx = tal_tmpctx(ctx);
/* If it doesn't free itself, freeing tmpctx will do it */
tal_steal(tmpctx, t);
t->cb(t->arg);
tal_free(tmpctx);
}

3
common/utils.h

@ -16,9 +16,6 @@ char *tal_hex(const tal_t *ctx, const tal_t *data);
/* Allocate and fill a buffer with the data of this hex string. */
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
/* FIXME: Remove in favor of global */
#define tal_tmpctx(ctx) tal((ctx), char)
/* Global temporary convenience context: freed in io loop core. */
extern const tal_t *tmpctx;

4
common/wireaddr.c

@ -77,7 +77,7 @@ REGISTER_TYPE_TO_STRING(wireaddr, fmt_wireaddr);
* Returns false if it wasn't one of these forms. If it returns true,
* it only overwrites *port if it was specified by <number> above.
*/
static bool separate_address_and_port(tal_t *ctx, const char *arg,
static bool separate_address_and_port(const tal_t *ctx, const char *arg,
char **addr, u16 *port)
{
char *portcolon;
@ -126,7 +126,6 @@ bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 defport,
u16 port;
char *ip;
bool res;
tal_t *tmpctx = tal_tmpctx(NULL);
res = false;
port = defport;
@ -195,6 +194,5 @@ bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 defport,
finish:
if (!res && err_msg && !*err_msg)
*err_msg = "Error parsing hostname";
tal_free(tmpctx);
return res;
}

13
gossipd/gossip.c

@ -456,7 +456,6 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
static void send_node_announcement(struct daemon *daemon)
{
tal_t *tmpctx = tal_tmpctx(daemon);
u32 timestamp = time_now().ts.tv_sec;
secp256k1_ecdsa_signature sig;
u8 *msg, *nannounce, *err;
@ -484,7 +483,6 @@ static void send_node_announcement(struct daemon *daemon)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected own node announcement: %s",
tal_hex(tmpctx, err));
tal_free(tmpctx);
}
/* Returns error if we should send an error. */
@ -1092,7 +1090,6 @@ static struct io_plan *release_peer(struct io_conn *conn, struct daemon *daemon,
static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
u8 *msg)
{
tal_t *tmpctx = tal_tmpctx(msg);
struct pubkey source, destination;
u32 msatoshi, final_cltv;
u16 riskfactor;
@ -1114,7 +1111,6 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
fuzz, &seed);
out = towire_gossip_getroute_reply(msg, hops);
tal_free(tmpctx);
daemon_conn_send(&daemon->master, out);
return daemon_conn_read_next(conn, &daemon->master);
}
@ -1163,7 +1159,6 @@ static void append_channel(struct gossip_getchannels_entry **entries,
static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daemon,
u8 *msg)
{
tal_t *tmpctx = tal_tmpctx(daemon);
u8 *out;
struct gossip_getchannels_entry *entries;
struct chan *chan;
@ -1188,7 +1183,6 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem
out = towire_gossip_getchannels_reply(daemon, entries);
daemon_conn_send(&daemon->master, take(out));
tal_free(tmpctx);
return daemon_conn_read_next(conn, &daemon->master);
}
@ -1215,7 +1209,6 @@ static void append_node(const struct gossip_getnodes_entry ***nodes,
static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
const u8 *msg)
{
tal_t *tmpctx = tal_tmpctx(daemon);
u8 *out;
struct node *n;
const struct gossip_getnodes_entry **nodes;
@ -1240,7 +1233,6 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
}
out = towire_gossip_getnodes_reply(daemon, nodes);
daemon_conn_send(&daemon->master, take(out));
tal_free(tmpctx);
return daemon_conn_read_next(conn, &daemon->master);
}
@ -1326,7 +1318,6 @@ fail:
static void gossip_send_keepalive_update(struct routing_state *rstate,
struct half_chan *hc)
{
tal_t *tmpctx = tal_tmpctx(rstate);
secp256k1_ecdsa_signature sig;
struct bitcoin_blkid chain_hash;
struct short_channel_id scid;
@ -1377,8 +1368,6 @@ static void gossip_send_keepalive_update(struct routing_state *rstate,
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected keepalive channel_update: %s",
tal_hex(tmpctx, err));
tal_free(tmpctx);
}
static void gossip_refresh_network(struct daemon *daemon)
@ -1860,7 +1849,6 @@ static struct io_plan *handle_txout_reply(struct io_conn *conn,
static struct io_plan *handle_disable_channel(struct io_conn *conn,
struct daemon *daemon, u8 *msg)
{
tal_t *tmpctx = tal_tmpctx(msg);
struct short_channel_id scid;
u8 direction;
struct chan *chan;
@ -1947,7 +1935,6 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
tal_hex(tmpctx, err));
fail:
tal_free(tmpctx);
return daemon_conn_read_next(conn, &daemon->master);
}
static struct io_plan *handle_routing_failure(struct io_conn *conn,

36
gossipd/routing.c

@ -893,7 +893,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
u64 htlc_minimum_msat;
u32 fee_base_msat;
u32 fee_proportional_millionths;
const tal_t *tmpctx = tal_tmpctx(rstate);
struct bitcoin_blkid chain_hash;
struct chan *chan;
u8 direction;
@ -909,7 +908,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
err = towire_errorfmt(rstate, NULL,
"Malformed channel_update %s",
tal_hex(tmpctx, serialized));
tal_free(tmpctx);
return err;
}
direction = flags & 0x1;
@ -923,7 +921,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
status_trace("Received channel_update for unknown chain %s",
type_to_string(tmpctx, struct bitcoin_blkid,
&chain_hash));
tal_free(tmpctx);
return NULL;
}
@ -937,7 +934,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
if (pending) {
update_pending(pending,
timestamp, serialized, direction);
tal_free(tmpctx);
return NULL;
}
@ -945,7 +941,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
SUPERVERBOSE("Ignoring update for unknown channel %s",
type_to_string(tmpctx, struct short_channel_id,
&short_channel_id));
tal_free(tmpctx);
return NULL;
}
}
@ -954,7 +949,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
if (c->last_timestamp >= timestamp) {
SUPERVERBOSE("Ignoring outdated update.");
tal_free(tmpctx);
return NULL;
}
@ -970,7 +964,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
* - MUST NOT process the message further.
* - SHOULD fail the connection.
*/
tal_free(tmpctx);
return err;
}
@ -992,7 +985,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
&chan->half[direction].channel_update_msgidx,
take(serialized));
tal_free(tmpctx);
return NULL;
}
@ -1041,7 +1033,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
u8 rgb_color[3];
u8 alias[32];
u8 *features, *addresses;
const tal_t *tmpctx = tal_tmpctx(rstate);
struct wireaddr *wireaddrs;
struct pending_node_announce *pna;
size_t len = tal_len(node_ann);
@ -1060,7 +1051,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
u8 *err = towire_errorfmt(rstate, NULL,
"Malformed node_announcement %s",
tal_hex(tmpctx, node_ann));
tal_free(tmpctx);
return err;
}
@ -1074,7 +1064,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
status_trace("Ignoring node announcement for node %s, unsupported features %s.",
type_to_string(tmpctx, struct pubkey, &node_id),
tal_hex(tmpctx, features));
tal_free(tmpctx);
return NULL;
}
@ -1099,7 +1088,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
struct sha256_double,
&hash),
tal_hex(tmpctx, node_ann));
tal_free(tmpctx);
return err;
}
@ -1115,7 +1103,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
"Malformed wireaddrs %s in %s.",
tal_hex(tmpctx, wireaddrs),
tal_hex(tmpctx, node_ann));
tal_free(tmpctx);
return err;
}
@ -1135,7 +1122,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
tal_free(pna->node_announcement);
pna->node_announcement = tal_dup_arr(pna, u8, node_ann, tal_len(node_ann), 0);
}
tal_free(tmpctx);
return NULL;
}
@ -1151,11 +1137,9 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
"node %s preceded by at least "
"channel_announcement?",
type_to_string(tmpctx, struct pubkey, &node_id));
tal_free(tmpctx);
return NULL;
} else if (node->last_timestamp >= timestamp) {
SUPERVERBOSE("Ignoring node announcement, it's outdated.");
tal_free(tmpctx);
return NULL;
}
@ -1174,11 +1158,10 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
replace_broadcast(node, rstate->broadcasts,
&node->node_announce_msgidx,
take(serialized));
tal_free(tmpctx);
return NULL;
}
struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *source,
const struct pubkey *destination,
const u32 msatoshi, double riskfactor,
@ -1258,7 +1241,6 @@ void routing_failure(struct routing_state *rstate,
enum onion_type failcode,
const u8 *channel_update)
{
const tal_t *tmpctx = tal_tmpctx(rstate);
struct node *node;
int i;
time_t now = time_now().ts.tv_sec;
@ -1277,7 +1259,7 @@ void routing_failure(struct routing_state *rstate,
erring_node_pubkey));
/* No node, so no channel, so any channel_update
* can also be ignored. */
goto out;
return;
}
/* BOLT #4:
@ -1325,12 +1307,12 @@ void routing_failure(struct routing_state *rstate,
/* Suppress UNUSUAL log if local failure */
if (structeq(&erring_node_pubkey->pubkey,
&rstate->local_id.pubkey))
goto out;
return;
status_unusual("routing_failure: "
"UPDATE bit set, no channel_update. "
"failcode: 0x%04x",
(int) failcode);
goto out;
return;
}
err = handle_channel_update(rstate, channel_update);
if (err) {
@ -1338,7 +1320,7 @@ void routing_failure(struct routing_state *rstate,
"bad channel_update %s",
sanitize_error(err, err, NULL));
tal_free(err);
goto out;
return;
}
} else {
if (tal_len(channel_update) != 0)
@ -1347,15 +1329,11 @@ void routing_failure(struct routing_state *rstate,
"failcode: 0x%04x",
(int) failcode);
}
out:
tal_free(tmpctx);
}
void mark_channel_unroutable(struct routing_state *rstate,
const struct short_channel_id *channel)
{
const tal_t *tmpctx = tal_tmpctx(rstate);
struct chan *chan;
time_t now = time_now().ts.tv_sec;
const char *scid = type_to_string(tmpctx, struct short_channel_id,
@ -1369,12 +1347,10 @@ void mark_channel_unroutable(struct routing_state *rstate,
status_unusual("mark_channel_unroutable: "
"channel %s not in routemap",
scid);
tal_free(tmpctx);
return;
}
chan->half[0].unroutable_until = now + 20;
chan->half[1].unroutable_until = now + 20;
tal_free(tmpctx);
}
void route_prune(struct routing_state *rstate)
@ -1382,7 +1358,7 @@ void route_prune(struct routing_state *rstate)
u64 now = time_now().ts.tv_sec;
/* Anything below this highwater mark ought to be pruned */
const s64 highwater = now - rstate->prune_timeout;
const tal_t *pruned = tal_tmpctx(rstate);
const tal_t *pruned = tal(NULL, char);
struct chan *chan;
u64 idx;

2
gossipd/routing.h

@ -230,7 +230,7 @@ void set_connection_values(struct chan *chan,
struct node *get_node(struct routing_state *rstate, const struct pubkey *id);
/* Compute a route to a destination, for a given amount and riskfactor. */
struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
const struct pubkey *source,
const struct pubkey *destination,
const u32 msatoshi, double riskfactor,

10
gossipd/test/run-bench-find_route.c

@ -94,8 +94,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
const void *trc;
/* Updates existing route if required. */
static struct half_chan *add_connection(struct routing_state *rstate,
const struct pubkey *from,
@ -172,7 +170,6 @@ static void run(const char *name)
int main(int argc, char *argv[])
{
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct routing_state *rstate;
size_t num_nodes = 100, num_runs = 1;
struct timemono start, end;
@ -184,8 +181,9 @@ int main(int argc, char *argv[])
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
rstate = new_routing_state(ctx, &zerohash, &me, 0);
rstate = new_routing_state(tmpctx, &zerohash, &me, 0);
opt_register_noarg("--perfme", opt_set_bool, &perfme,
"Run perfme-start and perfme-stop around benchmark");
@ -214,7 +212,7 @@ int main(int argc, char *argv[])
u64 fee;
struct chan **route;
route = find_route(ctx, rstate, &from, &to,
route = find_route(tmpctx, rstate, &from, &to,
pseudorand(100000),
riskfactor,
0.75, &base_seed,
@ -232,7 +230,7 @@ int main(int argc, char *argv[])
time_to_msec(timemono_between(end, start)),
time_to_nsec(time_divide(timemono_between(end, start), num_runs)));
tal_free(ctx);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
opt_free_table();
return 0;

10
gossipd/test/run-find_route-specific.c

@ -58,8 +58,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
const void *trc;
bool short_channel_id_from_str(const char *str, size_t strlen,
struct short_channel_id *dst);
@ -98,7 +96,6 @@ static bool channel_is_between(const struct chan *chan,
int main(void)
{
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct half_chan *nc;
struct routing_state *rstate;
struct pubkey a, b, c;
@ -108,6 +105,7 @@ int main(void)
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
pubkey_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
@ -119,7 +117,7 @@ int main(void)
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
&c);
rstate = new_routing_state(ctx, &zerohash, &a, 0);
rstate = new_routing_state(tmpctx, &zerohash, &a, 0);
/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
nc = get_or_make_connection(rstate, &c, &b, "6990:2:1");
@ -157,13 +155,13 @@ int main(void)
nc->flags = 1;
nc->last_timestamp = 1504064344;
route = find_route(ctx, rstate, &a, &c, 100000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &c, 100000, riskfactor, 0.0, NULL, &fee);
assert(route);
assert(tal_count(route) == 2);
assert(channel_is_between(route[0], &a, &b));
assert(channel_is_between(route[1], &b, &c));
tal_free(ctx);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
return 0;
}

26
gossipd/test/run-find_route.c

@ -56,8 +56,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
const void *trc;
/* Updates existing route if required. */
static struct half_chan *add_connection(struct routing_state *rstate,
const struct pubkey *from,
@ -141,7 +139,6 @@ static bool channel_is_between(const struct chan *chan,
int main(void)
{
static const struct bitcoin_blkid zerohash;
const tal_t *ctx = trc = tal_tmpctx(NULL);
struct routing_state *rstate;
struct pubkey a, b, c, d;
struct privkey tmp;
@ -151,9 +148,10 @@ int main(void)
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
memset(&tmp, 'a', sizeof(tmp));
rstate = new_routing_state(ctx, &zerohash, &a, 0);
rstate = new_routing_state(tmpctx, &zerohash, &a, 0);
pubkey_from_privkey(&tmp, &a);
new_node(rstate, &a);
@ -165,7 +163,7 @@ int main(void)
/* A<->B */
add_connection(rstate, &a, &b, 1, 1, 1);
route = find_route(ctx, rstate, &a, &b, 1000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &b, 1000, riskfactor, 0.0, NULL, &fee);
assert(tal_count(route) == 1);
assert(fee == 0);
@ -174,12 +172,12 @@ int main(void)
pubkey_from_privkey(&tmp, &c);
new_node(rstate, &c);
status_trace("A = %s", type_to_string(trc, struct pubkey, &a));
status_trace("B = %s", type_to_string(trc, struct pubkey, &b));
status_trace("C = %s", type_to_string(trc, struct pubkey, &c));
status_trace("A = %s", type_to_string(tmpctx, struct pubkey, &a));
status_trace("B = %s", type_to_string(tmpctx, struct pubkey, &b));
status_trace("C = %s", type_to_string(tmpctx, struct pubkey, &c));
add_connection(rstate, &b, &c, 1, 1, 1);
route = find_route(ctx, rstate, &a, &c, 1000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &c, 1000, riskfactor, 0.0, NULL, &fee);
assert(tal_count(route) == 2);
assert(fee == 1);
@ -187,20 +185,20 @@ int main(void)
memset(&tmp, 'd', sizeof(tmp));
pubkey_from_privkey(&tmp, &d);
new_node(rstate, &d);
status_trace("D = %s", type_to_string(trc, struct pubkey, &d));
status_trace("D = %s", type_to_string(tmpctx, struct pubkey, &d));
add_connection(rstate, &a, &d, 0, 2, 1);
add_connection(rstate, &d, &c, 0, 2, 1);
/* Will go via D for small amounts. */
route = find_route(ctx, rstate, &a, &c, 1000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &c, 1000, riskfactor, 0.0, NULL, &fee);
assert(tal_count(route) == 2);
assert(channel_is_between(route[0], &a, &d));
assert(channel_is_between(route[1], &d, &c));
assert(fee == 0);
/* Will go via B for large amounts. */
route = find_route(ctx, rstate, &a, &c, 3000000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &c, 3000000, riskfactor, 0.0, NULL, &fee);
assert(tal_count(route) == 2);
assert(channel_is_between(route[0], &a, &b));
assert(channel_is_between(route[1], &b, &c));
@ -208,13 +206,13 @@ int main(void)
/* Make B->C inactive, force it back via D */
get_connection(rstate, &b, &c)->active = false;
route = find_route(ctx, rstate, &a, &c, 3000000, riskfactor, 0.0, NULL, &fee);
route = find_route(tmpctx, rstate, &a, &c, 3000000, riskfactor, 0.0, NULL, &fee);
assert(tal_count(route) == 2);
assert(channel_is_between(route[0], &a, &d));
assert(channel_is_between(route[1], &d, &c));
assert(fee == 0 + 6);
tal_free(ctx);
tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
return 0;
}

10
gossipd/test/run-initiator-success.c

@ -178,7 +178,7 @@ static struct io_plan *success(struct io_conn *conn UNUSED,
const struct pubkey *them,
const struct wireaddr *addr UNUSED,
const struct crypto_state *cs,
void *ctx)
void *unused UNUSED)
{
assert(pubkey_eq(them, &rs_pub));
@ -187,7 +187,7 @@ static struct io_plan *success(struct io_conn *conn UNUSED,
/* No memory leaks please */
secp256k1_context_destroy(secp256k1_ctx);
tal_free(ctx);
tal_free(tmpctx);
exit(0);
}
@ -199,13 +199,11 @@ bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
int main(void)
{
tal_t *ctx = tal_tmpctx(NULL);
struct wireaddr dummy;
trc = tal_tmpctx(ctx);
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
/* BOLT #8:
@ -224,7 +222,7 @@ int main(void)
e_pub = pubkey("036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7");
dummy.addrlen = 0;
initiator_handshake(ctx, &ls_pub, &rs_pub, &dummy, success, ctx);
initiator_handshake((void *)tmpctx, &ls_pub, &rs_pub, &dummy, success, NULL);
/* Should not exit! */
abort();
}

11
gossipd/test/run-responder-success.c

@ -81,7 +81,6 @@ static bool secret_eq(const struct secret *s, const char *str)
}
secp256k1_context *secp256k1_ctx;
const void *trc;
static struct pubkey ls_pub, e_pub;
static struct privkey ls_priv, e_priv;
@ -178,14 +177,14 @@ static struct io_plan *success(struct io_conn *conn UNUSED,
const struct pubkey *them UNUSED,
const struct wireaddr *addr UNUSED,
const struct crypto_state *cs,
void *ctx)
void *unused UNUSED)
{
assert(secret_eq(&cs->sk, expect_sk));
assert(secret_eq(&cs->rk, expect_rk));
/* No memory leaks please */
secp256k1_context_destroy(secp256k1_ctx);
tal_free(ctx);
tal_free(tmpctx);
exit(0);
}
@ -197,13 +196,11 @@ bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
int main(void)
{
tal_t *ctx = tal_tmpctx(NULL);
struct wireaddr dummy;
trc = tal_tmpctx(ctx);
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
/* BOLT #8:
@ -220,7 +217,7 @@ int main(void)
e_pub = pubkey("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27");
dummy.addrlen = 0;
responder_handshake(ctx, &ls_pub, &dummy, success, ctx);
responder_handshake((void *)tmpctx, &ls_pub, &dummy, success, NULL);
/* Should not exit! */
abort();
}

12
hsmd/hsm.c

@ -150,7 +150,6 @@ static struct io_plan *handle_ecdh(struct io_conn *conn, struct daemon_conn *dc)
static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
struct daemon_conn *dc)
{
tal_t *ctx = tal_tmpctx(conn);
/* First 2 + 256 byte are the signatures and msg type, skip them */
size_t offset = 258;
struct privkey node_pkey;
@ -160,7 +159,7 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
u8 *ca;
struct pubkey bitcoin_id;
if (!fromwire_hsm_cannouncement_sig_req(ctx, dc->msg_in,
if (!fromwire_hsm_cannouncement_sig_req(tmpctx, dc->msg_in,
&bitcoin_id, &ca)) {
status_broken("Failed to parse cannouncement_sig_req: %s",
tal_hex(tmpctx, dc->msg_in));
@ -182,14 +181,12 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
reply = towire_hsm_cannouncement_sig_reply(ca, &node_sig);
daemon_conn_send(dc, take(reply));
tal_free(ctx);
return daemon_conn_read_next(conn, dc);
}
static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
struct daemon_conn *dc)
{
tal_t *tmpctx = tal_tmpctx(conn);
/* 2 bytes msg type + 64 bytes signature */
size_t offset = 66;
struct privkey node_pkey;
@ -234,7 +231,6 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
fee_base_msat, fee_proportional_mill);
daemon_conn_send(dc, take(towire_hsm_cupdate_sig_reply(tmpctx, cu)));
tal_free(tmpctx);
return daemon_conn_read_next(conn, dc);
}
@ -607,7 +603,6 @@ static void hsm_key_for_utxo(struct privkey *privkey, struct pubkey *pubkey,
* can broadcast it. */
static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
{
const tal_t *tmpctx = tal_tmpctx(master);
u64 satoshi_out, change_out;
u32 change_keyindex;
struct pubkey local_pubkey, remote_pubkey;
@ -668,7 +663,6 @@ static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
daemon_conn_send(master,
take(towire_hsm_sign_funding_reply(tmpctx, tx)));
tal_free(tmpctx);
}
/**
@ -676,7 +670,6 @@ static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
*/
static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
{
const tal_t *tmpctx = tal_tmpctx(master);
u64 satoshi_out, change_out;
u32 change_keyindex;
struct utxo **utxos;
@ -741,7 +734,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
daemon_conn_send(master,
take(towire_hsm_sign_withdrawal_reply(tmpctx, tx)));
tal_free(tmpctx);
}
/**
@ -749,7 +741,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
*/
static void sign_invoice(struct daemon_conn *master, const u8 *msg)
{
const tal_t *tmpctx = tal_tmpctx(master);
u5 *u5bytes;
u8 *hrpu8;
char *hrp;
@ -785,7 +776,6 @@ static void sign_invoice(struct daemon_conn *master, const u8 *msg)
daemon_conn_send(master,
take(towire_hsm_sign_invoice_reply(tmpctx, &rsig)));
tal_free(tmpctx);
}
static void sign_node_announcement(struct daemon_conn *master, const u8 *msg)

3
lightningd/channel_control.c

@ -168,7 +168,6 @@ bool peer_start_channeld(struct channel *channel,
const u8 *funding_signed,
bool reconnected)
{
const tal_t *tmpctx = tal_tmpctx(channel);
u8 *msg, *initmsg;
int hsmfd;
struct added_htlc *htlcs;
@ -209,7 +208,6 @@ bool peer_start_channeld(struct channel *channel,
log_unusual(channel->log, "Could not subdaemon channel: %s",
strerror(errno));
channel_fail_transient(channel, "Failed to subdaemon channel");
tal_free(tmpctx);
return true;
}
@ -281,6 +279,5 @@ bool peer_start_channeld(struct channel *channel,
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));
tal_free(tmpctx);
return true;
}

4
lightningd/closing_control.c

@ -140,7 +140,6 @@ void peer_start_closingd(struct channel *channel,
int peer_fd, int gossip_fd,
bool reconnected)
{
const tal_t *tmpctx = tal_tmpctx(channel);
u8 *initmsg;
u64 minfee, startfee, feelimit;
u64 num_revocations;
@ -150,7 +149,6 @@ void peer_start_closingd(struct channel *channel,
if (!channel->remote_shutdown_scriptpubkey) {
channel_internal_error(channel,
"Can't start closing: no remote info");
tal_free(tmpctx);
return;
}
@ -166,7 +164,6 @@ void peer_start_closingd(struct channel *channel,
log_unusual(channel->log, "Could not subdaemon closing: %s",
strerror(errno));
channel_fail_transient(channel, "Failed to subdaemon closing");
tal_free(tmpctx);
return;
}
@ -226,5 +223,4 @@ void peer_start_closingd(struct channel *channel,
/* We don't expect a response: it will give us feedback on
* signatures sent and received, then closing_complete. */
subd_send_msg(channel->owner, take(initmsg));
tal_free(tmpctx);
}

2
lightningd/gossip_control.c

@ -178,7 +178,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
* message */
void gossip_init(struct lightningd *ld)
{
tal_t *tmpctx = tal_tmpctx(ld);
u8 *msg;
int hsmfd;
u64 capabilities = HSM_CAP_ECDH | HSM_CAP_SIGN_GOSSIP;
@ -208,7 +207,6 @@ void gossip_init(struct lightningd *ld)
get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb,
ld->alias, ld->config.channel_update_interval);
subd_send_msg(ld->gossip, msg);
tal_free(tmpctx);
}
static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,

3
lightningd/hsm_control.c

@ -32,7 +32,6 @@ u8 *hsm_sync_read(const tal_t *ctx, struct lightningd *ld)
void hsm_init(struct lightningd *ld, bool newdir)
{
const tal_t *tmpctx = tal_tmpctx(ld);
u8 *msg;
bool create;
@ -56,6 +55,4 @@ void hsm_init(struct lightningd *ld, bool newdir)
&ld->peer_seed,
ld->wallet->bip32_base))
errx(1, "HSM did not give init reply");
tal_free(tmpctx);
}

2
lightningd/jsonrpc.c

@ -281,7 +281,6 @@ static void connection_complete_error(struct json_connection *jcon,
int code,
const struct json_result *data)
{
const tal_t *tmpctx = tal_tmpctx(jcon);
/* Use this to escape errmsg. */
struct json_result *errorres = new_json_result(tmpctx);
const char *data_str;
@ -305,7 +304,6 @@ static void connection_complete_error(struct json_connection *jcon,
json_result_string(errorres),
data_str,
id)));
tal_free(tmpctx);
}
struct json_result *null_response(const tal_t *ctx)

15
lightningd/lightningd.c

@ -93,11 +93,9 @@ static const char *daemons[] = {
void test_daemons(const struct lightningd *ld)
{
size_t i;
const tal_t *ctx = tal_tmpctx(ld);
for (i = 0; i < ARRAY_SIZE(daemons); i++) {
int outfd;
const char *dpath = path_join(ctx, ld->daemon_dir, daemons[i]);
const char *dpath = path_join(tmpctx, ld->daemon_dir, daemons[i]);
const char *verstring;
pid_t pid = pipecmd(&outfd, NULL, &outfd,
dpath, "--version", NULL);
@ -105,21 +103,19 @@ void test_daemons(const struct lightningd *ld)
log_debug(ld->log, "testing %s", dpath);
if (pid == -1)
err(1, "Could not run %s", dpath);
verstring = grab_fd(ctx, outfd);
verstring = grab_fd(tmpctx, outfd);
if (!verstring)
err(1, "Could not get output from %s", dpath);
if (!strstarts(verstring, version())
|| verstring[strlen(version())] != '\n')
errx(1, "%s: bad version '%s'", daemons[i], verstring);
}
tal_free(ctx);
}
/* Check if all daemons exist in specified directory. */
static bool has_all_daemons(const char* daemon_dir)
{
size_t i;
bool missing_daemon = false;
const tal_t *tmpctx = tal_tmpctx(NULL);
for (i = 0; i < ARRAY_SIZE(daemons); ++i) {
if (!path_is_file(path_join(tmpctx, daemon_dir, daemons[i]))) {
@ -128,13 +124,12 @@ static bool has_all_daemons(const char* daemon_dir)
}
}
tal_free(tmpctx);
return !missing_daemon;
}
static const char *find_my_path(const tal_t *ctx, const char *argv0)
{
char *me, *tmpctx = tal_tmpctx(ctx);
char *me;
if (strchr(argv0, PATH_SEP)) {
const char *path;
@ -173,7 +168,6 @@ static const char *find_my_path(const tal_t *ctx, const char *argv0)
errx(1, "Cannot find %s in $PATH", argv0);
}
tal_free(tmpctx);
return path_dirname(ctx, take(me));
}
static const char *find_my_pkglibexec_path(const tal_t *ctx,
@ -260,7 +254,6 @@ static void daemonize_but_keep_dir(struct lightningd *ld)
static void pidfile_create(const struct lightningd *ld)
{
char *pid;
const tal_t *tmpctx = tal_tmpctx(NULL);
/* Create PID file */
pid_fd = open(ld->pidfile, O_WRONLY|O_CREAT, 0640);
@ -275,8 +268,6 @@ static void pidfile_create(const struct lightningd *ld)
/* Get current PID and write to PID fie */
pid = tal_fmt(tmpctx, "%d\n", getpid());
write_all(pid_fd, pid, strlen(pid));
tal_free(tmpctx);
}
int main(int argc, char *argv[])

5
lightningd/onchain_control.c

@ -347,7 +347,6 @@ enum watch_result funding_spent(struct channel *channel,
u8 *msg;
struct bitcoin_txid our_last_txid;
struct htlc_stub *stubs;
const tal_t *tmpctx = tal_tmpctx(channel);
struct lightningd *ld = channel->peer->ld;
struct pubkey final_key;
@ -369,14 +368,12 @@ enum watch_result funding_spent(struct channel *channel,
if (!channel->owner) {
log_broken(channel->log, "Could not subdaemon onchain: %s",
strerror(errno));
tal_free(tmpctx);
return KEEP_WATCHING;
}
stubs = wallet_htlc_stubs(tmpctx, ld->wallet, channel);
if (!stubs) {
log_broken(channel->log, "Could not load htlc_stubs");
tal_free(tmpctx);
return KEEP_WATCHING;
}
@ -384,7 +381,6 @@ enum watch_result funding_spent(struct channel *channel,
channel->final_key_idx)) {
log_broken(channel->log, "Could not derive onchain key %"PRIu64,
channel->final_key_idx);
tal_free(tmpctx);
return KEEP_WATCHING;
}
/* This could be a mutual close, but it doesn't matter. */
@ -434,7 +430,6 @@ enum watch_result funding_spent(struct channel *channel,
watch_tx_and_outputs(channel, tx);
tal_free(tmpctx);
/* We keep watching until peer finally deleted, for reorgs. */
return KEEP_WATCHING;
}

2
lightningd/opening_control.c

@ -229,7 +229,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
const int *fds,
struct funding_channel *fc)
{
tal_t *tmpctx = tal_tmpctx(fc);
u8 *msg, *linear;
struct channel_info channel_info;
struct bitcoin_tx *fundingtx;
@ -412,7 +411,6 @@ static void opening_fundee_finished(struct subd *openingd,
u64 gossip_index;
secp256k1_ecdsa_signature remote_commit_sig;
struct bitcoin_tx *remote_commit;
const tal_t *tmpctx = tal_tmpctx(uc);
struct lightningd *ld = openingd->ld;
struct bitcoin_txid funding_txid;
u16 funding_outnum;

22
lightningd/pay.c

@ -105,14 +105,11 @@ static void payment_trigger_success(struct lightningd *ld,
const struct sha256 *payment_hash,
const struct preimage *payment_preimage)
{
const tal_t *tmpctx = tal_tmpctx(ld);
struct sendpay_result *result;
result = sendpay_result_success(tmpctx, payment_preimage);
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
tal_free(tmpctx);
}
static struct sendpay_result*
@ -141,7 +138,6 @@ static void payment_route_failure(struct lightningd *ld,
const u8 *onionreply,
const char *details)
{
const tal_t *tmpctx = tal_tmpctx(ld);
struct sendpay_result *result;
result = sendpay_result_route_failure(tmpctx,
@ -151,8 +147,6 @@ static void payment_route_failure(struct lightningd *ld,
details);
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
tal_free(tmpctx);
}
static struct sendpay_result *
@ -332,7 +326,6 @@ static void random_mark_channel_unroutable(struct log *log,
struct subd *gossip,
struct short_channel_id *route_channels)
{
const tal_t *tmpctx = tal_tmpctx(gossip);
size_t num_channels = tal_count(route_channels);
size_t i;
const struct short_channel_id *channel;
@ -352,15 +345,12 @@ static void random_mark_channel_unroutable(struct log *log,
channel));
msg = towire_gossip_mark_channel_unroutable(tmpctx, channel);
subd_send_msg(gossip, msg);
tal_free(tmpctx);
}
static void report_routing_failure(struct log *log,
struct subd *gossip,
struct routing_failure *fail)
{
const tal_t *tmpctx = tal_tmpctx(gossip);
u8 *gossip_msg;
assert(fail);
@ -379,14 +369,11 @@ static void report_routing_failure(struct log *log,
(u16) fail->failcode,
fail->channel_update);
subd_send_msg(gossip, gossip_msg);
tal_free(tmpctx);
}
void payment_store(struct lightningd *ld,
const struct sha256 *payment_hash)
{
const tal_t *tmpctx = tal_tmpctx(ld);
struct sendpay_command *pc;
struct sendpay_command *next;
struct sendpay_result *result;
@ -406,8 +393,6 @@ void payment_store(struct lightningd *ld,
tal_steal(tmpctx, pc);
pc->cb(result, pc->cbarg);
}
tal_free(tmpctx);
}
void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
@ -417,7 +402,6 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
enum onion_type failcode;
struct secret *path_secrets;
struct wallet_payment *payment;
const tal_t *tmpctx = tal_tmpctx(ld);
struct routing_failure* fail = NULL;
const char *failmsg;
bool retry_plausible;
@ -438,7 +422,6 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
&hout->payment_hash));
wallet_payment_set_status(ld->wallet, &hout->payment_hash,
PAYMENT_FAILED, NULL);
tal_free(tmpctx);
return;
}
#endif
@ -516,7 +499,6 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
payment_route_failure(ld, &hout->payment_hash,
retry_plausible, fail, hout->failuremsg,
failmsg);
tal_free(tmpctx);
}
/* Wait for a payment. If cxt is deleted, then cb will
@ -529,7 +511,6 @@ bool wait_payment(const tal_t *cxt,
void (*cb)(const struct sendpay_result *, void*),
void *cbarg)
{
const tal_t *tmpctx = tal_tmpctx(NULL);
struct wallet_payment *payment;
struct sendpay_result *result;
char const *details;
@ -610,7 +591,6 @@ bool wait_payment(const tal_t *cxt,
abort();
end:
tal_free(tmpctx);
return cb_not_called;
}
@ -629,7 +609,6 @@ send_payment(const tal_t *ctx,
struct onionpacket *packet;
struct secret *path_secrets;
enum onion_type failcode;
const tal_t *tmpctx = tal_tmpctx(ctx);
size_t i, n_hops = tal_count(route);
struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops);
struct pubkey *ids = tal_arr(tmpctx, struct pubkey, n_hops);
@ -776,7 +755,6 @@ send_payment(const tal_t *ctx,
add_sendpay_waiter(ctx, rhash, ld, cb, cbarg);
tal_free(tmpctx);
return true;
}

4
lightningd/payalgo.c

@ -222,12 +222,8 @@ static char const *stringify_route(const tal_t *ctx, struct route_hop *route)
static void log_route(struct pay *pay, struct route_hop *route)
{
const tal_t *tmpctx = tal_tmpctx(pay->try_parent);
log_info(pay->cmd->ld->log, "pay(%p): sendpay via route: %s",
pay, stringify_route(tmpctx, route));
tal_free(tmpctx);
}
static void json_pay_sendpay_resume(const struct sendpay_result *r,

3
lightningd/peer_control.c

@ -169,7 +169,6 @@ u32 feerate_max(struct lightningd *ld)
static void sign_last_tx(struct channel *channel)
{
const tal_t *tmpctx = tal_tmpctx(channel);
u8 *funding_wscript;
struct pubkey local_funding_pubkey;
struct secrets secrets;
@ -197,8 +196,6 @@ static void sign_last_tx(struct channel *channel)
&sig,
&channel->channel_info.remote_fundingkey,
&local_funding_pubkey);
tal_free(tmpctx);
}
static void remove_sig(struct bitcoin_tx *signed_tx)

7
lightningd/peer_htlcs.c

@ -232,7 +232,6 @@ static void handle_localpay(struct htlc_in *hin,
struct invoice invoice;
struct invoice_details details;
struct lightningd *ld = hin->key.channel->peer->ld;
const tal_t *tmpctx = tal_tmpctx(ld);
/* BOLT #4:
*
@ -308,15 +307,12 @@ static void handle_localpay(struct htlc_in *hin,
fulfill_htlc(hin, &details.r);
wallet_invoice_resolve(ld->wallet, invoice, hin->msatoshi);
tal_free(tmpctx);
return;
fail:
/* Final hop never sends an UPDATE. */
assert(!(failcode & UPDATE));
local_fail_htlc(hin, failcode, NULL);
tal_free(tmpctx);
}
/*
@ -563,7 +559,6 @@ static bool peer_accepted_htlc(struct channel *channel,
u8 *req;
struct route_step *rs;
struct onionpacket *op;
const tal_t *tmpctx = tal_tmpctx(channel);
struct lightningd *ld = channel->peer->ld;
hin = find_htlc_in(&ld->htlcs_in, channel, id);
@ -604,7 +599,6 @@ static bool peer_accepted_htlc(struct channel *channel,
"bad onion in got_revoke: %s",
tal_hexstr(channel, hin->onion_routing_packet,
sizeof(hin->onion_routing_packet)));
tal_free(tmpctx);
return false;
}
/* FIXME: could be bad version, bad key. */
@ -659,7 +653,6 @@ out:
log_debug(channel->log, "their htlc %"PRIu64" %s",
id, *failcode ? onion_type_name(*failcode) : "locked");
tal_free(tmpctx);
return true;
}

9
lightningd/subd.c

@ -285,7 +285,6 @@ static struct io_plan *sd_msg_reply(struct io_conn *conn, struct subd *sd,
{
int type = fromwire_peektype(sd->msg_in);
bool freed = false;
const tal_t *tmpctx = tal_tmpctx(conn);
int *fds_in;
log_debug(sd->log, "REPLY %s with %zu fds",
@ -309,7 +308,6 @@ static struct io_plan *sd_msg_reply(struct io_conn *conn, struct subd *sd,
/* Find out if they freed it. */
tal_add_destructor2(sd, mark_freed, &freed);
sr->replycb(sd, sd->msg_in, fds_in, sr->replycb_data);
tal_free(tmpctx);
if (freed)
return io_close(conn);
@ -428,7 +426,6 @@ static bool handle_set_billboard(struct subd *sd, const u8 *msg)
static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
{
int type = fromwire_peektype(sd->msg_in);
const tal_t *tmpctx;
struct subd_req *sr;
struct db *db = sd->ld->wallet->db;
struct io_plan *plan;
@ -452,8 +449,7 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
goto out;
}
/* If not stolen, we'll free this below. */
tmpctx = tal_tmpctx(sd);
/* If not stolen, we'll free this later. */
tal_steal(tmpctx, sd->msg_in);
/* We handle status messages ourselves. */
@ -487,7 +483,6 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
if (!sd->fds_in) {
/* Don't free msg_in: we go around again. */
tal_steal(sd, sd->msg_in);
tal_free(tmpctx);
plan = sd_collect_fds(conn, sd, 2);
goto out;
}
@ -518,7 +513,6 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
assert(!sd->fds_in);
/* Don't free msg_in: we go around again. */
tal_steal(sd, sd->msg_in);
tal_free(tmpctx);
plan = sd_collect_fds(conn, sd, i);
goto out;
}
@ -527,7 +521,6 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
next:
sd->msg_in = NULL;
sd->fds_in = tal_free(sd->fds_in);
tal_free(tmpctx);
plan = io_read_wire(conn, sd, &sd->msg_in, sd_msg_read, sd);
goto out;

15
lightningd/test/run-commit_tx.c

@ -60,7 +60,6 @@ static bool pubkey_from_secret(const struct secret *secret,
static void tx_must_be_eq(const struct bitcoin_tx *a,
const struct bitcoin_tx *b)
{
tal_t *tmpctx = tal_tmpctx(NULL);
u8 *lina, *linb;
size_t i;
@ -88,8 +87,6 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
"%s",
tal_hex(tmpctx, lina),
tal_hex(tmpctx, linb));
tal_free(tmpctx);
}
/* BOLT #3:
@ -189,7 +186,6 @@ static void report_htlcs(const struct bitcoin_tx *tx,
const struct pubkey *remote_revocation_key,
u32 feerate_per_kw)
{
tal_t *tmpctx = tal_tmpctx(NULL);
size_t i, n;
struct bitcoin_txid txid;
struct bitcoin_tx **htlc_tx;
@ -301,7 +297,6 @@ static void report_htlcs(const struct bitcoin_tx *tx,
htlc->id,
tal_hex(tmpctx, linearize_tx(tmpctx, htlc_tx[i])));
}
tal_free(tmpctx);
}
static void report(struct bitcoin_tx *tx,
@ -322,7 +317,6 @@ static void report(struct bitcoin_tx *tx,
u32 feerate_per_kw,
const struct htlc **htlc_map)
{
tal_t *tmpctx = tal_tmpctx(NULL);
char *txhex;
secp256k1_ecdsa_signature localsig, remotesig;
@ -354,7 +348,6 @@ static void report(struct bitcoin_tx *tx,
remotekey, remote_htlckey,
remote_revocation_key,
feerate_per_kw);
tal_free(tmpctx);
}
#ifdef DEBUG
@ -425,7 +418,6 @@ static const struct htlc **invert_htlcs(const struct htlc **htlcs)
int main(void)
{
tal_t *tmpctx = tal_tmpctx(NULL);
struct bitcoin_txid funding_txid;
u64 funding_amount_satoshi, dust_limit_satoshi;
u32 feerate_per_kw;
@ -454,11 +446,14 @@ int main(void)
u8 *wscript;
unsigned int funding_output_index;
u64 commitment_number, cn_obscurer, to_local_msat, to_remote_msat;
const struct htlc **htlcs = setup_htlcs(tmpctx), **htlc_map, **htlc_map2,
**inv_htlcs = invert_htlcs(htlcs);
const struct htlc **htlcs, **htlc_map, **htlc_map2, **inv_htlcs;
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
htlcs = setup_htlcs(tmpctx);
inv_htlcs = invert_htlcs(htlcs);
/* BOLT #3:
*

10
lightningd/test/run-cryptomsg.c

@ -98,13 +98,13 @@ static struct secret secret_from_hex(const char *hex)
int main(void)
{
tal_t *tmpctx = tal_tmpctx(NULL);
struct peer_crypto_state cs_out, cs_in;
struct secret sk, rk, ck;
const void *msg = tal_dup_arr(tmpctx, char, "hello", 5, 0);
const void *msg;
size_t i;
trc = tal_tmpctx(tmpctx);
setup_tmpctx();
msg = tal_dup_arr(tmpctx, char, "hello", 5, 0);
/* BOLT #8:
*
@ -125,8 +125,8 @@ int main(void)
cs_out.cs.sk = cs_in.cs.rk = sk;
cs_out.cs.rk = cs_in.cs.sk = rk;
cs_out.cs.s_ck = cs_out.cs.r_ck = cs_in.cs.s_ck = cs_in.cs.r_ck = ck;
init_peer_crypto_state(tmpctx, &cs_in);
init_peer_crypto_state(tmpctx, &cs_out);
init_peer_crypto_state((void *)tmpctx, &cs_in);
init_peer_crypto_state((void *)tmpctx, &cs_out);
for (i = 0; i < 1002; i++) {
write_buf = tal_arr(tmpctx, char, 0);

6
lightningd/test/run-find_my_path.c

@ -136,10 +136,12 @@ char *opt_subd_dev_disconnect(const char *optarg UNNEEDED, struct lightningd *ld
#undef main
int main(int argc UNUSED, char *argv[] UNUSED)
{
char *tmpctx = tal_tmpctx(NULL);
char *argv0;
/* We're assuming we're run from top build dir. */
const char *answer = path_canon(tmpctx, "lightningd/test");
const char *answer;
setup_tmpctx();
answer = path_canon(tmpctx, "lightningd/test");
/* Various different ways we could find ourselves. */
argv0 = path_join(tmpctx,

5
lightningd/test/run-funding_tx.c

@ -41,7 +41,6 @@ static struct privkey privkey_from_hex(const char *hex)
int main(void)
{
tal_t *tmpctx = tal_tmpctx(NULL);
struct bitcoin_tx *input, *funding;
u64 fee;
struct pubkey local_funding_pubkey, remote_funding_pubkey;
@ -49,7 +48,7 @@ int main(void)
struct pubkey inputkey;
bool testnet;
struct utxo utxo;
const struct utxo **utxomap = tal_arr(tmpctx, const struct utxo *, 1);
const struct utxo **utxomap;
u64 funding_satoshis;
u16 funding_outnum;
u8 *subscript;
@ -58,6 +57,7 @@ int main(void)
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
/* BOLT #3:
*
@ -109,6 +109,7 @@ int main(void)
printf("input[0] satoshis: %"PRIu64"\n", utxo.amount);
printf("funding satoshis: %"PRIu64"\n", funding_satoshis);
utxomap = tal_arr(tmpctx, const struct utxo *, 1);
utxomap[0] = &utxo;
funding = funding_tx(tmpctx, &funding_outnum, utxomap,
funding_satoshis,

16
onchaind/onchain.c

@ -1325,7 +1325,6 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
const secp256k1_ecdsa_signature *remote_htlc_sigs,
struct tracked_output **outs)
{
const tal_t *tmpctx = tal_tmpctx(NULL);
u8 **htlc_scripts;
u8 *local_wscript, *script[NUM_SIDES];
struct pubkey local_per_commitment_point;
@ -1550,7 +1549,6 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately);
wait_for_resolved(outs);
tal_free(tmpctx);
}
/* We produce individual penalty txs. It's less efficient, but avoids them
@ -1558,7 +1556,6 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
* delay */
static void steal_to_them_output(struct tracked_output *out)
{
const tal_t *tmpctx = tal_tmpctx(NULL);
u8 *wscript;
struct bitcoin_tx *tx;
enum tx_type tx_type = OUR_PENALTY_TX;
@ -1582,7 +1579,6 @@ static void steal_to_them_output(struct tracked_output *out)
&tx_type);
propose_resolution(out, tx, 0, tx_type);
tal_free(tmpctx);
}
static void steal_htlc(struct tracked_output *out)
@ -1631,7 +1627,6 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
const bool *tell_immediately,
struct tracked_output **outs)
{
const tal_t *tmpctx = tal_tmpctx(NULL);
u8 **htlc_scripts;
u8 *remote_wscript, *script[NUM_SIDES];
struct keyset *ks;
@ -1874,7 +1869,6 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately);
wait_for_resolved(outs);
tal_free(tmpctx);
}
static void handle_their_unilateral(const struct bitcoin_tx *tx,
@ -1894,7 +1888,6 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
const bool *tell_immediately,
struct tracked_output **outs)
{
const tal_t *tmpctx = tal_tmpctx(NULL);
u8 **htlc_scripts;
u8 *remote_wscript, *script[NUM_SIDES];
struct keyset *ks;
@ -2103,12 +2096,11 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
note_missing_htlcs(htlc_scripts, htlcs,
tell_if_missing, tell_immediately);
wait_for_resolved(outs);
tal_free(tmpctx);
}
int main(int argc, char *argv[])
{
const tal_t *ctx = tal_tmpctx(NULL);
const tal_t *ctx = tal(NULL, char);
u8 *msg;
struct privkey seed;
struct pubkey remote_payment_basepoint, remote_htlc_basepoint,
@ -2135,7 +2127,7 @@ int main(int argc, char *argv[])
missing_htlc_msgs = tal_arr(ctx, u8 *, 0);
msg = wire_sync_read(ctx, REQ_FD);
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_onchain_init(ctx, msg,
&seed, &shachain,
&funding_amount_satoshi,
@ -2174,7 +2166,7 @@ int main(int argc, char *argv[])
"Can't allocate %"PRIu64" htlcs", num_htlcs);
for (u64 i = 0; i < num_htlcs; i++) {
msg = wire_sync_read(ctx, REQ_FD);
msg = wire_sync_read(tmpctx, REQ_FD);
if (!fromwire_onchain_htlc(msg, &htlcs[i],
&tell_if_missing[i],
&tell_immediately[i]))
@ -2310,7 +2302,7 @@ int main(int argc, char *argv[])
"Unknown commitment index %"PRIu64
" for tx %s",
commit_num,
type_to_string(ctx, struct bitcoin_tx,
type_to_string(tmpctx, struct bitcoin_tx,
tx));
}

13
wallet/invoices.c

@ -56,7 +56,6 @@ static void trigger_invoice_waiter_resolve(struct invoices *invoices,
u64 id,
const struct invoice *invoice)
{
const tal_t *tmpctx = tal_tmpctx(invoices);
struct invoice_waiter *w;
struct invoice_waiter *n;
@ -67,15 +66,12 @@ static void trigger_invoice_waiter_resolve(struct invoices *invoices,
tal_steal(tmpctx, w);
trigger_invoice_waiter(w, invoice);
}
tal_free(tmpctx);
}
static void
trigger_invoice_waiter_expire_or_delete(struct invoices *invoices,
u64 id,
const struct invoice *invoice)
{
const tal_t *tmpctx = tal_tmpctx(invoices);
struct invoice_waiter *w;
struct invoice_waiter *n;
@ -86,8 +82,6 @@ trigger_invoice_waiter_expire_or_delete(struct invoices *invoices,
tal_steal(tmpctx, w);
trigger_invoice_waiter(w, invoice);
}
tal_free(tmpctx);
}
static void wallet_stmt2invoice_details(const tal_t *ctx,
@ -162,7 +156,6 @@ struct invoice_id_node {
static void install_expiration_timer(struct invoices *invoices);
static void trigger_expiration(struct invoices *invoices)
{
const tal_t *tmpctx = tal_tmpctx(invoices);
struct list_head idlist;
struct invoice_id_node *idn;
u64 now = time_now().ts.tv_sec;
@ -201,8 +194,6 @@ static void trigger_expiration(struct invoices *invoices)
}
install_expiration_timer(invoices);
tal_free(tmpctx);
}
static void install_expiration_timer(struct invoices *invoices)
@ -447,7 +438,6 @@ void invoices_resolve(struct invoices *invoices,
sqlite3_stmt *stmt;
s64 pay_index;
u64 paid_timestamp;
const tal_t *tmpctx = tal_tmpctx(NULL);
/* Assign a pay-index. */
pay_index = get_next_pay_index(invoices->db);
@ -470,9 +460,6 @@ void invoices_resolve(struct invoices *invoices,
/* Tell all the waiters about the paid invoice. */
trigger_invoice_waiter_resolve(invoices, invoice.id, &invoice);
/* Free all watchers. */
tal_free(tmpctx);
}
/* Called when an invoice waiter is destructed. */

6
wallet/test/run-wallet.c

@ -961,8 +961,10 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
int main(void)
{
bool ok = true;
tal_t *tmpctx = tal_tmpctx(NULL);
struct lightningd *ld = tal(tmpctx, struct lightningd);
struct lightningd *ld;
setup_tmpctx();
ld = tal(tmpctx, struct lightningd);
/* Only elements in ld we should access */
list_head_init(&ld->peers);

3
wallet/txfilter.c

@ -63,7 +63,6 @@ void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES)
void txfilter_add_derkey(struct txfilter *filter,
const u8 derkey[PUBKEY_DER_LEN])
{
tal_t *tmpctx = tal_tmpctx(filter);
u8 *skp, *p2sh;
skp = scriptpubkey_p2wpkh_derkey(tmpctx, derkey);
@ -71,8 +70,6 @@ void txfilter_add_derkey(struct txfilter *filter,
txfilter_add_scriptpubkey(filter, take(skp));
txfilter_add_scriptpubkey(filter, take(p2sh));
tal_free(tmpctx);
}

19
wallet/wallet.c

@ -528,7 +528,6 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
{
bool ok;
const unsigned char *addrstr;
tal_t *tmpctx = tal_tmpctx(w);
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT id, node_id, address FROM peers WHERE node_id=?;");
sqlite3_bind_pubkey(stmt, 1, nodeid);
@ -545,7 +544,6 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
peer->dbid = 0;
}
sqlite3_finalize(stmt);
tal_free(tmpctx);
return ok;
}
@ -584,7 +582,6 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
secp256k1_ecdsa_signature last_sig;
u8 *remote_shutdown_scriptpubkey;
struct changed_htlc *last_sent_commit;
const tal_t *tmpctx = tal_tmpctx(ctx);
s64 final_key_idx;
peer_dbid = sqlite3_column_int64(stmt, 1);
@ -592,7 +589,6 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
if (!peer) {
peer = wallet_peer_load(w, peer_dbid);
if (!peer) {
tal_free(tmpctx);
return NULL;
}
}
@ -638,14 +634,12 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
&channel_info.their_config);
if (!ok) {
tal_free(tmpctx);
return NULL;
}
final_key_idx = sqlite3_column_int64(stmt, 29);
if (final_key_idx < 0) {
log_broken(w->log, "%s: Final key < 0", __func__);
tal_free(tmpctx);
return NULL;
}
chan = new_channel(peer, sqlite3_column_int64(stmt, 0),
@ -678,7 +672,6 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
last_sent_commit,
sqlite3_column_int64(stmt, 35));
tal_free(tmpctx);
return chan;
}
@ -863,7 +856,6 @@ u64 wallet_get_channel_dbid(struct wallet *wallet)
void wallet_channel_save(struct wallet *w, struct channel *chan)
{
tal_t *tmpctx = tal_tmpctx(w);
sqlite3_stmt *stmt;
assert(chan->first_blocknum);
@ -962,13 +954,10 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
sqlite3_bind_int64(stmt, 3, chan->dbid);
db_exec_prepared(w->db, stmt);
}
tal_free(tmpctx);
}
void wallet_channel_insert(struct wallet *w, struct channel *chan)
{
tal_t *tmpctx = tal_tmpctx(w);
sqlite3_stmt *stmt;
if (chan->peer->dbid == 0) {
@ -999,7 +988,6 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
/* Now save path as normal */
wallet_channel_save(w, chan);
tal_free(tmpctx);
}
void wallet_channel_delete(struct wallet *w, u64 wallet_id)
@ -1099,7 +1087,6 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
void wallet_htlc_save_in(struct wallet *wallet,
const struct channel *chan, struct htlc_in *in)
{
tal_t *tmpctx = tal_tmpctx(wallet);
sqlite3_stmt *stmt;
stmt = db_prepare(
@ -1136,14 +1123,12 @@ void wallet_htlc_save_in(struct wallet *wallet,
db_exec_prepared(wallet->db, stmt);
in->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
tal_free(tmpctx);
}
void wallet_htlc_save_out(struct wallet *wallet,
const struct channel *chan,
struct htlc_out *out)
{
tal_t *tmpctx = tal_tmpctx(wallet);
sqlite3_stmt *stmt;
/* We absolutely need the incoming HTLC to be persisted before
@ -1184,7 +1169,6 @@ void wallet_htlc_save_out(struct wallet *wallet,
db_exec_prepared(wallet->db, stmt);
out->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
tal_free(tmpctx);
}
void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
@ -1771,7 +1755,6 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
const u8 *failupdate /*tal_arr*/)
{
sqlite3_stmt *stmt;
const tal_t *tmpctx = tal_tmpctx(wallet);
struct short_channel_id *scid;
stmt = db_prepare(wallet->db,
@ -1815,8 +1798,6 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
sqlite3_bind_sha256(stmt, 8, payment_hash);
db_exec_prepared(wallet->db, stmt);
tal_free(tmpctx);
}
const struct wallet_payment **

2
wire/towire.c

@ -159,10 +159,8 @@ void towire_wirestring(u8 **pptr, const char *str)
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
{
tal_t *tmpctx = tal_tmpctx(NULL);
u8 *lin = linearize_tx(tmpctx, tx);
towire_u8_array(pptr, lin, tal_len(lin));
tal_free(tmpctx);
}
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)

Loading…
Cancel
Save