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:
parent
db23e34f74
commit
e9baf0e4a2
@ -223,16 +223,20 @@ func (m *ChanStatusManager) Stop() error {
|
||||
// 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
|
||||
// machine.
|
||||
func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint) error {
|
||||
return m.submitRequest(m.enableRequests, outpoint)
|
||||
func (m *ChanStatusManager) RequestEnable(outpoint wire.OutPoint,
|
||||
manual bool) error {
|
||||
|
||||
return m.submitRequest(m.enableRequests, outpoint, manual)
|
||||
}
|
||||
|
||||
// RequestDisable submits a request to immediately disable a channel identified
|
||||
// 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
|
||||
// set and broadcast to the network.
|
||||
func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint) error {
|
||||
return m.submitRequest(m.disableRequests, outpoint)
|
||||
func (m *ChanStatusManager) RequestDisable(outpoint wire.OutPoint,
|
||||
manual bool) error {
|
||||
|
||||
return m.submitRequest(m.disableRequests, outpoint, manual)
|
||||
}
|
||||
|
||||
// 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.
|
||||
type statusRequest struct {
|
||||
outpoint wire.OutPoint
|
||||
manual bool
|
||||
errChan chan error
|
||||
}
|
||||
|
||||
@ -248,10 +253,11 @@ type statusRequest struct {
|
||||
// reqChan passed in, which can be either of the enableRequests or
|
||||
// disableRequests channels.
|
||||
func (m *ChanStatusManager) submitRequest(reqChan chan statusRequest,
|
||||
outpoint wire.OutPoint) error {
|
||||
outpoint wire.OutPoint, manual bool) error {
|
||||
|
||||
req := statusRequest{
|
||||
outpoint: outpoint,
|
||||
manual: manual,
|
||||
errChan: make(chan error, 1),
|
||||
}
|
||||
|
||||
@ -285,11 +291,11 @@ func (m *ChanStatusManager) statusManager() {
|
||||
|
||||
// Process any requests to mark channel as enabled.
|
||||
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.
|
||||
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.
|
||||
case <-m.statusSampleTicker.C:
|
||||
@ -317,7 +323,9 @@ func (m *ChanStatusManager) statusManager() {
|
||||
// ErrEnableInactiveChan will be returned. An update will be broadcast only if
|
||||
// the channel is currently disabled, otherwise no update will be sent on the
|
||||
// network.
|
||||
func (m *ChanStatusManager) processEnableRequest(outpoint wire.OutPoint) error {
|
||||
func (m *ChanStatusManager) processEnableRequest(outpoint wire.OutPoint,
|
||||
manual bool) error {
|
||||
|
||||
curState, err := m.getOrInitChanStatus(outpoint)
|
||||
if err != nil {
|
||||
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
|
||||
// other than ChanStatusEnabled, otherwise no update will be sent on the
|
||||
// network.
|
||||
func (m *ChanStatusManager) processDisableRequest(outpoint wire.OutPoint) error {
|
||||
func (m *ChanStatusManager) processDisableRequest(outpoint wire.OutPoint,
|
||||
manual bool) error {
|
||||
|
||||
curState, err := m.getOrInitChanStatus(outpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -428,7 +428,7 @@ func (h *testHarness) assertDisables(channels []*channeldb.OpenChannel, expErr e
|
||||
func (h *testHarness) assertEnable(outpoint wire.OutPoint, expErr error) {
|
||||
h.t.Helper()
|
||||
|
||||
err := h.mgr.RequestEnable(outpoint)
|
||||
err := h.mgr.RequestEnable(outpoint, false)
|
||||
if err != expErr {
|
||||
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) {
|
||||
h.t.Helper()
|
||||
|
||||
err := h.mgr.RequestDisable(outpoint)
|
||||
err := h.mgr.RequestDisable(outpoint, false)
|
||||
if err != expErr {
|
||||
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
|
||||
// channel is already active, the update won't be sent.
|
||||
for _, chanPoint := range activePublicChans {
|
||||
err := p.cfg.ChanStatusMgr.RequestEnable(chanPoint)
|
||||
err := p.cfg.ChanStatusMgr.RequestEnable(chanPoint, false)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Unable to enable channel %v: %v",
|
||||
chanPoint, err)
|
||||
@ -2360,7 +2360,9 @@ func (p *Brontide) fetchActiveChanCloser(chanID lnwire.ChannelID) (
|
||||
Channel: channel,
|
||||
UnregisterChannel: p.cfg.Switch.RemoveLink,
|
||||
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 {
|
||||
return p.cfg.DisconnectPeer(p.IdentityKey())
|
||||
},
|
||||
@ -2476,7 +2478,9 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
|
||||
Channel: channel,
|
||||
UnregisterChannel: p.cfg.Switch.RemoveLink,
|
||||
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 {
|
||||
return p.cfg.DisconnectPeer(p.IdentityKey())
|
||||
},
|
||||
|
@ -965,7 +965,9 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
return ErrServerShuttingDown
|
||||
}
|
||||
},
|
||||
DisableChannel: s.chanStatusMgr.RequestDisable,
|
||||
DisableChannel: func(chanPoint wire.OutPoint) error {
|
||||
return s.chanStatusMgr.RequestDisable(chanPoint, false)
|
||||
},
|
||||
Sweeper: s.sweeper,
|
||||
Registry: s.invoices,
|
||||
NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent,
|
||||
|
Loading…
Reference in New Issue
Block a user