multi: optionally enable and signal anchor support

Defaults to disabled.
This commit is contained in:
Johan T. Halseth 2020-03-06 16:11:48 +01:00
parent 44756b5811
commit 21126ab0f3
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
7 changed files with 60 additions and 10 deletions

@ -43,4 +43,8 @@ var defaultSetDesc = setDesc{
SetNodeAnn: {}, // N SetNodeAnn: {}, // N
SetInvoice: {}, // 9 SetInvoice: {}, // 9
}, },
lnwire.AnchorsOptional: {
SetInit: {}, // I
SetNodeAnn: {}, // N
},
} }

@ -55,6 +55,9 @@ var deps = depDesc{
lnwire.MPPOptional: { lnwire.MPPOptional: {
lnwire.PaymentAddrOptional: {}, lnwire.PaymentAddrOptional: {},
}, },
lnwire.AnchorsOptional: {
lnwire.StaticRemoteKeyOptional: {},
},
} }
// ValidateDeps asserts that a feature vector sets all features and their // ValidateDeps asserts that a feature vector sets all features and their

@ -17,6 +17,9 @@ type Config struct {
// NoStaticRemoteKey unsets any optional or required StaticRemoteKey // NoStaticRemoteKey unsets any optional or required StaticRemoteKey
// bits from all feature sets. // bits from all feature sets.
NoStaticRemoteKey bool NoStaticRemoteKey bool
// NoAnchors unsets any bits signaling support for anchor outputs.
NoAnchors bool
} }
// Manager is responsible for generating feature vectors for different requested // Manager is responsible for generating feature vectors for different requested
@ -76,6 +79,10 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) {
raw.Unset(lnwire.StaticRemoteKeyOptional) raw.Unset(lnwire.StaticRemoteKeyOptional)
raw.Unset(lnwire.StaticRemoteKeyRequired) raw.Unset(lnwire.StaticRemoteKeyRequired)
} }
if cfg.NoAnchors {
raw.Unset(lnwire.AnchorsOptional)
raw.Unset(lnwire.AnchorsRequired)
}
// Ensure that all of our feature sets properly set any // Ensure that all of our feature sets properly set any
// dependent features. // dependent features.

@ -15,8 +15,14 @@ func (l *ProtocolOptions) LegacyOnion() bool {
return false return false
} }
// LegacyCommitment returns true if the old commitment format should be used // NoStaticRemoteKey returns true if the old commitment format with a tweaked
// for new funded channels. // remote key should be used for new funded channels.
func (l *ProtocolOptions) LegacyCommitment() bool { func (l *ProtocolOptions) NoStaticRemoteKey() bool {
return false
}
// AnchorCommitments returns true if support for the the anchor commitment type
// should be signaled.
func (l *ProtocolOptions) AnchorCommitments() bool {
return false return false
} }

@ -16,6 +16,10 @@ type ProtocolOptions struct {
// remote party's output in the commitment. If set to true, then we // remote party's output in the commitment. If set to true, then we
// won't signal StaticRemoteKeyOptional. // won't signal StaticRemoteKeyOptional.
CommitmentTweak bool `long:"committweak" description:"force node to not advertise the new commitment format"` CommitmentTweak bool `long:"committweak" description:"force node to not advertise the new commitment format"`
// Anchors should be set if we want to support opening or accepting
// channels having the anchor commitment type.
Anchors bool `long:"anchors" description:"EXPERIMENTAL: enable experimental support for anchor commitments. Won't work with watchtowers or static channel backups"`
} }
// LegacyOnion returns true if the old legacy onion format should be used when // LegacyOnion returns true if the old legacy onion format should be used when
@ -25,8 +29,14 @@ func (l *ProtocolOptions) LegacyOnion() bool {
return l.LegacyOnionFormat return l.LegacyOnionFormat
} }
// LegacyCommitment returns true if the old commitment format should be used // NoStaticRemoteKey returns true if the old commitment format with a tweaked
// for new funded channels. // remote key should be used for new funded channels.
func (l *ProtocolOptions) LegacyCommitment() bool { func (l *ProtocolOptions) NoStaticRemoteKey() bool {
return l.CommitmentTweak return l.CommitmentTweak
} }
// AnchorCommitments returns true if support for the the anchor commitment type
// should be signaled.
func (l *ProtocolOptions) AnchorCommitments() bool {
return l.Anchors
}

@ -101,6 +101,16 @@ const (
// HTLC. // HTLC.
MPPOptional FeatureBit = 17 MPPOptional FeatureBit = 17
// AnchorsRequired is a required feature bit that signals that the node
// requires channels to be made using commitments having anchor
// outputs.
AnchorsRequired FeatureBit = 1336
// AnchorsRequired is an optional feature bit that signals that the
// node supports channels to be made using commitments having anchor
// outputs.
AnchorsOptional FeatureBit = 1337
// maxAllowedSize is a maximum allowed size of feature vector. // maxAllowedSize is a maximum allowed size of feature vector.
// //
// NOTE: Within the protocol, the maximum allowed message size is 65535 // NOTE: Within the protocol, the maximum allowed message size is 65535
@ -138,6 +148,8 @@ var Features = map[FeatureBit]string{
PaymentAddrRequired: "payment-addr", PaymentAddrRequired: "payment-addr",
MPPOptional: "multi-path-payments", MPPOptional: "multi-path-payments",
MPPRequired: "multi-path-payments", MPPRequired: "multi-path-payments",
AnchorsRequired: "anchor-commitments",
AnchorsOptional: "anchor-commitments",
} }
// RawFeatureVector represents a set of feature bits as defined in BOLT-09. A // RawFeatureVector represents a set of feature bits as defined in BOLT-09. A

@ -340,12 +340,19 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
globalFeatures.Set(lnwire.TLVOnionPayloadOptional) globalFeatures.Set(lnwire.TLVOnionPayloadOptional)
} }
// Similarly, we default to the new modern commitment format unless the // Similarly, we default to supporting the new modern commitment format
// legacy commitment config is set to true. // where the remote key is static unless the protocol config is set to
if !cfg.ProtocolOptions.LegacyCommitment() { // keep using the older format.
if !cfg.ProtocolOptions.NoStaticRemoteKey() {
globalFeatures.Set(lnwire.StaticRemoteKeyOptional) globalFeatures.Set(lnwire.StaticRemoteKeyOptional)
} }
// We only signal that we support the experimental anchor commitments
// if explicitly enabled in the config.
if cfg.ProtocolOptions.AnchorCommitments() {
globalFeatures.Set(lnwire.AnchorsOptional)
}
var serializedPubKey [33]byte var serializedPubKey [33]byte
copy(serializedPubKey[:], privKey.PubKey().SerializeCompressed()) copy(serializedPubKey[:], privKey.PubKey().SerializeCompressed())
@ -376,7 +383,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
featureMgr, err := feature.NewManager(feature.Config{ featureMgr, err := feature.NewManager(feature.Config{
NoTLVOnion: cfg.ProtocolOptions.LegacyOnion(), NoTLVOnion: cfg.ProtocolOptions.LegacyOnion(),
NoStaticRemoteKey: cfg.ProtocolOptions.LegacyCommitment(), NoStaticRemoteKey: cfg.ProtocolOptions.NoStaticRemoteKey(),
NoAnchors: !cfg.ProtocolOptions.AnchorCommitments(),
}) })
if err != nil { if err != nil {
return nil, err return nil, err