rpcserver: use protocol max for fundMax, not maxChanSize
The maxChanSize config option is documented to only apply to incoming channel requests. However, when using fundMax with OpenChannel, the code was incorrectly using maxChanSize as the upper bound for the outgoing channel size. This commit fixes the issue by using the protocol-level maximum (MaxBtcFundingAmount or MaxBtcFundingAmountWumbo depending on wumbo support) as the upper bound for fundMax operations. Fixes #10468.
This commit is contained in:
1 file changed
+15
-9
+15
-9
@@ -2152,15 +2152,26 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
"the channel opening")
|
"the channel opening")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch our own feature set and determine wumbo support early, as it's
|
||||||
|
// needed for both FundMax and explicit amount validation.
|
||||||
|
globalFeatureSet := r.server.featureMgr.Get(feature.SetNodeAnn)
|
||||||
|
wumboEnabled := globalFeatureSet.HasFeature(
|
||||||
|
lnwire.WumboChannelsOptional,
|
||||||
|
)
|
||||||
|
|
||||||
// If the FundMax flag is set, ensure that the acceptable minimum local
|
// If the FundMax flag is set, ensure that the acceptable minimum local
|
||||||
// amount adheres to the amount to be pushed to the remote, and to
|
// amount adheres to the amount to be pushed to the remote, and to
|
||||||
// current rules, while also respecting the settings for the maximum
|
// current rules, while also respecting the protocol-level maximum
|
||||||
// channel size.
|
// channel size.
|
||||||
var minFundAmt, fundUpToMaxAmt btcutil.Amount
|
var minFundAmt, fundUpToMaxAmt btcutil.Amount
|
||||||
if in.FundMax {
|
if in.FundMax {
|
||||||
// We assume the configured maximum channel size to be the upper
|
// Use the protocol-level maximum as the upper bound for our
|
||||||
// bound of our "maxed" out funding attempt.
|
// funding attempt.
|
||||||
fundUpToMaxAmt = btcutil.Amount(r.cfg.MaxChanSize)
|
if wumboEnabled {
|
||||||
|
fundUpToMaxAmt = funding.MaxBtcFundingAmountWumbo
|
||||||
|
} else {
|
||||||
|
fundUpToMaxAmt = MaxFundingAmount
|
||||||
|
}
|
||||||
|
|
||||||
// Since the standard non-fundmax flow requires the minimum
|
// Since the standard non-fundmax flow requires the minimum
|
||||||
// funding amount to be at least in the amount of the initial
|
// funding amount to be at least in the amount of the initial
|
||||||
@@ -2186,8 +2197,6 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
maxHtlcs := uint16(in.RemoteMaxHtlcs)
|
maxHtlcs := uint16(in.RemoteMaxHtlcs)
|
||||||
remoteChanReserve := btcutil.Amount(in.RemoteChanReserveSat)
|
remoteChanReserve := btcutil.Amount(in.RemoteChanReserveSat)
|
||||||
|
|
||||||
globalFeatureSet := r.server.featureMgr.Get(feature.SetNodeAnn)
|
|
||||||
|
|
||||||
// Determine if the user provided channel fees
|
// Determine if the user provided channel fees
|
||||||
// and if so pass them on to the funding workflow.
|
// and if so pass them on to the funding workflow.
|
||||||
var channelBaseFee, channelFeeRate *uint64
|
var channelBaseFee, channelFeeRate *uint64
|
||||||
@@ -2212,9 +2221,6 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
// in the wallet hence we do not check it here against the maximum
|
// in the wallet hence we do not check it here against the maximum
|
||||||
// funding amount. Only if the localFundingAmt is specified we can check
|
// funding amount. Only if the localFundingAmt is specified we can check
|
||||||
// if it exceeds the maximum funding amount.
|
// if it exceeds the maximum funding amount.
|
||||||
wumboEnabled := globalFeatureSet.HasFeature(
|
|
||||||
lnwire.WumboChannelsOptional,
|
|
||||||
)
|
|
||||||
if !in.FundMax && !wumboEnabled && localFundingAmt > MaxFundingAmount {
|
if !in.FundMax && !wumboEnabled && localFundingAmt > MaxFundingAmount {
|
||||||
return nil, fmt.Errorf("funding amount is too large, the max "+
|
return nil, fmt.Errorf("funding amount is too large, the max "+
|
||||||
"channel size is: %v", MaxFundingAmount)
|
"channel size is: %v", MaxFundingAmount)
|
||||||
|
|||||||
Reference in new issue
Block a user