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

More BOLT updates, to latest. #5592

Merged
merged 13 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../bolts/
DEFAULT_BOLTVERSION := 341ec844f13c0c0abc4fe849059fbb98173f9766
DEFAULT_BOLTVERSION := f32c6ddb5f11b431c9bb4f501cdec604172a90de
# Can be overridden on cmdline.
BOLTVERSION := $(DEFAULT_BOLTVERSION)

Expand Down
18 changes: 10 additions & 8 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,16 @@ static void send_channel_update(struct peer *peer, int disable_flag)
assert(peer->short_channel_ids[LOCAL].u64);

msg = towire_channeld_local_channel_update(NULL,
&peer->short_channel_ids[LOCAL],
disable_flag
== ROUTING_FLAGS_DISABLED,
peer->cltv_delta,
peer->htlc_minimum_msat,
peer->fee_base,
peer->fee_per_satoshi,
peer->htlc_maximum_msat);
&peer->short_channel_ids[LOCAL],
disable_flag
== ROUTING_FLAGS_DISABLED,
peer->cltv_delta,
peer->htlc_minimum_msat,
peer->fee_base,
peer->fee_per_satoshi,
peer->htlc_maximum_msat,
peer->channel_flags
& CHANNEL_FLAGS_ANNOUNCE_CHANNEL);
wire_sync_write(MASTER_FD, take(msg));
}

Expand Down
1 change: 1 addition & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ msgdata,channeld_local_channel_update,htlc_minimum_msat,amount_msat,
msgdata,channeld_local_channel_update,fee_base_msat,u32,
msgdata,channeld_local_channel_update,fee_proportional_millionths,u32,
msgdata,channeld_local_channel_update,htlc_maximum_msat,amount_msat,
msgdata,channeld_local_channel_update,public,bool,

# Channeld: tell gossipd about our channel_announcement
msgtype,channeld_local_channel_announcement,1014
Expand Down
16 changes: 9 additions & 7 deletions common/gossip_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

/* BOLT #7:
*
* The `message_flags` bitfield is used to indicate the presence of optional
* fields in the `channel_update` message:
* | Bit Position | Name | Field |
* | ------------- | ------------------------- | ----------------...- |
* | 0 | `option_channel_htlc_max` | `htlc_maximum_msat` |
* The `message_flags` bitfield is used to provide additional details about the message:
* | Bit Position | Name |
* | ------------- | ---------------|
* | 0 | `must_be_one` |
* | 1 | `dont_forward` |
*/
/* FIXME: This is the old name */
#define ROUTING_OPT_HTLC_MAX_MSAT (1 << 0)
#define ROUTING_OPT_DONT_FORWARD (1 << 1)

/* BOLT #7:
*
Expand Down Expand Up @@ -62,8 +64,8 @@
/* BOLT #7:
*
* A node:
* - if a channel's latest `channel_update`s `timestamp` is older than two weeks
* (1209600 seconds):
* - if the `timestamp` of the latest `channel_update` in
* either direction is older than two weeks (1209600 seconds):
* - MAY prune the channel.
* - MAY ignore the channel.
*/
Expand Down
23 changes: 19 additions & 4 deletions common/gossip_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ struct gossip_rcvd_filter;
/**
* gossip_store -- On-disk storage related information
*/
#define GOSSIP_STORE_VERSION 10

/* First byte of file is the version.
*
* Top three bits mean incompatible change.
* As of this writing, major == 0, minor == 11.
*/
#define GOSSIP_STORE_MAJOR_VERSION_MASK 0xE0
#define GOSSIP_STORE_MINOR_VERSION_MASK 0x1F

/* Extract version from first byte */
#define GOSSIP_STORE_MAJOR_VERSION(verbyte) (((u8)(verbyte)) >> 5)
#define GOSSIP_STORE_MINOR_VERSION(verbyte) ((verbyte) & GOSSIP_STORE_MINOR_VERSION_MASK)

