ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.87k stars 906 forks source link

CLN fails to sync with regtest node #5811

Closed evd0kim closed 1 year ago

evd0kim commented 1 year ago

Issue and Steps to Reproduce

Issue first appeared as part of building integration tests in Rust.

After that it was confirmed via running regular regtest setup locally.

While bitcoind shows "verificationprogress":1,"initialblockdownload":false, CLN remains in Still waiting for initial block download state indefinitely.

CLN script:

#!/bin/sh

lightningd  --lightning-dir=/tmp/hexstody-ln \
            --funding-confirms=1 \
            --dev-force-privkey=0000000000000000000000000000000000000000000000000000000000000001 \
            --dev-force-bip32-seed=0000000000000000000000000000000000000000000000000000000000000001 \
            --dev-force-channel-secrets=0000000000000000000000000000000000000000000000000000000000000010/0000000000000000000000000000000000000000000000000000000000000011/0000000000000000000000000000000000000000000000000000000000000012/0000000000000000000000000000000000000000000000000000000000000013/0000000000000000000000000000000000000000000000000000000000000014/FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF \
            --dev-bitcoind-poll=1 \
            --dev-fast-gossip \
            --dev-no-htlc-timeout \
            --bind-addr=127.0.0.1:9807 \
            --network=regtest \
            --bitcoin-rpcuser=regtest \
            --bitcoin-rpcpassword=regtest \
            --bitcoin-rpcport=9806 \
            --log-level=debug \
            --log-file=log \
            --htlc-maximum-msat=2000sat \
            --disable-plugin=offers \
            --disable-plugin=fetchinvoice \
            --disable-plugin=commando

Bitcoind setup:

bitcoind -txindex -regtest -fallbackfee=0.0001 -rpcuser=regtest -rpcpassword=regtest -rpcport=9806

getinfo output

{ id: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", alias: "SILENTSPAWN-v0.12.1", color: "0279be", num_peers: 0, num_pending_channels: 0, num_active_channels: 0, num_inactive_channels: 0, address: [], binding: [Ipv4 { address: 127.0.0.1, port: 35105 }, Ipv4 { address: 127.0.0.1, port: 45259 }], version: "v0.12.1", blockheight: 0, fees_collected_msat: 0msat, network: "regtest", ligthning_dir: "/tmp/cln-regtest-data.OmMDOyeawCUM/regtest", warning_bitcoind_sync: Some("Bitcoind is not up-to-date with network."), warning_lightningd_sync: None }

getblockchaininfo output

{"chain":"regtest","blocks":101,"headers":101,"bestblockhash":"19f78422d5e383949269529f8d2654ecb5d6d7d3038df6bec74d2877e44baa16","difficulty":4.656542373906925e-10,"mediantime":1670849133,"verificationprogress":1,"initialblockdownload":false,"chainwork":"00000000000000000000000000000000000000000000000000000000000000cc","size_on_disk":30476,"pruned":false,"softforks":{"bip34":{"type":"buried","active":false,"height":500},"bip66":{"type":"buried","active":false,"height":1251},"bip65":{"type":"buried","active":false,"height":1351},"csv":{"type":"buried","active":false,"height":432},"segwit":{"type":"buried","active":true,"height":0},"testdummy":{"type":"bip9","bip9":{"status":"defined","start_time":0,"timeout":9223372036854775807,"since":0,"min_activation_height":0},"active":false},"taproot":{"type":"bip9","bip9":{"status":"active","start_time":-1,"timeout":9223372036854775807,"since":0,"min_activation_height":0},"height":0,"active":true}},"warnings":""}
evd0kim commented 1 year ago

bitcoin-cli -regtest -generate 1 pushes CLN into right direction, it syncs.

The fun part is that after generating one more block, CLN syncs with bitcoind even after restart of both CLN and bitcoind.

evd0kim commented 1 year ago

In my particular case the problem was due to asyncronous environment and too fast requests to CLN. It needed something like 10 seconds to discover 200 blocks.

So putting sleep in right place solved the problem.

cdecker commented 1 year ago

What we usually do is poll getinfo to wait for the sync to complete, just having a fixed sleep will result in very flaky tests, because the time to sync depends on load on the machine, and various internal timeouts.

evd0kim commented 1 year ago

@cdecker thanks for response. Yes. I've put getinfo pooling into the test. Actually I've made it like general function for whole toy network so it tracks all CLN clients and main BTC regtest node and looks after CLNs so they aren't out of sync.