From 59bd617c976576df28a984ea06b0008f1010e17b Mon Sep 17 00:00:00 2001 From: Elliott Jin Date: Tue, 16 Feb 2021 09:42:37 -0800 Subject: [PATCH] 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. --- netann/chan_status_manager.go | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/netann/chan_status_manager.go b/netann/chan_status_manager.go index 1f67feb9..b0188625 100644 --- a/netann/chan_status_manager.go +++ b/netann/chan_status_manager.go @@ -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