diff --git a/lightningd/opening/opening.c b/lightningd/opening/opening.c index f652940cc..72fba6c8e 100644 --- a/lightningd/opening/opening.c +++ b/lightningd/opening/opening.c @@ -202,6 +202,7 @@ static u8 *funder_channel(struct state *state, const struct basepoints *ours, u32 max_minimum_depth, u64 change_satoshis, u32 change_keyindex, + u8 channel_flags, const struct utxo *utxos, const u8 *bip32_seed) { @@ -258,7 +259,8 @@ static u8 *funder_channel(struct state *state, &ours->revocation, &ours->payment, &ours->delayed_payment, - &state->next_per_commit[LOCAL]); + &state->next_per_commit[LOCAL], + channel_flags); if (!sync_crypto_write(&state->cs, PEER_FD, msg)) peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_WRITE_FAILED, "Writing open_channel"); @@ -468,6 +470,7 @@ static u8 *fundee_channel(struct state *state, struct sha256_double chain_hash; u8 *msg; const u8 **wscripts; + u8 channel_flags; state->remoteconf = tal(state, struct channel_config); @@ -491,7 +494,8 @@ static u8 *fundee_channel(struct state *state, &theirs.revocation, &theirs.payment, &theirs.delayed_payment, - &state->next_per_commit[REMOTE])) + &state->next_per_commit[REMOTE], + &channel_flags)) peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_BAD_INITIAL_MESSAGE, "Parsing open_channel %s", tal_hex(peer_msg, peer_msg)); @@ -666,6 +670,7 @@ static u8 *fundee_channel(struct state *state, state->funding_txout, state->funding_satoshis, state->push_msat, + channel_flags, msg); } @@ -681,6 +686,7 @@ int main(int argc, char *argv[]) u32 min_feerate, max_feerate; u64 change_satoshis; u32 change_keyindex; + u8 channel_flags; struct utxo *utxos; u8 *bip32_seed; @@ -734,10 +740,11 @@ int main(int argc, char *argv[]) &state->push_msat, &state->feerate_per_kw, &max_minimum_depth, &change_satoshis, &change_keyindex, - &utxos, &bip32_seed)) + &channel_flags, &utxos, &bip32_seed)) msg = funder_channel(state, &our_funding_pubkey, &our_points, max_minimum_depth, change_satoshis, - change_keyindex, utxos, bip32_seed); + change_keyindex, channel_flags, + utxos, bip32_seed); else if (fromwire_opening_fundee(state, msg, NULL, &minimum_depth, &min_feerate, &max_feerate, &peer_msg)) msg = fundee_channel(state, &our_funding_pubkey, &our_points, diff --git a/lightningd/opening/opening_wire.csv b/lightningd/opening/opening_wire.csv index b3ed6fe3c..5801e85f7 100644 --- a/lightningd/opening/opening_wire.csv +++ b/lightningd/opening/opening_wire.csv @@ -31,6 +31,7 @@ opening_funder,,feerate_per_kw,4 opening_funder,,max_minimum_depth,4 opening_funder,,change_satoshis,u64 opening_funder,,change_keyindex,u32 +opening_funder,,channel_flags,u8 #include opening_funder,,num_inputs,u16 opening_funder,,inputs,num_inputs*struct utxo @@ -72,6 +73,7 @@ opening_fundee_reply,,funding_txid,struct sha256_double opening_fundee_reply,,funding_txout,u16 opening_fundee_reply,,funding_satoshis,8 opening_fundee_reply,,push_msat,8 +opening_fundee_reply,,channel_flags,u8 # The (encrypted) funding signed message: send this and we're committed. opening_fundee_reply,,msglen,u16 opening_fundee_reply,,funding_signed_msg,msglen*u8 diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 0e8492134..c02fd9b2d 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include static void destroy_peer(struct peer *peer) @@ -793,6 +793,15 @@ static enum watch_result funding_lockin_cb(struct peer *peer, peer->scid))); } + /* BOLT #7: + * + * If the `open_channel` message had the `announce_channel` bit set, + * then both nodes must send the `announcement_signatures` message, + * otherwise they MUST NOT. + */ + if (!(peer->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)) + return DELETE_WATCH; + /* BOLT #7: * * If sent, `announcement_signatures` messages MUST NOT be sent until @@ -1338,6 +1347,7 @@ static bool opening_fundee_finished(struct subd *opening, &peer->funding_outnum, &peer->funding_satoshi, &peer->push_msat, + &peer->channel_flags, &funding_signed)) { log_broken(peer->log, "bad OPENING_FUNDEE_REPLY %s", tal_hex(reply, reply)); @@ -1524,6 +1534,8 @@ static bool gossip_peer_released(struct subd *gossip, &max_to_self_delay, &max_minimum_depth, &min_effective_htlc_capacity_msat); + fc->peer->channel_flags = OUR_CHANNEL_FLAGS; + fc->peer->seed = tal(fc->peer, struct privkey); derive_peer_seed(ld, fc->peer->seed, &fc->peer->id); msg = towire_opening_init(fc, &fc->peer->our_config, @@ -1545,6 +1557,7 @@ static bool gossip_peer_released(struct subd *gossip, fc->peer->push_msat, 15000, max_minimum_depth, fc->change, fc->change_keyindex, + fc->peer->channel_flags, utxos, bip32_base); subd_req(fc, opening, take(msg), -1, 2, opening_funder_finished, fc); return true; diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 9dba8bf94..c11e2ebc1 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -10,6 +10,7 @@ #include #include #include +#include #define ANNOUNCE_MIN_DEPTH 6 @@ -46,6 +47,9 @@ struct peer { struct log_book *log_book; struct log *log; + /* Channel flags from opening message. */ + u8 channel_flags; + /* If we've disconnected, this is set. */ bool reconnected; @@ -140,6 +144,9 @@ void add_peer(struct lightningd *ld, u64 unique_id, int fd, const struct pubkey *id, const struct crypto_state *cs); +/* Could be configurable. */ +#define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL + /* Peer has failed, but try reconnected. */ PRINTF_FMT(2,3) void peer_fail_transient(struct peer *peer, const char *fmt,...); /* Peer has failed, give up on it. */ diff --git a/wire/gen_peer_wire_csv b/wire/gen_peer_wire_csv index 7e5d027a6..ce3b2cba4 100644 --- a/wire/gen_peer_wire_csv +++ b/wire/gen_peer_wire_csv @@ -31,6 +31,7 @@ open_channel,153,revocation_basepoint,33 open_channel,186,payment_basepoint,33 open_channel,219,delayed_payment_basepoint,33 open_channel,252,first_per_commitment_point,33 +open_channel,285,channel_flags,1 accept_channel,33 accept_channel,0,temporary_channel_id,32 accept_channel,32,dust_limit_satoshis,8 diff --git a/wire/peer_wire.h b/wire/peer_wire.h index 2c516f2e7..e58b5307a 100644 --- a/wire/peer_wire.h +++ b/wire/peer_wire.h @@ -19,6 +19,15 @@ bool is_unknown_msg_discardable(const u8 *cursor); /* Return true if it's a gossip message. */ bool is_gossip_msg(const u8 *cursor); +/* BOLT #2: + * + * Only the least-significant bit of `channel_flags` is currently + * defined: `announce_channel`. This indicates whether the initiator + * of the funding flow wishes to advertise this channel publicly to + * the network as detailed within [BOLT #7] + */ +#define CHANNEL_FLAGS_ANNOUNCE_CHANNEL 1 + /* Compare two short_channel_ids and return true if they are the equal */ bool short_channel_id_eq(const struct short_channel_id *a, const struct short_channel_id *b); diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 63c731bed..056f43984 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -180,6 +180,7 @@ struct msg_open_channel { struct pubkey payment_basepoint; struct pubkey delayed_payment_basepoint; struct pubkey first_per_commitment_point; + u8 channel_flags; }; struct msg_update_fail_htlc { struct channel_id channel_id; @@ -268,7 +269,8 @@ static void *towire_struct_open_channel(const tal_t *ctx, &s->revocation_basepoint, &s->payment_basepoint, &s->delayed_payment_basepoint, - &s->first_per_commitment_point); + &s->first_per_commitment_point, + s->channel_flags); } static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const void *p, size_t *plen) @@ -291,7 +293,8 @@ static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, c &s->revocation_basepoint, &s->payment_basepoint, &s->delayed_payment_basepoint, - &s->first_per_commitment_point)) + &s->first_per_commitment_point, + &s->channel_flags)) return s; return tal_free(s); } @@ -788,7 +791,7 @@ static bool open_channel_eq(const struct msg_open_channel *a, const struct msg_open_channel *b) { return eq_with(a, b, max_accepted_htlcs) - && eq_between(a, b, funding_pubkey, first_per_commitment_point); + && eq_between(a, b, funding_pubkey, channel_flags); } static bool channel_update_eq(const struct msg_channel_update *a,