netann: add RequestAuto for restoring auto chan state management

If a channel was manually disabled, subsequent automatic / background
requests to update that channel's state will be ignored. A RequestAuto
call restores automatic / background state management and indicates
that such requests should no longer be ignored.
This commit is contained in:
Elliott Jin 2021-02-16 09:42:37 -08:00
parent e1709f20eb
commit 59bd617c97

@ -111,6 +111,10 @@ type ChanStatusManager struct {
// primary event loop.
disableRequests chan statusRequest
// autoRequests pipes external requests to restore automatic channel
// state management into the primary event loop.
autoRequests chan statusRequest
// statusSampleTicker fires at the interval prescribed by
// ChanStatusSampleInterval to check if channels in chanStates have
// become inactive.
@ -154,6 +158,7 @@ func NewChanStatusManager(cfg *ChanStatusConfig) (*ChanStatusManager, error) {
statusSampleTicker: time.NewTicker(cfg.ChanStatusSampleInterval),
enableRequests: make(chan statusRequest),
disableRequests: make(chan statusRequest),
autoRequests: make(chan statusRequest),
quit: make(chan struct{}),
}, nil
}
@ -263,6 +268,13 @@ func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint,
return m.submitRequest(m.disableRequests, outpoint, manual)
}
// RequestAuto submits a request to restore automatic channel state management.
// If the channel is in the state ChanStatusManuallyDisabled, it will be moved
// back to the state ChanStatusDisabled. Otherwise, no action will be taken.
func (m *ChanStatusManager) RequestAuto(outpoint wire.OutPoint) error {
return m.submitRequest(m.autoRequests, outpoint, true)
}
// statusRequest is passed to the statusManager to request a change in status
// for a particular channel point. The exact action is governed by passing the
// request through one of the enableRequests or disableRequests channels.
@ -321,6 +333,10 @@ func (m *ChanStatusManager) statusManager() {
case req := <-m.disableRequests:
req.errChan <- m.processDisableRequest(req.outpoint, req.manual)
// Process any requests to restore automatic channel state management.
case req := <-m.autoRequests:
req.errChan <- m.processAutoRequest(req.outpoint)
// Use long-polling to detect when channels become inactive.
case <-m.statusSampleTicker.C:
// First, do a sweep and mark any ChanStatusEnabled
@ -444,6 +460,27 @@ func (m *ChanStatusManager) processDisableRequest(outpoint wire.OutPoint,
return nil
}
// processAutoRequest attempts to restore automatic channel state management
// for the given outpoint. If the method returns nil, the state of the channel
// will no longer be ChanStatusManuallyDisabled (currently the only state in
// which automatic / background requests are ignored).
//
// No update will be sent on the network.
func (m *ChanStatusManager) processAutoRequest(outpoint wire.OutPoint) error {
curState, err := m.getOrInitChanStatus(outpoint)
if err != nil {
return err
}
if curState.Status == ChanStatusManuallyDisabled {
log.Debugf("Restoring automatic control for manually disabled "+
"channel(%v)", outpoint)
m.chanStates.markDisabled(outpoint)
}
return nil
}
// markPendingInactiveChannels performs a sweep of the database's active
// channels and determines which, if any, should have a disable announcement
// scheduled. Once an active channel is determined to be pending-inactive, one