Merge pull request #7177 from morehouse/fix_chantype_negotiation
funding: fix channel type negotiation bug
This commit is contained in:
5 files changed
+189
-136
No files matched your search
+35
-42
@@ -1504,9 +1504,8 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
||||
// the remote peer are signaling the proper feature bit if we're using
|
||||
// implicit negotiation, and simply the channel type sent over if we're
|
||||
// using explicit negotiation.
|
||||
wasExplicit, _, commitType, err := negotiateCommitmentType(
|
||||
chanType, commitType, err := negotiateCommitmentType(
|
||||
msg.ChannelType, peer.LocalFeatures(), peer.RemoteFeatures(),
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
// TODO(roasbeef): should be using soft errors
|
||||
@@ -1525,19 +1524,16 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
||||
}
|
||||
|
||||
var (
|
||||
chanTypeFeatureBits *lnwire.ChannelType
|
||||
zeroConf bool
|
||||
scid bool
|
||||
zeroConf bool
|
||||
scid bool
|
||||
)
|
||||
|
||||
if wasExplicit {
|
||||
// Only echo back a channel type in AcceptChannel if we actually
|
||||
// used explicit negotiation above.
|
||||
chanTypeFeatureBits = msg.ChannelType
|
||||
|
||||
// Only echo back a channel type in AcceptChannel if we actually used
|
||||
// explicit negotiation above.
|
||||
if chanType != nil {
|
||||
// Check if the channel type includes the zero-conf or
|
||||
// scid-alias bits.
|
||||
featureVec := lnwire.RawFeatureVector(*chanTypeFeatureBits)
|
||||
featureVec := lnwire.RawFeatureVector(*chanType)
|
||||
zeroConf = featureVec.IsSet(lnwire.ZeroConfRequired)
|
||||
scid = featureVec.IsSet(lnwire.ScidAliasRequired)
|
||||
|
||||
@@ -1773,7 +1769,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
remoteChanReserve: chanReserve,
|
||||
maxLocalCsv: f.cfg.MaxLocalCSVDelay,
|
||||
channelType: msg.ChannelType,
|
||||
channelType: chanType,
|
||||
err: make(chan error, 1),
|
||||
peer: peer,
|
||||
}
|
||||
@@ -1846,7 +1842,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer,
|
||||
HtlcPoint: ourContribution.HtlcBasePoint.PubKey,
|
||||
FirstCommitmentPoint: ourContribution.FirstCommitmentPoint,
|
||||
UpfrontShutdownScript: ourContribution.UpfrontShutdown,
|
||||
ChannelType: chanTypeFeatureBits,
|
||||
ChannelType: chanType,
|
||||
LeaseExpiry: msg.LeaseExpiry,
|
||||
}
|
||||
|
||||
@@ -1926,18 +1922,16 @@ func (f *Manager) handleFundingAccept(peer lnpeer.Peer,
|
||||
} else if msg.ChannelType != nil {
|
||||
// The spec isn't too clear about whether it's okay to set the
|
||||
// channel type in the accept_channel response if we didn't
|
||||
// explicitly set it in the open_channel message. For now, let's
|
||||
// just log the problem instead of failing the funding flow.
|
||||
_, implicitChannelType := implicitNegotiateCommitmentType(
|
||||
// explicitly set it in the open_channel message. For now, we
|
||||
// check that it's the same type we'd have arrived through
|
||||
// implicit negotiation. If it's another type, we fail the flow.
|
||||
_, implicitCommitType := implicitNegotiateCommitmentType(
|
||||
peer.LocalFeatures(), peer.RemoteFeatures(),
|
||||
)
|
||||
|
||||
// We pass in false here as the funder since at this point, we
|
||||
// didn't set a chan type ourselves, so falling back to
|
||||
// implicit funding is acceptable.
|
||||
_, _, negotiatedChannelType, err := negotiateCommitmentType(
|
||||
_, negotiatedCommitType, err := negotiateCommitmentType(
|
||||
msg.ChannelType, peer.LocalFeatures(),
|
||||
peer.RemoteFeatures(), false,
|
||||
peer.RemoteFeatures(),
|
||||
)
|
||||
if err != nil {
|
||||
err := errors.New("received unexpected channel type")
|
||||
@@ -1945,11 +1939,7 @@ func (f *Manager) handleFundingAccept(peer lnpeer.Peer,
|
||||
return
|
||||
}
|
||||
|
||||
// Even though we don't expect a channel type to be set when we
|
||||
// didn't send one in the first place, we check that it's the
|
||||
// same type we'd have arrived through implicit negotiation. If
|
||||
// it's another type, we fail the flow.
|
||||
if implicitChannelType != negotiatedChannelType {
|
||||
if implicitCommitType != negotiatedCommitType {
|
||||
err := errors.New("negotiated unexpected channel type")
|
||||
f.failFundingFlow(peer, cid, err)
|
||||
return
|
||||
@@ -4152,9 +4142,9 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
// Before we init the channel, we'll also check to see what commitment
|
||||
// format we can use with this peer. This is dependent on *both* us and
|
||||
// the remote peer are signaling the proper feature bit.
|
||||
_, chanType, commitType, err := negotiateCommitmentType(
|
||||
chanType, commitType, err := negotiateCommitmentType(
|
||||
msg.ChannelType, msg.Peer.LocalFeatures(),
|
||||
msg.Peer.RemoteFeatures(), true,
|
||||
msg.Peer.RemoteFeatures(),
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("channel type negotiation failed: %v", err)
|
||||
@@ -4167,20 +4157,23 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
scid bool
|
||||
)
|
||||
|
||||
// Check if the returned chanType includes either the zero-conf or
|
||||
// scid-alias bits.
|
||||
featureVec := lnwire.RawFeatureVector(*chanType)
|
||||
zeroConf = featureVec.IsSet(lnwire.ZeroConfRequired)
|
||||
scid = featureVec.IsSet(lnwire.ScidAliasRequired)
|
||||
if chanType != nil {
|
||||
// Check if the returned chanType includes either the zero-conf
|
||||
// or scid-alias bits.
|
||||
featureVec := lnwire.RawFeatureVector(*chanType)
|
||||
zeroConf = featureVec.IsSet(lnwire.ZeroConfRequired)
|
||||
scid = featureVec.IsSet(lnwire.ScidAliasRequired)
|
||||
|
||||
// The option-scid-alias channel type for a public channel is
|
||||
// disallowed.
|
||||
if scid && !msg.Private {
|
||||
err = fmt.Errorf("option-scid-alias chantype for public " +
|
||||
"channel")
|
||||
log.Error(err)
|
||||
msg.Err <- err
|
||||
return
|
||||
// The option-scid-alias channel type for a public channel is
|
||||
// disallowed.
|
||||
if scid && !msg.Private {
|
||||
err = fmt.Errorf("option-scid-alias chantype for " +
|
||||
"public channel")
|
||||
log.Error(err)
|
||||
msg.Err <- err
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// First, we'll query the fee estimator for a fee that should get the
|
||||
@@ -4338,7 +4331,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
||||
remoteMaxHtlcs: maxHtlcs,
|
||||
remoteChanReserve: chanReserve,
|
||||
maxLocalCsv: maxCSV,
|
||||
channelType: msg.ChannelType,
|
||||
channelType: chanType,
|
||||
reservation: reservation,
|
||||
peer: msg.Peer,
|
||||
updates: msg.Updates,
|
||||
|
||||
Reference in new issue
Block a user