From 3f2d4f108d81221bc51de6628616a10db7c8062c Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 25 May 2021 09:45:48 +0200 Subject: [PATCH] rpcserver: check router state only if it is validating Fixes #5325. Corrects a problem introduced in #5281 that caused the synced_to_chain flag in the GetInfo call to never become true when the router subsystem is running in Neutrino mode (channel validation turned off). --- rpcserver.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 114ccb11..9c6d182f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2470,8 +2470,8 @@ func (r *rpcServer) AbandonChannel(_ context.Context, // GetInfo returns general information concerning the lightning node including // its identity pubkey, alias, the chains it is connected to, and information // concerning the number of open+pending channels. -func (r *rpcServer) GetInfo(ctx context.Context, - in *lnrpc.GetInfoRequest) (*lnrpc.GetInfoResponse, error) { +func (r *rpcServer) GetInfo(_ context.Context, + _ *lnrpc.GetInfoRequest) (*lnrpc.GetInfoResponse, error) { serverPeers := r.server.Peers() @@ -2511,16 +2511,18 @@ func (r *rpcServer) GetInfo(ctx context.Context, "with current best block in the main chain: %v", err) } - // The router has a lot of work to do for each block. So it might be - // possible that it isn't yet up to date with the most recent block, - // even if the wallet is. This can happen in environments with high CPU - // load (such as parallel itests). Since the `synced_to_chain` flag in - // the response of this call is used by many wallets (and also our - // itests) to make sure everything's up to date, we add the router's - // state to it. So the flag will only toggle to true once the router was - // also able to catch up. - routerHeight := r.server.chanRouter.SyncedHeight() - isSynced = isSynced && uint32(bestHeight) == routerHeight + // If the router does full channel validation, it has a lot of work to + // do for each block. So it might be possible that it isn't yet up to + // date with the most recent block, even if the wallet is. This can + // happen in environments with high CPU load (such as parallel itests). + // Since the `synced_to_chain` flag in the response of this call is used + // by many wallets (and also our itests) to make sure everything's up to + // date, we add the router's state to it. So the flag will only toggle + // to true once the router was also able to catch up. + if !r.cfg.Routing.AssumeChannelValid { + routerHeight := r.server.chanRouter.SyncedHeight() + isSynced = isSynced && uint32(bestHeight) == routerHeight + } network := lncfg.NormalizeNetwork(r.cfg.ActiveNetParams.Name) activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains()) @@ -2529,7 +2531,6 @@ func (r *rpcServer) GetInfo(ctx context.Context, Chain: chain.String(), Network: network, } - } // Check if external IP addresses were provided to lnd and use them