Skip to content

Commit

Permalink
lightningd: save peer's commitment anchor info into db.
Browse files Browse the repository at this point in the history
We actually only need to remember the last two, worst case.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 27, 2023
1 parent be96d33 commit 484deb9
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,34 @@ static void handle_local_channel_update(struct channel *channel,
tell_gossipd_local_channel_update(channel->peer->ld, channel, enable);
}

static void handle_local_anchors(struct channel *channel, const u8 *msg)
{
u64 remote_commitnum;
struct local_anchor_info *anchors;

if (!fromwire_channeld_local_anchor_info(msg, msg, &remote_commitnum,
&anchors)) {
channel_internal_error(channel,
"bad channeld_local_anchor_info %s",
tal_hex(channel, msg));
return;
}

/* Update all these anchors */
for (size_t i = 0; i < tal_count(anchors); i++) {
wallet_set_local_anchor(channel->peer->ld->wallet,
channel->dbid,
anchors + i,
remote_commitnum);
}
/* Now safe to forget old ones */
if (remote_commitnum > 2) {
wallet_remove_local_anchors(channel->peer->ld->wallet,
channel->dbid,
remote_commitnum - 2);
}
}

static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
{
enum channeld_wire t = fromwire_peektype(msg);
Expand All @@ -1229,7 +1257,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
peer_sending_commitsig(sd->channel, msg);
break;
case WIRE_CHANNELD_LOCAL_ANCHOR_INFO:
/* FIXME */
handle_local_anchors(sd->channel, msg);
break;
case WIRE_CHANNELD_GOT_COMMITSIG:
peer_got_commitsig(sd->channel, msg);
Expand Down

0 comments on commit 484deb9

Please sign in to comment.