Skip to content

Commit

Permalink
lightningd: implement unblacklist.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `blacklistrune` now has an option to un-blacklist (`relist`).
  • Loading branch information
rustyrussell committed Jan 28, 2025
1 parent 7c9a038 commit d50aa0d
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@
},
"BlacklistruneRequest": {
"BlacklistRune.end": 2,
"BlacklistRune.relist": 3,
"BlacklistRune.start": 1
},
"BlacklistruneResponse": {
Expand Down Expand Up @@ -5127,6 +5128,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
"BlacklistRune.relist": {
"added": "v25.02",
"deprecated": null
},
"BlacklistRune.start": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
1 change: 1 addition & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions contrib/msggen/msggen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4678,6 +4678,13 @@
"description": [
"Final rune unique id to blacklist (defaults to start)."
]
},
"relist": {
"type": "boolean",
"added": "v25.02",
"description": [
"Undo the blacklisting (if any) of every rune in range start to end (inclusive)"
]
}
},
"dependentUpon": {
Expand Down Expand Up @@ -4785,6 +4792,31 @@
}
]
}
},
{
"description": [
"This undoes the blacklisting of rune 3 only"
],
"request": {
"id": "example:blacklistrune#4",
"method": "blacklistrune",
"params": {
"start": 3,
"relist": true
}
},
"response": {
"blacklist": [
{
"start": 0,
"end": 2
},
{
"start": 4,
"end": 4
}
]
}
}
]
},
Expand Down
296 changes: 148 additions & 148 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions doc/schemas/lightning-blacklistrune.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"description": [
"Final rune unique id to blacklist (defaults to start)."
]
},
"relist": {
"type": "boolean",
"added": "v25.02",
"description": [
"Undo the blacklisting (if any) of every rune in range start to end (inclusive)"
]
}
},
"dependentUpon": {
Expand Down Expand Up @@ -133,6 +140,31 @@
}
]
}
},
{
"description": [
"This undoes the blacklisting of rune 3 only"
],
"request": {
"id": "example:blacklistrune#4",
"method": "blacklistrune",
"params": {
"start": 3,
"relist": true
}
},
"response": {
"blacklist": [
{
"start": 0,
"end": 2
},
{
"start": 4,
"end": 4
}
]
}
}
]
}
13 changes: 10 additions & 3 deletions lightningd/runes.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,13 @@ static struct command_result *json_blacklistrune(struct command *cmd,
{
u64 *start, *end;
struct rune_blacklist *blist;
bool *relist;

if (!param_check(cmd, buffer, params,
p_opt("start", param_u64, &start), p_opt("end", param_u64, &end), NULL))
p_opt("start", param_u64, &start),
p_opt("end", param_u64, &end),
p_opt_def("relist", param_bool, &relist, false),
NULL))
return command_param_failed();

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

if (*end >= MAX_BLACKLIST_NUM) {
if (end && *end >= MAX_BLACKLIST_NUM) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Cannot blacklist beyond %u", MAX_BLACKLIST_NUM);
}

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

/* Include end */
bitmap_fill_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);
if (*relist)
bitmap_zero_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);
else
bitmap_fill_range(cmd->ld->runes->blist_bitmap, *start, (*end)+1);

/* Convert to list once, use for db and for list_blacklist */
blist = bitmap_to_blacklist(cmd, cmd->ld->runes->blist_bitmap, MAX_BLACKLIST_NUM);
Expand Down
2 changes: 2 additions & 0 deletions tests/autogenerate-rpc-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ def generate_runes_examples(l1, l2, l3):
update_example(node=l2, method='blacklistrune', params={'start': 1})
update_example(node=l2, method='blacklistrune', params={'start': 0, 'end': 2})
update_example(node=l2, method='blacklistrune', params={'start': 3, 'end': 4})
update_example(node=l2, method='blacklistrune', params={'start': 3, 'relist': True},
description=['This undoes the blacklisting of rune 3 only'])

# Commando runes
rune_l11 = update_example(node=l1, method='commando-rune', params={}, description=['This creates a fresh rune which can do anything:'])
Expand Down
33 changes: 33 additions & 0 deletions tests/test_runes.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,39 @@ def test_blacklistrune(node_factory):
blacklisted_rune = l1.rpc.showrunes(rune='geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==')['runes'][0]['blacklisted']
assert blacklisted_rune is True

# Sigh. Someone blacklisted too much, so we added this!
blacklist = l1.rpc.blacklistrune(start=10, relist=True)
assert blacklist == {'blacklist': [{'start': 0, 'end': 6},
{'start': 9, 'end': 9}]}

with pytest.raises(RpcError, match='Cannot blacklist beyond'):
l1.rpc.blacklistrune(start=100_000_000, relist=True)

blacklist = l1.rpc.blacklistrune(start=9, end=9, relist=True)
assert blacklist == {'blacklist': [{'start': 0, 'end': 6}]}

blacklist = l1.rpc.blacklistrune(start=1, end=2, relist=True)
assert blacklist == {'blacklist': [{'start': 0, 'end': 0},
{'start': 3, 'end': 6}]}

blacklist = l1.rpc.blacklistrune(start=4, relist=True)
assert blacklist == {'blacklist': [{'start': 0, 'end': 0},
{'start': 3, 'end': 3},
{'start': 5, 'end': 6}]}

blacklist = l1.rpc.blacklistrune(start=0, end=3, relist=True)
assert blacklist == {'blacklist': [{'start': 5, 'end': 6}]}

# Database should be persistent
l1.restart()

blacklist = l1.rpc.blacklistrune()
assert blacklist == {'blacklist': [{'start': 5, 'end': 6}]}

# Last deletion.
blacklist = l1.rpc.blacklistrune(start=0, end=99_999_999, relist=True)
assert blacklist == {'blacklist': []}


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

0 comments on commit d50aa0d

Please sign in to comment.