Merge pull request #5364 from guggero/prevent-stop-on-rescan

rpcserver: prevent shutdown during wallet recovery
This commit is contained in:
Olaoluwa Osuntokun 2021-06-18 14:11:30 -07:00 committed by GitHub
commit 9362f5d279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5535,8 +5535,24 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
// StopDaemon will send a shutdown request to the interrupt handler, triggering
// a graceful shutdown of the daemon.
func (r *rpcServer) StopDaemon(ctx context.Context,
func (r *rpcServer) StopDaemon(_ context.Context,
_ *lnrpc.StopRequest) (*lnrpc.StopResponse, error) {
// Before we even consider a shutdown, are we currently in recovery
// mode? We don't want to allow shutting down during recovery because
// that would mean the user would have to manually continue the rescan
// process next time by using `lncli unlock --recovery_window X`
// otherwise some funds wouldn't be picked up.
isRecoveryMode, progress, err := r.server.cc.Wallet.GetRecoveryInfo()
if err != nil {
return nil, fmt.Errorf("unable to get wallet recovery info: %v",
err)
}
if isRecoveryMode && progress < 1 {
return nil, fmt.Errorf("wallet recovery in progress, cannot " +
"shut down, please wait until rescan finishes")
}
r.interceptor.RequestShutdown()
return &lnrpc.StopResponse{}, nil
}