Skip to content

Commit

Permalink
gossipd: Update BOLT-split flags in channel_update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
niftynei authored and rustyrussell committed Sep 21, 2018
1 parent b1f15c2 commit b1ceaf9
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 61 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/
BOLTVERSION := a9195a84d07b9350f0eb1262ed0c1a82bc42e4ef
BOLTVERSION := 0891374d47ddffa64c5a2e6ad151247e3d6b7a59

-include config.vars

Expand Down
29 changes: 18 additions & 11 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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, &timestamp, &flags,
&local_update->scid, &timestamp,
&message_flags, &channel_flags,
&local_update->cltv_delta,
&local_update->htlc_minimum_msat,
&local_update->fee_base_msat,
Expand Down
47 changes: 28 additions & 19 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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, &timestamp, &flags,
&short_channel_id, &timestamp,
&message_flags, &channel_flags,
&expiry, &htlc_minimum_msat, &fee_base_msat,
&fee_proportional_millionths))
return false;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -1115,15 +1123,16 @@ 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,
&timestamp, &flags, &expiry,
&timestamp, &message_flags,
&channel_flags, &expiry,
&htlc_minimum_msat, &fee_base_msat,
&fee_proportional_millionths)) {
err = towire_errorfmt(rstate, NULL,
"Malformed channel_update %s",
tal_hex(tmpctx, serialized));
return err;
}
direction = flags & 0x1;
direction = channel_flags & 0x1;

/* BOLT #7:
*
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions gossipd/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gossipd/test/run-bench-find_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b1ceaf9

Please sign in to comment.