Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
343fa39
funding: fix channel type negotiation bug
morehouse Nov 18, 2022
99af93b
docs: update release notes
morehouse Nov 18, 2022
85ca5ca
lnwallet,funding: remove SetOurUpfrontShutdown
morehouse Nov 16, 2022
f04c086
lnwallet,funding: remove AddAlias
morehouse Nov 16, 2022
dba69bf
lnwallet: clarify ChanFunder behavior
morehouse Nov 17, 2022
7fdeda7
lnwallet: reduce temp variable scope
morehouse Nov 17, 2022
ea0e45c
lnwallet: pass remote amount to NewChannelReservation
morehouse Nov 17, 2022
9df04b5
lnwallet: remove unnecessary PushMSat
morehouse Nov 17, 2022
8804642
lnwallet: move funder balance checks to helper
morehouse Nov 17, 2022
ff4aaea
lnwallet: remove initOurContribution params
morehouse Nov 17, 2022
340249c
lnwallet: remove unnecessary nil check
morehouse Nov 17, 2022
a2a95a2
funding: remove chanAmt from reservation context
morehouse Nov 21, 2022
726e469
lnwallet: remove FundingAmount from ChannelContribution
morehouse Nov 21, 2022
22ae655
multi: remove default ChannelConstraints
morehouse Nov 22, 2022
0bd46a2
lnwallet,funding: set DustLimit in funding manager
morehouse Nov 22, 2022
d40a4fa
funding: encapsulate remote constraints
morehouse Nov 22, 2022
d2531ef
lnwallet: move validation to CommitConstraints
morehouse Nov 22, 2022
94a9443
lnwallet,funding: create ProcessChannelParams
morehouse Nov 23, 2022
98d73b9
lnwallet,funding: remove SetNumConfsRequired
morehouse Nov 23, 2022
05e96b6
lnwallet,funding: simplify shutdown script handling
morehouse Nov 28, 2022
fc03b85
lnwallet,funding: remove ProcessSingleContribution
morehouse Nov 29, 2022
d538dfa
lnwallet,funding: rework ProcessContribution params
morehouse Nov 29, 2022
7c6d348
lnwallet: update funding flow documentation
morehouse Nov 29, 2022
5d6f7de
docs: update release notes
morehouse Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions chainreg/chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ const (
BtcToLtcConversionRate = 60
)

// DefaultLtcChannelConstraints is the default set of channel constraints that
// are meant to be used when initially funding a Litecoin channel.
var DefaultLtcChannelConstraints = channeldb.ChannelConstraints{
DustLimit: DefaultLitecoinDustLimit,
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2,
}

// PartialChainControl contains all the primary interfaces of the chain control
// that can be purely constructed from the global configuration. No wallet
// instance is required for constructing this partial state.
Expand Down Expand Up @@ -196,9 +189,9 @@ type PartialChainControl struct {
// MinHtlcIn is the minimum HTLC we will accept.
MinHtlcIn lnwire.MilliSatoshi

// ChannelConstraints is the set of default constraints that will be
// used for any incoming or outgoing channel reservation requests.
ChannelConstraints channeldb.ChannelConstraints
// DefaultDustLimit is the default dust limit that will be used for any
// incoming or outgoing channel reservation requests.
DefaultDustLimit btcutil.Amount
}

// ChainControl couples the three primary interfaces lnd utilizes for a
Expand Down Expand Up @@ -233,17 +226,12 @@ type ChainControl struct {
Wallet *lnwallet.LightningWallet
}

// GenDefaultBtcConstraints generates the default set of channel constraints
// that are to be used when funding a Bitcoin channel.
func GenDefaultBtcConstraints() channeldb.ChannelConstraints {
// GenDefaultBtcDustLimit generates the default dust limit to be used when
// funding a Bitcoin channel.
func GenDefaultBtcDustLimit() btcutil.Amount {
// We use the dust limit for the maximally sized witness program with
// a 40-byte data push.
dustLimit := lnwallet.DustLimitForSize(input.UnknownWitnessSize)

return channeldb.ChannelConstraints{
DustLimit: dustLimit,
MaxAcceptedHtlcs: input.MaxHTLCNumber / 2,
}
return lnwallet.DustLimitForSize(input.UnknownWitnessSize)
}

// NewPartialChainControl creates a new partial chain control that contains all
Expand Down Expand Up @@ -788,9 +776,9 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
}

// Select the default channel constraints for the primary chain.
cc.ChannelConstraints = GenDefaultBtcConstraints()
cc.DefaultDustLimit = GenDefaultBtcDustLimit()
if cfg.PrimaryChain() == LitecoinChain {
cc.ChannelConstraints = DefaultLtcChannelConstraints
cc.DefaultDustLimit = DefaultLitecoinDustLimit
}

