mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +01:00
connectd: add network to init message
Changelog-Added: protocol: We now signal the network we are running on at init.
This commit is contained in:
committed by
Christian Decker
parent
4b13b88f6c
commit
3322048774
@@ -27,6 +27,15 @@ struct peer {
|
||||
u8 *msg;
|
||||
};
|
||||
|
||||
static bool contains_common_chain(struct bitcoin_blkid *chains)
|
||||
{
|
||||
for (size_t i = 0; i < tal_count(chains); i++) {
|
||||
if (bitcoin_blkid_eq(&chains[0], &chainparams->genesis_blockhash))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Here in case we need to read another message. */
|
||||
static struct io_plan *read_init(struct io_conn *conn, struct peer *peer);
|
||||
|
||||
@@ -36,6 +45,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
|
||||
u8 *msg = cryptomsg_decrypt_body(tmpctx, &peer->cs, peer->msg);
|
||||
u8 *globalfeatures, *features;
|
||||
int unsup;
|
||||
struct tlv_init_tlvs *tlvs = tlv_init_tlvs_new(msg);
|
||||
|
||||
if (!msg)
|
||||
return io_close(conn);
|
||||
@@ -51,13 +61,34 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
|
||||
if (unlikely(is_unknown_msg_discardable(msg)))
|
||||
return read_init(conn, peer);
|
||||
|
||||
if (!fromwire_init(tmpctx, msg, &globalfeatures, &features)) {
|
||||
if (!fromwire_init(tmpctx, msg, &globalfeatures, &features, tlvs)) {
|
||||
status_peer_debug(&peer->id,
|
||||
"bad fromwire_init '%s', closing",
|
||||
tal_hex(tmpctx, msg));
|
||||
return io_close(conn);
|
||||
}
|
||||
|
||||
/* BOLT-ef7c97c02b6fa67a1df1af30b3843eb576100ebd #1:
|
||||
* The receiving node:
|
||||
* ...
|
||||
* - upon receiving `networks` containing no common chains
|
||||
* - MAY fail the connection.
|
||||
*/
|
||||
if (tlvs->networks) {
|
||||
if (!tlvs->networks->chains) {
|
||||
status_peer_debug(&peer->id,
|
||||
"bad networks TLV in init '%s', closing",
|
||||
tal_hex(tmpctx, msg));
|
||||
return io_close(conn);
|
||||
}
|
||||
if (!contains_common_chain(tlvs->networks->chains)) {
|
||||
status_peer_debug(&peer->id,
|
||||
"No common chain with this peer '%s', closing",
|
||||
tal_hex(tmpctx, msg));
|
||||
return io_close(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/* The globalfeatures field is now unused, but there was a
|
||||
* window where it was: combine the two. */
|
||||
for (size_t i = 0; i < tal_bytelen(globalfeatures) * 8; i++) {
|
||||
@@ -136,18 +167,27 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
||||
/* If conn is closed, forget peer */
|
||||
struct peer *peer = tal(conn, struct peer);
|
||||
struct io_plan *(*next)(struct io_conn *, struct peer *);
|
||||
struct tlv_init_tlvs *tlvs;
|
||||
|
||||
peer->daemon = daemon;
|
||||
peer->id = *id;
|
||||
peer->addr = *addr;
|
||||
peer->cs = *cs;
|
||||
|
||||
/* BOLT #1:
|
||||
/* BOLT-ef7c97c02b6fa67a1df1af30b3843eb576100ebd #1:
|
||||
*
|
||||
* The sending node:
|
||||
* - MUST send `init` as the first Lightning message for any
|
||||
* connection.
|
||||
* ...
|
||||
* - SHOULD set `networks` to all chains it will gossip or open
|
||||
* channels for.
|
||||
*/
|
||||
tlvs = tlv_init_tlvs_new(tmpctx);
|
||||
tlvs->networks = tal(tlvs, struct tlv_init_tlvs_networks);
|
||||
tlvs->networks->chains = tal_arr(tlvs->networks, struct bitcoin_blkid, 1);
|
||||
tlvs->networks->chains[0] = chainparams->genesis_blockhash;
|
||||
|
||||
/* Initially, there were two sets of feature bits: global and local.
|
||||
* Local affected peer nodes only, global affected everyone. Both were
|
||||
* sent in the `init` message, but node_announcement only advertized
|
||||
@@ -167,7 +207,8 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
||||
* from now on they'll all go in initfeatures. */
|
||||
peer->msg = towire_init(NULL,
|
||||
get_offered_globalinitfeatures(tmpctx),
|
||||
get_offered_initfeatures(tmpctx));
|
||||
get_offered_initfeatures(tmpctx),
|
||||
tlvs);
|
||||
status_peer_io(LOG_IO_OUT, &peer->id, peer->msg);
|
||||
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user