CLN plugin doesn't detect sync complete
From the Discord discussion here.
Peerswap 5.0.0-rc2
CLN v25.02.2
Elementsd v23.2.7
On lightningd startup, Peerswap logs end with plugin-peerswap: Waiting for cln to be synced..., but looking through the code, it seems that there should be a subsequent CLN synced message if the process continued successfully.
A quick investigation indicates there might be an infinite loop during the sync verification here, which checks on the glightning variables WarningBitcoinSync and WarningLightningSync here.
Tried to whip up a quick PR to test these values for nil instead of "", but the typing didn't work. I'm not a Go programmer (yet). Perhaps there is an issue with omitempty on these properties and the marshalling or unmarshalling of the values?
It's also possible my config or unique combination of versions is to blame, so any suggestions would be appreciated to gather more information on the RPC connectivity.
Are CLN and bitcoind running on the same machine?
Are CLN and bitcoind running on the same machine?
Yes they are. Using cookie authentication:
lightning-cli peerswap-listconfig
{
"bitcoin.rpcuser": "__cookie__",
"bitcoin.rpcpassword": "[redacted]",
"bitcoin.rpcpasswordfile": "/data/bitcoin/.cookie",
"bitcoin.rpchost": "http://127.0.0.1",
"bitcoin.rpcport": 8332,
"bitcoin.rpccookiefilepath": "/data/bitcoin/.cookie",
...
}
The file is readable by the lightningd user.
I've tried various changes to the config, some where calls to peerswap RPCs continually report it is "still starting up". Not sure exactly what is wrong with my config setup, but it could be a big improvement to have more verbose error / status messages on plugin startup (my plugin log level is info:plugin-peerswap).
One additional peculiarity to note:
~/.lightning/bitcoin/peerswap$ sqlite3 swaps
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
sqlite> .schema
Error: file is not a database
I think this can happen when the database is created with a cipher - is that so? Or should I consider moving the file and allowing peerswap to create a new database?
Oh yes I would try allowing peerswap to create the database. What you're trying is untested and likely won't work (happy to be proven wrong there), though it's something we could consider adding support for down the road.
I stopped lightningd, renamed the existing swaps database, restarted lightningd. A new swaps database was created, but same behavior -- last message from the peerswap plugin is Waiting for cln to be synced.... Also, when accessing the new database directly using sqlite3, inspecting the schema gives the same error as above: Error: file is not a database.
To be clear, I didn't manually create the db during my first install attempt either -- peerswap created it, so this is a reproduction of behavior from my original install.
Based on the circumstances, it appears that waitForClnSynced blocks, so it is likely that one or both of them have not yet finished syncing.
Could you attach the dump of the lightning-cli getinfo response, as well as the CLN/Peerswap logs?
Here is the information with some [redacted]:
$ lightning-cli getinfo
{
"id": "[redacted]",
"alias": "[redacted]",
"color": "009900",
"num_peers": 25,
"num_pending_channels": 0,
"num_active_channels": 10,
"num_inactive_channels": 0,
"address": [
{
"type": "torv3",
"address": "[redacted]",
"port": 9736
}
],
"binding": [
{
"type": "ipv4",
"address": "0.0.0.0",
"port": 9736
}
],
"version": "v25.02.2",
"blockheight": 901206,
"network": "bitcoin",
"fees_collected_msat": 12593180,
"lightning-dir": "/home/lightningd/.lightning/bitcoin",
"our_features": {
"init": "08a0882a8a59a1",
"node": "88a0882a8a59a1",
"channel": "",
"invoice": "02000002024100"
}
}
Hope this helps! LMK if I can provide any more info.
Based on the command’s output, PeerSwap should judge that the sync is complete.
WarningBitcoinSync string `json:"warning_bitcoind_sync,omitempty"`
WarningLightningSync string `json:"warning_lightningd_sync,omitempty"`
Because of this:
• If the JSON key is absent → an empty string "" is set
• If the key exists but its value is an empty string → "" is set
⇒ In either case, IsSync() returns true.
Therefore, the connection to Core Lightning may be failing for some reason.
Improving observability—e.g., by adding a timeout for the cln connection—might make the cause clearer, but I’m afraid I don’t have any further information at this point.
We added a reconnection mechanism to PeerSwap and improved its observability.
Could you please verify that it works on the latest master branch?
To follow up here, running v5.0.0, I get the following output:
plugin-peerswap: PeerSwap starting up with commit 8f670390ff9277f02bd6d422d518de757ce2faf8
plugin-peerswap: DB version: v0.2, Protocol version: 5
plugin-peerswap: Using data dir: /data/lightningd/bitcoin
plugin-peerswap: Using core-lightning version v25.09-modded
plugin-peerswap: Waiting for cln to be synced...
plugin-peerswap: Waiting for Core Lightning to sync (checking every 10s)
FYI - my CLN is modded with a recent commit to master slated for v25.09.1, I don't think that should be the issue.