@@ -152,6 +152,10 @@ type LndServicesConfig struct {
152152 // calls to lnd. If this value is not set, it will default to 30
153153 // seconds.
154154 RPCTimeout time.Duration
155+
156+ // ChainSyncPollInterval is the interval in which we poll the GetInfo
157+ // call to find out if lnd is fully synced to its chain backend.
158+ ChainSyncPollInterval time.Duration
155159}
156160
157161// DialerFunc is a function that is used as grpc.WithContextDialer().
@@ -285,7 +289,8 @@ func NewLndServices(cfg *LndServicesConfig) (*GrpcLndServices, error) {
285289 readonlyMac = serializedMacaroon (cfg .CustomMacaroonHex )
286290 } else {
287291 readonlyMac , err = loadMacaroon (
288- macaroonDir , string (ReadOnlyServiceMac ), cfg .CustomMacaroonPath ,
292+ macaroonDir , string (ReadOnlyServiceMac ),
293+ cfg .CustomMacaroonPath ,
289294 )
290295 if err != nil {
291296 return nil , err
@@ -297,6 +302,10 @@ func NewLndServices(cfg *LndServicesConfig) (*GrpcLndServices, error) {
297302 timeout = cfg .RPCTimeout
298303 }
299304
305+ if cfg .ChainSyncPollInterval == 0 {
306+ cfg .ChainSyncPollInterval = chainSyncPollInterval
307+ }
308+
300309 basicClient := lnrpc .NewLightningClient (conn )
301310 stateClient := newStateClient (conn , readonlyMac )
302311 versionerClient := newVersionerClient (conn , readonlyMac , timeout )
@@ -413,7 +422,9 @@ func NewLndServices(cfg *LndServicesConfig) (*GrpcLndServices, error) {
413422 log .Infof ("Waiting for lnd to be fully synced to its chain " +
414423 "backend, this might take a while" )
415424
416- err := services .waitForChainSync (cfg .CallerCtx , timeout )
425+ err := services .waitForChainSync (
426+ cfg .CallerCtx , timeout , cfg .ChainSyncPollInterval ,
427+ )
417428 if err != nil {
418429 cleanup ()
419430 return nil , fmt .Errorf ("error waiting for chain to " +
@@ -453,7 +464,7 @@ func (s *GrpcLndServices) Close() {
453464// synced to its chain backend. This could theoretically take hours if the
454465// initial block download is still in progress.
455466func (s * GrpcLndServices ) waitForChainSync (ctx context.Context ,
456- timeout time.Duration ) error {
467+ timeout , pollInterval time.Duration ) error {
457468
458469 mainCtx := ctx
459470 if mainCtx == nil {
@@ -488,7 +499,7 @@ func (s *GrpcLndServices) waitForChainSync(ctx context.Context,
488499
489500 select {
490501 // If we're not yet done, let's now wait a few seconds.
491- case <- time .After (chainSyncPollInterval ):
502+ case <- time .After (pollInterval ):
492503
493504 // If the user cancels the context, we should also
494505 // abort the wait.
0 commit comments