Commit Graph

49 Commits

Author SHA1 Message Date
Rusty Russell
aff1d6b97f commando, chanbackup: use custommsg hooks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
Rusty Russell
8b9020d7b9 global: use clock_time in place of time_now().
Except for tracing, that sticks with time_now().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-13 21:21:29 +10:30
Rusty Russell
42f9361375 ccan: update to get improved grab_file API, and adapt code.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Rusty Russell
75616f6b77 common: add new_htable() macro to allocate, initialize and setup memleak coverage for any typed hash table.
You can now simply add per-tal-object helpers for memleak, but our older pattern required
calling memleak functions explicitly during memleak handling.  Hash tables in particular need
to be dynamically allocated (we override the allocators using htable_set_allocator and assume
this), so it makes sense to have a helper macro that does all three.

This eliminates a huge amount of code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-24 11:30:17 +10:30
Rusty Russell
6e5cb299dd global: remove unnecessary includes from C files.
Basically, `devtools/reduce-includes.sh */*.c`.

Build time from make clean (RUST=0) (includes building external libs):

Before:
	real    0m38.944000-40.416000(40.1131+/-0.4)s
	user    3m6.790000-17.159000(15.0571+/-2.8)s
	sys     0m35.304000-37.336000(36.8942+/-0.57)s
After:
	real    0m37.872000-39.974000(39.5466+/-0.59)s
	user    3m1.211000-14.968000(12.4556+/-3.9)s
	sys     0m35.008000-36.830000(36.4143+/-0.5)s

Build time after touch config.vars (RUST=0):

Before:
	real    0m19.831000-21.862000(21.5528+/-0.58)s
	user    2m15.361000-30.731000(28.4798+/-4.4)s
	sys     0m21.056000-22.339000(22.0346+/-0.35)s

After:
	real    0m18.384000-21.307000(20.8605+/-0.92)s
	user    2m5.585000-26.843000(23.6017+/-6.7)s
	sys     0m19.650000-22.003000(21.4943+/-0.69)s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
f6a4e79420 global: remove unnecessary includes from headers.
Each header should only include the other headers it needs to compile;
`devtools/reduce-includes.sh */*.h` does this.  The C files then need
additional includes if they don't compile.

And remove the entirely useless wire/onion_wire.h, which only serves to include wire/onion_wiregen.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
a25c1d45ad libplugin: make jsonrpc_set_datastore_binary() take an explicit length.
This means it doesn't have to be a tal ptr.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
44972b2e15 chanbackup: unbias our random peer selection.
We picked one node and iterated.  This means we would only sent to 1,
not 2 nodes if we picked the last (common if there were only a few
peers).  But it also means we would generally send to the same pair of
nodes, which isn't great for redundancy.

Rework to be more random.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
49ccb0eeb8 chanbackup: don't send our backups to peers if they would be overlength.
They will in fact get truncated, and never restore.  Large nodes should be using some real
backup strategy!

For this reason, we split "peer_backup" support into send vs store support, so we can
turn off send of our own without disabling storing/sending theirs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
c5cde13af6 chanbackup: only send channel backups to max 2 peers at a time.
This, too, is vital for large nodes, which don't want a significant
traffic increase.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
90bbd8aedc chanbackup: use peer table instead of calling "listpeerchannels".
This is much better for very large nodes with lots of channel activity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
4eafc1a2e1 chanbackup: cache available peers.
We already get the connected hook, so in there we can add to a hash
table of suitable peers.  Rather than subscribe to disconnection, we
simply remove the peer if a sendcustommsg fails.

