bitcoinlightning

How to re-sync c-lightning with mainnet blockchain?


I am playing around with the lightning implementation from https://github.com/ElementsProject/lightning and after the following steps the cli-client cannot list funds which I deposited at the generated address from the internal wallet

  1. I installed bitcoind-0.16 and fully synced the mainnet-blockchain
  2. I installed c-lightning and synced with the local full node
  3. I generated a new address with ./lightning-cli newaddr
  4. I funded this address from my Electrum wallet (not from the local node wallet) and saw the incoming transaction with ./lightning-cli listfunds
  5. Then I accidentally deleted the file .lightning/lightningd.sqlite3
  6. After restart the lightningd recreated the file but now ./lightning-cli listfunds is showing empty results but the funds have to be there because the funding transaction is visible in the blockchain.

I investigated ./lightning-cli dev-listaddrs which shows all addresses of the internal wallet and there is my funding address. So I think I need to re-sync the lightningd with the bitcoin blockchain, but a ./lightning-cli dev-rescan-outputs had no success.

What can I do to be able to see and spend the funds again? Or, how can I get the seed/private key of the internal (lightning) wallet?


Solution

  • A perfect answer was given from a c-lightning member here: https://github.com/ElementsProject/lightning/issues/1170

    In case the link dies:

    Well, the short answer is do not delete the db, that will end up losing funds, just like deleting the wallet.dat would in bitcoind.

    The long answer is, use newaddr to regenerate all addresses you had (it's ok to call it a few times too many). Then stop lightningd, open lightningd.sqlite3 and tell it to scan from an earlier block:

    sqlite3 $HOME/.lightning/lightningd.sqlite3 "UPDATE vars SET val= 500000 WHERE name='last_processed_block';"

    Then restart lightningd and it should start scanning the blocks from height 500'000 (which will take quite some time).

    Notice that this only works as long as you don't have channels open, since in that case you're no longer the sole owner of the funds. So never delete the DB!