Skip to content

Commit f0461b4

Browse files
aaraniknocte
authored andcommitted
Add support for option_support_large_channel
This commit adds support for option_support_large_channel and there are some changes made to validation process; more specifically when validating our OpenChannel msg, instead of just sending out an Error if the funding_satoshis is greater than the limit, we check if support_large_channel is activated as mandatory (cause if we don't set that option as mandatory the openChannel will be invalid if sent to a peet with no support for support_large_channel) and also when we are validating someone else's openChannelMsg, we check that we have support_large_channel option activated (it doesn't matter if mandatory or optional). Upstream PR: joemphilips#174
1 parent 25c8ca9 commit f0461b4

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/DotNetLightning.Core/Channel/Channel.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module Channel =
170170
ShutdownScriptPubKey = cs.Config.ChannelOptions.ShutdownScriptPubKey
171171
}
172172
result {
173-
do! Validation.checkOurOpenChannelMsgAcceptable (cs.Config) openChannelMsgToSend
173+
do! Validation.checkOurOpenChannelMsgAcceptable cs.Config inputInitFunder.LocalParams openChannelMsgToSend
174174
return [
175175
NewOutboundChannelStarted(
176176
openChannelMsgToSend, {
@@ -293,8 +293,8 @@ module Channel =
293293
makeChannelReestablish cs.ChannelPrivKeys state
294294
| WaitForOpenChannel state, ApplyOpenChannel msg ->
295295
result {
296-
do! Validation.checkOpenChannelMsgAcceptable (cs.FeeEstimator) (cs.Config) msg
297296
let localParams = state.InitFundee.LocalParams
297+
do! Validation.checkOpenChannelMsgAcceptable cs.FeeEstimator cs.Config localParams msg
298298
let channelKeys = state.InitFundee.ChannelPrivKeys
299299
let localCommitmentPubKey = channelKeys.CommitmentSeed.DerivePerCommitmentPoint CommitmentNumber.FirstCommitment
300300
let acceptChannelMsg: AcceptChannelMsg = {

src/DotNetLightning.Core/Channel/ChannelError.fs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open NBitcoinExtensions
55
open DotNetLightning.Utils.OnionError
66
open DotNetLightning.Chain
77
open DotNetLightning.Crypto
8+
open DotNetLightning.Serialization
89
open DotNetLightning.Serialization.Msgs
910
open DotNetLightning.Transactions
1011

@@ -325,9 +326,21 @@ module internal OpenChannelMsgValidation =
325326
else
326327
Ok()
327328

328-
let checkFundingSatoshisLessThanMax (msg: OpenChannelMsg) =
329-
if (msg.FundingSatoshis >= ChannelConstants.MAX_FUNDING_SATOSHIS) then
330-
sprintf "funding_satoshis must be less than %A. It was %A" ChannelConstants.MAX_FUNDING_SATOSHIS msg.FundingSatoshis
329+
let checkFundingSatoshisLessThanMax (localParams: LocalParams) (isOurOpenChannelMsg: bool) (msg: OpenChannelMsg) =
330+
// If we are validating our own open message we make sure we are forcing support for option_support_large_channel on the other peer
331+
let featureType =
332+
match isOurOpenChannelMsg with
333+
| true ->
334+
Some FeaturesSupport.Mandatory
335+
| false ->
336+
None
337+
338+
if msg.FundingSatoshis >= ChannelConstants.MAX_FUNDING_SATOSHIS &&
339+
not (localParams.Features.HasFeature (Feature.OptionSupportLargeChannel, ?featureType = featureType)) then
340+
sprintf
341+
"funding_satoshis must be less than %A. It was %A, consider activating option_support_large_channel feature."
342+
ChannelConstants.MAX_FUNDING_SATOSHIS
343+
msg.FundingSatoshis
331344
|> Error
332345
else
333346
Ok()

src/DotNetLightning.Core/Channel/ChannelValidation.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,18 @@ module internal ChannelHelpers =
161161
module internal Validation =
162162

163163
open DotNetLightning.Channel
164-
let checkOurOpenChannelMsgAcceptable (_conf: ChannelConfig) (msg: OpenChannelMsg) =
165-
Validation.ofResult(OpenChannelMsgValidation.checkFundingSatoshisLessThanMax msg)
164+
let checkOurOpenChannelMsgAcceptable (_conf: ChannelConfig) (localParams: LocalParams) (msg: OpenChannelMsg) =
165+
Validation.ofResult(OpenChannelMsgValidation.checkFundingSatoshisLessThanMax localParams true msg)
166166
*^> OpenChannelMsgValidation.checkChannelReserveSatohisLessThanFundingSatoshis msg
167167
*^> OpenChannelMsgValidation.checkPushMSatLesserThanFundingValue msg
168168
*^> OpenChannelMsgValidation.checkFundingSatoshisLessThanDustLimitSatoshis msg
169169
*^> OpenChannelMsgValidation.checkMaxAcceptedHTLCs msg
170170
*^> OpenChannelMsgValidation.checkFunderCanAffordFee (msg.FeeRatePerKw) msg
171171
|> Result.mapError((@)["open_channel msg is invalid"] >> InvalidOpenChannelError.Create msg >> InvalidOpenChannel)
172172

173-
let internal checkOpenChannelMsgAcceptable (feeEstimator: IFeeEstimator) (conf: ChannelConfig) (msg: OpenChannelMsg) =
173+
let internal checkOpenChannelMsgAcceptable (feeEstimator: IFeeEstimator) (conf: ChannelConfig) (localParams: LocalParams) (msg: OpenChannelMsg) =
174174
let feeRate = feeEstimator.GetEstSatPer1000Weight(ConfirmationTarget.Background)
175-
Validation.ofResult(OpenChannelMsgValidation.checkFundingSatoshisLessThanMax msg)
175+
Validation.ofResult(OpenChannelMsgValidation.checkFundingSatoshisLessThanMax localParams false msg)
176176
*^> OpenChannelMsgValidation.checkChannelReserveSatohisLessThanFundingSatoshis msg
177177
*^> OpenChannelMsgValidation.checkPushMSatLesserThanFundingValue msg
178178
*^> OpenChannelMsgValidation.checkFundingSatoshisLessThanDustLimitSatoshis msg

src/DotNetLightning.Core/Serialization/Features.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ module internal Feature =
142142
yield Feature.PaymentSecret
143143
// TODO: support this feature
144144
// Feature.BasicMultiPartPayment
145+
yield Feature.OptionSupportLargeChannel
145146
}
146147
|> Seq.map(fun f -> f.Mandatory)
147148
|> Set

tests/DotNetLightning.Core.Tests/Serialization.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ module SerializationTest =
834834
1L <<< Feature.BasicMultiPartPayment.MandatoryBitPosition, false
835835
1L <<< Feature.BasicMultiPartPayment.OptionalBitPosition, true
836836

837-
1L <<< Feature.OptionSupportLargeChannel.MandatoryBitPosition, false
837+
1L <<< Feature.OptionSupportLargeChannel.MandatoryBitPosition, true
838838
1L <<< Feature.OptionSupportLargeChannel.OptionalBitPosition, true
839839
]
840840
for (s, expected) in testCases do
@@ -860,8 +860,9 @@ module SerializationTest =
860860
// unknown optional feature bits
861861
|> Map.add " 10000000000000000000" true
862862
|> Map.add " 001000000000000000000000" true
863+
// support_large_channel_option(mandatory)
864+
|> Map.add " 000001000000000000000000" true
863865
// those are useful for nonreg testing of the areSupported method (which needs to be updated with every new supported mandatory bit)
864-
|> Map.add " 000001000000000000000000" false
865866
|> Map.add " 000100000000000000000000" false
866867
|> Map.add " 010000000000000000000000" false
867868
|> Map.add " 0001000000000000000000000000" false

0 commit comments

Comments
 (0)