Skip to content

Commit

Permalink
db: Store the local alias for forwarded incoming payments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdecker committed Jul 4, 2022
1 parent 92b891b commit 252ccfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 8 additions & 10 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand All @@ -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);

Expand Down

0 comments on commit 252ccfa

Please sign in to comment.