peerswap icon indicating copy to clipboard operation
peerswap copied to clipboard

CLN plugin doesn't detect sync complete

Open s373nZ opened this issue 6 months ago • 10 comments

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.

s373nZ avatar Jun 03 '25 11:06 s373nZ

Are CLN and bitcoind running on the same machine?

grubles avatar Jun 04 '25 15:06 grubles

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).

s373nZ avatar Jun 05 '25 08:06 s373nZ

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?

s373nZ avatar Jun 05 '25 08:06 s373nZ

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.

grubles avatar Jun 05 '25 12:06 grubles

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.

s373nZ avatar Jun 06 '25 08:06 s373nZ

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?

YusukeShimizu avatar Jun 09 '25 04:06 YusukeShimizu

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"
   }
}

lightningd-20250606.log

Hope this helps! LMK if I can provide any more info.

s373nZ avatar Jun 14 '25 12:06 s373nZ

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.

YusukeShimizu avatar Jun 18 '25 06:06 YusukeShimizu

We added a reconnection mechanism to PeerSwap and improved its observability.
Could you please verify that it works on the latest master branch?

YusukeShimizu avatar Jul 07 '25 05:07 YusukeShimizu

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.

s373nZ avatar Oct 10 '25 09:10 s373nZ