return cc, ccCleanup, nil
Expand Down
36 changes: 18 additions & 18 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,15 @@ func (d *DefaultWalletImpl) BuildChainControl(
// Create, and start the lnwallet, which handles the core payment
// channel logic, and exposes control via proxy state machines.
lnWalletConfig := lnwallet.Config{
Database: partialChainControl.Cfg.ChanStateDB,
Notifier: partialChainControl.ChainNotifier,
WalletController: walletController,
Signer: walletController,
FeeEstimator: partialChainControl.FeeEstimator,
SecretKeyRing: keyRing,
ChainIO: walletController,
DefaultConstraints: partialChainControl.ChannelConstraints,
NetParams: *walletConfig.NetParams,
Database: partialChainControl.Cfg.ChanStateDB,
Notifier: partialChainControl.ChainNotifier,
WalletController: walletController,
Signer: walletController,
FeeEstimator: partialChainControl.FeeEstimator,
SecretKeyRing: keyRing,
ChainIO: walletController,
DefaultDustLimit: partialChainControl.DefaultDustLimit,
NetParams: *walletConfig.NetParams,
}

// We've created the wallet configuration now, so we can finish
Expand Down Expand Up @@ -717,15 +717,15 @@ func (d *RPCSignerWalletImpl) BuildChainControl(
// Create, and start the lnwallet, which handles the core payment
// channel logic, and exposes control via proxy state machines.
lnWalletConfig := lnwallet.Config{
Database: partialChainControl.Cfg.ChanStateDB,
Notifier: partialChainControl.ChainNotifier,
WalletController: rpcKeyRing,
Signer: rpcKeyRing,
FeeEstimator: partialChainControl.FeeEstimator,
SecretKeyRing: rpcKeyRing,
ChainIO: walletController,
DefaultConstraints: partialChainControl.ChannelConstraints,
NetParams: *walletConfig.NetParams,
Database: partialChainControl.Cfg.ChanStateDB,
Notifier: partialChainControl.ChainNotifier,
WalletController: rpcKeyRing,
Signer: rpcKeyRing,
FeeEstimator: partialChainControl.FeeEstimator,
SecretKeyRing: rpcKeyRing,
ChainIO: walletController,
DefaultDustLimit: partialChainControl.DefaultDustLimit,
NetParams: *walletConfig.NetParams,
}

// We've created the wallet configuration now, so we can finish
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.16.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ certain large transactions](https://github.com/lightningnetwork/lnd/pull/7100).
of using a comma separated list of
values](https://github.com/lightningnetwork/lnd/pull/7207).

* [Fixed a validation bug in `channel_type`
negotiation](https://github.com/lightningnetwork/lnd/pull/7177).

## `lncli`

* [Add an `insecure` flag to skip tls auth as well as a `metadata` string slice
Expand Down Expand Up @@ -207,6 +210,9 @@ certain large transactions](https://github.com/lightningnetwork/lnd/pull/7100).

* [Fix loop and other temporary variables being accessed in
goroutines](https://github.com/lightningnetwork/lnd/pull/7188).

* [Simplify intial funding flow
logic](https://github.com/lightningnetwork/lnd/pull/7210).

## Watchtowers

Expand Down
66 changes: 36 additions & 30 deletions funding/commitment_type_negotiation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (
)

var (
// errUnsupportedExplicitNegotiation is an error returned when explicit
// channel commitment negotiation is attempted but either peer of the
// channel does not support it.
errUnsupportedExplicitNegotiation = errors.New("explicit channel " +
"type negotiation not supported")

// errUnsupportedCommitmentType is an error returned when a specific
// channel commitment type is being explicitly negotiated but either
// peer of the channel does not support it.
Expand All @@ -22,37 +16,49 @@ var (
)

// negotiateCommitmentType negotiates the commitment type of a newly opened
// channel. If a channelType is provided, explicit negotiation for said type
// 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. Two booleans are
// returned letting the caller know if the option-scid-alias or zero-conf
// channel types were negotiated.
func negotiateCommitmentType(channelType *lnwire.ChannelType, local,
remote *lnwire.FeatureVector, mustBeExplicit bool) (bool,
*lnwire.ChannelType, lnwallet.CommitmentType, error) {

if channelType != nil {
// If the peer does know explicit negotiation, let's attempt
// that now.
if hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
chanType, err := explicitNegotiateCommitmentType(
*channelType, local, remote,
// Otherwise, implicit negotiation will be attempted.
//
// The returned ChannelType is nil when implicit negotiation is used. An error
// is only returned if desiredChanType is not supported.
func negotiateCommitmentType(desiredChanType *lnwire.ChannelType, local,
remote *lnwire.FeatureVector) (*lnwire.ChannelType,
lnwallet.CommitmentType, error) {

// BOLT#2 specifies we MUST use explicit negotiation if both peers
// signal for it.
if hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
if desiredChanType != nil {
commitType, err := explicitNegotiateCommitmentType(
*desiredChanType, local, remote,
)
return true, channelType, chanType, err
}

// If we're the funder, and we are attempting to use an
// explicit channel type, but the remote party doesn't signal
// the bit, then we actually want to exit here, to ensure the
// user doesn't end up with an unexpected channel type via
// implicit negotiation.
if mustBeExplicit {
return false, nil, 0, errUnsupportedExplicitNegotiation
return desiredChanType, commitType, err
}

// Explicitly signal the "implicit" negotiation commitment type
// as default when a desired channel type isn't specified.
chanType, commitType := implicitNegotiateCommitmentType(local,
remote)

return chanType, commitType, nil
}

// Otherwise, we'll use implicit negotiation. In this case, we are
// restricted to the newest channel type advertised. If the passed-in
// channelType doesn't match what was advertised, we fail.
chanType, commitType := implicitNegotiateCommitmentType(local, remote)
return false, chanType, commitType, nil

if desiredChanType != nil {
expected := lnwire.RawFeatureVector(*desiredChanType)
actual := lnwire.RawFeatureVector(*chanType)
if !expected.Equals(&actual) {
return nil, 0, errUnsupportedChannelType
}
}

return nil, commitType, nil
}

// explicitNegotiateCommitmentType attempts to explicitly negotiate for a
Expand Down
Loading