vincenzopalazzo / lampo.rs

lampo (lightning in Italian) is a experimental implementation of a tiny lightning node
http://lampo.devcrew.cc
BSD 3-Clause "New" or "Revised" License
31 stars 14 forks source link

`funds` command needs some more love. #233

Open Harshit933 opened 1 month ago

Harshit933 commented 1 month ago

I freshly created a new wallet inside lampo. But lampo-cli --network regtest funds give me some different transactions.

[doom@archlinux ~]$ lampo-cli --network regtest funds
{
  "transactions": [
    {
      "txid": "d6aab3d6b12da6b65930b9ff2784d95472b00f68c850b11d9ceefe998219109c",
      "vout": 0,
      "reserved": false,
      "confirmed": 102,
      "amount_msat": 5000000000000
    },
    {
      "txid": "e7e931bf6c32bc659800f2bcf28785d7685d86eef76947d57b70960f2d21aec0",
      "vout": 0,
      "reserved": false,
      "confirmed": 104,
      "amount_msat": 5000000000000
    },
    {
      "txid": "930c512b5cda54c04892ca5d7bd465b9fce9b36dbbe193e322516dded7ece496",
      "vout": 0,
      "reserved": false,
      "confirmed": 101,
      "amount_msat": 5000000000000
    },
    {
      "txid": "95acde8656faff00fdd515963166ccde9f7a1d937d43a9a9e70c36456d1694a7",
      "vout": 0,
      "reserved": false,
      "confirmed": 105,
      "amount_msat": 5000000000000
    },
    {
      "txid": "c0f36f0db361331ab3ff1bec755845c8fc0b4e647ec5d3f0e796201225eff692",
      "vout": 0,
      "reserved": false,
      "confirmed": 103,
      "amount_msat": 5000000000000
    }
  ]
}

This should not happen.

Harshit933 commented 1 month ago

My conf :

network=regtest
backend=core
core-user=user
core-pass=pass
core-url=http://127.0.0.1:38332
port=39736
log-level=trace
alias=doom
Harshit933 commented 3 weeks ago

I investigated about this issue and came up with the following :

Suppose we create a fresh wallet using lampod-cli --network testnet. It creates a new core wallet inside .bitcoin/testnet3/lampo-wallet/ and stores all the wallet.dat files there and manager file which is created by LampoChannelManager stores the LampoKeys inside .lampo/testnet/.

But if the .lampo directory gets deleted which contains the manager file. Our wallet keys are then gone. Then, when we try to spin up a new wallet with the same lampod-cli --network testnet command the new wallet does spin up but just points to the old one because : https://github.com/vincenzopalazzo/lampo.rs/blob/e3e0b910bfce740f2530a80ed94fe59b0e35142d/lampo-core-wallet/src/lib.rs#L214 The configure_wallet fails with the condition : https://github.com/vincenzopalazzo/lampo.rs/blob/e3e0b910bfce740f2530a80ed94fe59b0e35142d/lampo-core-wallet/src/lib.rs#L107 As listwallets rpc does contains the old wallet. Thus, when we use lampo-cli --network testnet funds it points to the transaction which was present inside the old wallet (as it never gets deleted, only keys are deleted from manager).

vincenzopalazzo commented 3 weeks ago

Correct, this is expected! if you delete your lightning dir you are fuck up anyway and you lose your funds.

When you talk about real funds this is a really bead deal and you should not, and I repeat SHOULD NOT delete your folder.

The case that you described is a feature, because you did not restore your wallet.

So maybe when let wallet_name = Self::configure_bitcoin_wallet(&rpc, conf.clone(), wallet)?; return a wallet, but you are not passing a --restore-wallet, lampo should return an error and tell the user, that there is already a wallet and you need to restore it in order to generate the correct keys and secret in lampo.

Harshit933 commented 3 weeks ago

So maybe when let wallet_name = Self::configure_bitcoin_wallet(&rpc, conf.clone(), wallet)?; return a wallet, but you are not passing a --restore-wallet, lampo should return an error and tell the user, that there is already a wallet and you need to restore it in order to generate the correct keys and secret in lampo.

This seems the correct thing to do!

vincenzopalazzo commented 1 week ago

@Harshit933 When you have time can you close this issue and open another one that describe the problem?