Skip to content

Commit b78b323

Browse files
rustyrussellendothermicdev
authored andcommitted
lightningd: implement unblacklist.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: JSON-RPC: `blacklistrune` now has an option to un-blacklist (`relist`).
1 parent d72f045 commit b78b323

File tree

10 files changed

+267
-151
lines changed

10 files changed

+267
-151
lines changed

.msggen.json

+5
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@
997997
},
998998
"BlacklistruneRequest": {
999999
"BlacklistRune.end": 2,
1000+
"BlacklistRune.relist": 3,
10001001
"BlacklistRune.start": 1
10011002
},
10021003
"BlacklistruneResponse": {
@@ -5127,6 +5128,10 @@
51275128
"added": "pre-v0.10.1",
51285129
"deprecated": null
51295130
},
5131+
"BlacklistRune.relist": {
5132+
"added": "v25.02",
5133+
"deprecated": null
5134+
},
51305135
"BlacklistRune.start": {
51315136
"added": "pre-v0.10.1",
51325137
"deprecated": null

cln-grpc/proto/node.proto

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/model.rs

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/msggen/msggen/schema.json

+32
Original file line numberDiff line numberDiff line change
@@ -4678,6 +4678,13 @@
46784678
"description": [
46794679
"Final rune unique id to blacklist (defaults to start)."
46804680
]
4681+
},
4682+
"relist": {
4683+
"type": "boolean",
4684+
"added": "v25.02",
4685+
"description": [
4686+
"Undo the blacklisting (if any) of every rune in range start to end (inclusive)"
4687+
]
46814688
}
46824689
},
46834690
"dependentUpon": {
@@ -4785,6 +4792,31 @@
47854792
}
47864793
]
47874794
}
4795+
},
4796+
{
4797+
"description": [
4798+
"This undoes the blacklisting of rune 3 only"
4799+
],
4800+
"request": {
4801+
"id": "example:blacklistrune#4",
4802+
"method": "blacklistrune",
4803+
"params": {
4804+
"start": 3,
4805+
"relist": true
4806+
}
4807+
},
4808+
"response": {
4809+
"blacklist": [
4810+
{
4811+
"start": 0,
4812+
"end": 2
4813+
},
4814+
{
4815+
"start": 4,
4816+
"end": 4
4817+
}
4818+
]
4819+
}
47884820
}
47894821
]
47904822
},

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

+148-148
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/schemas/lightning-blacklistrune.json

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
"description": [
2727
"Final rune unique id to blacklist (defaults to start)."
2828
]
29+
},
30+
"relist": {
31+
"type": "boolean",
32+
"added": "v25.02",
33+
"description": [
34+
"Undo the blacklisting (if any) of every rune in range start to end (inclusive)"
35+
]
2936
}
3037
},
3138
"dependentUpon": {
@@ -133,6 +140,31 @@
133140
}
134141
]
135142
}
143+
},
144+
{
145+
"description": [
146+
"This undoes the blacklisting of rune 3 only"
147+
],
148+
"request": {
149+
"id": "example:blacklistrune#4",
150+
"method": "blacklistrune",
151+
"params": {
152+
"start": 3,
153+
"relist": true
154+
}
155+
},
156+
"response": {
157+
"blacklist": [
158+
{
159+
"start": 0,
160+
"end": 2
161+
},
162+
{
163+
"start": 4,
164+
"end": 4
165+
}
166+
]
167+
}
136168
}
137169
]
138170
}

lightningd/runes.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,13 @@ static struct command_result *json_blacklistrune(struct command *cmd,
646646
{
647647
u64 *start, *end;
648648
struct rune_blacklist *blist;
649+
bool *relist;
649650

650651
if (!param_check(cmd, buffer, params,
651-
p_opt("start", param_u64, &start), p_opt("end", param_u64, &end), NULL))
652+
p_opt("start", param_u64, &start),
653+
p_opt("end", param_u64, &end),
654+
p_opt_def("relist", param_bool, &relist, false),
655+
NULL))
652656
return command_param_failed();
653657

