mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
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>
This commit is contained in:
@@ -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:
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user