Skip to content

Commit 0ec301e

Browse files
committed
lightningd: --experimental-gossip-status option.
This activates the logic, by enabling the feature bit. Changelog-EXPERIMENTAL: Protocol: `gossip_status` support (lightning/bolts#1186) Signed-off-by: Rusty Russell <[email protected]>
1 parent 038abef commit 0ec301e

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

lightningd/options.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,14 @@ static char *opt_set_anchor_zero_fee_htlc_tx(struct lightningd *ld)
13131313
return NULL;
13141314
}
13151315

1316+
static char *opt_set_gossip_status(struct lightningd *ld)
1317+
{
1318+
feature_set_or(ld->our_features,
1319+
take(feature_set_for_feature(NULL,
1320+
OPTIONAL_FEATURE(OPT_GOSSIP_STATUS))));
1321+
return NULL;
1322+
}
1323+
13161324
static char *opt_set_offers(struct lightningd *ld)
13171325
{
13181326
ld->config.exp_offers = true;
@@ -1516,6 +1524,10 @@ static void register_opts(struct lightningd *ld)
15161524
opt_register_early_noarg("--experimental-anchors",
15171525
opt_set_anchor_zero_fee_htlc_tx, ld,
15181526
opt_hidden);
1527+
opt_register_early_noarg("--experimental-gossip-status",
1528+
opt_set_gossip_status, ld,
1529+
"EXPERIMENTAL: Send and process gossip_status messages for gossip bootstrap");
1530+
15191531
clnopt_witharg("--announce-addr-dns", OPT_EARLY|OPT_SHOWBOOL,
15201532
opt_set_bool_arg, opt_show_bool,
15211533
&ld->announce_dns,

tests/test_gossip.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,3 +2207,75 @@ def test_generate_gossip_store(node_factory):
22072207
expected = sorted(expected, key=lambda x: x['source'] + x['destination'])
22082208

22092209
assert lchans == expected
2210+
2211+
2212+
def test_gossip_status(node_factory, chainparams):
2213+
# Since we respond if we have > 100 more than them, we need a big gossmap.
2214+
l1 = node_factory.get_node(start=False)
2215+
chans = [GenChannel(0, i) for i in range(1, 102)]
2216+
gsfile, nodemap = generate_gossip_store(chans)
2217+
shutil.copy(gsfile.name, os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'gossip_store'))
2218+
2219+
l1.daemon.opts['experimental-gossip-status'] = None
2220+
l1.start()
2221+
2222+
assert len(l1.rpc.listchannels()['channels']) == 101 * 2
2223+
2224+
# If I say I have 1/102/1, you won't give me anything.
2225+
out = subprocess.run(['devtools/gossipwith',
2226+
'--no-gossip',
2227+
'--hex',
2228+
'--network={}'.format(TEST_NETWORK),
2229+
'--timeout-after={}'.format(int(math.sqrt(TIMEOUT) + 1)),
2230+
'{}@localhost:{}'.format(l1.info['id'], l1.port),
2231+
# BOLT-gossip_status #7:
2232+
# 1. type: 267 (`gossip_status`)
2233+
# 2. data:
2234+
# * [`chain_hash`:`chain_hash`]
2235+
# * [`bigsize`:`num_channel_announcements`]
2236+
# * [`bigsize`:`num_channel_updates`]
2237+
# * [`bigsize`:`num_node_announcements`]
2238+
'763B' + chainparams['chain_hash'] + '016601'],
2239+
check=True,
2240+
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
2241+
2242+
# No channel_announcments, channel_updates or node_announcements
2243+
assert [m for m in out if m.startswith(b'0100') or m.startswith(b'0101') or m.startswith(b'0102')] == []
2244+
2245+
# If I say I have 0 channel_announcments, you spew gossip...
2246+
out = subprocess.run(['devtools/gossipwith',
2247+
'--no-gossip',
2248+
'--hex',
2249+
'--network={}'.format(TEST_NETWORK),
2250+
'--timeout-after={}'.format(int(math.sqrt(TIMEOUT) + 1)),
2251+
'{}@localhost:{}'.format(l1.info['id'], l1.port),
2252+
# BOLT-gossip_status #7:
2253+
# 1. type: 267 (`gossip_status`)
2254+
# 2. data:
2255+
# * [`chain_hash`:`chain_hash`]
2256+
# * [`bigsize`:`num_channel_announcements`]
2257+
# * [`bigsize`:`num_channel_updates`]
2258+
# * [`bigsize`:`num_node_announcements`]
2259+
'763B' + chainparams['chain_hash'] + '00CA01'],
2260+
check=True,
2261+
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
2262+
assert len([m for m in out if m.startswith(b'0100') or m.startswith(b'0101') or m.startswith(b'0102')]) == 303
2263+
2264+
# If I say I have 101 channel_updates, you spew gossip...
2265+
out = subprocess.run(['devtools/gossipwith',
2266+
'--no-gossip',
2267+
'--hex',
2268+
'--network={}'.format(TEST_NETWORK),
2269+
'--timeout-after={}'.format(int(math.sqrt(TIMEOUT) + 1)),
2270+
'{}@localhost:{}'.format(l1.info['id'], l1.port),
2271+
# BOLT-gossip_status #7:
2272+
# 1. type: 267 (`gossip_status`)
2273+
# 2. data:
2274+
# * [`chain_hash`:`chain_hash`]
2275+
# * [`bigsize`:`num_channel_announcements`]
2276+
# * [`bigsize`:`num_channel_updates`]
2277+
# * [`bigsize`:`num_node_announcements`]
2278+
'763B' + chainparams['chain_hash'] + '656501'],
2279+
check=True,
2280+
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
2281+
assert len([m for m in out if m.startswith(b'0100') or m.startswith(b'0101') or m.startswith(b'0102')]) == 303

0 commit comments

Comments
 (0)