mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
lnd: require blocks to be synced in regtest/simnet
This commit is contained in:
92
lnd.go
92
lnd.go
@@ -915,56 +915,52 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not in regtest or simnet mode, We'll wait until we're fully
|
// We'll wait until we're fully synced to continue the start up of the
|
||||||
// synced to continue the start up of the remainder of the daemon. This
|
// remainder of the daemon. This ensures that we don't accept any
|
||||||
// ensures that we don't accept any possibly invalid state transitions, or
|
// possibly invalid state transitions, or accept channels with spent
|
||||||
// accept channels with spent funds.
|
// funds.
|
||||||
if !(cfg.Bitcoin.RegTest || cfg.Bitcoin.SimNet ||
|
_, bestHeight, err := activeChainControl.ChainIO.GetBestBlock()
|
||||||
cfg.Litecoin.RegTest || cfg.Litecoin.SimNet) {
|
if err != nil {
|
||||||
|
err := fmt.Errorf("unable to determine chain tip: %v",
|
||||||
_, bestHeight, err := activeChainControl.ChainIO.GetBestBlock()
|
err)
|
||||||
if err != nil {
|
ltndLog.Error(err)
|
||||||
err := fmt.Errorf("unable to determine chain tip: %v",
|
return err
|
||||||
err)
|
|
||||||
ltndLog.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
|
||||||
"start_height=%v", bestHeight)
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !interceptor.Alive() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
synced, _, err := activeChainControl.Wallet.IsSynced()
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("unable to determine if "+
|
|
||||||
"wallet is synced: %v", err)
|
|
||||||
ltndLog.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if synced {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, bestHeight, err = activeChainControl.ChainIO.GetBestBlock()
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("unable to determine chain tip: %v",
|
|
||||||
err)
|
|
||||||
ltndLog.Error(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ltndLog.Infof("Chain backend is fully synced (end_height=%v)!",
|
|
||||||
bestHeight)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ltndLog.Infof("Waiting for chain backend to finish sync, "+
|
||||||
|
"start_height=%v", bestHeight)
|
||||||
|
|
||||||
|
for {
|
||||||
|
if !interceptor.Alive() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
synced, _, err := activeChainControl.Wallet.IsSynced()
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("unable to determine if "+
|
||||||
|
"wallet is synced: %v", err)
|
||||||
|
ltndLog.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if synced {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, bestHeight, err = activeChainControl.ChainIO.GetBestBlock()
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("unable to determine chain tip: %v",
|
||||||
|
err)
|
||||||
|
ltndLog.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ltndLog.Infof("Chain backend is fully synced (end_height=%v)!",
|
||||||
|
bestHeight)
|
||||||
|
|
||||||
// With all the relevant chains initialized, we can finally start the
|
// With all the relevant chains initialized, we can finally start the
|
||||||
// server itself.
|
// server itself.
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
|
Reference in New Issue
Block a user