Commit Graph

25 Commits

Author SHA1 Message Date
Rusty Russell 3b622f06c3 lightningd: use param_check on all commands which do extra checks.
This makes `check` much more thorough, and useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `check` now does much more checking on every command (not just basic parameter types).
2023-10-26 12:59:55 +10:30
Rusty Russell 03e51ae879 Revert "runes: fix `checkrune` when `method` parameter is the empty string."
This reverts commit ae94be4ce2.
2023-10-17 14:58:40 +10:30
Tony Aldon ae94be4ce2 runes: fix `checkrune` when `method` parameter is the empty string.
This fix #6725.

Changelog-Fixed: fix `checkrune` when `method` parameter is the empty string.
2023-10-12 20:42:43 +02:00
ShahanaFarooqui c15fc54586 runes: Runes will use unique id returned from `runes` table not `runes_uniqueid` from `vars` 2023-10-03 08:56:53 +10:30
ShahanaFarooqui 9bcabbc912 runes: Reimplement `rate` in terms of `per`
Changelog-Changed: JSON-RPC: `checkrune` `rate` restriction is slightly stricter (exact division of time like `per`)
2023-10-03 06:57:54 +10:30
Rusty Russell 3e124d9ec1 lightningd: remove #if DEVELOPER.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
ShahanaFarooqui 91eb184141 lightningd/runes: Added last_time_check for validating rune for `per` restriction
Changelog-Added: runes: `per=Nsec/min/hour/msec/usec/nsec` for general ratelimiting
2023-09-21 13:31:34 +09:30
ShahanaFarooqui d745323f74 lightning/runes: added last_used in showrunes
Changelog-Added: JSON-RPC: `showrunes` new field `last_used`
2023-09-21 13:31:34 +09:30
ShahanaFarooqui db55deae2a lightningd/runes: update last_used timestamp when a rune successfully used 2023-09-21 13:31:34 +09:30
ShahanaFarooqui eacf0b502c wallet: add last_used_nsec in runes table
We will use this for better rate limiting
2023-09-21 13:31:34 +09:30
Rusty Russell 2765939adb runes: fix weird unnecessary zero-test.
This seems to be a cut & paste bug (mine, AFAICT!) from the command code:

```
	rune = rune_derive_start(cmd, master_rune,
				 tal_fmt(tmpctx, "%"PRIu64,
					 rune_counter ? *rune_counter : 0));
```

In that case, rune_counter was a pointer, which could be NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell 785fe973a6 runes: ensure that uniqueid is a valid number.
It always is for runes we create, but in theory you can take our secret key
and make our own runes with your own tools.

(We correctly refuse runes without uniqueids if they're *not* ours
anyway: uniqueid is only used for our own runes).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell ecb09778db lightningd: refuse to create rune with empty fields.
These look like uniqueids, and so can confuse us (I discovered this by
making a typo in a test!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell bb38f83b88 checkrune: make nodeid and method optional.
nodeid is only useful when we know the peer we're talking to (e.g. commando).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
No-schema-diff-check: We're simply making optional, not deprecating!
2023-09-12 15:19:02 +09:30
Rusty Russell 9239278cdd plugins: fix compile warning with some gcc versions and -Og
Indeed, we can fall through this if it's not a valid enum value.

gcc-12 (Ubuntu 12.2.0-17ubuntu1) 12.2.0

```
In file included from plugins/commando.c:10:
ccan/ccan/tal/str/str.h: In function ‘rune_altern_to_english’:
ccan/ccan/tal/str/str.h:43:9: error: ‘cond_str’ may be used uninitialized [-Werror=maybe-uninitialized]
   43 |         tal_fmt_(ctx, TAL_LABEL(char, "[]"), __VA_ARGS__)
      |         ^~~~~~~~
plugins/commando.c:97:21: note: ‘cond_str’ was declared here
   97 |         const char *cond_str;
      |                     ^~~~~~~~
cc1: all warnings being treated as errors
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 06:21:23 +09:30
Rusty Russell c4c4768577 lightningd: initialize runes way earlier, and add rune_is_ours helper.
We want to access this in db migrations, which happen very early, but
runes_init needs the db, creating a circular dependency which must be
split.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell 8df29db48f runes: fix `stored` field.
The uid isn't enough: it could be someone else's rune.  This is tested
in the command rune list tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Shahana Farooqui 49fdc0df99 runes: Renamed `listrunes` to `showrunes` 2023-07-25 11:07:43 +09:30
Shahana Farooqui a649e8b517 runes: create and blacklist commands aliases
- Added `invokerune` alias for `createrune`
- Added `destroyrune` alias for `blacklistrune`
2023-07-25 11:07:43 +09:30
Rusty Russell 0ceee9390a lightningd: avoid notleak markers: move global into struct runes.
This is neater anyway, but we still need to tell memleak code about the htable.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30
Shahana Farooqui 4d16b220c2 lightningd: implement `blacklistrune` command. 2023-07-21 16:44:22 +09:30
Rusty Russell 5774737a5c lightningd: implement `checkrune` command.
This extracts the core checking functionality for a rune, so they can
easily be used more widely than just commando.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30
Rusty Russell b9169d7862 lightningd: implement `createrune` command.
This looks suspiciously like `commando-rune`!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30
Rusty Russell 5987c156a0 lightningd: implement listrunes command.
Most code stolen from commando, but uses db directly not datastore.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30
Rusty Russell 9177084505 lightningd: new runes infrastructure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30