From b1ceaf99101448f3bbc7dd228732047387b8376e Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 19 Sep 2018 17:59:46 -0700 Subject: [PATCH] gossipd: Update BOLT-split flags in channel_update BOLT 7's been updated to split the flags field in `channel_update` into two: `channel_flags` and `message_flags`. This changeset does the minimal necessary to get to building with the new flags. --- CHANGELOG.md | 3 ++ Makefile | 2 +- gossipd/gossipd.c | 29 ++++++++++------ gossipd/routing.c | 47 +++++++++++++++----------- gossipd/routing.h | 8 +++-- gossipd/test/run-bench-find_route.c | 4 +-- gossipd/test/run-find_route-specific.c | 24 +++++++------ gossipd/test/run-find_route.c | 6 ++-- hsmd/hsmd.c | 7 ++-- lightningd/gossip_control.c | 9 +++-- lightningd/gossip_msg.c | 6 ++-- lightningd/gossip_msg.h | 3 +- tests/utils.py | 2 +- wire/gen_peer_wire_csv | 3 +- wire/test/run-peer-wire.c | 9 +++-- 15 files changed, 101 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42634719073e..b8d6b99d4a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - JSON API: `listpeers` has new field `scratch_txid`: the latest tx in channel. +- JSON API: `listchannels` has two new fields: `message_flags` and `channel_flags`. This replaces `flags`. - Bitcoind: more parallelism in requests, for very slow nodes. - Testing: fixed logging, cleaner interception of bitcoind, minor fixes. @@ -19,6 +20,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Note: You should always set `allow-deprecated-apis=false` to test for changes. +- JSON RPC: `listchannels`' `flags` field. This has been split into two fields, see Added. + ### Removed ### Fixed diff --git a/Makefile b/Makefile index 4fdd27876296..4e730bf22b7b 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := a9195a84d07b9350f0eb1262ed0c1a82bc42e4ef +BOLTVERSION := 0891374d47ddffa64c5a2e6ad151247e3d6b7a59 -include config.vars diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 7d1d6247d70a..6b842ebac20c 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -1008,7 +1008,11 @@ static u8 *create_channel_update(const tal_t *ctx, secp256k1_ecdsa_signature dummy_sig; u8 *update, *msg; u32 timestamp = time_now().ts.tv_sec; - u16 flags; + u8 message_flags, channel_flags; + + /* `message_flags` are optional. + * Currently, not set by c-lightning */ + message_flags = 0; /* So valgrind doesn't complain */ memset(&dummy_sig, 0, sizeof(dummy_sig)); @@ -1018,15 +1022,16 @@ static u8 *create_channel_update(const tal_t *ctx, && timestamp == chan->half[direction].last_timestamp) timestamp++; - flags = direction; + channel_flags = direction; if (disable) - flags |= ROUTING_FLAGS_DISABLED; + channel_flags |= ROUTING_FLAGS_DISABLED; update = towire_channel_update(ctx, &dummy_sig, &rstate->chain_hash, &chan->scid, timestamp, - flags, cltv_expiry_delta, + message_flags, channel_flags, + cltv_expiry_delta, htlc_minimum_msat, fee_base_msat, fee_proportional_millionths); @@ -1055,7 +1060,7 @@ static bool update_redundant(const struct half_chan *hc, if (!is_halfchan_defined(hc)) return false; - return !(hc->flags & ROUTING_FLAGS_DISABLED) == !disable + return !(hc->channel_flags & ROUTING_FLAGS_DISABLED) == !disable && hc->delay == cltv_delta && hc->htlc_minimum_msat == htlc_minimum_msat && hc->base_fee == fee_base_msat @@ -1108,11 +1113,11 @@ static void apply_delayed_local_update(struct local_update *local_update) &local_update->scid), local_update->direction, is_halfchan_defined(hc) - ? (hc->flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE") + ? (hc->channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE") : "UNDEFINED", hc->last_timestamp, (u32)time_now().ts.tv_sec, - hc->flags, + hc->channel_flags, local_update->disable); tal_free(local_update); return; @@ -1441,7 +1446,8 @@ static void append_half_channel(struct gossip_getchannels_entry **entries, e->source = chan->nodes[idx]->id; e->destination = chan->nodes[!idx]->id; e->satoshis = chan->satoshis; - e->flags = c->flags; + e->channel_flags = c->channel_flags; + e->message_flags = c->message_flags; e->local_disabled = chan->local_disabled; e->public = is_chan_public(chan); e->short_channel_id = chan->scid; @@ -1767,7 +1773,7 @@ static void gossip_send_keepalive_update(struct routing_state *rstate, /* Generate a new update, with up to date timestamp */ update = create_channel_update(tmpctx, rstate, chan, - hc->flags & ROUTING_FLAGS_DIRECTION, + hc->channel_flags & ROUTING_FLAGS_DIRECTION, false, hc->delay, hc->htlc_minimum_msat, @@ -1834,7 +1840,7 @@ static void gossip_disable_outgoing_halfchan(struct daemon *daemon, { u8 direction; struct half_chan *hc; - u16 flags; + u8 message_flags, channel_flags; u32 timestamp; struct bitcoin_blkid chain_hash; secp256k1_ecdsa_signature sig; @@ -1858,7 +1864,8 @@ static void gossip_disable_outgoing_halfchan(struct daemon *daemon, if (!fromwire_channel_update( hc->channel_update, &sig, &chain_hash, - &local_update->scid, ×tamp, &flags, + &local_update->scid, ×tamp, + &message_flags, &channel_flags, &local_update->cltv_delta, &local_update->htlc_minimum_msat, &local_update->fee_base_msat, diff --git a/gossipd/routing.c b/gossipd/routing.c index a0ab36a8054a..67fed194a940 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -259,13 +259,17 @@ static void destroy_chan(struct chan *chan, struct routing_state *rstate) static void init_half_chan(struct routing_state *rstate, struct chan *chan, - int idx) + int channel_idx) { - struct half_chan *c = &chan->half[idx]; + struct half_chan *c = &chan->half[channel_idx]; c->channel_update = NULL; c->unroutable_until = 0; - c->flags = idx; + + /* Set the channel direction */ + c->channel_flags = channel_idx; + // TODO: wireup message_flags + c->message_flags = 0; /* We haven't seen channel_update: make it halfway to prune time, * which should be older than any update we'd see. */ c->last_timestamp = time_now().ts.tv_sec - rstate->prune_timeout/2; @@ -1003,7 +1007,8 @@ static void set_connection_values(struct chan *chan, u32 base_fee, u32 proportional_fee, u32 delay, - u16 flags, + u8 message_flags, + u8 channel_flags, u64 timestamp, u32 htlc_minimum_msat) { @@ -1013,9 +1018,10 @@ static void set_connection_values(struct chan *chan, c->htlc_minimum_msat = htlc_minimum_msat; c->base_fee = base_fee; c->proportional_fee = proportional_fee; - c->flags = flags; + c->message_flags = message_flags; + c->channel_flags = channel_flags; c->last_timestamp = timestamp; - assert((c->flags & ROUTING_FLAGS_DIRECTION) == idx); + assert((c->channel_flags & ROUTING_FLAGS_DIRECTION) == idx); /* If it was temporarily unroutable, re-enable */ c->unroutable_until = 0; @@ -1031,7 +1037,7 @@ static void set_connection_values(struct chan *chan, &chan->scid), idx, c->proportional_fee); - c->flags |= ROUTING_FLAGS_DISABLED; + c->channel_flags |= ROUTING_FLAGS_DISABLED; } } @@ -1041,7 +1047,7 @@ bool routing_add_channel_update(struct routing_state *rstate, secp256k1_ecdsa_signature signature; struct short_channel_id short_channel_id; u32 timestamp; - u16 flags; + u8 message_flags, channel_flags; u16 expiry; u64 htlc_minimum_msat; u32 fee_base_msat; @@ -1052,7 +1058,8 @@ bool routing_add_channel_update(struct routing_state *rstate, bool have_broadcast_announce; if (!fromwire_channel_update(update, &signature, &chain_hash, - &short_channel_id, ×tamp, &flags, + &short_channel_id, ×tamp, + &message_flags, &channel_flags, &expiry, &htlc_minimum_msat, &fee_base_msat, &fee_proportional_millionths)) return false; @@ -1064,10 +1071,11 @@ bool routing_add_channel_update(struct routing_state *rstate, have_broadcast_announce = is_halfchan_defined(&chan->half[0]) || is_halfchan_defined(&chan->half[1]); - direction = flags & 0x1; + direction = channel_flags & 0x1; set_connection_values(chan, direction, fee_base_msat, fee_proportional_millionths, expiry, - flags, timestamp, htlc_minimum_msat); + message_flags, channel_flags, + timestamp, htlc_minimum_msat); /* Replace any old one. */ tal_free(chan->half[direction].channel_update); @@ -1101,7 +1109,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, secp256k1_ecdsa_signature signature; struct short_channel_id short_channel_id; u32 timestamp; - u16 flags; + u8 message_flags, channel_flags; u16 expiry; u64 htlc_minimum_msat; u32 fee_base_msat; @@ -1115,7 +1123,8 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, serialized = tal_dup_arr(tmpctx, u8, update, len, 0); if (!fromwire_channel_update(serialized, &signature, &chain_hash, &short_channel_id, - ×tamp, &flags, &expiry, + ×tamp, &message_flags, + &channel_flags, &expiry, &htlc_minimum_msat, &fee_base_msat, &fee_proportional_millionths)) { err = towire_errorfmt(rstate, NULL, @@ -1123,7 +1132,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, tal_hex(tmpctx, serialized)); return err; } - direction = flags & 0x1; + direction = channel_flags & 0x1; /* BOLT #7: * @@ -1160,7 +1169,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, type_to_string(tmpctx, struct short_channel_id, &short_channel_id), - flags)); + channel_flags)); return NULL; } } @@ -1198,7 +1207,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, type_to_string(tmpctx, struct short_channel_id, &short_channel_id), - flags, + channel_flags, tal_hex(tmpctx, c->channel_update), tal_hex(tmpctx, serialized)); } @@ -1224,10 +1233,10 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, status_trace("Received channel_update for channel %s(%d) now %s was %s (from %s)", type_to_string(tmpctx, struct short_channel_id, &short_channel_id), - flags & 0x01, - flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE", + channel_flags & 0x01, + channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE", is_halfchan_defined(c) - ? (c->flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE") + ? (c->channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE") : "UNDEFINED", source); diff --git a/gossipd/routing.h b/gossipd/routing.h index f8552611ea95..6fb15d941a2e 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -31,7 +31,11 @@ struct half_chan { /* Flags as specified by the `channel_update`s, among other * things indicated direction wrt the `channel_id` */ - u16 flags; + u8 channel_flags; + + /* Flags as specified by the `channel_update`s, indicates + * optional fields. */ + u8 message_flags; /* If greater than current time, this connection should not * be used for routing. */ @@ -81,7 +85,7 @@ static inline bool is_halfchan_defined(const struct half_chan *hc) static inline bool is_halfchan_enabled(const struct half_chan *hc) { - return is_halfchan_defined(hc) && !(hc->flags & ROUTING_FLAGS_DISABLED); + return is_halfchan_defined(hc) && !(hc->channel_flags & ROUTING_FLAGS_DISABLED); } struct node { diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 9984bce8b825..0347217c26bc 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -63,7 +63,7 @@ void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED) { fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); } /* Generated stub for fromwire_channel_update */ -bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) +bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) @@ -160,7 +160,7 @@ static void add_connection(struct routing_state *rstate, c->base_fee = base_fee; c->proportional_fee = proportional_fee; c->delay = delay; - c->flags = get_channel_direction(from, to); + c->channel_flags = get_channel_direction(from, to); } static struct pubkey nodeid(size_t n) diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 79d25b5b356b..90b8d70404ae 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -3,7 +3,7 @@ * Expect route 03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf -> 0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae -> 02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06 * * getchannels: - * {'channels': [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} + * {'channels': [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */ #include @@ -27,7 +27,7 @@ void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED) { fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); } /* Generated stub for fromwire_channel_update */ -bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) +bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) @@ -172,38 +172,42 @@ int main(void) rstate = new_routing_state(tmpctx, &zerohash, &a, 0); - /* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */ + /* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */ nc = get_or_make_connection(rstate, &c, &b, "6990:2:1", 1000); nc->base_fee = 0; nc->proportional_fee = 10; nc->delay = 5; - nc->flags = 1; + nc->channel_flags = 1; + nc->message_flags = 0; nc->last_timestamp = 1504064344; - /* {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */ + /* {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */ nc = get_or_make_connection(rstate, &b, &a, "6989:2:1", 1000); nc->base_fee = 0; nc->proportional_fee = 10; nc->delay = 5; - nc->flags = 0; + nc->channel_flags = 0; + nc->message_flags = 0; nc->last_timestamp = 1504064344; - /* {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */ + /* {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */ nc = get_or_make_connection(rstate, &b, &c, "6990:2:1", 1000); nc->base_fee = 0; nc->proportional_fee = 10; nc->delay = 5; - nc->flags = 0; + nc->channel_flags = 0; + nc->message_flags = 0; nc->last_timestamp = 1504064344; nc->htlc_minimum_msat = 100; - /* {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */ + /* {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */ nc = get_or_make_connection(rstate, &a, &b, "6989:2:1", 1000); nc->base_fee = 0; nc->proportional_fee = 10; nc->delay = 5; - nc->flags = 1; + nc->channel_flags = 1; + nc->message_flags = 0; nc->last_timestamp = 1504064344; route = find_route(tmpctx, rstate, &a, &c, 100000, riskfactor, 0.0, NULL, &fee); diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 372106fabe0a..88ed4660c022 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -25,7 +25,7 @@ void broadcast_del(struct broadcast_state *bstate UNNEEDED, u64 index UNNEEDED, bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED) { fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); } /* Generated stub for fromwire_channel_update */ -bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) +bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u8 *message_flags UNNEEDED, u8 *channel_flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) @@ -127,7 +127,7 @@ static void add_connection(struct routing_state *rstate, c->base_fee = base_fee; c->proportional_fee = proportional_fee; c->delay = delay; - c->flags = get_channel_direction(from, to); + c->channel_flags = get_channel_direction(from, to); c->htlc_minimum_msat = 0; } @@ -258,7 +258,7 @@ int main(void) assert(fee == 1 + 3); /* Make B->C inactive, force it back via D */ - get_connection(rstate, &b, &c)->flags |= ROUTING_FLAGS_DISABLED; + get_connection(rstate, &b, &c)->channel_flags |= ROUTING_FLAGS_DISABLED; route = find_route(tmpctx, rstate, &a, &c, 3000000, riskfactor, 0.0, NULL, &fee); assert(route); assert(tal_count(route) == 2); diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index d047e8e917b5..95642c528a11 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -653,7 +653,8 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn, struct short_channel_id scid; u32 timestamp, fee_base_msat, fee_proportional_mill; u64 htlc_minimum_msat; - u16 flags, cltv_expiry_delta; + u8 message_flags, channel_flags; + u16 cltv_expiry_delta; struct bitcoin_blkid chain_hash; u8 *cu; @@ -661,7 +662,7 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn, return bad_req(conn, c, msg_in); if (!fromwire_channel_update(cu, &sig, &chain_hash, - &scid, ×tamp, &flags, + &scid, ×tamp, &message_flags, &channel_flags, &cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat, &fee_proportional_mill)) { return bad_req_fmt(conn, c, msg_in, "Bad inner channel_update"); @@ -676,7 +677,7 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn, sign_hash(&node_pkey, &hash, &sig); cu = towire_channel_update(tmpctx, &sig, &chain_hash, - &scid, timestamp, flags, + &scid, timestamp, message_flags, channel_flags, cltv_expiry_delta, htlc_minimum_msat, fee_base_msat, fee_proportional_mill); return req_reply(conn, c, take(towire_hsm_cupdate_sig_reply(NULL, cu))); diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 5ebf00b7b09a..a8217edddcb5 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -346,9 +347,13 @@ static void json_listchannels_reply(struct subd *gossip UNUSED, const u8 *reply, &entries[i].short_channel_id)); json_add_bool(response, "public", entries[i].public); json_add_u64(response, "satoshis", entries[i].satoshis); - json_add_num(response, "flags", entries[i].flags); + json_add_num(response, "message_flags", entries[i].message_flags); + json_add_num(response, "channel_flags", entries[i].channel_flags); + /* Prior to spec v0891374d47ddffa64c5a2e6ad151247e3d6b7a59, these two were a single u16 field */ + if (deprecated_apis) + json_add_num(response, "flags", ((u16)entries[i].message_flags << 8) | entries[i].channel_flags); json_add_bool(response, "active", - !(entries[i].flags & ROUTING_FLAGS_DISABLED) + !(entries[i].channel_flags & ROUTING_FLAGS_DISABLED) && !entries[i].local_disabled); json_add_num(response, "last_update", entries[i].last_update_timestamp); diff --git a/lightningd/gossip_msg.c b/lightningd/gossip_msg.c index c29d9a9c76d3..60628cf2f549 100644 --- a/lightningd/gossip_msg.c +++ b/lightningd/gossip_msg.c @@ -84,7 +84,8 @@ void fromwire_gossip_getchannels_entry(const u8 **pptr, size_t *max, fromwire_pubkey(pptr, max, &entry->source); fromwire_pubkey(pptr, max, &entry->destination); entry->satoshis = fromwire_u64(pptr, max); - entry->flags = fromwire_u16(pptr, max); + entry->message_flags = fromwire_u8(pptr, max); + entry->channel_flags = fromwire_u8(pptr, max); entry->public = fromwire_bool(pptr, max); entry->local_disabled = fromwire_bool(pptr, max); entry->last_update_timestamp = fromwire_u32(pptr, max); @@ -100,7 +101,8 @@ void towire_gossip_getchannels_entry(u8 **pptr, towire_pubkey(pptr, &entry->source); towire_pubkey(pptr, &entry->destination); towire_u64(pptr, entry->satoshis); - towire_u16(pptr, entry->flags); + towire_u8(pptr, entry->message_flags); + towire_u8(pptr, entry->channel_flags); towire_bool(pptr, entry->public); towire_bool(pptr, entry->local_disabled); towire_u32(pptr, entry->last_update_timestamp); diff --git a/lightningd/gossip_msg.h b/lightningd/gossip_msg.h index b6c61ca046b8..2fa30ac08a37 100644 --- a/lightningd/gossip_msg.h +++ b/lightningd/gossip_msg.h @@ -22,7 +22,8 @@ struct gossip_getchannels_entry { struct pubkey source, destination; u64 satoshis; struct short_channel_id short_channel_id; - u16 flags; + u8 message_flags; + u8 channel_flags; bool public; bool local_disabled; u32 last_update_timestamp; diff --git a/tests/utils.py b/tests/utils.py index 7ec68a812f17..02387f4a77fc 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -557,7 +557,7 @@ def get_channel_scid(self, other): def is_channel_active(self, chanid): channels = self.rpc.listchannels()['channels'] - active = [(c['short_channel_id'], c['flags']) for c in channels if c['active']] + active = [(c['short_channel_id'], c['channel_flags']) for c in channels if c['active']] return (chanid, 0) in active and (chanid, 1) in active def wait_for_channel_onchain(self, peerid): diff --git a/wire/gen_peer_wire_csv b/wire/gen_peer_wire_csv index 0e07d96131aa..4afd7776fa63 100644 --- a/wire/gen_peer_wire_csv +++ b/wire/gen_peer_wire_csv @@ -143,7 +143,8 @@ channel_update,0,signature,64 channel_update,64,chain_hash,32 channel_update,96,short_channel_id,8 channel_update,104,timestamp,4 -channel_update,108,flags,2 +channel_update,108,message_flags,1 +channel_update,109,channel_flags,1 channel_update,110,cltv_expiry_delta,2 channel_update,112,htlc_minimum_msat,8 channel_update,120,fee_base_msat,4 diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 00fef90521a6..d21778a30ad6 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -123,7 +123,8 @@ struct msg_revoke_and_ack { struct msg_channel_update { secp256k1_ecdsa_signature signature; u32 timestamp; - u16 flags; + u8 message_flags; + u8 channel_flags; u16 expiry; u64 htlc_minimum_msat; u32 fee_base_msat; @@ -376,7 +377,8 @@ static void *towire_struct_channel_update(const tal_t *ctx, &s->chain_hash, &s->short_channel_id, s->timestamp, - s->flags, + s->message_flags, + s->channel_flags, s->expiry, s->htlc_minimum_msat, s->fee_base_msat, @@ -392,7 +394,8 @@ static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ct &s->chain_hash, &s->short_channel_id, &s->timestamp, - &s->flags, + &s->message_flags, + &s->channel_flags, &s->expiry, &s->htlc_minimum_msat, &s->fee_base_msat,