From 43a355321fe54610c8d5ffb876eb37c23e25d639 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 8 Jul 2020 14:26:05 -0700 Subject: [PATCH] lncfg: split off protocol options into normal and legacy, normal reqs no build tag In this commit, we split off the protocol options into a normal and legacy sub-config. The legacy sub-config protected by a built tag, and will only be populated if thet tag is set. Legacy options now have a `legacy` prefix. So `--protocol.legacyonion` is now `--protocol.onion`, and `--protocol.committweak`, is now `--protocol.legacy.committweak`. We also create a new experimental protocol feature sub-config for newer features that may not yet been fully complete, so they require a build tag. --- lncfg/protocol.go | 15 +++++++++++++++ lncfg/protocol_experimental_off.go | 14 ++++++++++++++ lncfg/protocol_experimental_on.go | 17 +++++++++++++++++ lncfg/protocol_legacy_off.go | 18 ++++++------------ lncfg/protocol_legacy_on.go | 24 +++++++----------------- lntest/itest/lnd_multi-hop-payments.go | 2 +- lntest/itest/lnd_test.go | 2 +- 7 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 lncfg/protocol.go create mode 100644 lncfg/protocol_experimental_off.go create mode 100644 lncfg/protocol_experimental_on.go diff --git a/lncfg/protocol.go b/lncfg/protocol.go new file mode 100644 index 000000000..ea4b1bfc9 --- /dev/null +++ b/lncfg/protocol.go @@ -0,0 +1,15 @@ +package lncfg + +// 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. +type ProtocolOptions struct { + // LegacyProtocol is a sub-config that houses all the legacy protocol + // options. These are mostly used for integration tests as most modern + // nodes shuld 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 +} diff --git a/lncfg/protocol_experimental_off.go b/lncfg/protocol_experimental_off.go new file mode 100644 index 000000000..20d1ce48a --- /dev/null +++ b/lncfg/protocol_experimental_off.go @@ -0,0 +1,14 @@ +// +build !dev + +package lncfg + +// ExperimentalProtocol is a sub-config that houses any experimental protocol +// features that also require a build-tag to activate. +type ExperimentalProtocol struct { +} + +// AnchorCommitments returns true if support for the anchor commitment type +// should be signaled. +func (l *ExperimentalProtocol) AnchorCommitments() bool { + return false +} diff --git a/lncfg/protocol_experimental_on.go b/lncfg/protocol_experimental_on.go new file mode 100644 index 000000000..dac8cfeae --- /dev/null +++ b/lncfg/protocol_experimental_on.go @@ -0,0 +1,17 @@ +// +build dev + +package lncfg + +// ExperimentalProtocol is a sub-config that houses any experimental protocol +// features that also require a build-tag to activate. +type ExperimentalProtocol struct { + // 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"` +} + +// AnchorCommitments returns true if support for the anchor commitment type +// should be signaled. +func (l *ExperimentalProtocol) AnchorCommitments() bool { + return l.Anchors +} diff --git a/lncfg/protocol_legacy_off.go b/lncfg/protocol_legacy_off.go index bd589c245..060569d83 100644 --- a/lncfg/protocol_legacy_off.go +++ b/lncfg/protocol_legacy_off.go @@ -2,27 +2,21 @@ package lncfg -// 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. -type ProtocolOptions struct { +// Legacy is a sub-config that houses all the legacy protocol options. These +// are mostly used for integration tests as most modern nodes shuld always run +// with them on by default. +type LegacyProtocol struct { } // LegacyOnion returns true if the old legacy onion format should be used when // we're an intermediate or final hop. This controls if we set the // TLVOnionPayloadOptional bit or not. -func (l *ProtocolOptions) LegacyOnion() bool { +func (l *LegacyProtocol) LegacyOnion() bool { return false } // 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 { +func (l *LegacyProtocol) NoStaticRemoteKey() bool { return false } diff --git a/lncfg/protocol_legacy_on.go b/lncfg/protocol_legacy_on.go index ac388f020..712d5fede 100644 --- a/lncfg/protocol_legacy_on.go +++ b/lncfg/protocol_legacy_on.go @@ -2,41 +2,31 @@ package lncfg -// 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. -type ProtocolOptions struct { +// Legacy is a sub-config that houses all the legacy protocol options. These +// are mostly used for integration tests as most modern nodes shuld always run +// with them on by default. +type LegacyProtocol struct { // LegacyOnionFormat if set to true, then we won't signal // TLVOnionPayloadOptional. As a result, nodes that include us in the // route won't use the new modern onion framing. - LegacyOnionFormat bool `long:"legacyonion" description:"force node to not advertise the new modern TLV onion format"` + LegacyOnionFormat bool `long:"onion" description:"force node to not advertise the new modern TLV onion format"` // CommitmentTweak guards if we should use the old legacy commitment // protocol, or the newer variant that doesn't have a tweak for the // 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"` } // LegacyOnion returns true if the old legacy onion format should be used when // we're an intermediate or final hop. This controls if we set the // TLVOnionPayloadOptional bit or not. -func (l *ProtocolOptions) LegacyOnion() bool { +func (l *LegacyProtocol) LegacyOnion() bool { return l.LegacyOnionFormat } // 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 { +func (l *LegacyProtocol) NoStaticRemoteKey() bool { return l.CommitmentTweak } - -// AnchorCommitments returns true if support for the anchor commitment type -// should be signaled. -func (l *ProtocolOptions) AnchorCommitments() bool { - return l.Anchors -} diff --git a/lntest/itest/lnd_multi-hop-payments.go b/lntest/itest/lnd_multi-hop-payments.go index fb9e79cb3..a7dfee5a5 100644 --- a/lntest/itest/lnd_multi-hop-payments.go +++ b/lntest/itest/lnd_multi-hop-payments.go @@ -48,7 +48,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { // // First, we'll create Dave and establish a channel to Alice. Dave will // be running an older node that requires the legacy onion payload. - daveArgs := []string{"--protocol.legacyonion"} + daveArgs := []string{"--protocol.legacy.onion"} dave, err := net.NewNode("Dave", daveArgs) if err != nil { t.Fatalf("unable to create new nodes: %v", err) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 0cf06fd1c..90a938435 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -1178,7 +1178,7 @@ func (c commitType) String() string { func (c commitType) Args() []string { switch c { case commitTypeLegacy: - return []string{"--protocol.committweak"} + return []string{"--protocol.legacy.committweak"} case commitTypeTweakless: return []string{} case commitTypeAnchors: