From 433e61fcb9823d8d0a086a39b31942866fedd893 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 13 Oct 2021 14:15:35 +1030 Subject: [PATCH] wallet: remove unnecessary data from channel_htlcs when htlc is dead. In particular, the onion and errors can be large, but now we'll never need to retransmit them. Signed-off-by: Rusty Russell --- wallet/wallet.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index e7530d1f6..71794fc04 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2423,6 +2423,8 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid, bool *we_filled) { struct db_stmt *stmt; + bool terminal = (new_state == RCVD_REMOVE_ACK_REVOCATION + || new_state == SENT_REMOVE_ACK_REVOCATION); /* We should only use this for badonion codes */ assert(!badonion || (badonion & BADONION)); @@ -2459,13 +2461,22 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid, db_bind_null(stmt, 5); /* Set max_commit_num iff we're in final state. */ - if (new_state == RCVD_REMOVE_ACK_REVOCATION - || new_state == SENT_REMOVE_ACK_REVOCATION) + if (terminal) db_bind_u64(stmt, 6, max_commit_num); else db_bind_null(stmt, 6); db_exec_prepared_v2(take(stmt)); + + if (terminal) { + /* If it's terminal, remove the data we needed for re-xmission. */ + stmt = db_prepare_v2( + wallet->db, + SQL("UPDATE channel_htlcs SET payment_key=NULL, routing_onion=NULL, failuremsg=NULL, shared_secret=NULL, localfailmsg=NULL " + " WHERE id=?")); + db_bind_u64(stmt, 0, htlc_dbid); + db_exec_prepared_v2(take(stmt)); + } } static bool wallet_stmt2htlc_in(struct channel *channel,