654658
if (end && !start) {
@@ -659,7 +663,7 @@ static struct command_result *json_blacklistrune(struct command *cmd,
659663
end = start;
660664
}
661665

662-
if (*end >= MAX_BLACKLIST_NUM) {
666+
if (end && *end >= MAX_BLACKLIST_NUM) {
663667
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Cannot blacklist beyond %u", MAX_BLACKLIST_NUM);
664668
}
665669

@@ -672,7 +676,10 @@ static struct command_result *json_blacklistrune(struct command *cmd,
672676
}
673677

674678
/* Include end */
675-
bitmap_fill_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);
679+
if (*relist)
680+
bitmap_zero_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);
681+
else
682+
bitmap_fill_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);
676683

677684
/* Convert to list once, use for db and for list_blacklist */
678685
blist = bitmap_to_blacklist(cmd, cmd->ld->runes->blist_bitmap, MAX_BLACKLIST_NUM);

tests/autogenerate-rpc-examples.py

+2
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ def generate_runes_examples(l1, l2, l3):
795795
update_example(node=l2, method='blacklistrune', params={'start': 1})
796796
update_example(node=l2, method='blacklistrune', params={'start': 0, 'end': 2})
797797
update_example(node=l2, method='blacklistrune', params={'start': 3, 'end': 4})
798+
update_example(node=l2, method='blacklistrune', params={'start': 3, 'relist': True},
799+
description=['This undoes the blacklisting of rune 3 only'])
798800

799801
# Commando runes
800802
rune_l11 = update_example(node=l1, method='commando-rune', params={}, description=['This creates a fresh rune which can do anything:'])

tests/test_runes.py

+33
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,39 @@ def test_blacklistrune(node_factory):
409409
blacklisted_rune = l1.rpc.showrunes(rune='geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==')['runes'][0]['blacklisted']
410410
assert blacklisted_rune is True
411411

412+
# Sigh. Someone blacklisted too much, so we added this!
413+
blacklist = l1.rpc.blacklistrune(start=10, relist=True)
414+
assert blacklist == {'blacklist': [{'start': 0, 'end': 6},
415+
{'start': 9, 'end': 9}]}
416+
417+
with pytest.raises(RpcError, match='Cannot blacklist beyond'):
418+
l1.rpc.blacklistrune(start=100_000_000, relist=True)
419+
420+
blacklist = l1.rpc.blacklistrune(start=9, end=9, relist=True)
421+
assert blacklist == {'blacklist': [{'start': 0, 'end': 6}]}
422+
423+
blacklist = l1.rpc.blacklistrune(start=1, end=2, relist=True)
424+
assert blacklist == {'blacklist': [{'start': 0, 'end': 0},
425+
{'start': 3, 'end': 6}]}
426+
427+
blacklist = l1.rpc.blacklistrune(start=4, relist=True)
428+
assert blacklist == {'blacklist': [{'start': 0, 'end': 0},
429+
{'start': 3, 'end': 3},
430+
{'start': 5, 'end': 6}]}
431+
432+
blacklist = l1.rpc.blacklistrune(start=0, end=3, relist=True)
433+
assert blacklist == {'blacklist': [{'start': 5, 'end': 6}]}
434+
435+
# Database should be persistent
436+
l1.restart()
437+
438+
blacklist = l1.rpc.blacklistrune()
439+
assert blacklist == {'blacklist': [{'start': 5, 'end': 6}]}
440+
441+
# Last deletion.
442+
blacklist = l1.rpc.blacklistrune(start=0, end=99_999_999, relist=True)
443+
assert blacklist == {'blacklist': []}
444+
412445

413446
def test_badrune(node_factory):
414447
"""Test invalid UTF-8 encodings in rune: used to make us kill the offers plugin which implements decode, as it gave bad utf8!"""

0 commit comments

Comments
 (0)