Skip to content

Commit

Permalink
utils: remove tal_tmpctx altogether, use global.
Browse files Browse the repository at this point in the history
In particular, we now only free tmpctx at the end of main().

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Mar 16, 2018
1 parent 40fe5b7 commit 0a6e3d1
Show file tree
Hide file tree
Showing 45 changed files with 115 additions and 375 deletions.
38 changes: 0 additions & 38 deletions channeld/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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));
}
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -929,21 +909,18 @@ 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;

#if DEVELOPER
/* Hack to suppress all commit sends if dev_disconnect says to */
if (dev_suppress_commit) {
peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}
#endif
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -1016,7 +991,6 @@ static void send_commit(struct peer *peer)
maybe_send_shutdown(peer);

peer->commit_timer = NULL;
tal_free(tmpctx);
return;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);

Expand All @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 0a6e3d1

Please sign in to comment.