From 6052a446dcc6727819021d3df1c644397b7e7b4b Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 13 Jul 2021 15:20:46 -0700 Subject: [PATCH] lnwire+feature: add feature bit for script enforced lease support --- feature/default_sets.go | 4 ++++ feature/deps.go | 4 ++++ feature/manager.go | 8 ++++++++ lnwire/features.go | 20 ++++++++++++++++++++ server.go | 9 +++++---- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/feature/default_sets.go b/feature/default_sets.go index 5ee98792a..d345c90df 100644 --- a/feature/default_sets.go +++ b/feature/default_sets.go @@ -64,4 +64,8 @@ var defaultSetDesc = setDesc{ SetInit: {}, // I SetNodeAnn: {}, // N }, + lnwire.ScriptEnforcedLeaseOptional: { + SetInit: {}, // I + SetNodeAnn: {}, // N + }, } diff --git a/feature/deps.go b/feature/deps.go index d6f57cb90..92b0c03d5 100644 --- a/feature/deps.go +++ b/feature/deps.go @@ -65,6 +65,10 @@ var deps = depDesc{ lnwire.PaymentAddrOptional: {}, }, lnwire.ExplicitChannelTypeOptional: {}, + lnwire.ScriptEnforcedLeaseOptional: { + lnwire.ExplicitChannelTypeOptional: {}, + lnwire.AnchorsZeroFeeHtlcTxOptional: {}, + }, } // ValidateDeps asserts that a feature vector sets all features and their diff --git a/feature/manager.go b/feature/manager.go index 989180715..50a54d625 100644 --- a/feature/manager.go +++ b/feature/manager.go @@ -23,6 +23,10 @@ type Config struct { // NoWumbo unsets any bits signalling support for wumbo channels. NoWumbo bool + + // NoScriptEnforcementLease unsets any bits signaling support for script + // enforced leases. + NoScriptEnforcementLease bool } // Manager is responsible for generating feature vectors for different requested @@ -92,6 +96,10 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) { raw.Unset(lnwire.WumboChannelsOptional) raw.Unset(lnwire.WumboChannelsRequired) } + if cfg.NoScriptEnforcementLease { + raw.Unset(lnwire.ScriptEnforcedLeaseOptional) + raw.Unset(lnwire.ScriptEnforcedLeaseRequired) + } // Ensure that all of our feature sets properly set any // dependent features. diff --git a/lnwire/features.go b/lnwire/features.go index 98202841f..16dc83949 100644 --- a/lnwire/features.go +++ b/lnwire/features.go @@ -159,6 +159,24 @@ const ( // TODO: Decide on actual feature bit value. ExplicitChannelTypeOptional = 2021 + // ScriptEnforcedLeaseOptional is an optional feature bit that signals + // that the node requires channels having zero-fee second-level HTLC + // transactions, which also imply anchor commitments, along with an + // additional CLTV constraint of a channel lease's expiration height + // applied to all outputs that pay directly to the channel initiator. + // + // TODO: Decide on actual feature bit value. + ScriptEnforcedLeaseRequired FeatureBit = 2022 + + // ScriptEnforcedLeaseOptional is a required feature bit that signals + // that the node requires channels having zero-fee second-level HTLC + // transactions, which also imply anchor commitments, along with an + // additional CLTV constraint of a channel lease's expiration height + // applied to all outputs that pay directly to the channel initiator. + // + // TODO: Decide on actual feature bit value. + ScriptEnforcedLeaseOptional FeatureBit = 2023 + // maxAllowedSize is a maximum allowed size of feature vector. // // NOTE: Within the protocol, the maximum allowed message size is 65535 @@ -206,6 +224,8 @@ var Features = map[FeatureBit]string{ AMPOptional: "amp", ExplicitChannelTypeOptional: "explicit-commitment-type", ExplicitChannelTypeRequired: "explicit-commitment-type", + ScriptEnforcedLeaseRequired: "script-enforced-lease", + ScriptEnforcedLeaseOptional: "script-enforced-lease", } // RawFeatureVector represents a set of feature bits as defined in BOLT-09. A diff --git a/server.go b/server.go index 356e056da..e2eb3039f 100644 --- a/server.go +++ b/server.go @@ -516,10 +516,11 @@ func newServer(cfg *Config, listenAddrs []net.Addr, ) featureMgr, err := feature.NewManager(feature.Config{ - NoTLVOnion: cfg.ProtocolOptions.LegacyOnion(), - NoStaticRemoteKey: cfg.ProtocolOptions.NoStaticRemoteKey(), - NoAnchors: cfg.ProtocolOptions.NoAnchorCommitments(), - NoWumbo: !cfg.ProtocolOptions.Wumbo(), + NoTLVOnion: cfg.ProtocolOptions.LegacyOnion(), + NoStaticRemoteKey: cfg.ProtocolOptions.NoStaticRemoteKey(), + NoAnchors: cfg.ProtocolOptions.NoAnchorCommitments(), + NoWumbo: !cfg.ProtocolOptions.Wumbo(), + NoScriptEnforcementLease: cfg.ProtocolOptions.NoScriptEnforcementLease(), }) if err != nil { return nil, err