/**
* Bit of length we use to mark a deleted record.
Expand All @@ -26,12 +37,16 @@ struct gossip_rcvd_filter;
/**
* Bit of length used to define a rate-limited record (do not rebroadcast)
*/
#define GOSSIP_STORE_LEN_RATELIMIT_BIT 0x20000000U
#define GOSSIP_STORE_LEN_RATELIMIT_BIT 0x20000000U

/**
* Full flags mask
*/
#define GOSSIP_STORE_FLAGS_MASK 0xFFFF0000U

/* Mask for extracting just the length part of len field */
#define GOSSIP_STORE_LEN_MASK \
(~(GOSSIP_STORE_LEN_PUSH_BIT | GOSSIP_STORE_LEN_DELETED_BIT | \
GOSSIP_STORE_LEN_RATELIMIT_BIT))
(~(GOSSIP_STORE_FLAGS_MASK))

/**
* gossip_hdr -- On-disk format header.
Expand Down
27 changes: 8 additions & 19 deletions common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
* * [`u64`:`htlc_minimum_msat`]
* * [`u32`:`fee_base_msat`]
* * [`u32`:`fee_proportional_millionths`]
* * [`u64`:`htlc_maximum_msat`] (option_channel_htlc_max)
* * [`u64`:`htlc_maximum_msat`]
*/
static bool update_channel(struct gossmap *map, size_t cupdate_off)
{
Expand All @@ -509,15 +509,7 @@ static bool update_channel(struct gossmap *map, size_t cupdate_off)

/* We round this *down*, since too-low min is more conservative */
hc.htlc_min = u64_to_fp16(map_be64(map, htlc_minimum_off), false);
/* I checked my node: 60189 of 62358 channel_update have
* htlc_maximum_msat, so we don't bother setting the rest to the
* channel size (which we don't even read from the gossip_store, let
* alone give up precious bytes to remember) */
if (map_u8(map, message_flags_off) & 1)
hc.htlc_max
= u64_to_fp16(map_be64(map, htlc_maximum_off), true);
else
hc.htlc_max = 0xFFFF;
hc.htlc_max = u64_to_fp16(map_be64(map, htlc_maximum_off), true);

chanflags = map_u8(map, channel_flags_off);
hc.enabled = !(chanflags & 2);
Expand Down Expand Up @@ -672,7 +664,8 @@ static bool load_gossip_store(struct gossmap *map, size_t *num_rejected)
if (map->mmap == MAP_FAILED)
map->mmap = NULL;

if (map_u8(map, 0) != GOSSIP_STORE_VERSION) {
/* We only support major version 0 */
if (GOSSIP_STORE_MAJOR_VERSION(map_u8(map, 0)) != 0) {
close(map->fd);
if (map->mmap)
munmap(map->mmap, map->map_size);
Expand Down Expand Up @@ -1224,7 +1217,7 @@ u8 *gossmap_chan_get_features(const tal_t *ctx,
* * [`u64`:`htlc_minimum_msat`]
* * [`u32`:`fee_base_msat`]
* * [`u32`:`fee_proportional_millionths`]
* * [`u64`:`htlc_maximum_msat`] (option_channel_htlc_max)
* * [`u64`:`htlc_maximum_msat`]
*/
void gossmap_chan_get_update_details(const struct gossmap *map,
const struct gossmap_chan *chan,
Expand All @@ -1235,7 +1228,6 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
u32 *fee_base_msat,
u32 *fee_proportional_millionths,
struct amount_msat *htlc_minimum_msat,
/* iff message_flags & 1 */
struct amount_msat *htlc_maximum_msat)
{
/* Note that first two bytes are message type */
Expand All @@ -1248,26 +1240,23 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
const size_t fee_base_off = htlc_minimum_off + 8;
const size_t fee_prop_off = fee_base_off + 4;
const size_t htlc_maximum_off = fee_prop_off + 4;
u8 mflags;

assert(gossmap_chan_set(chan, dir));

if (timestamp)
*timestamp = map_be32(map, timestamp_off);
/* We need this (below), even if they don't want it */
mflags = map_u8(map, message_flags_off);
if (message_flags)
*message_flags = mflags;
if (channel_flags)
*channel_flags = map_u8(map, channel_flags_off);
if (message_flags)
*message_flags = map_u8(map, message_flags_off);
if (fee_base_msat)
*fee_base_msat = map_be32(map, fee_base_off);
if (fee_proportional_millionths)
*fee_proportional_millionths = map_be32(map, fee_prop_off);
if (htlc_minimum_msat)
*htlc_minimum_msat
= amount_msat(map_be64(map, htlc_minimum_off));
if (htlc_maximum_msat && (mflags & 1))
if (htlc_maximum_msat)
*htlc_maximum_msat
= amount_msat(map_be64(map, htlc_maximum_off));
}
Expand Down
1 change: 0 additions & 1 deletion common/gossmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
u32 *fee_base_msat,
u32 *fee_proportional_millionths,
struct amount_msat *htlc_minimum_msat,
/* iff message_flags & 1 */
struct amount_msat *htlc_maximum_msat);

/* Given a struct node, get the nth channel, and tell us if we're half[0/1].
Expand Down
5 changes: 3 additions & 2 deletions common/htlc_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,

/* BOLT #3:
* * txout count: 1
* * `txout[0]` amount: the HTLC amount minus fees
* (see [Fee Calculation](#fee-calculation))
* * `txout[0]` amount: the HTLC `amount_msat` divided by 1000
* (rounding down) minus fees in satoshis (see
* [Fee Calculation](#fee-calculation))
* * `txout[0]` script: version-0 P2WSH with witness script as shown
* below
*/
Expand Down
26 changes: 13 additions & 13 deletions common/test/run-route-specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ static void update_connection(int store_fd,
if (!short_channel_id_from_str(shortid, strlen(shortid), &scid))
abort();

msg = towire_channel_update_option_channel_htlc_max(tmpctx,
&dummy_sig,
&chainparams->genesis_blockhash,
&scid, 0,
ROUTING_OPT_HTLC_MAX_MSAT,
node_id_idx(from, to)
+ (disable ? ROUTING_FLAGS_DISABLED : 0),
delay,
min,
base_fee,
proportional_fee,
max);
msg = towire_channel_update(tmpctx,
&dummy_sig,
&chainparams->genesis_blockhash,
&scid, 0,
ROUTING_OPT_HTLC_MAX_MSAT,
node_id_idx(from, to)
+ (disable ? ROUTING_FLAGS_DISABLED : 0),
delay,
min,
base_fee,
proportional_fee,
max);

write_to_store(store_fd, msg);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ int main(int argc, char *argv[])
int store_fd;
struct gossmap *gossmap;
const double riskfactor = 1.0;
char gossip_version = GOSSIP_STORE_VERSION;
char gossip_version = 10;
char *gossipfilename;

common_setup(argv[0]);
Expand Down
26 changes: 13 additions & 13 deletions common/test/run-route.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ static void update_connection(int store_fd,
memcpy(&scid, from, sizeof(scid) / 2);
memcpy((char *)&scid + sizeof(scid) / 2, to, sizeof(scid) / 2);

msg = towire_channel_update_option_channel_htlc_max(tmpctx,
&dummy_sig,
&chainparams->genesis_blockhash,
&scid, 0,
ROUTING_OPT_HTLC_MAX_MSAT,
node_id_idx(from, to)
+ (disable ? ROUTING_FLAGS_DISABLED : 0),
delay,
AMOUNT_MSAT(0),
base_fee,
proportional_fee,
AMOUNT_MSAT(100000 * 1000));
msg = towire_channel_update(tmpctx,
&dummy_sig,
&chainparams->genesis_blockhash,
&scid, 0,
ROUTING_OPT_HTLC_MAX_MSAT,
node_id_idx(from, to)
+ (disable ? ROUTING_FLAGS_DISABLED : 0),
delay,
AMOUNT_MSAT(0),
base_fee,
proportional_fee,
AMOUNT_MSAT(100000 * 1000));

write_to_store(store_fd, msg);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ int main(int argc, char *argv[])
int store_fd;
struct gossmap *gossmap;
const double riskfactor = 1.0;
char gossip_version = GOSSIP_STORE_VERSION;
char gossip_version = 10;
char *gossipfilename;

chainparams = chainparams_for_network("regtest");
Expand Down
9 changes: 4 additions & 5 deletions contrib/pyln-client/pyln/client/gossmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import struct

# These duplicate constants in lightning/common/gossip_store.h
GOSSIP_STORE_VERSIONS = [0x09, 0x0a]
GOSSIP_STORE_MAJOR_VERSION = (0 << 5)
GOSSIP_STORE_MAJOR_VERSION_MASK = 0xE0
GOSSIP_STORE_LEN_DELETED_BIT = 0x80000000
GOSSIP_STORE_LEN_PUSH_BIT = 0x40000000
GOSSIP_STORE_LEN_RATELIMIT_BIT = 0x20000000
GOSSIP_STORE_LEN_MASK = (~(GOSSIP_STORE_LEN_PUSH_BIT
| GOSSIP_STORE_LEN_DELETED_BIT
| GOSSIP_STORE_LEN_RATELIMIT_BIT))
GOSSIP_STORE_LEN_MASK = (0x0000FFFF)

# These duplicate constants in lightning/gossipd/gossip_store_wiregen.h
WIRE_GOSSIP_STORE_PRIVATE_CHANNEL = 4104
Expand Down Expand Up @@ -174,7 +173,7 @@ def __init__(self, store_filename: str = "gossip_store"):
self.channels: Dict[ShortChannelId, GossmapChannel] = {}
self._last_scid: Optional[str] = None
version = self.store_file.read(1)[0]
if version not in GOSSIP_STORE_VERSIONS:
if (version & GOSSIP_STORE_MAJOR_VERSION_MASK) != GOSSIP_STORE_MAJOR_VERSION:
raise ValueError("Invalid gossip store version {}".format(version))
self.bytes_read = 1
self.refresh()
Expand Down
6 changes: 1 addition & 5 deletions contrib/pyln-testing/pyln/testing/gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ def from_bytes(cls, b: io.BytesIO) -> "ChannelUpdate":
(cu.htlc_minimum_msat,) = struct.unpack("!Q", b.read(8))
(cu.fee_base_msat,) = struct.unpack("!I", b.read(4))
(cu.fee_proportional_millionths,) = struct.unpack("!I", b.read(4))
t = b.read(8)
if len(t) == 8:
(cu.htlc_maximum_msat,) = struct.unpack("!Q", t)
else:
cu.htlc_maximum_msat = None
(cu.htlc_maximum_msat,) = struct.unpack("!Q", b.read(8))

return cu

Expand Down
8 changes: 4 additions & 4 deletions devtools/create-gossipstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ static u32 get_update_timestamp(const u8 *msg, struct short_channel_id *scid)
u8 u8_ignore;
u16 u16_ignore;
u32 u32_ignore;
struct amount_msat msat;
struct amount_msat msat_ignore;

if (fromwire_channel_update(msg, &sig, &chain_hash, scid,
&timestamp, &u8_ignore, &u8_ignore,
&u16_ignore, &msat, &u32_ignore,
&u32_ignore))
&u16_ignore, &msat_ignore, &u32_ignore,
&u32_ignore, &msat_ignore))
return timestamp;
errx(1, "Invalid channel_update");
}
Expand Down Expand Up @@ -155,7 +155,7 @@ int main(int argc, char *argv[])
} else
outfd = STDOUT_FILENO;

version = GOSSIP_STORE_VERSION;
version = ((0 << 5) | 10);
if (!write_all(outfd, &version, sizeof(version)))
err(1, "Writing version");

Expand Down
Loading