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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-10-13 14:15:36 +10:30 committed by Christian Decker
parent 3b5c24ada1
commit da03985996
3 changed files with 8 additions and 4 deletions

View file

@ -130,7 +130,8 @@ static void handle_onchain_init_reply(struct channel *channel, const u8 *msg)
/* Tell it about any relevant HTLCs */
/* FIXME: Filter by commitnum! */
stubs = wallet_htlc_stubs(tmpctx, channel->peer->ld->wallet, channel);
stubs = wallet_htlc_stubs(tmpctx, channel->peer->ld->wallet, channel,
commit_num);
tell = tal_arr(stubs, bool, tal_count(stubs));
tell_immediate = tal_arr(stubs, bool, tal_count(stubs));

View file

@ -2836,7 +2836,7 @@ const struct invoice_details *wallet_invoice_details(const tal_t *ctx,
}
struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
struct channel *chan)
struct channel *chan, u64 commit_num)
{
struct htlc_stub *stubs;
struct sha256 payment_hash;
@ -2845,9 +2845,11 @@ struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
stmt = db_prepare_v2(wallet->db,
SQL("SELECT channel_id, direction, cltv_expiry, "
"channel_htlc_id, payment_hash "
"FROM channel_htlcs WHERE channel_id = ?;"));
"FROM channel_htlcs WHERE channel_id = ? AND min_commit_num <= ? AND ((max_commit_num IS NULL) OR max_commit_num >= ?);"));
db_bind_u64(stmt, 0, chan->dbid);
db_bind_u64(stmt, 1, commit_num);
db_bind_u64(stmt, 2, commit_num);
db_query_prepared(stmt);
stubs = tal_arr(ctx, struct htlc_stub, 0);

View file

@ -1058,9 +1058,10 @@ const struct invoice_details *wallet_invoice_details(const tal_t *ctx,
* @ctx: Allocation context for the return value
* @wallet: Wallet to load from
* @chan: Channel to fetch stubs for
* @commit_num: The commitment number of the commit tx.
*/
struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet,
struct channel *chan);
struct channel *chan, u64 commit_num);
/**
* wallet_payment_setup - Remember this payment for later committing.