Skip to content

Commit da03985

Browse files
rustyrussellcdecker
authored andcommitted
wallet: only hand onchaind the HTLCs it needs to know.
This will make closing long-lived channels more efficient, and it's just nicer. Signed-off-by: Rusty Russell <[email protected]>
1 parent 3b5c24a commit da03985

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lightningd/onchain_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ static void handle_onchain_init_reply(struct channel *channel, const u8 *msg)
130130

131131
/* Tell it about any relevant HTLCs */
132132
/* FIXME: Filter by commitnum! */
133-
stubs = wallet_htlc_stubs(tmpctx, channel->peer->ld->wallet, channel);
133+
stubs = wallet_htlc_stubs(tmpctx, channel->peer->ld->wallet, channel,
134+
commit_num);
134135
tell = tal_arr(stubs, bool, tal_count(stubs));
135136
tell_immediate = tal_arr(stubs, bool, tal_count(stubs));
136137

wallet/wallet.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,7 +2836,7 @@ const struct invoice_details *wallet_invoice_details(const tal_t *ctx,
28362836
}
28372837

28382838
struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
2839-
struct channel *chan)
2839+
struct channel *chan, u64 commit_num)
28402840
{
28412841
struct htlc_stub *stubs;
28422842
struct sha256 payment_hash;
@@ -2845,9 +2845,11 @@ struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
28452845
stmt = db_prepare_v2(wallet->db,
28462846
SQL("SELECT channel_id, direction, cltv_expiry, "
28472847
"channel_htlc_id, payment_hash "
2848-
"FROM channel_htlcs WHERE channel_id = ?;"));
2848+
"FROM channel_htlcs WHERE channel_id = ? AND min_commit_num <= ? AND ((max_commit_num IS NULL) OR max_commit_num >= ?);"));
28492849

28502850
db_bind_u64(stmt, 0, chan->dbid);
2851+
db_bind_u64(stmt, 1, commit_num);
2852+
db_bind_u64(stmt, 2, commit_num);
28512853
db_query_prepared(stmt);
28522854

28532855
stubs = tal_arr(ctx, struct htlc_stub, 0);

wallet/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,10 @@ const struct invoice_details *wallet_invoice_details(const tal_t *ctx,
10581058
* @ctx: Allocation context for the return value
10591059
* @wallet: Wallet to load from
10601060
* @chan: Channel to fetch stubs for
1061+
* @commit_num: The commitment number of the commit tx.
10611062
*/
10621063
struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
1063-
struct channel *chan);
1064+
struct channel *chan, u64 commit_num);
10641065

10651066
/**
10661067
* wallet_payment_setup - Remember this payment for later committing.

0 commit comments

Comments
 (0)