From 111c9b05f338abbcc029ee478fe298611597118d Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Fri, 9 Aug 2024 20:33:34 -0700 Subject: [PATCH] htlcswitch+peer: allow the disabling of quiescence Here we add a flag where we can disable quiescence. This will be used in the case where the feature is not negotiated with our peer. --- feature/default_sets.go | 4 ++++ feature/manager.go | 6 ++++++ htlcswitch/link.go | 27 ++++++++++++++++++--------- lncfg/protocol.go | 5 +++++ lncfg/protocol_integration.go | 8 ++++++++ peer/brontide.go | 6 ++++++ server.go | 2 ++ 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/feature/default_sets.go b/feature/default_sets.go index 616abc8ba3..9aee982ca7 100644 --- a/feature/default_sets.go +++ b/feature/default_sets.go @@ -84,6 +84,10 @@ var defaultSetDesc = setDesc{ SetNodeAnn: {}, // N SetInvoice: {}, // 9 }, + lnwire.QuiescenceOptional: { + SetInit: {}, // I + SetNodeAnn: {}, // N + }, lnwire.ShutdownAnySegwitOptional: { SetInit: {}, // I SetNodeAnn: {}, // N diff --git a/feature/manager.go b/feature/manager.go index e0bcfc96bb..9538832163 100644 --- a/feature/manager.go +++ b/feature/manager.go @@ -63,6 +63,9 @@ type Config struct { // NoRouteBlinding unsets route blinding feature bits. NoRouteBlinding bool + // NoQuiescence unsets quiescence feature bits. + NoQuiescence bool + // NoTaprootOverlay unsets the taproot overlay channel feature bits. NoTaprootOverlay bool @@ -199,6 +202,9 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) { raw.Unset(lnwire.Bolt11BlindedPathsOptional) raw.Unset(lnwire.Bolt11BlindedPathsRequired) } + if cfg.NoQuiescence { + raw.Unset(lnwire.QuiescenceOptional) + } if cfg.NoTaprootOverlay { raw.Unset(lnwire.SimpleTaprootOverlayChansOptional) raw.Unset(lnwire.SimpleTaprootOverlayChansRequired) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 980f4dcb6d..d2d8802a3d 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -283,6 +283,10 @@ type ChannelLinkConfig struct { // invalid. DisallowRouteBlinding bool + // DisallowQuiescence is a flag that can be used to disable the + // quiescence protocol. + DisallowQuiescence bool + // MaxFeeExposure is the threshold in milli-satoshis after which we'll // restrict the flow of HTLCs and fee updates. MaxFeeExposure lnwire.MilliSatoshi @@ -476,14 +480,19 @@ func NewChannelLink(cfg ChannelLinkConfig, cfg.MaxFeeExposure = DefaultMaxFeeExposure } - quiescerCfg := QuiescerCfg{ - chanID: lnwire.NewChanIDFromOutPoint( - channel.ChannelPoint(), - ), - channelInitiator: channel.Initiator(), - sendMsg: func(s lnwire.Stfu) error { - return cfg.Peer.SendMessage(false, &s) - }, + var qsm Quiescer + if !cfg.DisallowQuiescence { + qsm = NewQuiescer(QuiescerCfg{ + chanID: lnwire.NewChanIDFromOutPoint( + channel.ChannelPoint(), + ), + channelInitiator: channel.Initiator(), + sendMsg: func(s lnwire.Stfu) error { + return cfg.Peer.SendMessage(false, &s) + }, + }) + } else { + qsm = &quiescerNoop{} } quiescenceReqs := make( @@ -499,7 +508,7 @@ func NewChannelLink(cfg ChannelLinkConfig, flushHooks: newHookMap(), outgoingCommitHooks: newHookMap(), incomingCommitHooks: newHookMap(), - quiescer: NewQuiescer(quiescerCfg), + quiescer: qsm, quiescenceReqs: quiescenceReqs, ContextGuard: fn.NewContextGuard(), } diff --git a/lncfg/protocol.go b/lncfg/protocol.go index 80809f49d6..5852d032e0 100644 --- a/lncfg/protocol.go +++ b/lncfg/protocol.go @@ -141,6 +141,11 @@ func (l *ProtocolOptions) NoExperimentalEndorsement() bool { return l.NoExperimentalEndorsementOption } +// NoQuiescence returns true if quiescence is disabled. +func (l *ProtocolOptions) NoQuiescence() bool { + return true +} + // CustomMessageOverrides returns the set of protocol messages that we override // to allow custom handling. func (p ProtocolOptions) CustomMessageOverrides() []uint16 { diff --git a/lncfg/protocol_integration.go b/lncfg/protocol_integration.go index 52cc658c3b..e9f32d9dfb 100644 --- a/lncfg/protocol_integration.go +++ b/lncfg/protocol_integration.go @@ -73,6 +73,9 @@ type ProtocolOptions struct { // NoExperimentalEndorsementOption disables experimental endorsement. NoExperimentalEndorsementOption bool `long:"no-experimental-endorsement" description:"do not forward experimental endorsement signals"` + // NoQuiescenceOption disables quiescence for all channels. + NoQuiescenceOption bool `long:"no-quiescence" description:"do not allow or advertise quiescence for any channel"` + // CustomMessage allows the custom message APIs to handle messages with // the provided protocol numbers, which fall outside the custom message // number range. @@ -136,6 +139,11 @@ func (l *ProtocolOptions) NoExperimentalEndorsement() bool { return l.NoExperimentalEndorsementOption } +// NoQuiescence returns true if quiescence is disabled. +func (l *ProtocolOptions) NoQuiescence() bool { + return l.NoQuiescenceOption +} + // CustomMessageOverrides returns the set of protocol messages that we override // to allow custom handling. func (l ProtocolOptions) CustomMessageOverrides() []uint16 { diff --git a/peer/brontide.go b/peer/brontide.go index 17bef3234e..3bae1be1bc 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -411,6 +411,10 @@ type Config struct { // invalid. DisallowRouteBlinding bool + // DisallowQuiescence is a flag that indicates whether the Brontide + // should have the quiescence feature disabled. + DisallowQuiescence bool + // MaxFeeExposure limits the number of outstanding fees in a channel. // This value will be passed to created links. MaxFeeExposure lnwire.MilliSatoshi @@ -1324,6 +1328,8 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, DisallowRouteBlinding: p.cfg.DisallowRouteBlinding, MaxFeeExposure: p.cfg.MaxFeeExposure, ShouldFwdExpEndorsement: p.cfg.ShouldFwdExpEndorsement, + DisallowQuiescence: p.cfg.DisallowQuiescence || + !p.remoteFeatures.HasFeature(lnwire.QuiescenceOptional), } // Before adding our new link, purge the switch of any pending or live diff --git a/server.go b/server.go index 3b8224f5b0..c186d36560 100644 --- a/server.go +++ b/server.go @@ -587,6 +587,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, NoTaprootOverlay: !cfg.ProtocolOptions.TaprootOverlayChans, NoRouteBlinding: cfg.ProtocolOptions.NoRouteBlinding(), NoExperimentalEndorsement: cfg.ProtocolOptions.NoExperimentalEndorsement(), + NoQuiescence: cfg.ProtocolOptions.NoQuiescence(), }) if err != nil { return nil, err @@ -4214,6 +4215,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, RequestAlias: s.aliasMgr.RequestAlias, AddLocalAlias: s.aliasMgr.AddLocalAlias, DisallowRouteBlinding: s.cfg.ProtocolOptions.NoRouteBlinding(), + DisallowQuiescence: s.cfg.ProtocolOptions.NoQuiescence(), MaxFeeExposure: thresholdMSats, Quit: s.quit, AuxLeafStore: s.implCfg.AuxLeafStore,