Skip to content

Commit

Permalink
cfg: move experimental options to main protocol cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed May 12, 2024
1 parent 4256260 commit ef3740a
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 87 deletions.
3 changes: 1 addition & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,8 +1667,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,

// If the experimental protocol options specify any protocol messages
// that we want to handle as custom messages, set them now.
//nolint:lll
customMsg := cfg.ProtocolOptions.ExperimentalProtocol.CustomMessageOverrides()
customMsg := cfg.ProtocolOptions.CustomMessageOverrides()

// We can safely set our custom override values during startup because
// startup is blocked on config parsing.
Expand Down
54 changes: 50 additions & 4 deletions lncfg/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

package lncfg

import (
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/lnwire"
)

// ProtocolOptions is a struct that we use to be able to test backwards
// compatibility of protocol additions, while defaulting to the latest within
// lnd, or to enable experimental protocol changes.
Expand All @@ -13,10 +18,6 @@ type ProtocolOptions struct {
// nodes should always run with them on by default.
LegacyProtocol `group:"legacy" namespace:"legacy"`

// ExperimentalProtocol is a sub-config that houses any experimental
// protocol features that also require a build-tag to activate.
ExperimentalProtocol

// WumboChans should be set if we want to enable support for wumbo
// (channels larger than 0.16 BTC) channels, which is the opposite of
// mini.
Expand Down Expand Up @@ -57,6 +58,23 @@ type ProtocolOptions struct {

// NoRouteBlindingOption disables forwarding of payments in blinded routes.
NoRouteBlindingOption bool `long:"no-route-blinding" description:"do not forward payments that are a part of a blinded route"`

// CustomMessage allows the custom message APIs to handle messages with
// the provided protocol numbers, which fall outside the custom message
// number range.
CustomMessage []uint16 `long:"custom-message" description:"allows the custom message apis to send and report messages with the protocol number provided that fall outside of the custom message number range."`

// CustomInit specifies feature bits to advertise in the node's init
// message.
CustomInit []uint16 `long:"custom-init" description:"custom feature bits to advertise in the node's init message"`

// CustomNodeAnn specifies custom feature bits to advertise in the
// node's announcement message.
CustomNodeAnn []uint16 `long:"custom-nodeann" description:"custom feature bits to advertise in the node's announcement message"`

// CustomInvoice specifies custom feature bits to advertise in the
// node's invoices.
CustomInvoice []uint16 `long:"custom-invoice" description:"custom feature bits to advertise in the node's invoices"`
}

// Wumbo returns true if lnd should permit the creation and acceptance of wumbo
Expand Down Expand Up @@ -105,3 +123,31 @@ func (l *ProtocolOptions) NoTimestampsQuery() bool {
func (l *ProtocolOptions) NoRouteBlinding() bool {
return l.NoRouteBlindingOption
}

// CustomMessageOverrides returns the set of protocol messages that we override
// to allow custom handling.
func (p ProtocolOptions) CustomMessageOverrides() []uint16 {
return p.CustomMessage
}

// CustomFeatures returns a custom set of feature bits to advertise.
//
//nolint:lll
func (p ProtocolOptions) CustomFeatures() map[feature.Set][]lnwire.FeatureBit {
customFeatures := make(map[feature.Set][]lnwire.FeatureBit)

setFeatures := func(set feature.Set, bits []uint16) {
for _, customFeature := range bits {
customFeatures[set] = append(
customFeatures[set],
lnwire.FeatureBit(customFeature),
)
}
}

setFeatures(feature.SetInit, p.CustomInit)
setFeatures(feature.SetNodeAnn, p.CustomNodeAnn)
setFeatures(feature.SetInvoice, p.CustomInvoice)

return customFeatures
}
25 changes: 0 additions & 25 deletions lncfg/protocol_experimental_off.go

This file was deleted.

51 changes: 0 additions & 51 deletions lncfg/protocol_experimental_on.go

This file was deleted.

52 changes: 48 additions & 4 deletions lncfg/protocol_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

package lncfg

import (
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/lnwire"
)

// ProtocolOptions is a struct that we use to be able to test backwards
// compatibility of protocol additions, while defaulting to the latest within
// lnd, or to enable experimental protocol changes.
Expand All @@ -15,10 +20,6 @@ type ProtocolOptions struct {
// nodes should always run with them on by default.
LegacyProtocol `group:"legacy" namespace:"legacy"`

// ExperimentalProtocol is a sub-config that houses any experimental
// protocol features that also require a build-tag to activate.
ExperimentalProtocol

// WumboChans should be set if we want to enable support for wumbo
// (channels larger than 0.16 BTC) channels, which is the opposite of
// mini.
Expand Down Expand Up @@ -60,6 +61,23 @@ type ProtocolOptions struct {

// NoRouteBlindingOption disables forwarding of payments in blinded routes.
NoRouteBlindingOption bool `long:"no-route-blinding" description:"do not forward payments that are a part of a blinded route"`

// CustomMessage allows the custom message APIs to handle messages with
// the provided protocol numbers, which fall outside the custom message
// number range.
CustomMessage []uint16 `long:"custom-message" description:"allows the custom message apis to send and report messages with the protocol number provided that fall outside of the custom message number range."`

// CustomInit specifies feature bits to advertise in the node's init
// message.
CustomInit []uint16 `long:"custom-init" description:"custom feature bits to advertise in the node's init message"`

// CustomNodeAnn specifies custom feature bits to advertise in the
// node's announcement message.
CustomNodeAnn []uint16 `long:"custom-nodeann" description:"custom feature bits to advertise in the node's announcement message"`

// CustomInvoice specifies custom feature bits to advertise in the
// node's invoices.
CustomInvoice []uint16 `long:"custom-invoice" description:"custom feature bits to advertise in the node's invoices"`
}

// Wumbo returns true if lnd should permit the creation and acceptance of wumbo
Expand Down Expand Up @@ -100,3 +118,29 @@ func (l *ProtocolOptions) NoAnySegwit() bool {
func (l *ProtocolOptions) NoRouteBlinding() bool {
return l.NoRouteBlindingOption
}

// CustomMessageOverrides returns the set of protocol messages that we override
// to allow custom handling.
func (l ProtocolOptions) CustomMessageOverrides() []uint16 {
return l.CustomMessage
}

// CustomFeatures returns a custom set of feature bits to advertise.
func (l ProtocolOptions) CustomFeatures() map[feature.Set][]lnwire.FeatureBit {
customFeatures := make(map[feature.Set][]lnwire.FeatureBit)

setFeatures := func(set feature.Set, bits []uint16) {
for _, customFeature := range bits {
customFeatures[set] = append(
customFeatures[set],
lnwire.FeatureBit(customFeature),
)
}
}

setFeatures(feature.SetInit, l.CustomInit)
setFeatures(feature.SetNodeAnn, l.CustomNodeAnn)
setFeatures(feature.SetInvoice, l.CustomInvoice)

return customFeatures
}
13 changes: 13 additions & 0 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,19 @@
; Set to disable blinded route forwarding.
; protocol.no-route-blinding=false

; Set to handle messages of a particular type that falls outside of the
; custom message number range (i.e. 513 is onion messages)
; protocol.custom-message=

; Specifies feature bits to advertise in the node's init message.
; protocol.custom-init=

; Specifies custom feature bits to advertise in the node's announcement message.
; protocol.custom-nodeann=

; Specifies custom feature bits to advertise in the node's invoices.
; protocol.custom-invoice=

[db]

; The selected database backend. The current default backend is "bolt". lnd
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
NoOptionScidAlias: !cfg.ProtocolOptions.ScidAlias(),
NoZeroConf: !cfg.ProtocolOptions.ZeroConf(),
NoAnySegwit: cfg.ProtocolOptions.NoAnySegwit(),
CustomFeatures: cfg.ProtocolOptions.ExperimentalProtocol.CustomFeatures(),
CustomFeatures: cfg.ProtocolOptions.CustomFeatures(),
NoTaprootChans: !cfg.ProtocolOptions.TaprootChans,
NoRouteBlinding: cfg.ProtocolOptions.NoRouteBlinding(),
})
Expand Down

0 comments on commit ef3740a

Please sign in to comment.