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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-10-13 14:15:35 +10:30 committed by Christian Decker
parent 8a85bf6880
commit 433e61fcb9
1 changed files with 13 additions and 2 deletions

View File

@ -2423,6 +2423,8 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
bool *we_filled) bool *we_filled)
{ {
struct db_stmt *stmt; 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 */ /* We should only use this for badonion codes */
assert(!badonion || (badonion & BADONION)); assert(!badonion || (badonion & BADONION));
@ -2459,13 +2461,22 @@ void wallet_htlc_update(struct wallet *wallet, const u64 htlc_dbid,
db_bind_null(stmt, 5); db_bind_null(stmt, 5);
/* Set max_commit_num iff we're in final state. */ /* Set max_commit_num iff we're in final state. */
if (new_state == RCVD_REMOVE_ACK_REVOCATION if (terminal)
|| new_state == SENT_REMOVE_ACK_REVOCATION)
db_bind_u64(stmt, 6, max_commit_num); db_bind_u64(stmt, 6, max_commit_num);
else else
db_bind_null(stmt, 6); db_bind_null(stmt, 6);
db_exec_prepared_v2(take(stmt)); 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, static bool wallet_stmt2htlc_in(struct channel *channel,