Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce support for alternative addresses for peer connections #7422

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
60 changes: 60 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,9 @@
"ListConfigs.configs.addr": 47,
"ListConfigs.configs.alias": 30,
"ListConfigs.configs.allow-deprecated-apis": 14,
"ListConfigs.configs.alt-addr": 71,
"ListConfigs.configs.alt-announce-addr": 73,
"ListConfigs.configs.alt-bind-addr": 72,
"ListConfigs.configs.always-use-proxy": 17,
"ListConfigs.configs.announce-addr": 48,
"ListConfigs.configs.announce-addr-discovered": 54,
Expand Down Expand Up @@ -1688,6 +1691,22 @@
"ListConfigs.configs.allow-deprecated-apis.source": 2,
"ListConfigs.configs.allow-deprecated-apis.value_bool": 1
},
"ListconfigsConfigsAlt-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1
},
"ListconfigsConfigsAlt-announce-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1,
"ListConfigs.configs.alt-announce-addr.sources[]": 2,
"ListConfigs.configs.alt-announce-addr.values_str[]": 1
},
"ListconfigsConfigsAlt-bind-addr": {
"ListConfigs.configs.alt-addr.sources[]": 2,
"ListConfigs.configs.alt-addr.values_str[]": 1,
"ListConfigs.configs.alt-bind-addr.sources[]": 2,
"ListConfigs.configs.alt-bind-addr.values_str[]": 1
},
"ListconfigsConfigsAlways-use-proxy": {
"ListConfigs.configs.always-use-proxy.source": 2,
"ListConfigs.configs.always-use-proxy.value_bool": 1
Expand Down Expand Up @@ -2378,6 +2397,7 @@
"ListPeerChannels.channels[]": 1
},
"ListpeersPeers": {
"ListPeers.peers[].alt_addrs[]": 9,
"ListPeers.peers[].channels[]": 4,
"ListPeers.peers[].connected": 2,
"ListPeers.peers[].features": 6,
Expand Down Expand Up @@ -6746,6 +6766,42 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"ListConfigs.configs.alt-addr": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-addr.sources[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-addr.values_str[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr.sources[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-announce-addr.values_str[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr.sources[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.alt-bind-addr.values_str[]": {
"added": "v24.11",
"deprecated": false
},
"ListConfigs.configs.always-use-proxy": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down Expand Up @@ -8818,6 +8874,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"ListPeers.peers[].alt_addrs[]": {
"added": "v24.11",
"deprecated": null
},
"ListPeers.peers[].channels[]": {
"added": "pre-v0.10.1",
"deprecated": "v23.02"
Expand Down
41 changes: 40 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct peer {
bool channel_ready[NUM_SIDES];
u64 next_index[NUM_SIDES];

/* ID of peer */
struct node_id id;
maxrantil marked this conversation as resolved.
Show resolved Hide resolved

/* --developer? */
bool developer;

Expand Down Expand Up @@ -169,6 +172,9 @@ struct peer {
u64 revocations_received;
u8 channel_flags;

/* Alt address for peer connections not publicly announced */
u8 *my_alt_addr;

/* Make sure timestamps move forward. */
u32 last_update_timestamp;

Expand Down Expand Up @@ -533,6 +539,17 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
check_mutual_splice_locked(peer);
}

static void send_peer_my_alt_addr(struct peer *peer)
{
/* Send my alt addr to peer db */
u8 *peer_msg = towire_peer_alt_addr(peer, peer->my_alt_addr);
peer_write(peer->pps, take(peer_msg));

/* We need the addrs in my own db too for later whitelist confirmation */
u8 *msg = towire_channeld_my_alt_addr(tmpctx, peer->my_alt_addr);
wire_sync_write(MASTER_FD, take(msg));
}

static void handle_peer_channel_ready(struct peer *peer, const u8 *msg)
{
struct channel_id chanid;
Expand Down Expand Up @@ -4158,6 +4175,9 @@ static void peer_in(struct peer *peer, const u8 *msg)

check_tx_abort(peer, msg);

if (peer->my_alt_addr)
send_peer_my_alt_addr(peer);

/* If we're in STFU mode and aren't waiting for a STFU mode
* specific message, the only valid message was tx_abort */
if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) {
Expand Down Expand Up @@ -4290,6 +4310,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_ONION_MESSAGE:
case WIRE_PEER_STORAGE:
case WIRE_YOUR_PEER_STORAGE:
case WIRE_PEER_ALT_ADDR:
abort();
}

Expand Down Expand Up @@ -5660,6 +5681,18 @@ static void handle_dev_quiesce(struct peer *peer, const u8 *msg)
maybe_send_stfu(peer);
}

static void handle_channeld_peer_alt_addr(struct peer *peer, const u8 *msg)
{
u8 *my_alt_addr;

if (!fromwire_channeld_peer_alt_addr(peer, msg, &my_alt_addr))
master_badmsg(WIRE_CHANNELD_PEER_ALT_ADDR, msg);

u8 *peer_msg = towire_peer_alt_addr(peer, my_alt_addr);
peer_write(peer->pps, take(peer_msg));
tal_free(my_alt_addr);
}

static void req_in(struct peer *peer, const u8 *msg)
{
enum channeld_wire t = fromwire_peektype(msg);
Expand Down Expand Up @@ -5699,6 +5732,9 @@ static void req_in(struct peer *peer, const u8 *msg)
case WIRE_CHANNELD_SEND_ERROR:
handle_send_error(peer, msg);
return;
case WIRE_CHANNELD_PEER_ALT_ADDR:
handle_channeld_peer_alt_addr(peer, msg);
return;
case WIRE_CHANNELD_SPLICE_INIT:
handle_splice_init(peer, msg);
return;
Expand Down Expand Up @@ -5762,6 +5798,7 @@ static void req_in(struct peer *peer, const u8 *msg)
case WIRE_CHANNELD_SPLICE_STATE_ERROR:
case WIRE_CHANNELD_LOCAL_ANCHOR_INFO:
case WIRE_CHANNELD_REESTABLISHED:
case WIRE_CHANNELD_MY_ALT_ADDR:
break;
}
master_badmsg(-1, msg);
Expand Down Expand Up @@ -5847,7 +5884,9 @@ static void init_channel(struct peer *peer)
&reestablish_only,
&peer->experimental_upgrade,
&peer->splice_state->inflights,
&peer->local_alias)) {
&peer->local_alias,
&peer->my_alt_addr,
&peer->id)) {
master_badmsg(WIRE_CHANNELD_INIT, msg);
}

Expand Down
13 changes: 13 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ msgdata,channeld_init,experimental_upgrade,bool,
msgdata,channeld_init,num_inflights,u16,
msgdata,channeld_init,inflights,inflight,num_inflights
msgdata,channeld_init,scid_alias,short_channel_id,
msgdata,channeld_init,alt_addr_len,u16,
msgdata,channeld_init,alt_addr,u8,alt_addr_len,
msgdata,channeld_init,id,node_id,

# channeld->lightningd: successfully negotated reestablishment.
msgtype,channeld_reestablished,1101
Expand Down Expand Up @@ -347,3 +350,13 @@ msgdata,channeld_upgraded,new_type,channel_type,
# Tell peer about our latest and greatest blockheight.
msgtype,channeld_blockheight,1012
msgdata,channeld_blockheight,blockheight,u32,

# master -> channeld: send peer our alternative addresses
msgtype,channeld_peer_alt_addr,1035
msgdata,channeld_peer_alt_addr,alt_addr_len,u16,
msgdata,channeld_peer_alt_addr,alt_addr,u8,alt_addr_len,

# channeld -> master: send our alternative addresses to our db
msgtype,channeld_my_alt_addr,1037
msgdata,channeld_my_alt_addr,alt_addr_len,u16,
msgdata,channeld_my_alt_addr,alt_addr,u8,alt_addr_len,
19 changes: 19 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ COMMON_SRC_NOGEN := \
common/utxo.c \
common/version.c \
common/wallet.c \
common/whitelisted_peer.c \
common/wireaddr.c \
common/wire_error.c

Expand Down
1 change: 1 addition & 0 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ const void *gossmap_stream_next(const tal_t *ctx,
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_ONION_MESSAGE:
case WIRE_PEER_ALT_ADDR:
break;
}
}
Expand Down
Loading
Loading