staticbackup: don't use wireaddr_internal.

This is an internal type: it has no API guarantees (indeed, I'm about
to change it, which is how I discovered scb was using it).

Fortunately for every case we care about, it is actually a wireaddr
(in theory the peer can connect locally using a local socket, but this
is mostly for testing and is a very strange setup, and so simply don't
do scb for those).

In this case, the wire encoding is a single byte followed by the
wireaddr, so open-code that in scb_wire.csv for compatibility.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-05-30 13:57:56 +09:30
parent 5ccdab71e5
commit 1b6ff0b2fc
4 changed files with 34 additions and 18 deletions

View File

@ -10,10 +10,12 @@ subtype,scb_chan
subtypedata,scb_chan,id,u64,
subtypedata,scb_chan,cid,channel_id,
subtypedata,scb_chan,node_id,node_id,
subtypedata,scb_chan,addr,wireaddr_internal,
subtypedata,scb_chan,unused,u8,
subtypedata,scb_chan,addr,wireaddr,
subtypedata,scb_chan,funding,bitcoin_outpoint,
subtypedata,scb_chan,funding_sats,amount_sat,
subtypedata,scb_chan,type,channel_type,
msgtype,static_chan_backup,6135,
msgdata,static_chan_backup,version,u64,
msgdata,static_chan_backup,timestamp,u32,

1 #include <common/node_id.h>
10 subtypedata,scb_chan,cid,channel_id,
11 subtypedata,scb_chan,node_id,node_id,
12 subtypedata,scb_chan,addr,wireaddr_internal, subtypedata,scb_chan,unused,u8,
13 subtypedata,scb_chan,funding,bitcoin_outpoint, subtypedata,scb_chan,addr,wireaddr,
14 subtypedata,scb_chan,funding,bitcoin_outpoint,
15 subtypedata,scb_chan,funding_sats,amount_sat,
16 subtypedata,scb_chan,type,channel_type,
17 msgtype,static_chan_backup,6135,
18 msgdata,static_chan_backup,version,u64,
19 msgdata,static_chan_backup,version,u64, msgdata,static_chan_backup,timestamp,u32,
20 msgdata,static_chan_backup,timestamp,u32, msgdata,static_chan_backup,num,u16,
21 msgdata,static_chan_backup,num,u16, msgdata,static_chan_backup,channels,scb_chan,num

View File

@ -411,14 +411,20 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->owner = NULL;
memset(&channel->billboard, 0, sizeof(channel->billboard));
channel->billboard.transient = tal_strdup(channel, transient_billboard);
channel->scb = tal(channel, struct scb_chan);
channel->scb->id = dbid;
channel->scb->addr = peer->addr;
channel->scb->node_id = peer->id;
channel->scb->funding = *funding;
channel->scb->cid = *cid;
channel->scb->funding_sats = funding_sats;
channel->scb->type = channel_type_dup(channel->scb, type);
/* If it's a unix domain socket connection, we don't save it */
if (peer->addr.itype == ADDR_INTERNAL_WIREADDR) {
channel->scb = tal(channel, struct scb_chan);
channel->scb->id = dbid;
channel->scb->unused = 0;
channel->scb->addr = peer->addr.u.wireaddr;
channel->scb->node_id = peer->id;
channel->scb->funding = *funding;
channel->scb->cid = *cid;
channel->scb->funding_sats = funding_sats;
channel->scb->type = channel_type_dup(channel->scb, type);
} else
channel->scb = NULL;
if (!log) {
channel->log = new_log(channel,

View File

@ -1261,13 +1261,17 @@ wallet_commit_channel(struct lightningd *ld,
&commitment_feerate);
channel->min_possible_feerate = commitment_feerate;
channel->max_possible_feerate = commitment_feerate;
channel->scb = tal(channel, struct scb_chan);
channel->scb->id = channel->dbid;
channel->scb->addr = channel->peer->addr;
channel->scb->node_id = channel->peer->id;
channel->scb->funding = *funding;
channel->scb->cid = channel->cid;
channel->scb->funding_sats = total_funding;
if (channel->peer->addr.itype == ADDR_INTERNAL_WIREADDR) {
channel->scb = tal(channel, struct scb_chan);
channel->scb->id = channel->dbid;
channel->scb->unused = 0;
channel->scb->addr = channel->peer->addr.u.wireaddr;
channel->scb->node_id = channel->peer->id;
channel->scb->funding = *funding;
channel->scb->cid = channel->cid;
channel->scb->funding_sats = total_funding;
} else
channel->scb = NULL;
channel->type = channel_type_dup(channel, type);
channel->scb->type = channel_type_dup(channel->scb, type);

View File

@ -1309,7 +1309,7 @@ static struct channel *stub_chan(struct command *cmd,
struct node_id nodeid,
struct channel_id cid,
struct bitcoin_outpoint funding,
struct wireaddr_internal addr,
struct wireaddr addr,
struct amount_sat funding_sats,
struct channel_type *type)
{
@ -1342,10 +1342,14 @@ static struct channel *stub_chan(struct command *cmd,
return NULL;
}
} else {
struct wireaddr_internal wint;
wint.itype = ADDR_INTERNAL_WIREADDR;
wint.u.wireaddr = addr;
peer = new_peer(cmd->ld,
0,
&nodeid,
&addr,
&wint,
false);
}