multi: add bool param to channel enable/disable methods

Add a new boolean parameter without changing any existing
functionality. The parameter will be used to indicate
whether a request to update a channel's status was made
manually by a user (currently always false).
This commit is contained in:
Elliott Jin 2021-02-15 21:13:50 -08:00
parent db23e34f74
commit e9baf0e4a2
4 changed files with 31 additions and 15 deletions

@ -223,16 +223,20 @@ func (m *ChanStatusManager) Stop() error {
// channel's peer has lasted at least the ChanEnableTimeout. Failure to do so // channel's peer has lasted at least the ChanEnableTimeout. Failure to do so
// may result in behavior that deviates from the expected behavior of the state // may result in behavior that deviates from the expected behavior of the state
// machine. // machine.
func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint) error { func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint,
return m.submitRequest(m.enableRequests, outpoint) manual bool) error {
return m.submitRequest(m.enableRequests, outpoint, manual)
} }
// RequestDisable submits a request to immediately disable a channel identified // RequestDisable submits a request to immediately disable a channel identified
// by the provided outpoint. If the channel is already disabled, no action will // by the provided outpoint. If the channel is already disabled, no action will
// be taken. Otherwise, a new announcement will be signed with the disabled bit // be taken. Otherwise, a new announcement will be signed with the disabled bit
// set and broadcast to the network. // set and broadcast to the network.
func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint) error { func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint,
return m.submitRequest(m.disableRequests, outpoint) manual bool) error {
return m.submitRequest(m.disableRequests, outpoint, manual)
} }
// statusRequest is passed to the statusManager to request a change in status // statusRequest is passed to the statusManager to request a change in status
@ -240,6 +244,7 @@ func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint) error {
// request through one of the enableRequests or disableRequests channels. // request through one of the enableRequests or disableRequests channels.
type statusRequest struct { type statusRequest struct {
outpoint wire.OutPoint outpoint wire.OutPoint
manual bool
errChan chan error errChan chan error
} }
@ -248,10 +253,11 @@ type statusRequest struct {
// reqChan passed in, which can be either of the enableRequests or // reqChan passed in, which can be either of the enableRequests or
// disableRequests channels. // disableRequests channels.
func (m *ChanStatusManager) submitRequest(reqChan chan statusRequest, func (m *ChanStatusManager) submitRequest(reqChan chan statusRequest,
outpoint wire.OutPoint) error { outpoint wire.OutPoint, manual bool) error {
req := statusRequest{ req := statusRequest{
outpoint: outpoint, outpoint: outpoint,
manual: manual,
errChan: make(chan error, 1), errChan: make(chan error, 1),
} }
@ -285,11 +291,11 @@ func (m *ChanStatusManager) statusManager() {
// Process any requests to mark channel as enabled. // Process any requests to mark channel as enabled.
case req := <-m.enableRequests: case req := <-m.enableRequests:
req.errChan <- m.processEnableRequest(req.outpoint) req.errChan <- m.processEnableRequest(req.outpoint, req.manual)
// Process any requests to mark channel as disabled. // Process any requests to mark channel as disabled.
case req := <-m.disableRequests: case req := <-m.disableRequests:
req.errChan <- m.processDisableRequest(req.outpoint) req.errChan <- m.processDisableRequest(req.outpoint, req.manual)
// Use long-polling to detect when channels become inactive. // Use long-polling to detect when channels become inactive.
case <-m.statusSampleTicker.C: case <-m.statusSampleTicker.C:
@ -317,7 +323,9 @@ func (m *ChanStatusManager) statusManager() {
// ErrEnableInactiveChan will be returned. An update will be broadcast only if // ErrEnableInactiveChan will be returned. An update will be broadcast only if
// the channel is currently disabled, otherwise no update will be sent on the // the channel is currently disabled, otherwise no update will be sent on the
// network. // network.
func (m *ChanStatusManager) processEnableRequest(outpoint wire.OutPoint) error { func (m *ChanStatusManager) processEnableRequest(outpoint wire.OutPoint,
manual bool) error {
curState, err := m.getOrInitChanStatus(outpoint) curState, err := m.getOrInitChanStatus(outpoint)
if err != nil { if err != nil {
return err return err
@ -362,7 +370,9 @@ func (m *ChanStatusManager) processEnableRequest(outpoint wire.OutPoint) error {
// ChanStatusDisabled. An update will only be sent if the channel has a status // ChanStatusDisabled. An update will only be sent if the channel has a status
// other than ChanStatusEnabled, otherwise no update will be sent on the // other than ChanStatusEnabled, otherwise no update will be sent on the
// network. // network.
func (m *ChanStatusManager) processDisableRequest(outpoint wire.OutPoint) error { func (m *ChanStatusManager) processDisableRequest(outpoint wire.OutPoint,
manual bool) error {
curState, err := m.getOrInitChanStatus(outpoint) curState, err := m.getOrInitChanStatus(outpoint)
if err != nil { if err != nil {
return err return err

@ -428,7 +428,7 @@ func (h *testHarness) assertDisables(channels []*channeldb.OpenChannel, expErr e
func (h *testHarness) assertEnable(outpoint wire.OutPoint, expErr error) { func (h *testHarness) assertEnable(outpoint wire.OutPoint, expErr error) {
h.t.Helper() h.t.Helper()
err := h.mgr.RequestEnable(outpoint) err := h.mgr.RequestEnable(outpoint, false)
if err != expErr { if err != expErr {
h.t.Fatalf("expected enable error: %v, got %v", expErr, err) h.t.Fatalf("expected enable error: %v, got %v", expErr, err)
} }
@ -439,7 +439,7 @@ func (h *testHarness) assertEnable(outpoint wire.OutPoint, expErr error) {
func (h *testHarness) assertDisable(outpoint wire.OutPoint, expErr error) { func (h *testHarness) assertDisable(outpoint wire.OutPoint, expErr error) {
h.t.Helper() h.t.Helper()
err := h.mgr.RequestDisable(outpoint) err := h.mgr.RequestDisable(outpoint, false)
if err != expErr { if err != expErr {
h.t.Fatalf("expected disable error: %v, got %v", expErr, err) h.t.Fatalf("expected disable error: %v, got %v", expErr, err)
} }

@ -2285,7 +2285,7 @@ func (p *Brontide) reenableActiveChannels() {
// disabled bit to false and send out a new ChannelUpdate. If this // disabled bit to false and send out a new ChannelUpdate. If this
// channel is already active, the update won't be sent. // channel is already active, the update won't be sent.
for _, chanPoint := range activePublicChans { for _, chanPoint := range activePublicChans {
err := p.cfg.ChanStatusMgr.RequestEnable(chanPoint) err := p.cfg.ChanStatusMgr.RequestEnable(chanPoint, false)
if err != nil { if err != nil {
peerLog.Errorf("Unable to enable channel %v: %v", peerLog.Errorf("Unable to enable channel %v: %v",
chanPoint, err) chanPoint, err)
@ -2360,7 +2360,9 @@ func (p *Brontide) fetchActiveChanCloser(chanID lnwire.ChannelID) (
Channel: channel, Channel: channel,
UnregisterChannel: p.cfg.Switch.RemoveLink, UnregisterChannel: p.cfg.Switch.RemoveLink,
BroadcastTx: p.cfg.Wallet.PublishTransaction, BroadcastTx: p.cfg.Wallet.PublishTransaction,
DisableChannel: p.cfg.ChanStatusMgr.RequestDisable, DisableChannel: func(chanPoint wire.OutPoint) error {
return p.cfg.ChanStatusMgr.RequestDisable(chanPoint, false)
},
Disconnect: func() error { Disconnect: func() error {
return p.cfg.DisconnectPeer(p.IdentityKey()) return p.cfg.DisconnectPeer(p.IdentityKey())
}, },
@ -2476,7 +2478,9 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
Channel: channel, Channel: channel,
UnregisterChannel: p.cfg.Switch.RemoveLink, UnregisterChannel: p.cfg.Switch.RemoveLink,
BroadcastTx: p.cfg.Wallet.PublishTransaction, BroadcastTx: p.cfg.Wallet.PublishTransaction,
DisableChannel: p.cfg.ChanStatusMgr.RequestDisable, DisableChannel: func(chanPoint wire.OutPoint) error {
return p.cfg.ChanStatusMgr.RequestDisable(chanPoint, false)
},
Disconnect: func() error { Disconnect: func() error {
return p.cfg.DisconnectPeer(p.IdentityKey()) return p.cfg.DisconnectPeer(p.IdentityKey())
}, },

@ -965,7 +965,9 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
return ErrServerShuttingDown return ErrServerShuttingDown
} }
}, },
DisableChannel: s.chanStatusMgr.RequestDisable, DisableChannel: func(chanPoint wire.OutPoint) error {
return s.chanStatusMgr.RequestDisable(chanPoint, false)
},
Sweeper: s.sweeper, Sweeper: s.sweeper,
Registry: s.invoices, Registry: s.invoices,
NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent, NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent,