Skip to content

Commit 6a82c61

Browse files
authored
Merge pull request #10280 from mohamedawnallah/optimize-neutrino-rescan
rpcserver: resolve root cause of premature wallet rescanning
2 parents 1a30ac2 + f761dc4 commit 6a82c61

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
# Bug Fixes
2222

23+
- [Fixed premature wallet
24+
rescanning](https://github.com/lightningnetwork/lnd/pull/10280) that occurred
25+
when a wallet was created during header sync. This issue primarily affected
26+
neutrino chain backends. The fix ensures headers are fully synced before
27+
starting the chain notifier backend.
28+
2329
- Fixed potential update inconsistencies in node announcements [by creating
2430
a shallow copy before modifications](
2531
https://github.com/lightningnetwork/lnd/pull/9815). This ensures the original

server.go

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -733,17 +733,6 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
733733
quit: make(chan struct{}),
734734
}
735735

736-
// Start the low-level services once they are initialized.
737-
//
738-
// TODO(yy): break the server startup into four steps,
739-
// 1. init the low-level services.
740-
// 2. start the low-level services.
741-
// 3. init the high-level services.
742-
// 4. start the high-level services.
743-
if err := s.startLowLevelServices(); err != nil {
744-
return nil, err
745-
}
746-
747736
currentHash, currentHeight, err := s.cc.ChainIO.GetBestBlock()
748737
if err != nil {
749738
return nil, err
@@ -2125,41 +2114,12 @@ func (c cleaner) run() {
21252114
}
21262115
}
21272116

2128-
// startLowLevelServices starts the low-level services of the server. These
2129-
// services must be started successfully before running the main server. The
2130-
// services are,
2131-
// 1. the chain notifier.
2132-
//
2133-
// TODO(yy): identify and add more low-level services here.
2134-
func (s *server) startLowLevelServices() error {
2135-
var startErr error
2136-
2137-
cleanup := cleaner{}
2138-
2139-
cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
2140-
if err := s.cc.ChainNotifier.Start(); err != nil {
2141-
startErr = err
2142-
}
2143-
2144-
if startErr != nil {
2145-
cleanup.run()
2146-
}
2147-
2148-
return startErr
2149-
}
2150-
21512117
// Start starts the main daemon server, all requested listeners, and any helper
21522118
// goroutines.
21532119
// NOTE: This function is safe for concurrent access.
21542120
//
21552121
//nolint:funlen
21562122
func (s *server) Start(ctx context.Context) error {
2157-
// Get the current blockbeat.
2158-
beat, err := s.getStartingBeat()
2159-
if err != nil {
2160-
return err
2161-
}
2162-
21632123
var startErr error
21642124

21652125
// If one sub system fails to start, the following code ensures that the
@@ -2213,6 +2173,12 @@ func (s *server) Start(ctx context.Context) error {
22132173
return
22142174
}
22152175

2176+
cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
2177+
if err := s.cc.ChainNotifier.Start(); err != nil {
2178+
startErr = err
2179+
return
2180+
}
2181+
22162182
cleanup = cleanup.add(s.cc.BestBlockTracker.Stop)
22172183
if err := s.cc.BestBlockTracker.Start(); err != nil {
22182184
startErr = err
@@ -2247,6 +2213,12 @@ func (s *server) Start(ctx context.Context) error {
22472213
}
22482214
}
22492215

2216+
beat, err := s.getStartingBeat()
2217+
if err != nil {
2218+
startErr = err
2219+
return
2220+
}
2221+
22502222
cleanup = cleanup.add(s.txPublisher.Stop)
22512223
if err := s.txPublisher.Start(beat); err != nil {
22522224
startErr = err

0 commit comments

Comments
 (0)