Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] If bitcoind is not fully synched when clightning starts, clightning will start to scan #1819

Closed
NicolasDorier opened this issue Aug 10, 2018 · 7 comments

Comments

@NicolasDorier
Copy link
Collaborator

NicolasDorier commented Aug 10, 2018

If bitcoind is not fully synched when clightning starts for the first time, it seems clightning is starting to scan blocks from the beginning of time.

See: btcpayserver/btcpayserver-docker#18 (comment)

Reported by @sosthene and @ndeet , based on 0.6.

Workaround: Using a utilities waiting for bitcoind to be fully synched before starting lnd. (Using NBXplorer/NBXplorer.NodeWaiter in BTCPay)

@NicolasDorier NicolasDorier changed the title If bitcoind is not fully synched when clightning starts, clightning will start to scan [Bug] If bitcoind is not fully synched when clightning starts, clightning will start to scan Aug 10, 2018
@NicolasDorier
Copy link
Collaborator Author

NicolasDorier commented Oct 11, 2018

At the very least clightning should not scan things before lightning was cool.
Better, clightning should not try to scan things while your bitcoind is synching and pruned.

BTCPay is using pruned node, so running clightning while bitcoind is not fully sync might end up badly as clightning might be too slow and bitcoind might prune blocks clightning is trying to scan.

By starting clightning only when bitcoind start, I make sure that clightning does not start scanning from long time ago.

Scanning a brand new wallet is only useful for getting the channels in the network, which is only useful when you want to send payment. For a merchant case, the most important is not to send but to receive, so they don't really care about the tradeoff.

@yaraaer
Copy link

yaraaer commented Jun 6, 2019

If bitcoind is not fully synched when clightning starts for the first time, it seems clightning is starting to scan blocks from the beginning of time.

this sounds right. clightning has to walk the chain as well, fetching blocks from bitcoind as it goes. I'm not sure what the workaround accomplishes, you would still need to walk the chain even after bitcoind is fully synced. Perhaps I'm missing something...

it is not right. I restarted my server, but after reboot I didn't mount disk where bitcoind data were stored. I just started bitcoind, then clightning, not realizing that initial sync is running. I found out next day. I have stopped cln + bitcoind, erased useless bitcoind data, mounted storage, started bitcoin and get to synced state within few minutes - for bitcoind. but clightning did not recover so easily. it is syncing blocks from the begining and it is taking ages.
on top of that I have to stop/start cln time to time and do the backup of sqlite file. since it happens that file gets malformed during that sync (no idea why).
is there any work around to skip that long useless sync? I did try to manually replace "blocks" table, but that did not work for me. seems that there are some dependencies with other tables :-(
at least CLN should complain when being started with non-synced bitcoind.
probably that's what should be somehow modified? https://github.com/ElementsProject/lightning/blob/master/lightningd/chaintopology.c#L741

@NicolasDorier
Copy link
Collaborator Author

NicolasDorier commented Jun 6, 2019

@yaraaer I ended up have a marker file file "bitcoind_fully_synched" that some middleware of mine is generating, and the script starting lightningd just sleeping until it sees this file before starting lightningd.

Hack, but never got any problem since then.

@darosior
Copy link
Collaborator

darosior commented Nov 4, 2019

I think this is now handled correctly ?

@rustyrussell
Copy link
Contributor

Nope, just got a report from Javier on Telegram. He ran bitcoind -reindex and it found corruption. lightningd started syncing from block 119,000 or so! Presumably he started it up before bitcoind was finished.

@rustyrussell rustyrussell self-assigned this Nov 5, 2019
@rustyrussell rustyrussell added this to the 0.7.4 milestone Nov 5, 2019
@JavierRSobrino
Copy link

Right, that was what happened to me today.

Nope, just got a report from Javier on Telegram. He ran bitcoind -reindex and it found corruption. lightningd started syncing from block 119,000 or so! Presumably he started it up before bitcoind was finished.

@cdecker cdecker modified the milestones: 0.7.4, next Dec 11, 2019
@cdecker
Copy link
Member

cdecker commented Jan 13, 2020

This was fixed in faded9a, and I verified that lightningd refuses to start with the following test:

def test_ibd(node_factory):
    l1 = node_factory.get_node(start=False)

    mock_getblockchaininfo = {
        "chain": "regtest",
        "blocks": 1000,
        "headers": 2000,
        "initialblockdownload": True,
    }

    l1.daemon.rpcproxy.mock_rpc('getblockchaininfo', mock_getblockchaininfo)
    l1.start()

@cdecker cdecker closed this as completed Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants