multi: add new method ChainArbitrator.RedispatchBlockbeat
This commit adds a new method to enable us resending the blockbeat in `ChainArbitrator`, which is needed for the channel restore as the chain watcher and channel arbitrator are added after the start of the chain arbitrator.
This commit is contained in:
2 files changed
+52
-1
No files matched your search
@@ -1371,3 +1371,43 @@ func (c *ChainArbitrator) loadPendingCloseChannels() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RedispatchBlockbeat resends the current blockbeat to the channels specified
|
||||
// by the chanPoints. It is used when a channel is added to the chain
|
||||
// arbitrator after it has been started, e.g., during the channel restore
|
||||
// process.
|
||||
func (c *ChainArbitrator) RedispatchBlockbeat(chanPoints []wire.OutPoint) {
|
||||
// Get the current blockbeat.
|
||||
beat := c.beat
|
||||
|
||||
// Prepare two sets of consumers.
|
||||
channels := make([]chainio.Consumer, 0, len(chanPoints))
|
||||
watchers := make([]chainio.Consumer, 0, len(chanPoints))
|
||||
|
||||
// Read the active channels in a lock.
|
||||
c.Lock()
|
||||
for _, op := range chanPoints {
|
||||
if channel, ok := c.activeChannels[op]; ok {
|
||||
channels = append(channels, channel)
|
||||
}
|
||||
|
||||
if watcher, ok := c.activeWatchers[op]; ok {
|
||||
watchers = append(watchers, watcher)
|
||||
}
|
||||
}
|
||||
c.Unlock()
|
||||
|
||||
// Iterate all the copied watchers and send the blockbeat to them.
|
||||
err := chainio.DispatchConcurrent(beat, watchers)
|
||||
if err != nil {
|
||||
log.Errorf("Notify blockbeat for chainWatcher failed: %v", err)
|
||||
}
|
||||
|
||||
// Iterate all the copied channels and send the blockbeat to them.
|
||||
err = chainio.DispatchConcurrent(beat, channels)
|
||||
if err != nil {
|
||||
// Shutdown lnd if there's an error processing the block.
|
||||
log.Errorf("Notify blockbeat for ChannelArbitrator failed: %v",
|
||||
err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user