This does make after_send_scb_single() a bit more complex, since it
needs this specific node_id: we use a `struct info` per node and a
pointer to a shared "idx" reference counter.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
bda52c315c chanbackup: use the cache instead of calling listdatastore every time.
Now actually use our cache.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
dc2c3668e6 chanbackup: use local memory to store peer backups.
By keeping a local hash table, we won't have to look up every time.
We still write to the datastore when it changes, and we need to
initialize it at plugin start.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
adf7663fef chanbackup: only store backups for peers with current/previous channels.
This seems fair.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
cdce113d57 chanbackup: use modern plugin_data.
This avoids globals, which is a bit neater.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
f590962be2 chanbackup: less logging in preparation for default enable.
We should not send a message on unknown custom message receipt (we
expect this!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
e8690021ee chanbackup: remove unnecessary allocation.
after_listpeers() doesn't use the argument, so we don't need to allocate anything.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Rusty Russell
9357954bd9 chanbackup: add spec quotes now we have this in the spec.
This is the only way to track spec changes in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-16 23:39:35 +09:30
Aditya Sharma
9a5ef91d62 Change LOG_INFORM to LOG_TRACE in chanbackup
plugin_log inside after_send_scb_single was logging after sending peer storage
to each peer which could lead to spam in logs for big nodes, hence we should reduce
the log level to log_trace for it.

Changelog-Fixed: Suppress logs from chanbackup
2025-05-01 19:24:51 -07:00
Rusty Russell
67c91a7e5c BOLTs: Update to version with peer storage merged.
Unfortunately a spec typo means the data fields are missing (PR pending),
so we still patch those in.

The message "your_peer_storage" got renamed to "peer_storage_retrieval",
and the option "want_peer_backup_storage" was removed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `experimental-peer-storage` now only advertizes feature 43, not 41.
2025-03-18 14:30:58 +10:30
Alex Myers
4f7df828b4 gossipd, chanbackup: reduce logging levels
The vast majority of incoming channel updates seem to be cut due
to age, which results in noisy logs.  Similarly, the chanbackup
logging verbosity might better match the equivalent actions in
channeld, which are at the debug level.

Fixes: #8058

Changelog-None: introduced in 25.02
2025-02-26 14:15:13 +10:30
Aditya Sharma
1a54888e2d Update SCB on every commitment update and handle new format
The chanbackup plugin should update emergency.recover every time we
receive a new commitment secret.

Additionally, chanbackup should be able to serialize both the new
SCB format and the legacy format.

Key Changes:
 - Added a commitment_revocation plugin hook to update emergency.recover whenever a new revocation secret is received.
 - Implemented support for the new emergency.recover format while maintaining compatibility with the legacy format.
2025-02-22 11:51:54 -06:00
Rusty Russell
c797b6fb20 libplugin: add method string to jsonrpc callbacks, implement generic helpers.
Without knowing what method was called, we can't have useful general logging
methods, so go through the pain of adding "const char *method" everywhere,
and add:

1. ignore_and_complete - we're done when jsonrpc returned
2. log_broken_and_complete - we're done, but emit BROKEN log.
3. plugin_broken_cb - if this happens, fail the plugin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-11-07 17:04:35 +10:30
Rusty Russell
c5099b1647 libplugin: clean up API.
When we used to allow cmd to be NULL, we had to hand the plugin
everywhere.  We no longer do.

1. Various jsonrpc_ functions no longer need the plugin arg.
2. send_outreq no longer needs a plugin arg.
3. The init function takes a command, not a plugin.
4. Remove command_deprecated_in_nocmd_ok.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-11-07 17:04:35 +10:30
Aditya Sharma
4c775f16aa plugins/chanbackup: Add RPC to fetch data from emergency.recover file. 2024-10-03 18:59:10 -07:00
Rusty Russell
11bfbf5deb libplugin: add data pointer for plugin convenience.
This avoids globals (and means memleak traverses the variables!): we
only change over the test plugin though, to avoid unnecessary churn.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-07 20:35:30 +09:30
ShahanaFarooqui
2ff3e55f08 plugin: Removing category, description and long_description from plugin_command struct
Changelog-None.
2024-07-31 14:42:58 +09:30
Aditya Sharma
4789eb9fa0 chanbackup: typo fix. 2024-05-29 10:34:58 -05:00
Rusty Russell
e0e879c003 common: remove type_to_string files altogther.
This means including <common/utils.h> where it was indirectly included.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
37d22f9141 global: change all type_to_string to fmt_X.
This has the benefit of being shorter, as well as more reliable (you
will get a link error if we can't print it, not a runtime one!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-03-20 13:51:48 +10:30
Rusty Russell
df10c62508 chanbackup: even if they enable experimental-peer-storage, check peers
Seems like LND is hanging up on receiving these messages, even though
they're odd :(

So, when a peer connects, check if it supplies or wants peer backup
(even if it doesn't support both, it shouldn't hang up, and I didn't
want to separate the two paths).

And when we go to send our own, updated backup, check features before
sending.

Fixes: #6065
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `experimental-peer-storage` caused LND to hang up on us, so only send to peers which support it.
2023-03-08 18:46:21 -06:00
Vincenzo Palazzo
bcc94b2d43 fix: do not send send peerstorage msg when disabled
This commit will disable the peerstorage plugins
when the feature is not enabled.

I found this issue with lnprototest, and I guess
we did not find it with normal run because
other the unknown messages are ingored?

Changelog-Fixed: Disable the protocol messages when peerstorage is disabled.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-27 11:18:56 -06:00
Rusty Russell
a71bd3ea37 options: create enable/disable option for peer storage.
Since it's not spec-final yet (hell, it's not even properly specified
yet!) we need to put it behind an experimental flag.

Unfortunately, we don't have support for doing this in a plugin; a
plugin must present features before parsing options.  So we need to do
it in core.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-02-08 08:37:59 -06:00
Rusty Russell
c60ea5bcbb plugins/chanbackup: make get_file_data take ctx.
When you return an allocated pointer, you should always hand in the
context you want it allocated from.  This is more explicit, because it may
really matter to the caller!

This also folds some simple operations, and avoids doing too much
variable assignment in the declarations themselves: some coding styles
prohibit such initializers, but that's a bit exteme.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-02-08 08:37:59 -06:00
Rusty Russell
17c35819d8 plugins/chanbackup: neaten a little.
node_id can be on the stack, avoiding a tal call.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-02-08 08:37:59 -06:00
Rusty Russell
f1fed40ac2 features: make name of peer storage features match spec.
And we should always represent them as is, not as optional: it's
possible in future we could *require* "WANT_PEER_BACKUP_STORAGE".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-02-08 08:37:59 -06:00
Rusty Russell
68d9b21aec plugins/chanbackup: switch to normal indentation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-02-08 08:37:59 -06:00
adi2011
e637e843e7 Plugins/chanbackup: Add RPC for recovering from the latestscb received from peers. 2023-02-08 08:37:59 -06:00
adi2011
7affaff728 Plugins/chanbackup: Add hook for exchanging msgs on connect with a peer 2023-02-08 08:37:59 -06:00
adi2011
d205f489bd Plugins/chanbackup: Add hook for receiving custommsg 2023-02-08 08:37:59 -06:00
adi2011
01cafe478b Plugins/chanbackup: Add SCB on CHANNELD_AWAITING_LOCKING stage 2023-02-08 08:37:59 -06:00
adi2011
33f0c4ec0b plugins/chanbackup: use grab_file. 2023-02-08 08:37:59 -06:00
adi2011
ff777e3238 plugins/chanbackup: Define FILENAME globally (Good Manners) 2023-02-08 08:37:59 -06:00
adi2011
2b1867aca3 Plugins/chanbackup: Add featurebit Peerstrg and YourPeerStrg. 2023-02-08 08:37:59 -06:00
adi2011
93d03bf9e8 plugins/chanbackup: PLUGIN_RESTARTABLE to PLUGIN_STATIC... 2023-02-08 08:37:59 -06:00
Rusty Russell
401f1debc5 common: clean up json routine locations.
We have them split over common/param.c, common/json.c,
common/json_helpers.c, common/json_tok.c and common/json_stream.c.

Change that to:
* common/json_parse (all the json_to_xxx routines)
* common/json_parse_simple (simplest the json parsing routines, for cli too)
* common/json_stream (all the json_add_xxx routines)
* common/json_param (all the param and param_xxx routines)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 12:24:00 -05:00
Rusty Russell
c34a0a22ad makesecret: change info_hex arg to simply "hex" to match datastore command.
And fix schema: it wasn't tested as there was no test-by-parameter-name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 22:17:58 +09:30
adi2011
1450f1758c Plugin: Add new plugin for SCB, Updated makefile and gitignore as well 2022-07-14 12:24:48 -05:00