Skip to content
changes made to help fix a corrupted channel.db
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
aezeed
autopilot
brontide
buffer
build
chainntnfs
chanbackup
channelcheck
channeldb
channelnotifier
cmd/lncli
contractcourt
contrib
discovery
docker
docs
htlcswitch
input
invoices
keychain
lncfg
lnpeer
lnrpc
lntest
lntypes lntypes: return a value from constructors Mar 15, 2019
lnwallet
lnwire
macaroons
make
multimutex multimutex: add new multimutex package Jan 24, 2018
nat
netann
pool pool/worker_test: add tests for concrete Worker pools Feb 22, 2019
queue
routing
shachain
signal
subscribe
sweep
ticker
tor
walletunlocker
watchtower
zpay32
.gitignore
.travis.yml
Dockerfile
LICENSE
Makefile
README.md
breacharbiter.go
breacharbiter_test.go breacharbiter_test: add table-driven breach spend tests Mar 20, 2019
chainparams.go
chainregistry.go
chancloser.go
config.go Merge pull request #2736 from cfromknecht/config-num-workers Mar 19, 2019
doc.go
fundingmanager.go
fundingmanager_test.go
go.mod
go.sum
lnd.go
lnd_test.go
log.go
logo.png
mock.go
nursery_store.go
nursery_store_test.go
peer.go
peer_test.go
pilot.go
release.sh
rpcserver.go
sample-lnd.conf
server.go
server_test.go
subrpcserver_config.go
test_utils.go
utxonursery.go
utxonursery_test.go
witness_beacon.go

README.md

Recover funds off a LND node that has a corrupted channel.db.

See this issue for reference on the situation. https://github.com/lightningnetwork/lnd/issues/2825

Inital Info & Disclaimer.

  • Use this repo completely at your own risk. Hopefully you will never have a courrpted channel.db, if you do please let me know of your success stories. This repo has proven effective for my situation, your milage may vary.
  • This is in no-way officially part of the LND repo. LND very well may have a robust recovery feature in the future. (This is neither official or robust).
  • If you are working with a corrupted harddrive you will first need to run commands like fsck or similar to try and fix the corrupted drive. This has worked for me.
  • If you are using a lightning node / Raspberry Pi / etc / you will need to shutdown LND and retrieve the channel.db
    • I then recommend spinning up your LND instance as a recovery environment.
  • Please create a branch for your unique situation and push if you find success outside of the code in master.
    • go get -d github.com/miketwenty1/lightningrecovery
    • cd ~/gocode/src/github.com/miketwenty1/lightningrecovery
    • git checkout -b [Descriptive Branch]
  • If you follow these steps, make sure to git rm any sensitive files like your channel.db from channelcheck directory.

When using this repo I recommend making a complete copy of your .lnd directory.

mkdir ~/recoverybkp
cp -R ~/.lnd ~/recoverybkp

Check corrupted channel.db with channelcheck

First thing we will want to do is see if we can parse the channel.db and find funds.
cp ~/.lnd/data/graph/mainnet/channel.db ~/gocode/src/github.com/miketwenty1/lightningrecovery/channelcheck/
Path to your channel.db may vary based on your setup
cd ~/gocode/src/github.com/miketwenty1/lightningrecovery/channelcheck/
Change line 12 in go.mod to be the path of your lnd
ls make sure your channel.db is in this directory
./main
Hopefully you will see Channel information along with a summation totaled at the bottom.
You should only expect to recover this amount of less.
If you don't see any channel or amount... (I'm sorry, but your situation is much different than mine) - Feel free to continue at your own risk.

LND Conf

~/.lnd/lnd.conf

[Application Options]
nolisten=1
nobootstrap=1
debuglevel=CNCT=debug,SWPR=debug,UTXN=debug

[Bitcoin]
bitcoin.mainnet=1
bitcoin.active=1
...
...
...

It's recommended to enable nolisten and nobootstrap options, it might also help to enable extra debugging.

Running LND

When you run lnd, hopefully you will be able to close channels, see pending channels, see sweep transactions. You might run into a situation where pending channels do not get earsed. This is ok, as channels might still be closed.
lncli closedchannel -h you will want to close all channels.
In my case I needed to force close all channels then wait 2 weeks before continuing. I then needed to start LND a couple times and retrieve some blocks. Shutdown LND, restart, retrieve a few blocks. I eventually swept all the funds that were locked up.
Example command to send coins off.
lncli sendcoins --addr=[BTC address] --sweepall
Hopefully you never are in this situation, but if you are.. hopefully you see some numbers in lncli walletbalance. Good luck!

Special Thanks to Conner Fromknecht

You can’t perform that action at this time.