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

View File

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

View File

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

View File

@ -17,6 +17,9 @@ type Config struct {
// NoStaticRemoteKey unsets any optional or required StaticRemoteKey
// bits from all feature sets.
NoStaticRemoteKey bool
// NoAnchors unsets any bits signaling support for anchor outputs.
NoAnchors bool
}
// 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.StaticRemoteKeyRequired)
}
if cfg.NoAnchors {
raw.Unset(lnwire.AnchorsOptional)
raw.Unset(lnwire.AnchorsRequired)
}
// Ensure that all of our feature sets properly set any
// dependent features.

View File

@ -15,8 +15,14 @@ func (l *ProtocolOptions) LegacyOnion() bool {
return false
}
// LegacyCommitment returns true if the old commitment format should be used
// for new funded channels.
func (l *ProtocolOptions) LegacyCommitment() bool {
// NoStaticRemoteKey returns true if the old commitment format with a tweaked
// remote key should be used for new funded channels.
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
}

View File

@ -16,6 +16,10 @@ type ProtocolOptions struct {
// remote party's output in the commitment. If set to true, then we
// won't signal StaticRemoteKeyOptional.
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
@ -25,8 +29,14 @@ func (l *ProtocolOptions) LegacyOnion() bool {
return l.LegacyOnionFormat
}
// LegacyCommitment returns true if the old commitment format should be used
// for new funded channels.
func (l *ProtocolOptions) LegacyCommitment() bool {
// NoStaticRemoteKey returns true if the old commitment format with a tweaked
// remote key should be used for new funded channels.
func (l *ProtocolOptions) NoStaticRemoteKey() bool {
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
}

View File

@ -101,6 +101,16 @@ const (
// HTLC.
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.
//
// NOTE: Within the protocol, the maximum allowed message size is 65535
@ -138,6 +148,8 @@ var Features = map[FeatureBit]string{
PaymentAddrRequired: "payment-addr",
MPPOptional: "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

View File

@ -340,12 +340,19 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
globalFeatures.Set(lnwire.TLVOnionPayloadOptional)
}
// Similarly, we default to the new modern commitment format unless the
// legacy commitment config is set to true.
if !cfg.ProtocolOptions.LegacyCommitment() {
// Similarly, we default to supporting the new modern commitment format
// where the remote key is static unless the protocol config is set to
// keep using the older format.
if !cfg.ProtocolOptions.NoStaticRemoteKey() {
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
copy(serializedPubKey[:], privKey.PubKey().SerializeCompressed())
@ -376,7 +383,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
featureMgr, err := feature.NewManager(feature.Config{
NoTLVOnion: cfg.ProtocolOptions.LegacyOnion(),
NoStaticRemoteKey: cfg.ProtocolOptions.LegacyCommitment(),
NoStaticRemoteKey: cfg.ProtocolOptions.NoStaticRemoteKey(),
NoAnchors: !cfg.ProtocolOptions.AnchorCommitments(),
})
if err != nil {
return nil, err