Skip to content

Commit

Permalink
htlcswitch+peer: allow the disabling of quiescence
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ProofOfKeags committed Nov 26, 2024
1 parent 48ee643 commit 111c9b0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
4 changes: 4 additions & 0 deletions feature/default_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ var defaultSetDesc = setDesc{
SetNodeAnn: {}, // N
SetInvoice: {}, // 9
},
lnwire.QuiescenceOptional: {
SetInit: {}, // I
SetNodeAnn: {}, // N
},
lnwire.ShutdownAnySegwitOptional: {
SetInit: {}, // I
SetNodeAnn: {}, // N
Expand Down
6 changes: 6 additions & 0 deletions feature/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
27 changes: 18 additions & 9 deletions htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -499,7 +508,7 @@ func NewChannelLink(cfg ChannelLinkConfig,
flushHooks: newHookMap(),
outgoingCommitHooks: newHookMap(),
incomingCommitHooks: newHookMap(),
quiescer: NewQuiescer(quiescerCfg),
quiescer: qsm,
quiescenceReqs: quiescenceReqs,
ContextGuard: fn.NewContextGuard(),
}
Expand Down
5 changes: 5 additions & 0 deletions lncfg/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions lncfg/protocol_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 111c9b0

Please sign in to comment.