From 252ccfa7ab3ebb6934b90f80f2271537d4b7e82a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 6 May 2022 15:40:23 +0200 Subject: [PATCH] db: Store the local alias for forwarded incoming payments Not only can the outgoing edge be a zeroconf channel, it can also be the incoming channel. So we revert to the usual trick of using the local alias if the short_channel_id isn't known yet. We use the LOCAL alias instead of the REMOTE alias even though the sender likely used the REMOTE alias to refer to the channel. This is because we control the LOCAL alias, and we keep it stable during the lifetime of the channel, whereas the REMOTE one could change or not be there yet. --- lightningd/notification.c | 8 +++++++- wallet/wallet.c | 18 ++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lightningd/notification.c b/lightningd/notification.c index 403ae1187..79f41980c 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -303,7 +303,13 @@ static void forward_event_notification_serialize(struct json_stream *stream, /* Here is more neat to initial a forwarding structure than * to pass in a bunch of parameters directly*/ struct forwarding *cur = tal(tmpctx, struct forwarding); - cur->channel_in = *in->key.channel->scid; + + /* We use the LOCAL alias, not the REMOTE, despite the route + * the the sender is using probably using the REMOTE + * alias. The LOCAL one is controlled by us, and we keep it + * stable. */ + cur->channel_in = *channel_scid_or_local_alias(in->key.channel); + cur->msat_in = in->msat; if (scid_out) { cur->channel_out = *scid_out; diff --git a/wallet/wallet.c b/wallet/wallet.c index ddd0de046..1cc1703e4 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -4334,7 +4334,6 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, { struct db_stmt *stmt; struct timeabs *resolved_time; - struct channel *outchan; if (state == FORWARD_SETTLED || state == FORWARD_FAILED) { resolved_time = tal(tmpctx, struct timeabs); @@ -4363,18 +4362,12 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, db_bind_u64(stmt, 0, in->dbid); if (out) { - outchan = out->key.channel; db_bind_u64(stmt, 1, out->dbid); - /* IF we forward we must have a name for this + /* If we forward we must have a name for this * channel. It can be either a locally assigned alias, * or the real scid. */ - assert(outchan->scid != NULL || outchan->alias[LOCAL]); - if (out->key.channel->scid) - db_bind_u64(stmt, 3, outchan->scid->u64); - else - db_bind_u64(stmt, 3, outchan->alias[LOCAL]->u64); - + db_bind_u64(stmt, 3, channel_scid_or_local_alias(out->key.channel)->u64); db_bind_amount_msat(stmt, 5, &out->msat); } else { /* FORWARD_LOCAL_FAILED may occur before we get htlc_out */ @@ -4385,7 +4378,12 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, db_bind_null(stmt, 5); } - db_bind_u64(stmt, 2, in->key.channel->scid->u64); + /* We use the LOCAL alias, since that's under our control, and + * we keep it stable, whereas the REMOTE alias is likely what + * the sender used to specify the channel, but that's under + * control of the remote end. */ + assert(in->key.channel->scid != NULL || in->key.channel->alias[LOCAL]); + db_bind_u64(stmt, 2, channel_scid_or_local_alias(in->key.channel)->u64); db_bind_amount_msat(stmt, 4, &in->msat);