mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +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:
@@ -174,7 +174,6 @@ static void start_commit_timer(struct peer *peer);
|
|||||||
|
|
||||||
static void billboard_update(const 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;
|
const char *funding_status, *announce_status, *shutdown_status;
|
||||||
|
|
||||||
if (peer->funding_locked[LOCAL] && peer->funding_locked[REMOTE])
|
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 */
|
* our own outgoing payments */
|
||||||
static void send_temporary_announcement(struct peer *peer)
|
static void send_temporary_announcement(struct peer *peer)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx;
|
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
|
||||||
/* If we are supposed to send a real announcement, don't do a
|
/* 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])
|
!peer->funding_locked[REMOTE])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tmpctx = tal_tmpctx(peer);
|
|
||||||
|
|
||||||
msg = towire_gossip_local_add_channel(
|
msg = towire_gossip_local_add_channel(
|
||||||
tmpctx, &peer->short_channel_ids[LOCAL], &peer->chain_hash,
|
tmpctx, &peer->short_channel_ids[LOCAL], &peer->chain_hash,
|
||||||
&peer->node_ids[REMOTE], peer->cltv_delta,
|
&peer->node_ids[REMOTE], peer->cltv_delta,
|
||||||
peer->conf[REMOTE].htlc_minimum_msat, peer->fee_base,
|
peer->conf[REMOTE].htlc_minimum_msat, peer->fee_base,
|
||||||
peer->fee_per_satoshi);
|
peer->fee_per_satoshi);
|
||||||
wire_sync_write(GOSSIP_FD, take(msg));
|
wire_sync_write(GOSSIP_FD, take(msg));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_announcement_signatures(struct peer *peer)
|
static void send_announcement_signatures(struct peer *peer)
|
||||||
{
|
{
|
||||||
/* First 2 + 256 byte are the signatures and msg type, skip them */
|
/* First 2 + 256 byte are the signatures and msg type, skip them */
|
||||||
size_t offset = 258;
|
size_t offset = 258;
|
||||||
const tal_t *tmpctx;
|
|
||||||
struct sha256_double hash;
|
struct sha256_double hash;
|
||||||
u8 *msg, *ca, *req;
|
u8 *msg, *ca, *req;
|
||||||
|
|
||||||
@@ -378,7 +371,6 @@ static void send_announcement_signatures(struct peer *peer)
|
|||||||
!peer->funding_locked[REMOTE])
|
!peer->funding_locked[REMOTE])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tmpctx = tal_tmpctx(peer);
|
|
||||||
status_trace("Exchanging announcement signatures.");
|
status_trace("Exchanging announcement signatures.");
|
||||||
ca = create_channel_announcement(tmpctx, peer);
|
ca = create_channel_announcement(tmpctx, peer);
|
||||||
req = towire_hsm_cannouncement_sig_req(
|
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_node_sigs[LOCAL],
|
||||||
&peer->announcement_bitcoin_sigs[LOCAL]);
|
&peer->announcement_bitcoin_sigs[LOCAL]);
|
||||||
enqueue_peer_msg(peer, take(msg));
|
enqueue_peer_msg(peer, take(msg));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 *create_channel_update(const tal_t *ctx,
|
static u8 *create_channel_update(const tal_t *ctx,
|
||||||
struct peer *peer, bool disabled)
|
struct peer *peer, bool disabled)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u32 timestamp = time_now().ts.tv_sec;
|
u32 timestamp = time_now().ts.tv_sec;
|
||||||
u16 flags;
|
u16 flags;
|
||||||
u8 *cupdate, *msg;
|
u8 *cupdate, *msg;
|
||||||
@@ -460,7 +450,6 @@ static u8 *create_channel_update(const tal_t *ctx,
|
|||||||
status_failed(STATUS_FAIL_HSM_IO,
|
status_failed(STATUS_FAIL_HSM_IO,
|
||||||
"Reading cupdate_sig_req: %s",
|
"Reading cupdate_sig_req: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
tal_free(tmpctx);
|
|
||||||
return cupdate;
|
return cupdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,7 +546,6 @@ static void check_short_ids_match(struct peer *peer)
|
|||||||
|
|
||||||
static void announce_channel(struct peer *peer)
|
static void announce_channel(struct peer *peer)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(peer);
|
|
||||||
u8 *cannounce, *cupdate;
|
u8 *cannounce, *cupdate;
|
||||||
|
|
||||||
check_short_ids_match(peer);
|
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, cannounce);
|
||||||
wire_sync_write(GOSSIP_FD, cupdate);
|
wire_sync_write(GOSSIP_FD, cupdate);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg)
|
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,
|
static bool get_shared_secret(const struct htlc *htlc,
|
||||||
struct secret *shared_secret)
|
struct secret *shared_secret)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(htlc);
|
|
||||||
struct pubkey ephemeral;
|
struct pubkey ephemeral;
|
||||||
struct onionpacket *op;
|
struct onionpacket *op;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
@@ -616,7 +601,6 @@ static bool get_shared_secret(const struct htlc *htlc,
|
|||||||
if (!op) {
|
if (!op) {
|
||||||
/* Return an invalid shared secret. */
|
/* Return an invalid shared secret. */
|
||||||
memset(shared_secret, 0, sizeof(*shared_secret));
|
memset(shared_secret, 0, sizeof(*shared_secret));
|
||||||
tal_free(tmpctx);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +613,6 @@ static bool get_shared_secret(const struct htlc *htlc,
|
|||||||
/* Gives all-zero shares_secret if it was invalid. */
|
/* Gives all-zero shares_secret if it was invalid. */
|
||||||
if (!msg || !fromwire_hsm_ecdh_resp(msg, shared_secret))
|
if (!msg || !fromwire_hsm_ecdh_resp(msg, shared_secret))
|
||||||
status_failed(STATUS_FAIL_HSM_IO, "Reading ecdh response");
|
status_failed(STATUS_FAIL_HSM_IO, "Reading ecdh response");
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
return !memeqzero(shared_secret, sizeof(*shared_secret));
|
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 *commit_sig,
|
||||||
const secp256k1_ecdsa_signature *htlc_sigs)
|
const secp256k1_ecdsa_signature *htlc_sigs)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
struct changed_htlc *changed;
|
struct changed_htlc *changed;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
|
|
||||||
@@ -755,7 +737,6 @@ static u8 *sending_commitsig_msg(const tal_t *ctx,
|
|||||||
msg = towire_channel_sending_commitsig(ctx, remote_commit_index,
|
msg = towire_channel_sending_commitsig(ctx, remote_commit_index,
|
||||||
remote_feerate,
|
remote_feerate,
|
||||||
changed, commit_sig, htlc_sigs);
|
changed, commit_sig, htlc_sigs);
|
||||||
tal_free(tmpctx);
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -852,7 +833,6 @@ static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
|
|||||||
const struct peer *peer,
|
const struct peer *peer,
|
||||||
u64 commit_index)
|
u64 commit_index)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
size_t i;
|
size_t i;
|
||||||
struct bitcoin_tx **txs;
|
struct bitcoin_tx **txs;
|
||||||
const u8 **wscripts;
|
const u8 **wscripts;
|
||||||
@@ -929,13 +909,11 @@ static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
|
|||||||
&commit_sigs->htlc_sigs[i]));
|
&commit_sigs->htlc_sigs[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return commit_sigs;
|
return commit_sigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_commit(struct peer *peer)
|
static void send_commit(struct peer *peer)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(peer);
|
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
const struct htlc **changed_htlcs;
|
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 */
|
/* Hack to suppress all commit sends if dev_disconnect says to */
|
||||||
if (dev_suppress_commit) {
|
if (dev_suppress_commit) {
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -963,7 +940,6 @@ static void send_commit(struct peer *peer)
|
|||||||
/* Mark this as done and try again. */
|
/* Mark this as done and try again. */
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
start_commit_timer(peer);
|
start_commit_timer(peer);
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -976,7 +952,6 @@ static void send_commit(struct peer *peer)
|
|||||||
status_trace("Can't send commit: final shutdown phase");
|
status_trace("Can't send commit: final shutdown phase");
|
||||||
|
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1016,7 +991,6 @@ static void send_commit(struct peer *peer)
|
|||||||
maybe_send_shutdown(peer);
|
maybe_send_shutdown(peer);
|
||||||
|
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1050,7 +1024,6 @@ static void send_commit(struct peer *peer)
|
|||||||
/* Timer now considered expired, you can add a new one. */
|
/* Timer now considered expired, you can add a new one. */
|
||||||
peer->commit_timer = NULL;
|
peer->commit_timer = NULL;
|
||||||
start_commit_timer(peer);
|
start_commit_timer(peer);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_commit_timer(struct peer *peer)
|
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 htlc **changed_htlcs,
|
||||||
const struct bitcoin_tx *committx)
|
const struct bitcoin_tx *committx)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
struct changed_htlc *changed;
|
struct changed_htlc *changed;
|
||||||
struct fulfilled_htlc *fulfilled;
|
struct fulfilled_htlc *fulfilled;
|
||||||
const struct failed_htlc **failed;
|
const struct failed_htlc **failed;
|
||||||
@@ -1187,13 +1159,11 @@ static u8 *got_commitsig_msg(const tal_t *ctx,
|
|||||||
failed,
|
failed,
|
||||||
changed,
|
changed,
|
||||||
committx);
|
committx);
|
||||||
tal_free(tmpctx);
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_peer_commit_sig(struct peer *peer, const u8 *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;
|
struct channel_id channel_id;
|
||||||
secp256k1_ecdsa_signature commit_sig, *htlc_sigs;
|
secp256k1_ecdsa_signature commit_sig, *htlc_sigs;
|
||||||
struct pubkey remote_htlckey, point;
|
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),
|
master_wait_sync_reply(tmpctx, peer, take(msg),
|
||||||
WIRE_CHANNEL_GOT_COMMITSIG_REPLY);
|
WIRE_CHANNEL_GOT_COMMITSIG_REPLY);
|
||||||
tal_free(tmpctx);
|
|
||||||
return send_revocation(peer);
|
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 pubkey *next_per_commit_point,
|
||||||
const struct htlc **changed_htlcs)
|
const struct htlc **changed_htlcs)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
struct changed_htlc *changed = tal_arr(tmpctx, struct changed_htlc, 0);
|
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,
|
msg = towire_channel_got_revoke(ctx, revoke_num, per_commitment_secret,
|
||||||
next_per_commit_point, changed);
|
next_per_commit_point, changed);
|
||||||
tal_free(tmpctx);
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1349,7 +1316,6 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
|
|||||||
struct privkey privkey;
|
struct privkey privkey;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct pubkey per_commit_point, next_per_commit;
|
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);
|
const struct htlc **changed_htlcs = tal_arr(msg, const struct htlc *, 0);
|
||||||
|
|
||||||
if (!fromwire_revoke_and_ack(msg, &channel_id, &old_commit_secret,
|
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));
|
&peer->old_remote_per_commit));
|
||||||
|
|
||||||
start_commit_timer(peer);
|
start_commit_timer(peer);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg)
|
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,
|
struct peer *peer,
|
||||||
const struct short_channel_id *scid)
|
const struct short_channel_id *scid)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u8 *msg, *update;
|
u8 *msg, *update;
|
||||||
|
|
||||||
msg = towire_gossip_get_update(tmpctx, scid);
|
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))
|
if (!fromwire_gossip_get_update_reply(ctx, msg, &update))
|
||||||
status_failed(STATUS_FAIL_GOSSIP_IO,
|
status_failed(STATUS_FAIL_GOSSIP_IO,
|
||||||
"Invalid update reply");
|
"Invalid update reply");
|
||||||
tal_free(tmpctx);
|
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
u64 obscured_commitment_number,
|
u64 obscured_commitment_number,
|
||||||
enum side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u64 base_fee_msat;
|
u64 base_fee_msat;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
size_t i, n, untrimmed;
|
size_t i, n, untrimmed;
|
||||||
@@ -287,6 +286,5 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
|||||||
/* Input amount needed for signature code. */
|
/* Input amount needed for signature code. */
|
||||||
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
|
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,12 +293,10 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
struct htlc **htlcp,
|
struct htlc **htlcp,
|
||||||
bool enforce_aggregate_limits)
|
bool enforce_aggregate_limits)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
struct htlc *htlc, *old;
|
struct htlc *htlc, *old;
|
||||||
s64 msat_in_htlcs, fee_msat, balance_msat;
|
s64 msat_in_htlcs, fee_msat, balance_msat;
|
||||||
enum side sender = htlc_state_owner(state), recipient = !sender;
|
enum side sender = htlc_state_owner(state), recipient = !sender;
|
||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
enum channel_add_err e;
|
|
||||||
const struct channel_view *view;
|
const struct channel_view *view;
|
||||||
size_t i;
|
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.
|
* `cltv_expiry` to greater or equal to 500000000.
|
||||||
*/
|
*/
|
||||||
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) {
|
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) {
|
||||||
e = CHANNEL_ERR_INVALID_EXPIRY;
|
return CHANNEL_ERR_INVALID_EXPIRY;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
htlc->rhash = *payment_hash;
|
htlc->rhash = *payment_hash;
|
||||||
@@ -333,10 +330,9 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
|| old->msatoshi != htlc->msatoshi
|
|| old->msatoshi != htlc->msatoshi
|
||||||
|| old->expiry.locktime != htlc->expiry.locktime
|
|| old->expiry.locktime != htlc->expiry.locktime
|
||||||
|| !structeq(&old->rhash, &htlc->rhash))
|
|| !structeq(&old->rhash, &htlc->rhash))
|
||||||
e = CHANNEL_ERR_DUPLICATE_ID_DIFFERENT;
|
return CHANNEL_ERR_DUPLICATE_ID_DIFFERENT;
|
||||||
else
|
else
|
||||||
e = CHANNEL_ERR_DUPLICATE;
|
return CHANNEL_ERR_DUPLICATE;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're always considering the recipient's view of the channel here */
|
/* 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...
|
* or...
|
||||||
*/
|
*/
|
||||||
if (htlc->msatoshi == 0) {
|
if (htlc->msatoshi == 0) {
|
||||||
e = CHANNEL_ERR_HTLC_BELOW_MINIMUM;
|
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
if (htlc->msatoshi < htlc_minimum_msat(channel, recipient)) {
|
if (htlc->msatoshi < htlc_minimum_msat(channel, recipient)) {
|
||||||
e = CHANNEL_ERR_HTLC_BELOW_MINIMUM;
|
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
@@ -364,8 +358,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
* `amount_msat` to zero.
|
* `amount_msat` to zero.
|
||||||
*/
|
*/
|
||||||
if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) {
|
if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) {
|
||||||
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Figure out what receiver will already be committed to. */
|
/* 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
|
if (enforce_aggregate_limits
|
||||||
&& tal_count(committed) - tal_count(removing) + tal_count(adding)
|
&& tal_count(committed) - tal_count(removing) + tal_count(adding)
|
||||||
> max_accepted_htlcs(channel, recipient)) {
|
> max_accepted_htlcs(channel, recipient)) {
|
||||||
e = CHANNEL_ERR_TOO_MANY_HTLCS;
|
return CHANNEL_ERR_TOO_MANY_HTLCS;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msat_in_htlcs = total_offered_msatoshis(committed, htlc_owner(htlc))
|
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 */
|
* HTLCs to its local commitment transaction */
|
||||||
if (enforce_aggregate_limits
|
if (enforce_aggregate_limits
|
||||||
&& msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
|
&& msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
|
||||||
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
@@ -446,13 +437,11 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
", reserve is %"PRIu64,
|
", reserve is %"PRIu64,
|
||||||
balance_msat, fee_msat,
|
balance_msat, fee_msat,
|
||||||
channel_reserve_msat(channel, sender));
|
channel_reserve_msat(channel, sender));
|
||||||
e = CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_htlc(htlc, "NEW:");
|
dump_htlc(htlc, "NEW:");
|
||||||
htlc_map_add(channel->htlcs, tal_steal(channel, htlc));
|
htlc_map_add(channel->htlcs, tal_steal(channel, htlc));
|
||||||
e = CHANNEL_ERR_ADD_OK;
|
|
||||||
if (htlcp)
|
if (htlcp)
|
||||||
*htlcp = htlc;
|
*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)
|
if (htlc_state_flags(htlc->state) & HTLC_REMOTE_F_PENDING)
|
||||||
channel->changes_pending[REMOTE] = true;
|
channel->changes_pending[REMOTE] = true;
|
||||||
|
|
||||||
out:
|
return CHANNEL_ERR_ADD_OK;
|
||||||
tal_free(tmpctx);
|
|
||||||
return e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum channel_add_err channel_add_htlc(struct channel *channel,
|
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;
|
size_t num;
|
||||||
u64 weight;
|
u64 weight;
|
||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
|
|
||||||
gather_htlcs(tmpctx, channel, !channel->funder,
|
gather_htlcs(tmpctx, channel, !channel->funder,
|
||||||
&committed, &removing, &adding);
|
&committed, &removing, &adding);
|
||||||
|
|
||||||
/* Assume none are trimmed; this gives lower bound on feerate. */
|
/* Assume none are trimmed; this gives lower bound on feerate. */
|
||||||
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
|
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
weight = 724 + 172 * num;
|
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);
|
u64 fee_msat, dust = dust_limit_satoshis(channel, !channel->funder);
|
||||||
size_t untrimmed;
|
size_t untrimmed;
|
||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
|
|
||||||
gather_htlcs(tmpctx, channel, !channel->funder,
|
gather_htlcs(tmpctx, channel, !channel->funder,
|
||||||
&committed, &removing, &adding);
|
&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);
|
fee_msat = commit_tx_base_fee(feerate_per_kw, untrimmed);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
/* BOLT #2:
|
/* BOLT #2:
|
||||||
*
|
*
|
||||||
* A receiving node SHOULD fail the channel if the sender cannot afford
|
* A receiving node SHOULD fail the channel if the sender cannot afford
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ void status_fmt(enum log_level level UNUSED, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *trc;
|
|
||||||
|
|
||||||
/* bitcoind loves its backwards txids! */
|
/* bitcoind loves its backwards txids! */
|
||||||
static struct bitcoin_txid txid_from_hex(const char *hex)
|
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,
|
static void tx_must_be_eq(const struct bitcoin_tx *a,
|
||||||
const struct bitcoin_tx *b)
|
const struct bitcoin_tx *b)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 *lina, *linb;
|
u8 *lina, *linb;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@@ -211,7 +208,6 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
|
|||||||
"%s",
|
"%s",
|
||||||
tal_hex(tmpctx, lina),
|
tal_hex(tmpctx, lina),
|
||||||
tal_hex(tmpctx, linb));
|
tal_hex(tmpctx, linb));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void txs_must_be_eq(struct bitcoin_tx **a, struct bitcoin_tx **b)
|
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct bitcoin_txid funding_txid;
|
struct bitcoin_txid funding_txid;
|
||||||
/* We test from both sides. */
|
/* We test from both sides. */
|
||||||
struct channel *lchannel, *rchannel;
|
struct channel *lchannel, *rchannel;
|
||||||
u64 funding_amount_satoshi;
|
u64 funding_amount_satoshi;
|
||||||
u32 *feerate_per_kw = tal_arr(tmpctx, u32, NUM_SIDES);
|
u32 *feerate_per_kw;
|
||||||
unsigned int funding_output_index;
|
unsigned int funding_output_index;
|
||||||
struct keyset keyset;
|
struct keyset keyset;
|
||||||
struct pubkey local_funding_pubkey, remote_funding_pubkey;
|
struct pubkey local_funding_pubkey, remote_funding_pubkey;
|
||||||
struct pubkey local_per_commitment_point;
|
struct pubkey local_per_commitment_point;
|
||||||
struct basepoints localbase, remotebase;
|
struct basepoints localbase, remotebase;
|
||||||
struct pubkey *unknown = tal(tmpctx, struct pubkey);
|
struct pubkey *unknown;
|
||||||
struct bitcoin_tx *raw_tx, **txs, **txs2;
|
struct bitcoin_tx *raw_tx, **txs, **txs2;
|
||||||
struct channel_config *local_config = tal(tmpctx, struct channel_config);
|
struct channel_config *local_config, *remote_config;
|
||||||
struct channel_config *remote_config = tal(tmpctx, struct channel_config);
|
|
||||||
u64 to_local_msat, to_remote_msat;
|
u64 to_local_msat, to_remote_msat;
|
||||||
const struct htlc **htlc_map, **htlcs;
|
const struct htlc **htlc_map, **htlcs;
|
||||||
const u8 *funding_wscript, **wscripts;
|
const u8 *funding_wscript, **wscripts;
|
||||||
@@ -343,8 +337,12 @@ int main(void)
|
|||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| 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:
|
/* BOLT #3:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -410,7 +410,6 @@ static char *decode_r(struct bolt11 *b11,
|
|||||||
u5 **data, size_t *data_len,
|
u5 **data, size_t *data_len,
|
||||||
size_t data_length)
|
size_t data_length)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(b11);
|
|
||||||
size_t rlen = data_length * 5 / 8;
|
size_t rlen = data_length * 5 / 8;
|
||||||
u8 *r8 = tal_arr(tmpctx, u8, rlen);
|
u8 *r8 = tal_arr(tmpctx, u8, rlen);
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
@@ -423,7 +422,6 @@ static char *decode_r(struct bolt11 *b11,
|
|||||||
do {
|
do {
|
||||||
tal_resize(&r, n+1);
|
tal_resize(&r, n+1);
|
||||||
if (!fromwire_route_info(&cursor, &rlen, &r[n])) {
|
if (!fromwire_route_info(&cursor, &rlen, &r[n])) {
|
||||||
tal_free(tmpctx);
|
|
||||||
return tal_fmt(b11, "r: hop %zu truncated", n);
|
return tal_fmt(b11, "r: hop %zu truncated", n);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
@@ -434,7 +432,6 @@ static char *decode_r(struct bolt11 *b11,
|
|||||||
tal_resize(&b11->routes, n+1);
|
tal_resize(&b11->routes, n+1);
|
||||||
b11->routes[n] = tal_steal(b11, r);
|
b11->routes[n] = tal_steal(b11, r);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +461,6 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
|
|||||||
u5 *data;
|
u5 *data;
|
||||||
size_t data_len;
|
size_t data_len;
|
||||||
struct bolt11 *b11 = new_bolt11(ctx, NULL);
|
struct bolt11 *b11 = new_bolt11(ctx, NULL);
|
||||||
tal_t *tmpctx = tal_tmpctx(b11);
|
|
||||||
u8 sig_and_recid[65];
|
u8 sig_and_recid[65];
|
||||||
secp256k1_ecdsa_recoverable_signature sig;
|
secp256k1_ecdsa_recoverable_signature sig;
|
||||||
struct hash_u5 hu5;
|
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");
|
return decode_fail(b11, fail, "invalid signature");
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return b11;
|
return b11;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +888,6 @@ char *bolt11_encode_(const tal_t *ctx,
|
|||||||
void *arg),
|
void *arg),
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u5 *data = tal_arr(tmpctx, u5, 0);
|
u5 *data = tal_arr(tmpctx, u5, 0);
|
||||||
char *hrp, *output;
|
char *hrp, *output;
|
||||||
char postfix;
|
char postfix;
|
||||||
@@ -971,12 +965,12 @@ char *bolt11_encode_(const tal_t *ctx,
|
|||||||
|
|
||||||
/* FIXME: towire_ should check this? */
|
/* FIXME: towire_ should check this? */
|
||||||
if (tal_len(data) > 65535)
|
if (tal_len(data) > 65535)
|
||||||
return tal_free(tmpctx);
|
return NULL;
|
||||||
|
|
||||||
/* Need exact length here */
|
/* Need exact length here */
|
||||||
hrpu8 = tal_dup_arr(tmpctx, u8, (const u8 *)hrp, strlen(hrp), 0);
|
hrpu8 = tal_dup_arr(tmpctx, u8, (const u8 *)hrp, strlen(hrp), 0);
|
||||||
if (!sign(data, hrpu8, &rsig, arg))
|
if (!sign(data, hrpu8, &rsig, arg))
|
||||||
return tal_free(tmpctx);
|
return NULL;
|
||||||
|
|
||||||
secp256k1_ecdsa_recoverable_signature_serialize_compact(
|
secp256k1_ecdsa_recoverable_signature_serialize_compact(
|
||||||
secp256k1_ctx,
|
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))
|
if (!bech32_encode(output, hrp, data, tal_count(data), (size_t)-1))
|
||||||
output = tal_free(output);
|
output = tal_free(output);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
u64 obscured_commitment_number,
|
u64 obscured_commitment_number,
|
||||||
enum side side)
|
enum side side)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
u64 base_fee_msat;
|
u64 base_fee_msat;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
size_t n, untrimmed;
|
size_t n, untrimmed;
|
||||||
@@ -195,6 +194,5 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
|||||||
/* Input amount needed for signature code. */
|
/* Input amount needed for signature code. */
|
||||||
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
|
tx->input[0].amount = tal_dup(tx->input, u64, &funding_satoshis);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,7 +530,6 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
|
|||||||
const struct secret *shared_secrets,
|
const struct secret *shared_secrets,
|
||||||
const int numhops, const u8 *reply)
|
const int numhops, const u8 *reply)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
struct onionreply *oreply = tal(tmpctx, struct onionreply);
|
struct onionreply *oreply = tal(tmpctx, struct onionreply);
|
||||||
u8 *msg = tal_arr(oreply, u8, tal_len(reply));
|
u8 *msg = tal_arr(oreply, u8, tal_len(reply));
|
||||||
u8 key[KEY_LEN], hmac[HMAC_SIZE];
|
u8 key[KEY_LEN], hmac[HMAC_SIZE];
|
||||||
@@ -539,7 +538,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
|
|||||||
u16 msglen;
|
u16 msglen;
|
||||||
|
|
||||||
if (tal_len(reply) != ONION_REPLY_SIZE + sizeof(hmac) + 4) {
|
if (tal_len(reply) != ONION_REPLY_SIZE + sizeof(hmac) + 4) {
|
||||||
goto fail;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(msg, reply, tal_len(reply));
|
memcpy(msg, reply, tal_len(reply));
|
||||||
@@ -561,7 +560,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (oreply->origin_index == -1) {
|
if (oreply->origin_index == -1) {
|
||||||
goto fail;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = msg + sizeof(hmac);
|
cursor = msg + sizeof(hmac);
|
||||||
@@ -569,15 +568,13 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
|
|||||||
msglen = fromwire_u16(&cursor, &max);
|
msglen = fromwire_u16(&cursor, &max);
|
||||||
|
|
||||||
if (msglen > ONION_REPLY_SIZE) {
|
if (msglen > ONION_REPLY_SIZE) {
|
||||||
goto fail;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
oreply->msg = tal_arr(oreply, u8, msglen);
|
oreply->msg = tal_arr(oreply, u8, msglen);
|
||||||
fromwire(&cursor, &max, oreply->msg, msglen);
|
fromwire(&cursor, &max, oreply->msg, msglen);
|
||||||
|
|
||||||
tal_steal(ctx, oreply);
|
tal_steal(ctx, oreply);
|
||||||
tal_free(tmpctx);
|
|
||||||
return oreply;
|
return oreply;
|
||||||
fail:
|
|
||||||
return tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ static void test_b11(const char *b11str,
|
|||||||
const char *hashed_desc)
|
const char *hashed_desc)
|
||||||
{
|
{
|
||||||
struct bolt11 *b11;
|
struct bolt11 *b11;
|
||||||
const void *tmpctx = tal_tmpctx(NULL);
|
|
||||||
char *fail;
|
char *fail;
|
||||||
char *reproduce;
|
char *reproduce;
|
||||||
|
|
||||||
@@ -111,7 +110,6 @@ static void test_b11(const char *b11str,
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
assert(streq(reproduce, b11str));
|
assert(streq(reproduce, b11str));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@@ -119,10 +117,10 @@ int main(void)
|
|||||||
struct bolt11 *b11;
|
struct bolt11 *b11;
|
||||||
struct pubkey node;
|
struct pubkey node;
|
||||||
u64 msatoshi;
|
u64 msatoshi;
|
||||||
const void *ctx = tal_tmpctx(NULL);
|
|
||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
/* BOLT #11:
|
/* BOLT #11:
|
||||||
*
|
*
|
||||||
@@ -159,7 +157,7 @@ int main(void)
|
|||||||
* * `8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcq`: signature
|
* * `8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcq`: signature
|
||||||
* * `ca784w`: Bech32 checksum
|
* * `ca784w`: Bech32 checksum
|
||||||
*/
|
*/
|
||||||
b11 = new_bolt11(ctx, NULL);
|
b11 = new_bolt11(tmpctx, NULL);
|
||||||
b11->chain = chainparams_for_network("bitcoin");
|
b11->chain = chainparams_for_network("bitcoin");
|
||||||
b11->timestamp = 1496314658;
|
b11->timestamp = 1496314658;
|
||||||
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
||||||
@@ -193,7 +191,7 @@ int main(void)
|
|||||||
* * `fj9srp`: Bech32 checksum
|
* * `fj9srp`: Bech32 checksum
|
||||||
*/
|
*/
|
||||||
msatoshi = 2500 * (1000ULL * 100000000) / 1000000;
|
msatoshi = 2500 * (1000ULL * 100000000) / 1000000;
|
||||||
b11 = new_bolt11(ctx, &msatoshi);
|
b11 = new_bolt11(tmpctx, &msatoshi);
|
||||||
b11->chain = chainparams_for_network("bitcoin");
|
b11->chain = chainparams_for_network("bitcoin");
|
||||||
b11->timestamp = 1496314658;
|
b11->timestamp = 1496314658;
|
||||||
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
||||||
@@ -225,7 +223,7 @@ int main(void)
|
|||||||
* * `2yxxz7`: Bech32 checksum
|
* * `2yxxz7`: Bech32 checksum
|
||||||
*/
|
*/
|
||||||
msatoshi = 20 * (1000ULL * 100000000) / 1000;
|
msatoshi = 20 * (1000ULL * 100000000) / 1000;
|
||||||
b11 = new_bolt11(ctx, &msatoshi);
|
b11 = new_bolt11(tmpctx, &msatoshi);
|
||||||
b11->chain = chainparams_for_network("bitcoin");
|
b11->chain = chainparams_for_network("bitcoin");
|
||||||
b11->timestamp = 1496314658;
|
b11->timestamp = 1496314658;
|
||||||
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
|
||||||
@@ -239,6 +237,6 @@ int main(void)
|
|||||||
/* FIXME: Test the others! */
|
/* FIXME: Test the others! */
|
||||||
|
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,48 +28,49 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct wireaddr addr;
|
struct wireaddr addr;
|
||||||
tal_t *ctx = tal_tmpctx(NULL);
|
|
||||||
char *ip;
|
char *ip;
|
||||||
u16 port;
|
u16 port;
|
||||||
|
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
/* Grossly invalid. */
|
/* Grossly invalid. */
|
||||||
assert(!separate_address_and_port(ctx, "[", &ip, &port));
|
assert(!separate_address_and_port(tmpctx, "[", &ip, &port));
|
||||||
assert(!separate_address_and_port(ctx, "[123", &ip, &port));
|
assert(!separate_address_and_port(tmpctx, "[123", &ip, &port));
|
||||||
assert(!separate_address_and_port(ctx, "[::1]:8f", &ip, &port));
|
assert(!separate_address_and_port(tmpctx, "[::1]:8f", &ip, &port));
|
||||||
assert(!separate_address_and_port(ctx, "127.0.0.1:8f", &ip, &port));
|
assert(!separate_address_and_port(tmpctx, "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(tmpctx, "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, "127.0.0.1:ff", &ip, &port));
|
||||||
|
|
||||||
/* ret = getaddrinfo("[::1]:80", NULL, NULL, &res); */
|
/* 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(streq(ip, "::1"));
|
||||||
assert(port == 80);
|
assert(port == 80);
|
||||||
|
|
||||||
port = 0;
|
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(streq(ip, "ip6-localhost"));
|
||||||
assert(port == 0);
|
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(streq(ip, "::1"));
|
||||||
assert(port == 0);
|
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(streq(ip, "192.168.1.1"));
|
||||||
assert(port == 8000);
|
assert(port == 8000);
|
||||||
|
|
||||||
port = 0;
|
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(streq(ip, "192.168.2.255"));
|
||||||
assert(port == 0);
|
assert(port == 0);
|
||||||
|
|
||||||
// unusual but possibly valid case
|
// 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(streq(ip, "::1"));
|
||||||
assert(port == 0);
|
assert(port == 0);
|
||||||
|
|
||||||
// service names not supported yet
|
// 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
|
// localhost hostnames for backward compat
|
||||||
parse_wireaddr("localhost", &addr, 200, NULL);
|
parse_wireaddr("localhost", &addr, 200, NULL);
|
||||||
@@ -78,18 +79,18 @@ int main(void)
|
|||||||
// string should win the port battle
|
// string should win the port battle
|
||||||
parse_wireaddr("[::1]:9735", &addr, 500, NULL);
|
parse_wireaddr("[::1]:9735", &addr, 500, NULL);
|
||||||
assert(addr.port == 9735);
|
assert(addr.port == 9735);
|
||||||
ip = fmt_wireaddr(ctx, &addr);
|
ip = fmt_wireaddr(tmpctx, &addr);
|
||||||
assert(streq(ip, "[::1]:9735"));
|
assert(streq(ip, "[::1]:9735"));
|
||||||
|
|
||||||
// should use argument if we have no port in string
|
// should use argument if we have no port in string
|
||||||
parse_wireaddr("2001:db8:85a3::8a2e:370:7334", &addr, 9777, NULL);
|
parse_wireaddr("2001:db8:85a3::8a2e:370:7334", &addr, 9777, NULL);
|
||||||
assert(addr.port == 9777);
|
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(streq(ip, "[2001:db8:85a3::8a2e:370:7334]:9777"));
|
||||||
|
|
||||||
assert(parse_wireaddr("[::ffff:127.0.0.1]:49150", &addr, 1, NULL));
|
assert(parse_wireaddr("[::ffff:127.0.0.1]:49150", &addr, 1, NULL));
|
||||||
assert(addr.port == 49150);
|
assert(addr.port == 49150);
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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. */
|
* we match the test vectors and that we can also unwrap it. */
|
||||||
static void run_unit_tests(void)
|
static void run_unit_tests(void)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct onionreply *oreply;
|
struct onionreply *oreply;
|
||||||
u8 *reply;
|
u8 *reply;
|
||||||
u8 *raw = tal_hexdata(tmpctx, "2002", 4);
|
u8 *raw = tal_hexdata(tmpctx, "2002", 4);
|
||||||
@@ -155,19 +154,17 @@ static void run_unit_tests(void)
|
|||||||
oreply = unwrap_onionreply(tmpctx, ss, 5, reply);
|
oreply = unwrap_onionreply(tmpctx, ss, 5, reply);
|
||||||
printf("unwrapped %s\n", tal_hex(tmpctx, oreply->msg));
|
printf("unwrapped %s\n", tal_hex(tmpctx, oreply->msg));
|
||||||
assert(memcmp(raw, oreply->msg, tal_len(raw)) == 0);
|
assert(memcmp(raw, oreply->msg, tal_len(raw)) == 0);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
bool generate = false, decode = false, unit = false;
|
bool generate = false, decode = false, unit = false;
|
||||||
const tal_t *ctx = talz(NULL, tal_t);
|
|
||||||
u8 assocdata[32];
|
u8 assocdata[32];
|
||||||
memset(assocdata, 'B', sizeof(assocdata));
|
memset(assocdata, 'B', sizeof(assocdata));
|
||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(
|
secp256k1_ctx = secp256k1_context_create(
|
||||||
SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
|
SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||||
"--generate <pubkey1> <pubkey2>... OR\n"
|
"--generate <pubkey1> <pubkey2>... OR\n"
|
||||||
@@ -194,6 +191,6 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
opt_free_table();
|
opt_free_table();
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,8 @@ struct oneshot *new_reltimer_(struct timers *timers,
|
|||||||
void timer_expired(tal_t *ctx, struct timer *timer)
|
void timer_expired(tal_t *ctx, struct timer *timer)
|
||||||
{
|
{
|
||||||
struct oneshot *t = container_of(timer, struct oneshot, 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 */
|
/* If it doesn't free itself, freeing tmpctx will do it */
|
||||||
tal_steal(tmpctx, t);
|
tal_steal(tmpctx, t);
|
||||||
t->cb(t->arg);
|
t->cb(t->arg);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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. */
|
/* 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);
|
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. */
|
/* Global temporary convenience context: freed in io loop core. */
|
||||||
extern const tal_t *tmpctx;
|
extern const tal_t *tmpctx;
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
* 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.
|
* 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 **addr, u16 *port)
|
||||||
{
|
{
|
||||||
char *portcolon;
|
char *portcolon;
|
||||||
@@ -126,7 +126,6 @@ bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 defport,
|
|||||||
u16 port;
|
u16 port;
|
||||||
char *ip;
|
char *ip;
|
||||||
bool res;
|
bool res;
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
|
|
||||||
res = false;
|
res = false;
|
||||||
port = defport;
|
port = defport;
|
||||||
@@ -195,6 +194,5 @@ bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 defport,
|
|||||||
finish:
|
finish:
|
||||||
if (!res && err_msg && !*err_msg)
|
if (!res && err_msg && !*err_msg)
|
||||||
*err_msg = "Error parsing hostname";
|
*err_msg = "Error parsing hostname";
|
||||||
tal_free(tmpctx);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -456,7 +456,6 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
|
|||||||
|
|
||||||
static void send_node_announcement(struct daemon *daemon)
|
static void send_node_announcement(struct daemon *daemon)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(daemon);
|
|
||||||
u32 timestamp = time_now().ts.tv_sec;
|
u32 timestamp = time_now().ts.tv_sec;
|
||||||
secp256k1_ecdsa_signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
u8 *msg, *nannounce, *err;
|
u8 *msg, *nannounce, *err;
|
||||||
@@ -484,7 +483,6 @@ static void send_node_announcement(struct daemon *daemon)
|
|||||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
"rejected own node announcement: %s",
|
"rejected own node announcement: %s",
|
||||||
tal_hex(tmpctx, err));
|
tal_hex(tmpctx, err));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns error if we should send an error. */
|
/* 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,
|
static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
|
||||||
u8 *msg)
|
u8 *msg)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(msg);
|
|
||||||
struct pubkey source, destination;
|
struct pubkey source, destination;
|
||||||
u32 msatoshi, final_cltv;
|
u32 msatoshi, final_cltv;
|
||||||
u16 riskfactor;
|
u16 riskfactor;
|
||||||
@@ -1114,7 +1111,6 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
|
|||||||
fuzz, &seed);
|
fuzz, &seed);
|
||||||
|
|
||||||
out = towire_gossip_getroute_reply(msg, hops);
|
out = towire_gossip_getroute_reply(msg, hops);
|
||||||
tal_free(tmpctx);
|
|
||||||
daemon_conn_send(&daemon->master, out);
|
daemon_conn_send(&daemon->master, out);
|
||||||
return daemon_conn_read_next(conn, &daemon->master);
|
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,
|
static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daemon,
|
||||||
u8 *msg)
|
u8 *msg)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(daemon);
|
|
||||||
u8 *out;
|
u8 *out;
|
||||||
struct gossip_getchannels_entry *entries;
|
struct gossip_getchannels_entry *entries;
|
||||||
struct chan *chan;
|
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);
|
out = towire_gossip_getchannels_reply(daemon, entries);
|
||||||
daemon_conn_send(&daemon->master, take(out));
|
daemon_conn_send(&daemon->master, take(out));
|
||||||
tal_free(tmpctx);
|
|
||||||
return daemon_conn_read_next(conn, &daemon->master);
|
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,
|
static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon,
|
||||||
const u8 *msg)
|
const u8 *msg)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(daemon);
|
|
||||||
u8 *out;
|
u8 *out;
|
||||||
struct node *n;
|
struct node *n;
|
||||||
const struct gossip_getnodes_entry **nodes;
|
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);
|
out = towire_gossip_getnodes_reply(daemon, nodes);
|
||||||
daemon_conn_send(&daemon->master, take(out));
|
daemon_conn_send(&daemon->master, take(out));
|
||||||
tal_free(tmpctx);
|
|
||||||
return daemon_conn_read_next(conn, &daemon->master);
|
return daemon_conn_read_next(conn, &daemon->master);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1326,7 +1318,6 @@ fail:
|
|||||||
static void gossip_send_keepalive_update(struct routing_state *rstate,
|
static void gossip_send_keepalive_update(struct routing_state *rstate,
|
||||||
struct half_chan *hc)
|
struct half_chan *hc)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(rstate);
|
|
||||||
secp256k1_ecdsa_signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
struct bitcoin_blkid chain_hash;
|
struct bitcoin_blkid chain_hash;
|
||||||
struct short_channel_id scid;
|
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,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
"rejected keepalive channel_update: %s",
|
"rejected keepalive channel_update: %s",
|
||||||
tal_hex(tmpctx, err));
|
tal_hex(tmpctx, err));
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gossip_refresh_network(struct daemon *daemon)
|
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,
|
static struct io_plan *handle_disable_channel(struct io_conn *conn,
|
||||||
struct daemon *daemon, u8 *msg)
|
struct daemon *daemon, u8 *msg)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(msg);
|
|
||||||
struct short_channel_id scid;
|
struct short_channel_id scid;
|
||||||
u8 direction;
|
u8 direction;
|
||||||
struct chan *chan;
|
struct chan *chan;
|
||||||
@@ -1947,7 +1935,6 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
|
|||||||
tal_hex(tmpctx, err));
|
tal_hex(tmpctx, err));
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
tal_free(tmpctx);
|
|
||||||
return daemon_conn_read_next(conn, &daemon->master);
|
return daemon_conn_read_next(conn, &daemon->master);
|
||||||
}
|
}
|
||||||
static struct io_plan *handle_routing_failure(struct io_conn *conn,
|
static struct io_plan *handle_routing_failure(struct io_conn *conn,
|
||||||
|
|||||||
@@ -893,7 +893,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
u64 htlc_minimum_msat;
|
u64 htlc_minimum_msat;
|
||||||
u32 fee_base_msat;
|
u32 fee_base_msat;
|
||||||
u32 fee_proportional_millionths;
|
u32 fee_proportional_millionths;
|
||||||
const tal_t *tmpctx = tal_tmpctx(rstate);
|
|
||||||
struct bitcoin_blkid chain_hash;
|
struct bitcoin_blkid chain_hash;
|
||||||
struct chan *chan;
|
struct chan *chan;
|
||||||
u8 direction;
|
u8 direction;
|
||||||
@@ -909,7 +908,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
err = towire_errorfmt(rstate, NULL,
|
err = towire_errorfmt(rstate, NULL,
|
||||||
"Malformed channel_update %s",
|
"Malformed channel_update %s",
|
||||||
tal_hex(tmpctx, serialized));
|
tal_hex(tmpctx, serialized));
|
||||||
tal_free(tmpctx);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
direction = flags & 0x1;
|
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",
|
status_trace("Received channel_update for unknown chain %s",
|
||||||
type_to_string(tmpctx, struct bitcoin_blkid,
|
type_to_string(tmpctx, struct bitcoin_blkid,
|
||||||
&chain_hash));
|
&chain_hash));
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +934,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
if (pending) {
|
if (pending) {
|
||||||
update_pending(pending,
|
update_pending(pending,
|
||||||
timestamp, serialized, direction);
|
timestamp, serialized, direction);
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -945,7 +941,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
SUPERVERBOSE("Ignoring update for unknown channel %s",
|
SUPERVERBOSE("Ignoring update for unknown channel %s",
|
||||||
type_to_string(tmpctx, struct short_channel_id,
|
type_to_string(tmpctx, struct short_channel_id,
|
||||||
&short_channel_id));
|
&short_channel_id));
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -954,7 +949,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
|
|
||||||
if (c->last_timestamp >= timestamp) {
|
if (c->last_timestamp >= timestamp) {
|
||||||
SUPERVERBOSE("Ignoring outdated update.");
|
SUPERVERBOSE("Ignoring outdated update.");
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -970,7 +964,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
* - MUST NOT process the message further.
|
* - MUST NOT process the message further.
|
||||||
* - SHOULD fail the connection.
|
* - SHOULD fail the connection.
|
||||||
*/
|
*/
|
||||||
tal_free(tmpctx);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -992,7 +985,6 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
|
|||||||
&chan->half[direction].channel_update_msgidx,
|
&chan->half[direction].channel_update_msgidx,
|
||||||
take(serialized));
|
take(serialized));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1041,7 +1033,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
u8 rgb_color[3];
|
u8 rgb_color[3];
|
||||||
u8 alias[32];
|
u8 alias[32];
|
||||||
u8 *features, *addresses;
|
u8 *features, *addresses;
|
||||||
const tal_t *tmpctx = tal_tmpctx(rstate);
|
|
||||||
struct wireaddr *wireaddrs;
|
struct wireaddr *wireaddrs;
|
||||||
struct pending_node_announce *pna;
|
struct pending_node_announce *pna;
|
||||||
size_t len = tal_len(node_ann);
|
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,
|
u8 *err = towire_errorfmt(rstate, NULL,
|
||||||
"Malformed node_announcement %s",
|
"Malformed node_announcement %s",
|
||||||
tal_hex(tmpctx, node_ann));
|
tal_hex(tmpctx, node_ann));
|
||||||
tal_free(tmpctx);
|
|
||||||
return err;
|
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.",
|
status_trace("Ignoring node announcement for node %s, unsupported features %s.",
|
||||||
type_to_string(tmpctx, struct pubkey, &node_id),
|
type_to_string(tmpctx, struct pubkey, &node_id),
|
||||||
tal_hex(tmpctx, features));
|
tal_hex(tmpctx, features));
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1099,7 +1088,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
struct sha256_double,
|
struct sha256_double,
|
||||||
&hash),
|
&hash),
|
||||||
tal_hex(tmpctx, node_ann));
|
tal_hex(tmpctx, node_ann));
|
||||||
tal_free(tmpctx);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1115,7 +1103,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
"Malformed wireaddrs %s in %s.",
|
"Malformed wireaddrs %s in %s.",
|
||||||
tal_hex(tmpctx, wireaddrs),
|
tal_hex(tmpctx, wireaddrs),
|
||||||
tal_hex(tmpctx, node_ann));
|
tal_hex(tmpctx, node_ann));
|
||||||
tal_free(tmpctx);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1135,7 +1122,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
tal_free(pna->node_announcement);
|
tal_free(pna->node_announcement);
|
||||||
pna->node_announcement = tal_dup_arr(pna, u8, node_ann, tal_len(node_ann), 0);
|
pna->node_announcement = tal_dup_arr(pna, u8, node_ann, tal_len(node_ann), 0);
|
||||||
}
|
}
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1151,11 +1137,9 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
"node %s preceded by at least "
|
"node %s preceded by at least "
|
||||||
"channel_announcement?",
|
"channel_announcement?",
|
||||||
type_to_string(tmpctx, struct pubkey, &node_id));
|
type_to_string(tmpctx, struct pubkey, &node_id));
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (node->last_timestamp >= timestamp) {
|
} else if (node->last_timestamp >= timestamp) {
|
||||||
SUPERVERBOSE("Ignoring node announcement, it's outdated.");
|
SUPERVERBOSE("Ignoring node announcement, it's outdated.");
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1174,11 +1158,10 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
|||||||
replace_broadcast(node, rstate->broadcasts,
|
replace_broadcast(node, rstate->broadcasts,
|
||||||
&node->node_announce_msgidx,
|
&node->node_announce_msgidx,
|
||||||
take(serialized));
|
take(serialized));
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
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 *source,
|
||||||
const struct pubkey *destination,
|
const struct pubkey *destination,
|
||||||
const u32 msatoshi, double riskfactor,
|
const u32 msatoshi, double riskfactor,
|
||||||
@@ -1258,7 +1241,6 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
enum onion_type failcode,
|
enum onion_type failcode,
|
||||||
const u8 *channel_update)
|
const u8 *channel_update)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(rstate);
|
|
||||||
struct node *node;
|
struct node *node;
|
||||||
int i;
|
int i;
|
||||||
time_t now = time_now().ts.tv_sec;
|
time_t now = time_now().ts.tv_sec;
|
||||||
@@ -1277,7 +1259,7 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
erring_node_pubkey));
|
erring_node_pubkey));
|
||||||
/* No node, so no channel, so any channel_update
|
/* No node, so no channel, so any channel_update
|
||||||
* can also be ignored. */
|
* can also be ignored. */
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BOLT #4:
|
/* BOLT #4:
|
||||||
@@ -1325,12 +1307,12 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
/* Suppress UNUSUAL log if local failure */
|
/* Suppress UNUSUAL log if local failure */
|
||||||
if (structeq(&erring_node_pubkey->pubkey,
|
if (structeq(&erring_node_pubkey->pubkey,
|
||||||
&rstate->local_id.pubkey))
|
&rstate->local_id.pubkey))
|
||||||
goto out;
|
return;
|
||||||
status_unusual("routing_failure: "
|
status_unusual("routing_failure: "
|
||||||
"UPDATE bit set, no channel_update. "
|
"UPDATE bit set, no channel_update. "
|
||||||
"failcode: 0x%04x",
|
"failcode: 0x%04x",
|
||||||
(int) failcode);
|
(int) failcode);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
err = handle_channel_update(rstate, channel_update);
|
err = handle_channel_update(rstate, channel_update);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -1338,7 +1320,7 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
"bad channel_update %s",
|
"bad channel_update %s",
|
||||||
sanitize_error(err, err, NULL));
|
sanitize_error(err, err, NULL));
|
||||||
tal_free(err);
|
tal_free(err);
|
||||||
goto out;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tal_len(channel_update) != 0)
|
if (tal_len(channel_update) != 0)
|
||||||
@@ -1347,15 +1329,11 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
"failcode: 0x%04x",
|
"failcode: 0x%04x",
|
||||||
(int) failcode);
|
(int) failcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mark_channel_unroutable(struct routing_state *rstate,
|
void mark_channel_unroutable(struct routing_state *rstate,
|
||||||
const struct short_channel_id *channel)
|
const struct short_channel_id *channel)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(rstate);
|
|
||||||
struct chan *chan;
|
struct chan *chan;
|
||||||
time_t now = time_now().ts.tv_sec;
|
time_t now = time_now().ts.tv_sec;
|
||||||
const char *scid = type_to_string(tmpctx, struct short_channel_id,
|
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: "
|
status_unusual("mark_channel_unroutable: "
|
||||||
"channel %s not in routemap",
|
"channel %s not in routemap",
|
||||||
scid);
|
scid);
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chan->half[0].unroutable_until = now + 20;
|
chan->half[0].unroutable_until = now + 20;
|
||||||
chan->half[1].unroutable_until = now + 20;
|
chan->half[1].unroutable_until = now + 20;
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void route_prune(struct routing_state *rstate)
|
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;
|
u64 now = time_now().ts.tv_sec;
|
||||||
/* Anything below this highwater mark ought to be pruned */
|
/* Anything below this highwater mark ought to be pruned */
|
||||||
const s64 highwater = now - rstate->prune_timeout;
|
const s64 highwater = now - rstate->prune_timeout;
|
||||||
const tal_t *pruned = tal_tmpctx(rstate);
|
const tal_t *pruned = tal(NULL, char);
|
||||||
struct chan *chan;
|
struct chan *chan;
|
||||||
u64 idx;
|
u64 idx;
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ void set_connection_values(struct chan *chan,
|
|||||||
struct node *get_node(struct routing_state *rstate, const struct pubkey *id);
|
struct node *get_node(struct routing_state *rstate, const struct pubkey *id);
|
||||||
|
|
||||||
/* Compute a route to a destination, for a given amount and riskfactor. */
|
/* 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 *source,
|
||||||
const struct pubkey *destination,
|
const struct pubkey *destination,
|
||||||
const u32 msatoshi, double riskfactor,
|
const u32 msatoshi, double riskfactor,
|
||||||
|
|||||||
@@ -94,8 +94,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* AUTOGENERATED MOCKS END */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
const void *trc;
|
|
||||||
|
|
||||||
/* Updates existing route if required. */
|
/* Updates existing route if required. */
|
||||||
static struct half_chan *add_connection(struct routing_state *rstate,
|
static struct half_chan *add_connection(struct routing_state *rstate,
|
||||||
const struct pubkey *from,
|
const struct pubkey *from,
|
||||||
@@ -172,7 +170,6 @@ static void run(const char *name)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const struct bitcoin_blkid zerohash;
|
static const struct bitcoin_blkid zerohash;
|
||||||
const tal_t *ctx = trc = tal_tmpctx(NULL);
|
|
||||||
struct routing_state *rstate;
|
struct routing_state *rstate;
|
||||||
size_t num_nodes = 100, num_runs = 1;
|
size_t num_nodes = 100, num_runs = 1;
|
||||||
struct timemono start, end;
|
struct timemono start, end;
|
||||||
@@ -184,8 +181,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| 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,
|
opt_register_noarg("--perfme", opt_set_bool, &perfme,
|
||||||
"Run perfme-start and perfme-stop around benchmark");
|
"Run perfme-start and perfme-stop around benchmark");
|
||||||
|
|
||||||
@@ -214,7 +212,7 @@ int main(int argc, char *argv[])
|
|||||||
u64 fee;
|
u64 fee;
|
||||||
struct chan **route;
|
struct chan **route;
|
||||||
|
|
||||||
route = find_route(ctx, rstate, &from, &to,
|
route = find_route(tmpctx, rstate, &from, &to,
|
||||||
pseudorand(100000),
|
pseudorand(100000),
|
||||||
riskfactor,
|
riskfactor,
|
||||||
0.75, &base_seed,
|
0.75, &base_seed,
|
||||||
@@ -232,7 +230,7 @@ int main(int argc, char *argv[])
|
|||||||
time_to_msec(timemono_between(end, start)),
|
time_to_msec(timemono_between(end, start)),
|
||||||
time_to_nsec(time_divide(timemono_between(end, start), num_runs)));
|
time_to_nsec(time_divide(timemono_between(end, start), num_runs)));
|
||||||
|
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
opt_free_table();
|
opt_free_table();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* AUTOGENERATED MOCKS END */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
const void *trc;
|
|
||||||
|
|
||||||
bool short_channel_id_from_str(const char *str, size_t strlen,
|
bool short_channel_id_from_str(const char *str, size_t strlen,
|
||||||
struct short_channel_id *dst);
|
struct short_channel_id *dst);
|
||||||
|
|
||||||
@@ -98,7 +96,6 @@ static bool channel_is_between(const struct chan *chan,
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
static const struct bitcoin_blkid zerohash;
|
static const struct bitcoin_blkid zerohash;
|
||||||
const tal_t *ctx = trc = tal_tmpctx(NULL);
|
|
||||||
struct half_chan *nc;
|
struct half_chan *nc;
|
||||||
struct routing_state *rstate;
|
struct routing_state *rstate;
|
||||||
struct pubkey a, b, c;
|
struct pubkey a, b, c;
|
||||||
@@ -108,6 +105,7 @@ int main(void)
|
|||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
pubkey_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
|
pubkey_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
|
||||||
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
|
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
|
||||||
@@ -119,7 +117,7 @@ int main(void)
|
|||||||
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
|
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
|
||||||
&c);
|
&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}, */
|
/* [{'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");
|
nc = get_or_make_connection(rstate, &c, &b, "6990:2:1");
|
||||||
@@ -157,13 +155,13 @@ int main(void)
|
|||||||
nc->flags = 1;
|
nc->flags = 1;
|
||||||
nc->last_timestamp = 1504064344;
|
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(route);
|
||||||
assert(tal_count(route) == 2);
|
assert(tal_count(route) == 2);
|
||||||
assert(channel_is_between(route[0], &a, &b));
|
assert(channel_is_between(route[0], &a, &b));
|
||||||
assert(channel_is_between(route[1], &b, &c));
|
assert(channel_is_between(route[1], &b, &c));
|
||||||
|
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* AUTOGENERATED MOCKS END */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
const void *trc;
|
|
||||||
|
|
||||||
/* Updates existing route if required. */
|
/* Updates existing route if required. */
|
||||||
static struct half_chan *add_connection(struct routing_state *rstate,
|
static struct half_chan *add_connection(struct routing_state *rstate,
|
||||||
const struct pubkey *from,
|
const struct pubkey *from,
|
||||||
@@ -141,7 +139,6 @@ static bool channel_is_between(const struct chan *chan,
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
static const struct bitcoin_blkid zerohash;
|
static const struct bitcoin_blkid zerohash;
|
||||||
const tal_t *ctx = trc = tal_tmpctx(NULL);
|
|
||||||
struct routing_state *rstate;
|
struct routing_state *rstate;
|
||||||
struct pubkey a, b, c, d;
|
struct pubkey a, b, c, d;
|
||||||
struct privkey tmp;
|
struct privkey tmp;
|
||||||
@@ -151,9 +148,10 @@ int main(void)
|
|||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
memset(&tmp, 'a', sizeof(tmp));
|
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);
|
pubkey_from_privkey(&tmp, &a);
|
||||||
new_node(rstate, &a);
|
new_node(rstate, &a);
|
||||||
@@ -165,7 +163,7 @@ int main(void)
|
|||||||
/* A<->B */
|
/* A<->B */
|
||||||
add_connection(rstate, &a, &b, 1, 1, 1);
|
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(tal_count(route) == 1);
|
||||||
assert(fee == 0);
|
assert(fee == 0);
|
||||||
|
|
||||||
@@ -174,12 +172,12 @@ int main(void)
|
|||||||
pubkey_from_privkey(&tmp, &c);
|
pubkey_from_privkey(&tmp, &c);
|
||||||
new_node(rstate, &c);
|
new_node(rstate, &c);
|
||||||
|
|
||||||
status_trace("A = %s", type_to_string(trc, struct pubkey, &a));
|
status_trace("A = %s", type_to_string(tmpctx, struct pubkey, &a));
|
||||||
status_trace("B = %s", type_to_string(trc, struct pubkey, &b));
|
status_trace("B = %s", type_to_string(tmpctx, struct pubkey, &b));
|
||||||
status_trace("C = %s", type_to_string(trc, struct pubkey, &c));
|
status_trace("C = %s", type_to_string(tmpctx, struct pubkey, &c));
|
||||||
add_connection(rstate, &b, &c, 1, 1, 1);
|
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(tal_count(route) == 2);
|
||||||
assert(fee == 1);
|
assert(fee == 1);
|
||||||
|
|
||||||
@@ -187,20 +185,20 @@ int main(void)
|
|||||||
memset(&tmp, 'd', sizeof(tmp));
|
memset(&tmp, 'd', sizeof(tmp));
|
||||||
pubkey_from_privkey(&tmp, &d);
|
pubkey_from_privkey(&tmp, &d);
|
||||||
new_node(rstate, &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, &a, &d, 0, 2, 1);
|
||||||
add_connection(rstate, &d, &c, 0, 2, 1);
|
add_connection(rstate, &d, &c, 0, 2, 1);
|
||||||
|
|
||||||
/* Will go via D for small amounts. */
|
/* 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(tal_count(route) == 2);
|
||||||
assert(channel_is_between(route[0], &a, &d));
|
assert(channel_is_between(route[0], &a, &d));
|
||||||
assert(channel_is_between(route[1], &d, &c));
|
assert(channel_is_between(route[1], &d, &c));
|
||||||
assert(fee == 0);
|
assert(fee == 0);
|
||||||
|
|
||||||
/* Will go via B for large amounts. */
|
/* 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(tal_count(route) == 2);
|
||||||
assert(channel_is_between(route[0], &a, &b));
|
assert(channel_is_between(route[0], &a, &b));
|
||||||
assert(channel_is_between(route[1], &b, &c));
|
assert(channel_is_between(route[1], &b, &c));
|
||||||
@@ -208,13 +206,13 @@ int main(void)
|
|||||||
|
|
||||||
/* Make B->C inactive, force it back via D */
|
/* Make B->C inactive, force it back via D */
|
||||||
get_connection(rstate, &b, &c)->active = false;
|
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(tal_count(route) == 2);
|
||||||
assert(channel_is_between(route[0], &a, &d));
|
assert(channel_is_between(route[0], &a, &d));
|
||||||
assert(channel_is_between(route[1], &d, &c));
|
assert(channel_is_between(route[1], &d, &c));
|
||||||
assert(fee == 0 + 6);
|
assert(fee == 0 + 6);
|
||||||
|
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ static struct io_plan *success(struct io_conn *conn UNUSED,
|
|||||||
const struct pubkey *them,
|
const struct pubkey *them,
|
||||||
const struct wireaddr *addr UNUSED,
|
const struct wireaddr *addr UNUSED,
|
||||||
const struct crypto_state *cs,
|
const struct crypto_state *cs,
|
||||||
void *ctx)
|
void *unused UNUSED)
|
||||||
{
|
{
|
||||||
assert(pubkey_eq(them, &rs_pub));
|
assert(pubkey_eq(them, &rs_pub));
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ static struct io_plan *success(struct io_conn *conn UNUSED,
|
|||||||
|
|
||||||
/* No memory leaks please */
|
/* No memory leaks please */
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,13 +199,11 @@ bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *ctx = tal_tmpctx(NULL);
|
|
||||||
struct wireaddr dummy;
|
struct wireaddr dummy;
|
||||||
|
|
||||||
trc = tal_tmpctx(ctx);
|
|
||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
|
|
||||||
/* BOLT #8:
|
/* BOLT #8:
|
||||||
@@ -224,7 +222,7 @@ int main(void)
|
|||||||
e_pub = pubkey("036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7");
|
e_pub = pubkey("036360e856310ce5d294e8be33fc807077dc56ac80d95d9cd4ddbd21325eff73f7");
|
||||||
|
|
||||||
dummy.addrlen = 0;
|
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! */
|
/* Should not exit! */
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ static bool secret_eq(const struct secret *s, const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
secp256k1_context *secp256k1_ctx;
|
secp256k1_context *secp256k1_ctx;
|
||||||
const void *trc;
|
|
||||||
static struct pubkey ls_pub, e_pub;
|
static struct pubkey ls_pub, e_pub;
|
||||||
static struct privkey ls_priv, e_priv;
|
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 pubkey *them UNUSED,
|
||||||
const struct wireaddr *addr UNUSED,
|
const struct wireaddr *addr UNUSED,
|
||||||
const struct crypto_state *cs,
|
const struct crypto_state *cs,
|
||||||
void *ctx)
|
void *unused UNUSED)
|
||||||
{
|
{
|
||||||
assert(secret_eq(&cs->sk, expect_sk));
|
assert(secret_eq(&cs->sk, expect_sk));
|
||||||
assert(secret_eq(&cs->rk, expect_rk));
|
assert(secret_eq(&cs->rk, expect_rk));
|
||||||
|
|
||||||
/* No memory leaks please */
|
/* No memory leaks please */
|
||||||
secp256k1_context_destroy(secp256k1_ctx);
|
secp256k1_context_destroy(secp256k1_ctx);
|
||||||
tal_free(ctx);
|
tal_free(tmpctx);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,13 +196,11 @@ bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *ctx = tal_tmpctx(NULL);
|
|
||||||
struct wireaddr dummy;
|
struct wireaddr dummy;
|
||||||
|
|
||||||
trc = tal_tmpctx(ctx);
|
|
||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
|
|
||||||
/* BOLT #8:
|
/* BOLT #8:
|
||||||
@@ -220,7 +217,7 @@ int main(void)
|
|||||||
e_pub = pubkey("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27");
|
e_pub = pubkey("02466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f27");
|
||||||
|
|
||||||
dummy.addrlen = 0;
|
dummy.addrlen = 0;
|
||||||
responder_handshake(ctx, &ls_pub, &dummy, success, ctx);
|
responder_handshake((void *)tmpctx, &ls_pub, &dummy, success, NULL);
|
||||||
/* Should not exit! */
|
/* Should not exit! */
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|||||||
12
hsmd/hsm.c
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,
|
static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
|
||||||
struct daemon_conn *dc)
|
struct daemon_conn *dc)
|
||||||
{
|
{
|
||||||
tal_t *ctx = tal_tmpctx(conn);
|
|
||||||
/* First 2 + 256 byte are the signatures and msg type, skip them */
|
/* First 2 + 256 byte are the signatures and msg type, skip them */
|
||||||
size_t offset = 258;
|
size_t offset = 258;
|
||||||
struct privkey node_pkey;
|
struct privkey node_pkey;
|
||||||
@@ -160,7 +159,7 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
|
|||||||
u8 *ca;
|
u8 *ca;
|
||||||
struct pubkey bitcoin_id;
|
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)) {
|
&bitcoin_id, &ca)) {
|
||||||
status_broken("Failed to parse cannouncement_sig_req: %s",
|
status_broken("Failed to parse cannouncement_sig_req: %s",
|
||||||
tal_hex(tmpctx, dc->msg_in));
|
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);
|
reply = towire_hsm_cannouncement_sig_reply(ca, &node_sig);
|
||||||
daemon_conn_send(dc, take(reply));
|
daemon_conn_send(dc, take(reply));
|
||||||
|
|
||||||
tal_free(ctx);
|
|
||||||
return daemon_conn_read_next(conn, dc);
|
return daemon_conn_read_next(conn, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
|
static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
|
||||||
struct daemon_conn *dc)
|
struct daemon_conn *dc)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(conn);
|
|
||||||
/* 2 bytes msg type + 64 bytes signature */
|
/* 2 bytes msg type + 64 bytes signature */
|
||||||
size_t offset = 66;
|
size_t offset = 66;
|
||||||
struct privkey node_pkey;
|
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);
|
fee_base_msat, fee_proportional_mill);
|
||||||
|
|
||||||
daemon_conn_send(dc, take(towire_hsm_cupdate_sig_reply(tmpctx, cu)));
|
daemon_conn_send(dc, take(towire_hsm_cupdate_sig_reply(tmpctx, cu)));
|
||||||
tal_free(tmpctx);
|
|
||||||
return daemon_conn_read_next(conn, dc);
|
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. */
|
* can broadcast it. */
|
||||||
static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
|
static void sign_funding_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(master);
|
|
||||||
u64 satoshi_out, change_out;
|
u64 satoshi_out, change_out;
|
||||||
u32 change_keyindex;
|
u32 change_keyindex;
|
||||||
struct pubkey local_pubkey, remote_pubkey;
|
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,
|
daemon_conn_send(master,
|
||||||
take(towire_hsm_sign_funding_reply(tmpctx, tx)));
|
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)
|
static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(master);
|
|
||||||
u64 satoshi_out, change_out;
|
u64 satoshi_out, change_out;
|
||||||
u32 change_keyindex;
|
u32 change_keyindex;
|
||||||
struct utxo **utxos;
|
struct utxo **utxos;
|
||||||
@@ -741,7 +734,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg)
|
|||||||
|
|
||||||
daemon_conn_send(master,
|
daemon_conn_send(master,
|
||||||
take(towire_hsm_sign_withdrawal_reply(tmpctx, tx)));
|
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)
|
static void sign_invoice(struct daemon_conn *master, const u8 *msg)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(master);
|
|
||||||
u5 *u5bytes;
|
u5 *u5bytes;
|
||||||
u8 *hrpu8;
|
u8 *hrpu8;
|
||||||
char *hrp;
|
char *hrp;
|
||||||
@@ -785,7 +776,6 @@ static void sign_invoice(struct daemon_conn *master, const u8 *msg)
|
|||||||
|
|
||||||
daemon_conn_send(master,
|
daemon_conn_send(master,
|
||||||
take(towire_hsm_sign_invoice_reply(tmpctx, &rsig)));
|
take(towire_hsm_sign_invoice_reply(tmpctx, &rsig)));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sign_node_announcement(struct daemon_conn *master, const u8 *msg)
|
static void sign_node_announcement(struct daemon_conn *master, const u8 *msg)
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ bool peer_start_channeld(struct channel *channel,
|
|||||||
const u8 *funding_signed,
|
const u8 *funding_signed,
|
||||||
bool reconnected)
|
bool reconnected)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
u8 *msg, *initmsg;
|
u8 *msg, *initmsg;
|
||||||
int hsmfd;
|
int hsmfd;
|
||||||
struct added_htlc *htlcs;
|
struct added_htlc *htlcs;
|
||||||
@@ -209,7 +208,6 @@ bool peer_start_channeld(struct channel *channel,
|
|||||||
log_unusual(channel->log, "Could not subdaemon channel: %s",
|
log_unusual(channel->log, "Could not subdaemon channel: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
channel_fail_transient(channel, "Failed to subdaemon channel");
|
channel_fail_transient(channel, "Failed to subdaemon channel");
|
||||||
tal_free(tmpctx);
|
|
||||||
return true;
|
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. */
|
/* We don't expect a response: we are triggered by funding_depth_cb. */
|
||||||
subd_send_msg(channel->owner, take(initmsg));
|
subd_send_msg(channel->owner, take(initmsg));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,6 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
int peer_fd, int gossip_fd,
|
int peer_fd, int gossip_fd,
|
||||||
bool reconnected)
|
bool reconnected)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
u8 *initmsg;
|
u8 *initmsg;
|
||||||
u64 minfee, startfee, feelimit;
|
u64 minfee, startfee, feelimit;
|
||||||
u64 num_revocations;
|
u64 num_revocations;
|
||||||
@@ -150,7 +149,6 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
if (!channel->remote_shutdown_scriptpubkey) {
|
if (!channel->remote_shutdown_scriptpubkey) {
|
||||||
channel_internal_error(channel,
|
channel_internal_error(channel,
|
||||||
"Can't start closing: no remote info");
|
"Can't start closing: no remote info");
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +164,6 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
log_unusual(channel->log, "Could not subdaemon closing: %s",
|
log_unusual(channel->log, "Could not subdaemon closing: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
channel_fail_transient(channel, "Failed to subdaemon closing");
|
channel_fail_transient(channel, "Failed to subdaemon closing");
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,5 +223,4 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
/* We don't expect a response: it will give us feedback on
|
/* We don't expect a response: it will give us feedback on
|
||||||
* signatures sent and received, then closing_complete. */
|
* signatures sent and received, then closing_complete. */
|
||||||
subd_send_msg(channel->owner, take(initmsg));
|
subd_send_msg(channel->owner, take(initmsg));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,6 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
|
|||||||
* message */
|
* message */
|
||||||
void gossip_init(struct lightningd *ld)
|
void gossip_init(struct lightningd *ld)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
int hsmfd;
|
int hsmfd;
|
||||||
u64 capabilities = HSM_CAP_ECDH | HSM_CAP_SIGN_GOSSIP;
|
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,
|
get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb,
|
||||||
ld->alias, ld->config.channel_update_interval);
|
ld->alias, ld->config.channel_update_interval);
|
||||||
subd_send_msg(ld->gossip, msg);
|
subd_send_msg(ld->gossip, msg);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
static void json_getnodes_reply(struct subd *gossip UNUSED, const u8 *reply,
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ u8 *hsm_sync_read(const tal_t *ctx, struct lightningd *ld)
|
|||||||
|
|
||||||
void hsm_init(struct lightningd *ld, bool newdir)
|
void hsm_init(struct lightningd *ld, bool newdir)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
bool create;
|
bool create;
|
||||||
|
|
||||||
@@ -56,6 +55,4 @@ void hsm_init(struct lightningd *ld, bool newdir)
|
|||||||
&ld->peer_seed,
|
&ld->peer_seed,
|
||||||
ld->wallet->bip32_base))
|
ld->wallet->bip32_base))
|
||||||
errx(1, "HSM did not give init reply");
|
errx(1, "HSM did not give init reply");
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -281,7 +281,6 @@ static void connection_complete_error(struct json_connection *jcon,
|
|||||||
int code,
|
int code,
|
||||||
const struct json_result *data)
|
const struct json_result *data)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(jcon);
|
|
||||||
/* Use this to escape errmsg. */
|
/* Use this to escape errmsg. */
|
||||||
struct json_result *errorres = new_json_result(tmpctx);
|
struct json_result *errorres = new_json_result(tmpctx);
|
||||||
const char *data_str;
|
const char *data_str;
|
||||||
@@ -305,7 +304,6 @@ static void connection_complete_error(struct json_connection *jcon,
|
|||||||
json_result_string(errorres),
|
json_result_string(errorres),
|
||||||
data_str,
|
data_str,
|
||||||
id)));
|
id)));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct json_result *null_response(const tal_t *ctx)
|
struct json_result *null_response(const tal_t *ctx)
|
||||||
|
|||||||
@@ -93,11 +93,9 @@ static const char *daemons[] = {
|
|||||||
void test_daemons(const struct lightningd *ld)
|
void test_daemons(const struct lightningd *ld)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
const tal_t *ctx = tal_tmpctx(ld);
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(daemons); i++) {
|
for (i = 0; i < ARRAY_SIZE(daemons); i++) {
|
||||||
int outfd;
|
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;
|
const char *verstring;
|
||||||
pid_t pid = pipecmd(&outfd, NULL, &outfd,
|
pid_t pid = pipecmd(&outfd, NULL, &outfd,
|
||||||
dpath, "--version", NULL);
|
dpath, "--version", NULL);
|
||||||
@@ -105,21 +103,19 @@ void test_daemons(const struct lightningd *ld)
|
|||||||
log_debug(ld->log, "testing %s", dpath);
|
log_debug(ld->log, "testing %s", dpath);
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
err(1, "Could not run %s", dpath);
|
err(1, "Could not run %s", dpath);
|
||||||
verstring = grab_fd(ctx, outfd);
|
verstring = grab_fd(tmpctx, outfd);
|
||||||
if (!verstring)
|
if (!verstring)
|
||||||
err(1, "Could not get output from %s", dpath);
|
err(1, "Could not get output from %s", dpath);
|
||||||
if (!strstarts(verstring, version())
|
if (!strstarts(verstring, version())
|
||||||
|| verstring[strlen(version())] != '\n')
|
|| verstring[strlen(version())] != '\n')
|
||||||
errx(1, "%s: bad version '%s'", daemons[i], verstring);
|
errx(1, "%s: bad version '%s'", daemons[i], verstring);
|
||||||
}
|
}
|
||||||
tal_free(ctx);
|
|
||||||
}
|
}
|
||||||
/* Check if all daemons exist in specified directory. */
|
/* Check if all daemons exist in specified directory. */
|
||||||
static bool has_all_daemons(const char* daemon_dir)
|
static bool has_all_daemons(const char* daemon_dir)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
bool missing_daemon = false;
|
bool missing_daemon = false;
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(daemons); ++i) {
|
for (i = 0; i < ARRAY_SIZE(daemons); ++i) {
|
||||||
if (!path_is_file(path_join(tmpctx, daemon_dir, 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;
|
return !missing_daemon;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *find_my_path(const tal_t *ctx, const char *argv0)
|
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)) {
|
if (strchr(argv0, PATH_SEP)) {
|
||||||
const char *path;
|
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);
|
errx(1, "Cannot find %s in $PATH", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return path_dirname(ctx, take(me));
|
return path_dirname(ctx, take(me));
|
||||||
}
|
}
|
||||||
static const char *find_my_pkglibexec_path(const tal_t *ctx,
|
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)
|
static void pidfile_create(const struct lightningd *ld)
|
||||||
{
|
{
|
||||||
char *pid;
|
char *pid;
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
|
|
||||||
/* Create PID file */
|
/* Create PID file */
|
||||||
pid_fd = open(ld->pidfile, O_WRONLY|O_CREAT, 0640);
|
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 */
|
/* Get current PID and write to PID fie */
|
||||||
pid = tal_fmt(tmpctx, "%d\n", getpid());
|
pid = tal_fmt(tmpctx, "%d\n", getpid());
|
||||||
write_all(pid_fd, pid, strlen(pid));
|
write_all(pid_fd, pid, strlen(pid));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ enum watch_result funding_spent(struct channel *channel,
|
|||||||
u8 *msg;
|
u8 *msg;
|
||||||
struct bitcoin_txid our_last_txid;
|
struct bitcoin_txid our_last_txid;
|
||||||
struct htlc_stub *stubs;
|
struct htlc_stub *stubs;
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
struct lightningd *ld = channel->peer->ld;
|
struct lightningd *ld = channel->peer->ld;
|
||||||
struct pubkey final_key;
|
struct pubkey final_key;
|
||||||
|
|
||||||
@@ -369,14 +368,12 @@ enum watch_result funding_spent(struct channel *channel,
|
|||||||
if (!channel->owner) {
|
if (!channel->owner) {
|
||||||
log_broken(channel->log, "Could not subdaemon onchain: %s",
|
log_broken(channel->log, "Could not subdaemon onchain: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
tal_free(tmpctx);
|
|
||||||
return KEEP_WATCHING;
|
return KEEP_WATCHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
stubs = wallet_htlc_stubs(tmpctx, ld->wallet, channel);
|
stubs = wallet_htlc_stubs(tmpctx, ld->wallet, channel);
|
||||||
if (!stubs) {
|
if (!stubs) {
|
||||||
log_broken(channel->log, "Could not load htlc_stubs");
|
log_broken(channel->log, "Could not load htlc_stubs");
|
||||||
tal_free(tmpctx);
|
|
||||||
return KEEP_WATCHING;
|
return KEEP_WATCHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +381,6 @@ enum watch_result funding_spent(struct channel *channel,
|
|||||||
channel->final_key_idx)) {
|
channel->final_key_idx)) {
|
||||||
log_broken(channel->log, "Could not derive onchain key %"PRIu64,
|
log_broken(channel->log, "Could not derive onchain key %"PRIu64,
|
||||||
channel->final_key_idx);
|
channel->final_key_idx);
|
||||||
tal_free(tmpctx);
|
|
||||||
return KEEP_WATCHING;
|
return KEEP_WATCHING;
|
||||||
}
|
}
|
||||||
/* This could be a mutual close, but it doesn't matter. */
|
/* 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);
|
watch_tx_and_outputs(channel, tx);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
/* We keep watching until peer finally deleted, for reorgs. */
|
/* We keep watching until peer finally deleted, for reorgs. */
|
||||||
return KEEP_WATCHING;
|
return KEEP_WATCHING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,7 +229,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
|||||||
const int *fds,
|
const int *fds,
|
||||||
struct funding_channel *fc)
|
struct funding_channel *fc)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(fc);
|
|
||||||
u8 *msg, *linear;
|
u8 *msg, *linear;
|
||||||
struct channel_info channel_info;
|
struct channel_info channel_info;
|
||||||
struct bitcoin_tx *fundingtx;
|
struct bitcoin_tx *fundingtx;
|
||||||
@@ -412,7 +411,6 @@ static void opening_fundee_finished(struct subd *openingd,
|
|||||||
u64 gossip_index;
|
u64 gossip_index;
|
||||||
secp256k1_ecdsa_signature remote_commit_sig;
|
secp256k1_ecdsa_signature remote_commit_sig;
|
||||||
struct bitcoin_tx *remote_commit;
|
struct bitcoin_tx *remote_commit;
|
||||||
const tal_t *tmpctx = tal_tmpctx(uc);
|
|
||||||
struct lightningd *ld = openingd->ld;
|
struct lightningd *ld = openingd->ld;
|
||||||
struct bitcoin_txid funding_txid;
|
struct bitcoin_txid funding_txid;
|
||||||
u16 funding_outnum;
|
u16 funding_outnum;
|
||||||
|
|||||||
@@ -105,14 +105,11 @@ static void payment_trigger_success(struct lightningd *ld,
|
|||||||
const struct sha256 *payment_hash,
|
const struct sha256 *payment_hash,
|
||||||
const struct preimage *payment_preimage)
|
const struct preimage *payment_preimage)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
|
|
||||||
result = sendpay_result_success(tmpctx, payment_preimage);
|
result = sendpay_result_success(tmpctx, payment_preimage);
|
||||||
|
|
||||||
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sendpay_result*
|
static struct sendpay_result*
|
||||||
@@ -141,7 +138,6 @@ static void payment_route_failure(struct lightningd *ld,
|
|||||||
const u8 *onionreply,
|
const u8 *onionreply,
|
||||||
const char *details)
|
const char *details)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
|
|
||||||
result = sendpay_result_route_failure(tmpctx,
|
result = sendpay_result_route_failure(tmpctx,
|
||||||
@@ -151,8 +147,6 @@ static void payment_route_failure(struct lightningd *ld,
|
|||||||
details);
|
details);
|
||||||
|
|
||||||
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
waitsendpay_resolve(tmpctx, ld, payment_hash, result);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sendpay_result *
|
static struct sendpay_result *
|
||||||
@@ -332,7 +326,6 @@ static void random_mark_channel_unroutable(struct log *log,
|
|||||||
struct subd *gossip,
|
struct subd *gossip,
|
||||||
struct short_channel_id *route_channels)
|
struct short_channel_id *route_channels)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(gossip);
|
|
||||||
size_t num_channels = tal_count(route_channels);
|
size_t num_channels = tal_count(route_channels);
|
||||||
size_t i;
|
size_t i;
|
||||||
const struct short_channel_id *channel;
|
const struct short_channel_id *channel;
|
||||||
@@ -352,15 +345,12 @@ static void random_mark_channel_unroutable(struct log *log,
|
|||||||
channel));
|
channel));
|
||||||
msg = towire_gossip_mark_channel_unroutable(tmpctx, channel);
|
msg = towire_gossip_mark_channel_unroutable(tmpctx, channel);
|
||||||
subd_send_msg(gossip, msg);
|
subd_send_msg(gossip, msg);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void report_routing_failure(struct log *log,
|
static void report_routing_failure(struct log *log,
|
||||||
struct subd *gossip,
|
struct subd *gossip,
|
||||||
struct routing_failure *fail)
|
struct routing_failure *fail)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(gossip);
|
|
||||||
u8 *gossip_msg;
|
u8 *gossip_msg;
|
||||||
assert(fail);
|
assert(fail);
|
||||||
|
|
||||||
@@ -379,14 +369,11 @@ static void report_routing_failure(struct log *log,
|
|||||||
(u16) fail->failcode,
|
(u16) fail->failcode,
|
||||||
fail->channel_update);
|
fail->channel_update);
|
||||||
subd_send_msg(gossip, gossip_msg);
|
subd_send_msg(gossip, gossip_msg);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void payment_store(struct lightningd *ld,
|
void payment_store(struct lightningd *ld,
|
||||||
const struct sha256 *payment_hash)
|
const struct sha256 *payment_hash)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
struct sendpay_command *pc;
|
struct sendpay_command *pc;
|
||||||
struct sendpay_command *next;
|
struct sendpay_command *next;
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
@@ -406,8 +393,6 @@ void payment_store(struct lightningd *ld,
|
|||||||
tal_steal(tmpctx, pc);
|
tal_steal(tmpctx, pc);
|
||||||
pc->cb(result, pc->cbarg);
|
pc->cb(result, pc->cbarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
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;
|
enum onion_type failcode;
|
||||||
struct secret *path_secrets;
|
struct secret *path_secrets;
|
||||||
struct wallet_payment *payment;
|
struct wallet_payment *payment;
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
struct routing_failure* fail = NULL;
|
struct routing_failure* fail = NULL;
|
||||||
const char *failmsg;
|
const char *failmsg;
|
||||||
bool retry_plausible;
|
bool retry_plausible;
|
||||||
@@ -438,7 +422,6 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
|||||||
&hout->payment_hash));
|
&hout->payment_hash));
|
||||||
wallet_payment_set_status(ld->wallet, &hout->payment_hash,
|
wallet_payment_set_status(ld->wallet, &hout->payment_hash,
|
||||||
PAYMENT_FAILED, NULL);
|
PAYMENT_FAILED, NULL);
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -516,7 +499,6 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout,
|
|||||||
payment_route_failure(ld, &hout->payment_hash,
|
payment_route_failure(ld, &hout->payment_hash,
|
||||||
retry_plausible, fail, hout->failuremsg,
|
retry_plausible, fail, hout->failuremsg,
|
||||||
failmsg);
|
failmsg);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a payment. If cxt is deleted, then cb will
|
/* 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 (*cb)(const struct sendpay_result *, void*),
|
||||||
void *cbarg)
|
void *cbarg)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct wallet_payment *payment;
|
struct wallet_payment *payment;
|
||||||
struct sendpay_result *result;
|
struct sendpay_result *result;
|
||||||
char const *details;
|
char const *details;
|
||||||
@@ -610,7 +591,6 @@ bool wait_payment(const tal_t *cxt,
|
|||||||
abort();
|
abort();
|
||||||
|
|
||||||
end:
|
end:
|
||||||
tal_free(tmpctx);
|
|
||||||
return cb_not_called;
|
return cb_not_called;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +609,6 @@ send_payment(const tal_t *ctx,
|
|||||||
struct onionpacket *packet;
|
struct onionpacket *packet;
|
||||||
struct secret *path_secrets;
|
struct secret *path_secrets;
|
||||||
enum onion_type failcode;
|
enum onion_type failcode;
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
size_t i, n_hops = tal_count(route);
|
size_t i, n_hops = tal_count(route);
|
||||||
struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops);
|
struct hop_data *hop_data = tal_arr(tmpctx, struct hop_data, n_hops);
|
||||||
struct pubkey *ids = tal_arr(tmpctx, struct pubkey, 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);
|
add_sendpay_waiter(ctx, rhash, ld, cb, cbarg);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
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",
|
log_info(pay->cmd->ld->log, "pay(%p): sendpay via route: %s",
|
||||||
pay, stringify_route(tmpctx, route));
|
pay, stringify_route(tmpctx, route));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void json_pay_sendpay_resume(const struct sendpay_result *r,
|
static void json_pay_sendpay_resume(const struct sendpay_result *r,
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ u32 feerate_max(struct lightningd *ld)
|
|||||||
|
|
||||||
static void sign_last_tx(struct channel *channel)
|
static void sign_last_tx(struct channel *channel)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
u8 *funding_wscript;
|
u8 *funding_wscript;
|
||||||
struct pubkey local_funding_pubkey;
|
struct pubkey local_funding_pubkey;
|
||||||
struct secrets secrets;
|
struct secrets secrets;
|
||||||
@@ -197,8 +196,6 @@ static void sign_last_tx(struct channel *channel)
|
|||||||
&sig,
|
&sig,
|
||||||
&channel->channel_info.remote_fundingkey,
|
&channel->channel_info.remote_fundingkey,
|
||||||
&local_funding_pubkey);
|
&local_funding_pubkey);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remove_sig(struct bitcoin_tx *signed_tx)
|
static void remove_sig(struct bitcoin_tx *signed_tx)
|
||||||
|
|||||||
@@ -232,7 +232,6 @@ static void handle_localpay(struct htlc_in *hin,
|
|||||||
struct invoice invoice;
|
struct invoice invoice;
|
||||||
struct invoice_details details;
|
struct invoice_details details;
|
||||||
struct lightningd *ld = hin->key.channel->peer->ld;
|
struct lightningd *ld = hin->key.channel->peer->ld;
|
||||||
const tal_t *tmpctx = tal_tmpctx(ld);
|
|
||||||
|
|
||||||
/* BOLT #4:
|
/* BOLT #4:
|
||||||
*
|
*
|
||||||
@@ -308,15 +307,12 @@ static void handle_localpay(struct htlc_in *hin,
|
|||||||
fulfill_htlc(hin, &details.r);
|
fulfill_htlc(hin, &details.r);
|
||||||
wallet_invoice_resolve(ld->wallet, invoice, hin->msatoshi);
|
wallet_invoice_resolve(ld->wallet, invoice, hin->msatoshi);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* Final hop never sends an UPDATE. */
|
/* Final hop never sends an UPDATE. */
|
||||||
assert(!(failcode & UPDATE));
|
assert(!(failcode & UPDATE));
|
||||||
local_fail_htlc(hin, failcode, NULL);
|
local_fail_htlc(hin, failcode, NULL);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -563,7 +559,6 @@ static bool peer_accepted_htlc(struct channel *channel,
|
|||||||
u8 *req;
|
u8 *req;
|
||||||
struct route_step *rs;
|
struct route_step *rs;
|
||||||
struct onionpacket *op;
|
struct onionpacket *op;
|
||||||
const tal_t *tmpctx = tal_tmpctx(channel);
|
|
||||||
struct lightningd *ld = channel->peer->ld;
|
struct lightningd *ld = channel->peer->ld;
|
||||||
|
|
||||||
hin = find_htlc_in(&ld->htlcs_in, channel, id);
|
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",
|
"bad onion in got_revoke: %s",
|
||||||
tal_hexstr(channel, hin->onion_routing_packet,
|
tal_hexstr(channel, hin->onion_routing_packet,
|
||||||
sizeof(hin->onion_routing_packet)));
|
sizeof(hin->onion_routing_packet)));
|
||||||
tal_free(tmpctx);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* FIXME: could be bad version, bad key. */
|
/* FIXME: could be bad version, bad key. */
|
||||||
@@ -659,7 +653,6 @@ out:
|
|||||||
log_debug(channel->log, "their htlc %"PRIu64" %s",
|
log_debug(channel->log, "their htlc %"PRIu64" %s",
|
||||||
id, *failcode ? onion_type_name(*failcode) : "locked");
|
id, *failcode ? onion_type_name(*failcode) : "locked");
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
int type = fromwire_peektype(sd->msg_in);
|
||||||
bool freed = false;
|
bool freed = false;
|
||||||
const tal_t *tmpctx = tal_tmpctx(conn);
|
|
||||||
int *fds_in;
|
int *fds_in;
|
||||||
|
|
||||||
log_debug(sd->log, "REPLY %s with %zu fds",
|
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. */
|
/* Find out if they freed it. */
|
||||||
tal_add_destructor2(sd, mark_freed, &freed);
|
tal_add_destructor2(sd, mark_freed, &freed);
|
||||||
sr->replycb(sd, sd->msg_in, fds_in, sr->replycb_data);
|
sr->replycb(sd, sd->msg_in, fds_in, sr->replycb_data);
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
if (freed)
|
if (freed)
|
||||||
return io_close(conn);
|
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)
|
static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
|
||||||
{
|
{
|
||||||
int type = fromwire_peektype(sd->msg_in);
|
int type = fromwire_peektype(sd->msg_in);
|
||||||
const tal_t *tmpctx;
|
|
||||||
struct subd_req *sr;
|
struct subd_req *sr;
|
||||||
struct db *db = sd->ld->wallet->db;
|
struct db *db = sd->ld->wallet->db;
|
||||||
struct io_plan *plan;
|
struct io_plan *plan;
|
||||||
@@ -452,8 +449,7 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If not stolen, we'll free this below. */
|
/* If not stolen, we'll free this later. */
|
||||||
tmpctx = tal_tmpctx(sd);
|
|
||||||
tal_steal(tmpctx, sd->msg_in);
|
tal_steal(tmpctx, sd->msg_in);
|
||||||
|
|
||||||
/* We handle status messages ourselves. */
|
/* 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) {
|
if (!sd->fds_in) {
|
||||||
/* Don't free msg_in: we go around again. */
|
/* Don't free msg_in: we go around again. */
|
||||||
tal_steal(sd, sd->msg_in);
|
tal_steal(sd, sd->msg_in);
|
||||||
tal_free(tmpctx);
|
|
||||||
plan = sd_collect_fds(conn, sd, 2);
|
plan = sd_collect_fds(conn, sd, 2);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -518,7 +513,6 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
|
|||||||
assert(!sd->fds_in);
|
assert(!sd->fds_in);
|
||||||
/* Don't free msg_in: we go around again. */
|
/* Don't free msg_in: we go around again. */
|
||||||
tal_steal(sd, sd->msg_in);
|
tal_steal(sd, sd->msg_in);
|
||||||
tal_free(tmpctx);
|
|
||||||
plan = sd_collect_fds(conn, sd, i);
|
plan = sd_collect_fds(conn, sd, i);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -527,7 +521,6 @@ static struct io_plan *sd_msg_read(struct io_conn *conn, struct subd *sd)
|
|||||||
next:
|
next:
|
||||||
sd->msg_in = NULL;
|
sd->msg_in = NULL;
|
||||||
sd->fds_in = tal_free(sd->fds_in);
|
sd->fds_in = tal_free(sd->fds_in);
|
||||||
tal_free(tmpctx);
|
|
||||||
|
|
||||||
plan = io_read_wire(conn, sd, &sd->msg_in, sd_msg_read, sd);
|
plan = io_read_wire(conn, sd, &sd->msg_in, sd_msg_read, sd);
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ static bool pubkey_from_secret(const struct secret *secret,
|
|||||||
static void tx_must_be_eq(const struct bitcoin_tx *a,
|
static void tx_must_be_eq(const struct bitcoin_tx *a,
|
||||||
const struct bitcoin_tx *b)
|
const struct bitcoin_tx *b)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 *lina, *linb;
|
u8 *lina, *linb;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@@ -88,8 +87,6 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
|
|||||||
"%s",
|
"%s",
|
||||||
tal_hex(tmpctx, lina),
|
tal_hex(tmpctx, lina),
|
||||||
tal_hex(tmpctx, linb));
|
tal_hex(tmpctx, linb));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
@@ -189,7 +186,6 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
const struct pubkey *remote_revocation_key,
|
const struct pubkey *remote_revocation_key,
|
||||||
u32 feerate_per_kw)
|
u32 feerate_per_kw)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
size_t i, n;
|
size_t i, n;
|
||||||
struct bitcoin_txid txid;
|
struct bitcoin_txid txid;
|
||||||
struct bitcoin_tx **htlc_tx;
|
struct bitcoin_tx **htlc_tx;
|
||||||
@@ -301,7 +297,6 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
|||||||
htlc->id,
|
htlc->id,
|
||||||
tal_hex(tmpctx, linearize_tx(tmpctx, htlc_tx[i])));
|
tal_hex(tmpctx, linearize_tx(tmpctx, htlc_tx[i])));
|
||||||
}
|
}
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void report(struct bitcoin_tx *tx,
|
static void report(struct bitcoin_tx *tx,
|
||||||
@@ -322,7 +317,6 @@ static void report(struct bitcoin_tx *tx,
|
|||||||
u32 feerate_per_kw,
|
u32 feerate_per_kw,
|
||||||
const struct htlc **htlc_map)
|
const struct htlc **htlc_map)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
char *txhex;
|
char *txhex;
|
||||||
secp256k1_ecdsa_signature localsig, remotesig;
|
secp256k1_ecdsa_signature localsig, remotesig;
|
||||||
|
|
||||||
@@ -354,7 +348,6 @@ static void report(struct bitcoin_tx *tx,
|
|||||||
remotekey, remote_htlckey,
|
remotekey, remote_htlckey,
|
||||||
remote_revocation_key,
|
remote_revocation_key,
|
||||||
feerate_per_kw);
|
feerate_per_kw);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -425,7 +418,6 @@ static const struct htlc **invert_htlcs(const struct htlc **htlcs)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct bitcoin_txid funding_txid;
|
struct bitcoin_txid funding_txid;
|
||||||
u64 funding_amount_satoshi, dust_limit_satoshi;
|
u64 funding_amount_satoshi, dust_limit_satoshi;
|
||||||
u32 feerate_per_kw;
|
u32 feerate_per_kw;
|
||||||
@@ -454,11 +446,14 @@ int main(void)
|
|||||||
u8 *wscript;
|
u8 *wscript;
|
||||||
unsigned int funding_output_index;
|
unsigned int funding_output_index;
|
||||||
u64 commitment_number, cn_obscurer, to_local_msat, to_remote_msat;
|
u64 commitment_number, cn_obscurer, to_local_msat, to_remote_msat;
|
||||||
const struct htlc **htlcs = setup_htlcs(tmpctx), **htlc_map, **htlc_map2,
|
const struct htlc **htlcs, **htlc_map, **htlc_map2, **inv_htlcs;
|
||||||
**inv_htlcs = invert_htlcs(htlcs);
|
|
||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
|
htlcs = setup_htlcs(tmpctx);
|
||||||
|
inv_htlcs = invert_htlcs(htlcs);
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -98,13 +98,13 @@ static struct secret secret_from_hex(const char *hex)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct peer_crypto_state cs_out, cs_in;
|
struct peer_crypto_state cs_out, cs_in;
|
||||||
struct secret sk, rk, ck;
|
struct secret sk, rk, ck;
|
||||||
const void *msg = tal_dup_arr(tmpctx, char, "hello", 5, 0);
|
const void *msg;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
trc = tal_tmpctx(tmpctx);
|
setup_tmpctx();
|
||||||
|
msg = tal_dup_arr(tmpctx, char, "hello", 5, 0);
|
||||||
|
|
||||||
/* BOLT #8:
|
/* BOLT #8:
|
||||||
*
|
*
|
||||||
@@ -125,8 +125,8 @@ int main(void)
|
|||||||
cs_out.cs.sk = cs_in.cs.rk = sk;
|
cs_out.cs.sk = cs_in.cs.rk = sk;
|
||||||
cs_out.cs.rk = cs_in.cs.sk = rk;
|
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;
|
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((void *)tmpctx, &cs_in);
|
||||||
init_peer_crypto_state(tmpctx, &cs_out);
|
init_peer_crypto_state((void *)tmpctx, &cs_out);
|
||||||
|
|
||||||
for (i = 0; i < 1002; i++) {
|
for (i = 0; i < 1002; i++) {
|
||||||
write_buf = tal_arr(tmpctx, char, 0);
|
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
|
#undef main
|
||||||
int main(int argc UNUSED, char *argv[] UNUSED)
|
int main(int argc UNUSED, char *argv[] UNUSED)
|
||||||
{
|
{
|
||||||
char *tmpctx = tal_tmpctx(NULL);
|
|
||||||
char *argv0;
|
char *argv0;
|
||||||
/* We're assuming we're run from top build dir. */
|
/* 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. */
|
/* Various different ways we could find ourselves. */
|
||||||
argv0 = path_join(tmpctx,
|
argv0 = path_join(tmpctx,
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ static struct privkey privkey_from_hex(const char *hex)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
struct bitcoin_tx *input, *funding;
|
struct bitcoin_tx *input, *funding;
|
||||||
u64 fee;
|
u64 fee;
|
||||||
struct pubkey local_funding_pubkey, remote_funding_pubkey;
|
struct pubkey local_funding_pubkey, remote_funding_pubkey;
|
||||||
@@ -49,7 +48,7 @@ int main(void)
|
|||||||
struct pubkey inputkey;
|
struct pubkey inputkey;
|
||||||
bool testnet;
|
bool testnet;
|
||||||
struct utxo utxo;
|
struct utxo utxo;
|
||||||
const struct utxo **utxomap = tal_arr(tmpctx, const struct utxo *, 1);
|
const struct utxo **utxomap;
|
||||||
u64 funding_satoshis;
|
u64 funding_satoshis;
|
||||||
u16 funding_outnum;
|
u16 funding_outnum;
|
||||||
u8 *subscript;
|
u8 *subscript;
|
||||||
@@ -58,6 +57,7 @@ int main(void)
|
|||||||
|
|
||||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||||
| SECP256K1_CONTEXT_SIGN);
|
| SECP256K1_CONTEXT_SIGN);
|
||||||
|
setup_tmpctx();
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
*
|
*
|
||||||
@@ -109,6 +109,7 @@ int main(void)
|
|||||||
printf("input[0] satoshis: %"PRIu64"\n", utxo.amount);
|
printf("input[0] satoshis: %"PRIu64"\n", utxo.amount);
|
||||||
printf("funding satoshis: %"PRIu64"\n", funding_satoshis);
|
printf("funding satoshis: %"PRIu64"\n", funding_satoshis);
|
||||||
|
|
||||||
|
utxomap = tal_arr(tmpctx, const struct utxo *, 1);
|
||||||
utxomap[0] = &utxo;
|
utxomap[0] = &utxo;
|
||||||
funding = funding_tx(tmpctx, &funding_outnum, utxomap,
|
funding = funding_tx(tmpctx, &funding_outnum, utxomap,
|
||||||
funding_satoshis,
|
funding_satoshis,
|
||||||
|
|||||||
@@ -1325,7 +1325,6 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
|||||||
const secp256k1_ecdsa_signature *remote_htlc_sigs,
|
const secp256k1_ecdsa_signature *remote_htlc_sigs,
|
||||||
struct tracked_output **outs)
|
struct tracked_output **outs)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 **htlc_scripts;
|
u8 **htlc_scripts;
|
||||||
u8 *local_wscript, *script[NUM_SIDES];
|
u8 *local_wscript, *script[NUM_SIDES];
|
||||||
struct pubkey local_per_commitment_point;
|
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,
|
note_missing_htlcs(htlc_scripts, htlcs,
|
||||||
tell_if_missing, tell_immediately);
|
tell_if_missing, tell_immediately);
|
||||||
wait_for_resolved(outs);
|
wait_for_resolved(outs);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We produce individual penalty txs. It's less efficient, but avoids them
|
/* 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 */
|
* delay */
|
||||||
static void steal_to_them_output(struct tracked_output *out)
|
static void steal_to_them_output(struct tracked_output *out)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 *wscript;
|
u8 *wscript;
|
||||||
struct bitcoin_tx *tx;
|
struct bitcoin_tx *tx;
|
||||||
enum tx_type tx_type = OUR_PENALTY_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);
|
&tx_type);
|
||||||
|
|
||||||
propose_resolution(out, tx, 0, tx_type);
|
propose_resolution(out, tx, 0, tx_type);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void steal_htlc(struct tracked_output *out)
|
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,
|
const bool *tell_immediately,
|
||||||
struct tracked_output **outs)
|
struct tracked_output **outs)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 **htlc_scripts;
|
u8 **htlc_scripts;
|
||||||
u8 *remote_wscript, *script[NUM_SIDES];
|
u8 *remote_wscript, *script[NUM_SIDES];
|
||||||
struct keyset *ks;
|
struct keyset *ks;
|
||||||
@@ -1874,7 +1869,6 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
|||||||
note_missing_htlcs(htlc_scripts, htlcs,
|
note_missing_htlcs(htlc_scripts, htlcs,
|
||||||
tell_if_missing, tell_immediately);
|
tell_if_missing, tell_immediately);
|
||||||
wait_for_resolved(outs);
|
wait_for_resolved(outs);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
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,
|
const bool *tell_immediately,
|
||||||
struct tracked_output **outs)
|
struct tracked_output **outs)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 **htlc_scripts;
|
u8 **htlc_scripts;
|
||||||
u8 *remote_wscript, *script[NUM_SIDES];
|
u8 *remote_wscript, *script[NUM_SIDES];
|
||||||
struct keyset *ks;
|
struct keyset *ks;
|
||||||
@@ -2103,12 +2096,11 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
|||||||
note_missing_htlcs(htlc_scripts, htlcs,
|
note_missing_htlcs(htlc_scripts, htlcs,
|
||||||
tell_if_missing, tell_immediately);
|
tell_if_missing, tell_immediately);
|
||||||
wait_for_resolved(outs);
|
wait_for_resolved(outs);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const tal_t *ctx = tal_tmpctx(NULL);
|
const tal_t *ctx = tal(NULL, char);
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
struct privkey seed;
|
struct privkey seed;
|
||||||
struct pubkey remote_payment_basepoint, remote_htlc_basepoint,
|
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);
|
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,
|
if (!fromwire_onchain_init(ctx, msg,
|
||||||
&seed, &shachain,
|
&seed, &shachain,
|
||||||
&funding_amount_satoshi,
|
&funding_amount_satoshi,
|
||||||
@@ -2174,7 +2166,7 @@ int main(int argc, char *argv[])
|
|||||||
"Can't allocate %"PRIu64" htlcs", num_htlcs);
|
"Can't allocate %"PRIu64" htlcs", num_htlcs);
|
||||||
|
|
||||||
for (u64 i = 0; i < num_htlcs; i++) {
|
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],
|
if (!fromwire_onchain_htlc(msg, &htlcs[i],
|
||||||
&tell_if_missing[i],
|
&tell_if_missing[i],
|
||||||
&tell_immediately[i]))
|
&tell_immediately[i]))
|
||||||
@@ -2310,7 +2302,7 @@ int main(int argc, char *argv[])
|
|||||||
"Unknown commitment index %"PRIu64
|
"Unknown commitment index %"PRIu64
|
||||||
" for tx %s",
|
" for tx %s",
|
||||||
commit_num,
|
commit_num,
|
||||||
type_to_string(ctx, struct bitcoin_tx,
|
type_to_string(tmpctx, struct bitcoin_tx,
|
||||||
tx));
|
tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ static void trigger_invoice_waiter_resolve(struct invoices *invoices,
|
|||||||
u64 id,
|
u64 id,
|
||||||
const struct invoice *invoice)
|
const struct invoice *invoice)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(invoices);
|
|
||||||
struct invoice_waiter *w;
|
struct invoice_waiter *w;
|
||||||
struct invoice_waiter *n;
|
struct invoice_waiter *n;
|
||||||
|
|
||||||
@@ -67,15 +66,12 @@ static void trigger_invoice_waiter_resolve(struct invoices *invoices,
|
|||||||
tal_steal(tmpctx, w);
|
tal_steal(tmpctx, w);
|
||||||
trigger_invoice_waiter(w, invoice);
|
trigger_invoice_waiter(w, invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
trigger_invoice_waiter_expire_or_delete(struct invoices *invoices,
|
trigger_invoice_waiter_expire_or_delete(struct invoices *invoices,
|
||||||
u64 id,
|
u64 id,
|
||||||
const struct invoice *invoice)
|
const struct invoice *invoice)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(invoices);
|
|
||||||
struct invoice_waiter *w;
|
struct invoice_waiter *w;
|
||||||
struct invoice_waiter *n;
|
struct invoice_waiter *n;
|
||||||
|
|
||||||
@@ -86,8 +82,6 @@ trigger_invoice_waiter_expire_or_delete(struct invoices *invoices,
|
|||||||
tal_steal(tmpctx, w);
|
tal_steal(tmpctx, w);
|
||||||
trigger_invoice_waiter(w, invoice);
|
trigger_invoice_waiter(w, invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wallet_stmt2invoice_details(const tal_t *ctx,
|
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 install_expiration_timer(struct invoices *invoices);
|
||||||
static void trigger_expiration(struct invoices *invoices)
|
static void trigger_expiration(struct invoices *invoices)
|
||||||
{
|
{
|
||||||
const tal_t *tmpctx = tal_tmpctx(invoices);
|
|
||||||
struct list_head idlist;
|
struct list_head idlist;
|
||||||
struct invoice_id_node *idn;
|
struct invoice_id_node *idn;
|
||||||
u64 now = time_now().ts.tv_sec;
|
u64 now = time_now().ts.tv_sec;
|
||||||
@@ -201,8 +194,6 @@ static void trigger_expiration(struct invoices *invoices)
|
|||||||
}
|
}
|
||||||
|
|
||||||
install_expiration_timer(invoices);
|
install_expiration_timer(invoices);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void install_expiration_timer(struct invoices *invoices)
|
static void install_expiration_timer(struct invoices *invoices)
|
||||||
@@ -447,7 +438,6 @@ void invoices_resolve(struct invoices *invoices,
|
|||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
s64 pay_index;
|
s64 pay_index;
|
||||||
u64 paid_timestamp;
|
u64 paid_timestamp;
|
||||||
const tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
|
|
||||||
/* Assign a pay-index. */
|
/* Assign a pay-index. */
|
||||||
pay_index = get_next_pay_index(invoices->db);
|
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. */
|
/* Tell all the waiters about the paid invoice. */
|
||||||
trigger_invoice_waiter_resolve(invoices, invoice.id, &invoice);
|
trigger_invoice_waiter_resolve(invoices, invoice.id, &invoice);
|
||||||
|
|
||||||
/* Free all watchers. */
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when an invoice waiter is destructed. */
|
/* Called when an invoice waiter is destructed. */
|
||||||
|
|||||||
@@ -961,8 +961,10 @@ static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
struct lightningd *ld;
|
||||||
struct lightningd *ld = tal(tmpctx, struct lightningd);
|
|
||||||
|
setup_tmpctx();
|
||||||
|
ld = tal(tmpctx, struct lightningd);
|
||||||
|
|
||||||
/* Only elements in ld we should access */
|
/* Only elements in ld we should access */
|
||||||
list_head_init(&ld->peers);
|
list_head_init(&ld->peers);
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES)
|
|||||||
void txfilter_add_derkey(struct txfilter *filter,
|
void txfilter_add_derkey(struct txfilter *filter,
|
||||||
const u8 derkey[PUBKEY_DER_LEN])
|
const u8 derkey[PUBKEY_DER_LEN])
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(filter);
|
|
||||||
u8 *skp, *p2sh;
|
u8 *skp, *p2sh;
|
||||||
|
|
||||||
skp = scriptpubkey_p2wpkh_derkey(tmpctx, derkey);
|
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(skp));
|
||||||
txfilter_add_scriptpubkey(filter, take(p2sh));
|
txfilter_add_scriptpubkey(filter, take(p2sh));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -528,7 +528,6 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
|
|||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
const unsigned char *addrstr;
|
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_stmt *stmt = db_prepare(w->db, "SELECT id, node_id, address FROM peers WHERE node_id=?;");
|
||||||
sqlite3_bind_pubkey(stmt, 1, nodeid);
|
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;
|
peer->dbid = 0;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
tal_free(tmpctx);
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,7 +582,6 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
|
|||||||
secp256k1_ecdsa_signature last_sig;
|
secp256k1_ecdsa_signature last_sig;
|
||||||
u8 *remote_shutdown_scriptpubkey;
|
u8 *remote_shutdown_scriptpubkey;
|
||||||
struct changed_htlc *last_sent_commit;
|
struct changed_htlc *last_sent_commit;
|
||||||
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
||||||
s64 final_key_idx;
|
s64 final_key_idx;
|
||||||
|
|
||||||
peer_dbid = sqlite3_column_int64(stmt, 1);
|
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) {
|
if (!peer) {
|
||||||
peer = wallet_peer_load(w, peer_dbid);
|
peer = wallet_peer_load(w, peer_dbid);
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,14 +634,12 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
|
|||||||
&channel_info.their_config);
|
&channel_info.their_config);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
final_key_idx = sqlite3_column_int64(stmt, 29);
|
final_key_idx = sqlite3_column_int64(stmt, 29);
|
||||||
if (final_key_idx < 0) {
|
if (final_key_idx < 0) {
|
||||||
log_broken(w->log, "%s: Final key < 0", __func__);
|
log_broken(w->log, "%s: Final key < 0", __func__);
|
||||||
tal_free(tmpctx);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
chan = new_channel(peer, sqlite3_column_int64(stmt, 0),
|
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,
|
last_sent_commit,
|
||||||
sqlite3_column_int64(stmt, 35));
|
sqlite3_column_int64(stmt, 35));
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,7 +856,6 @@ u64 wallet_get_channel_dbid(struct wallet *wallet)
|
|||||||
|
|
||||||
void wallet_channel_save(struct wallet *w, struct channel *chan)
|
void wallet_channel_save(struct wallet *w, struct channel *chan)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(w);
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
assert(chan->first_blocknum);
|
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);
|
sqlite3_bind_int64(stmt, 3, chan->dbid);
|
||||||
db_exec_prepared(w->db, stmt);
|
db_exec_prepared(w->db, stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_channel_insert(struct wallet *w, struct channel *chan)
|
void wallet_channel_insert(struct wallet *w, struct channel *chan)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(w);
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
|
||||||
if (chan->peer->dbid == 0) {
|
if (chan->peer->dbid == 0) {
|
||||||
@@ -999,7 +988,6 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
|
|||||||
|
|
||||||
/* Now save path as normal */
|
/* Now save path as normal */
|
||||||
wallet_channel_save(w, chan);
|
wallet_channel_save(w, chan);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_channel_delete(struct wallet *w, u64 wallet_id)
|
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,
|
void wallet_htlc_save_in(struct wallet *wallet,
|
||||||
const struct channel *chan, struct htlc_in *in)
|
const struct channel *chan, struct htlc_in *in)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(wallet);
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
|
||||||
stmt = db_prepare(
|
stmt = db_prepare(
|
||||||
@@ -1136,14 +1123,12 @@ void wallet_htlc_save_in(struct wallet *wallet,
|
|||||||
|
|
||||||
db_exec_prepared(wallet->db, stmt);
|
db_exec_prepared(wallet->db, stmt);
|
||||||
in->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
|
in->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_htlc_save_out(struct wallet *wallet,
|
void wallet_htlc_save_out(struct wallet *wallet,
|
||||||
const struct channel *chan,
|
const struct channel *chan,
|
||||||
struct htlc_out *out)
|
struct htlc_out *out)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(wallet);
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
|
||||||
/* We absolutely need the incoming HTLC to be persisted before
|
/* 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);
|
db_exec_prepared(wallet->db, stmt);
|
||||||
|
|
||||||
out->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
|
out->dbid = sqlite3_last_insert_rowid(wallet->db->sql);
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
|
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*/)
|
const u8 *failupdate /*tal_arr*/)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
const tal_t *tmpctx = tal_tmpctx(wallet);
|
|
||||||
struct short_channel_id *scid;
|
struct short_channel_id *scid;
|
||||||
|
|
||||||
stmt = db_prepare(wallet->db,
|
stmt = db_prepare(wallet->db,
|
||||||
@@ -1815,8 +1798,6 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
|
|||||||
sqlite3_bind_sha256(stmt, 8, payment_hash);
|
sqlite3_bind_sha256(stmt, 8, payment_hash);
|
||||||
|
|
||||||
db_exec_prepared(wallet->db, stmt);
|
db_exec_prepared(wallet->db, stmt);
|
||||||
|
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wallet_payment **
|
const struct wallet_payment **
|
||||||
|
|||||||
@@ -159,10 +159,8 @@ void towire_wirestring(u8 **pptr, const char *str)
|
|||||||
|
|
||||||
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
|
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
|
||||||
u8 *lin = linearize_tx(tmpctx, tx);
|
u8 *lin = linearize_tx(tmpctx, tx);
|
||||||
towire_u8_array(pptr, lin, tal_len(lin));
|
towire_u8_array(pptr, lin, tal_len(lin));
|
||||||
tal_free(tmpctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)
|
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)
|
||||||
|
|||||||
Reference in New Issue
Block a user