From a668cb4f2bd38b99e0c26ff52b3dab46caecf1de Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 10 Oct 2017 14:05:36 +0200 Subject: [PATCH] onchain: Load HTLC stubs upon starting onchaind This wires in the loading of `struct htlc_stub`s on-demand when starting `onchaind` so that we don't need to keep them in memory. Signed-off-by: Christian Decker --- lightningd/peer_control.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index ac39147b5..d66478d88 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1400,6 +1400,7 @@ static enum watch_result funding_spent(struct peer *peer, struct sha256_double our_last_txid; s64 keyindex; struct pubkey ourkey; + struct htlc_stub *stubs; peer_fail_permanent_str(peer, "Funding transaction spent"); @@ -1419,6 +1420,12 @@ static enum watch_result funding_spent(struct peer *peer, return KEEP_WATCHING; } + stubs = wallet_htlc_stubs(peer, peer->ld->wallet, peer->channel); + if (!stubs) { + log_broken(peer->log, "Could not load htlc_stubs"); + return KEEP_WATCHING; + } + /* We re-use this key to send other outputs to. */ if (peer->local_shutdown_idx >= 0) keyindex = peer->local_shutdown_idx; @@ -1469,14 +1476,14 @@ static enum watch_result funding_spent(struct peer *peer, /* FIXME: config for 'reasonable depth' */ 3, peer->last_htlc_sigs, - tal_count(peer->htlcs)); + tal_count(stubs)); subd_send_msg(peer->owner, take(msg)); /* FIXME: Don't queue all at once, use an empty cb... */ - for (size_t i = 0; i < tal_count(peer->htlcs); i++) { + for (size_t i = 0; i < tal_count(stubs); i++) { bool tell_immediate; bool tell = tell_if_missing(peer, i, &tell_immediate); - msg = towire_onchain_htlc(peer, peer->htlcs+i, + msg = towire_onchain_htlc(peer, &stubs[i], tell, tell_immediate); subd_send_msg(peer->owner, take(msg)); }