funding: require explicit channel type in all negotiations - #11064
funding: require explicit channel type in all negotiations #11064NishantBansal2003 wants to merge 2 commits into
Conversation
🔴 PR Severity: CRITICAL
🔴 Critical (1 file)
🟢 Low (1 file)
AnalysisThis PR changes To override, add a |
|
We should remove implicit channel-type negotiation instead of gating this validation on Please require |
|
When removing the implicit negotiation paths, we should keep the backward-compatibility implications in mind. In particular, removing implicit negotiation should be separate from removing the Continuing to advertise bit 44 allows older LND versions that understand explicit channel types to enter their explicit path and send/echo I suggest always requiring, sending, and echoing |
686650d to
f781d03
Compare
Wanted to do that in the first place, since all the other implementations currently do this, but I was unsure why it wasn’t done in: #9637. Anyway, in the latest commit, I did the following:
|
LND allows `open_channel` with an omitted `channel_type`, violating BOLT 2 even though it signals the required `option_channel_type` feature bit. This will be tracked upstream and will be suppressed until fixed. see: lightningnetwork/lnd#11064 Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
LND allows `open_channel` with an omitted `channel_type`, violating BOLT 2 even though it signals the required `option_channel_type` feature bit. This will be tracked upstream and will be suppressed until fixed. see: lightningnetwork/lnd#11064 Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
There was a problem hiding this comment.
Agreed with @ziggie1984 .
The flip side is that the advertisement is now a prerequisite of this change rather than an independent feature flag: dropping that line silently breaks the funding flow against older peers, so a short note there would be cheap insurance:
// NOTE: Funding requires an explicit channel type, and older peers only
// enter their explicit path when we advertise this. Removing this bit
// breaks the funding flow against them until those versions age out.
lnwire.ExplicitChannelTypeRequired: {
SetInit: {}, // I
SetNodeAnn: {}, // N
},|
I've been building a coverage-guided fuzz harness for the funding manager, and added oracles for BOLT 2's
For now these are logged rather than fatal, so the fuzzer can keep running against master — it otherwise stops within seconds and reaches nothing else. The must-reject check for case 1 is commented out as well; the case still surfaces, All three pass with this branch applied. |
f781d03 to
b2b6678
Compare
MPins
left a comment
There was a problem hiding this comment.
LGTM 🎉
Verified the test fix does what it was meant to: with the check removed, the package now fails as expected, instead of panicking in copyPubKey and taking the binary down.
Two non-code leftovers before this lands: missing the release notes and the PR description, which still describe the conditional design "I think we should fail the funding flow if ChannelType is omitted when both peers have negotiated ExplicitChannelType".
| // channel. If a desiredChanType is provided, explicit negotiation for said type | ||
| // will be attempted if the set of both local and remote features support it. | ||
| // Otherwise, implicit negotiation will be attempted. | ||
| // Otherwise, a default type is selected based on feature compatibility, |
There was a problem hiding this comment.
Could we update the RPC-facing docs as part of this change? funding/manager.go:291-293 still says ChannelType is observed only when both sides support explicit negotiation, and both commitment_type fields in lnrpc/lightning.proto (around lines 2239 and 2412) say the field is only used if the remote advertises it. With option_channel_type now assumed, those statements are false: a requested type is validated regardless of bits 44/45, while nil/UNKNOWN selects a default that is sent explicitly. Suggested wording: "The commitment type to request. If UNKNOWN, lnd selects a default from both peers' supported features; the selected type is always sent explicitly." Please regenerate lightning.pb.go and lightning.swagger.json with make rpc.
There was a problem hiding this comment.
Done in c961526
I'll squash it and update the commit message to multi: require explicit channel type in all negotiations once the PR is finalized
| @@ -18,61 +18,30 @@ var ( | |||
| // negotiateCommitmentType negotiates the commitment type of a newly opened | |||
There was a problem hiding this comment.
Small pre-existing doc typo while we're touching this helper: the comment above names errUnsupportedCommitmentType, but the variable is errUnsupportedChannelType.
| "public channel") | ||
| log.Error(err) | ||
| msg.Err <- err | ||
| // Since we always negotiate an explicit channel type now, chanType is |
There was a problem hiding this comment.
The nearby comment above negotiateCommitmentType is now stale/misleading: This is dependent on *both* us and the remote peer are signaling the proper feature bit. A caller-supplied type comes from msg.ChannelType and is then validated against its underlying features; only a nil request uses feature-based default selection, and bit 44/45 is not a gate. Could we rewrite it to: Before initializing the reservation, validate the caller-requested channel type or select a default from the peers' mutually supported commitment features.
|
|
||
| // Set up feature bits for channel type negotiation. | ||
| featureBits := []lnwire.FeatureBit{ | ||
| lnwire.ExplicitChannelTypeOptional, |
There was a problem hiding this comment.
This test still sets ExplicitChannelTypeOptional, so it doesn't exercise the main compatibility case added by this PR: a peer omits bit 44/45 but sends a valid channel_type. Could we remove this bit here and keep only the underlying static-remotekey/anchors features? That would also let us update the stale comment in testNormalWorkflow around lines 1601-1602, which currently says both parties must support explicit channel-type negotiation.
| // using explicit negotiation. | ||
| // format we can use with this peer. This is dependent on the channel | ||
| // type sent by the funder and the feature bits both peers are signaling | ||
| chanType, commitType, err := negotiateCommitmentType( |
There was a problem hiding this comment.
nit: this comment is missing its terminating period — // type sent by the funder and the feature bits both peers are signaling. Its rewritten counterpart in handleInitFundingMsg (the Before initializing the reservation, ... block) ends properly, so this is the odd one out. Easy to fold into the squash.
| // Otherwise, implicit negotiation will be attempted. | ||
| // Otherwise, a default type is selected based on feature compatibility, | ||
| // particularly when the RPC caller does not request a specific channel type. | ||
| // |
There was a problem hiding this comment.
This doc comment is the one place that still carries the vocabulary the PR removes, and it's the entry point people will read first. Two things:
- "explicit negotiation for said type will be attempted if the set of both local and remote features support it" — nothing is negotiated here anymore. A caller-supplied type is validated against the commitment features both peers support; bits 44/45 are not consulted at all.
- "particularly when the RPC caller does not request a specific channel type" — that isn't a particular case, it's the only path that reaches default selection, so the qualifier implies there are others.
Suggested rewrite:
// negotiateCommitmentType determines the commitment type of a newly opened
// channel. If desiredChanType is provided, it is validated against the
// commitment features supported by both peers. Otherwise, a default type is
// selected from those features.
//
// The returned ChannelType is always non-nil and is always signaled on the
// wire. An error is only returned if desiredChanType is not supported.| // channels. | ||
| // selectDefaultChannelType selects a default channel type by choosing the | ||
| // latest non-taproot type supported by the local and remote features. | ||
| // Taproot channels must be requested explicitly, keeping default selections |
There was a problem hiding this comment.
The rename reads well — dropping "negotiate" is right, since this never touches the peer, and "default" lines up with the RPC wording ("If UNKNOWN, lnd selects a default..."). Two leftovers in the doc, both inherited from implicitNegotiateCommitmentType:
- "the latest non-taproot type" — "latest" reads temporally; what's meant is a preference ordering. "the most preferred non-taproot type" is clearer.
- "keeping default selections on channel types that can be used for both public and private channels" is a slightly garbled edit of "keeping implicit opens on ...". Maybe: "so that defaults stay on channel types usable for both public and private channels."
| expectsChanType: nil, | ||
| expectsErr: nil, | ||
| expectsChanType: (*lnwire.ChannelType)( | ||
| lnwire.NewRawFeatureVector( |
There was a problem hiding this comment.
Follow-on from removing the bit in TestFundingManagerAcceptChanType: the ExplicitChannelTypeOptional entries in this table's localFeatures/remoteFeatures are now inert, and leaving them in suggests the bit still steers the outcome.
After this change nothing in the funding path reads bit 44/45. The single read in the tree was the hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) call this PR deletes; grepping ExplicitChannelType outside lnwire/features.go now finds only feature/default_sets.go (a write into our advertised set) and feature/deps.go (dependency declarations). These vectors are the arguments to negotiateCommitmentType, which no longer looks at the bit.
I removed all 35 occurrences from this file's vectors locally and all 20 subtests still pass, so this is a pure signal-clarity change. It matters most on this first case, whose name — "explicit missing remote negotiation feature" — describes a condition the code no longer branches on; something like "explicit type without remote negotiation bit" would also convey that it now succeeds and signals the type.
To be explicit about scope: this is only about the test vectors. The advertisement in feature/default_sets.go must stay, since older lnd still gates its own explicit path on seeing the bit from us.
|
Looking good can you squash the commits |
ziggie1984
left a comment
There was a problem hiding this comment.
LGTM (pending fixup commit history), nice contribution thank you !!!
Move from optional implicit negotiation to mandatory explicit channel type in OpenChannel and AcceptChannel. The returned ChannelType is now always non-nil. Channel type is required in all negotiations now. We only fallback to a default channel type when the RPC caller does not explicitly specify one. Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
5b5d378 to
f5928a9
Compare
🟡 PR Severity: MEDIUM
🔴 Critical (2 files)
🟠 High (3 files)
🟢 Low / excluded (4 files)
AnalysisBy file content alone, this PR would classify as CRITICAL: it modifies To override, add a |
GeorgeTsagk
left a comment
There was a problem hiding this comment.
LGTM, two non-blocking nits inline.
Verified against current BOLT 2: rejecting open_channel without channel_type, requiring the echo in accept_channel, and always signaling the type are all mandatory since option_channel_type became ASSUMED. Keeping the ExplicitChannelTypeRequired advertisement is the right compat bridge for older LND peers that only enter their explicit path when they see the bit.
funding, feature, chanacceptor, and lnwire unit tests pass locally on this branch. The three CI failures are unrelated flakes (neutrino wallet test under race, etcd client test, htlc_timeout_resolver_extract_preimage_local itest), all in subsystems this PR does not touch.
| // Enforce BOLT-02: The funder MUST set the channel_type in | ||
| // open_channel. Reject if it's omitted. | ||
| if msg.ChannelType == nil { | ||
| err := errors.New("channel type required but not provided") | ||
| f.failFundingFlow(peer, cid, err) | ||
|
|
||
| return | ||
| } |
There was a problem hiding this comment.
The peer never learns why we rejected here: failFundingFlow downgrades non-whitelisted errors to "funding failed due to internal error" (manager.go:982). Since this check exists to flag non-conforming peers, an actionable reason helps interop debugging. Consider adding an lnwire.FundingError enum value (e.g. ErrChanTypeRequired = 3, "channel type required") and returning it here.
| return | ||
| } | ||
|
|
||
| // Enforce BOLT-02: The funder MUST set the channel_type in |
There was a problem hiding this comment.
Nit: this runs after OpenChannelPredicate.Accept (manager.go:1579), so spec-violating opens still reach external acceptors before being rejected. Protocol validation should precede user-defined policy; suggest moving this check above the acceptor call, next to the chain-hash and sync-state checks.
|
@NishantBansal2003 pls address the Nits from George. |
Currently, BOLT assumes
ExplicitChannelType, and LND sends it as required (#9637). However, when receiving anOpenChannelfrom peer, LND doesn’t enforce an explicitChannelTypeand falls back to implicit negotiation, even though both peers have negotiatedExplicitChannelType. According to BOLT 2, I think we should fail the funding flow ifChannelTypeis omitted from the receivedOpenChannelmessage and echo the same channel type (if valid) inAcceptChannel.So, we should remove implicit negotiation entirely. If the RPC caller doesn’t request a channel type, a default should be derived from both peers' features and signaled explicitly.