File tree Expand file tree Collapse file tree 5 files changed +26
-11
lines changed
tests/DotNetLightning.Core.Tests Expand file tree Collapse file tree 5 files changed +26
-11
lines changed Original file line number Diff line number Diff 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 = {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ open NBitcoinExtensions
55open DotNetLightning.Utils .OnionError
66open DotNetLightning.Chain
77open DotNetLightning.Crypto
8+ open DotNetLightning.Serialization
89open DotNetLightning.Serialization .Msgs
910open 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()
Original file line number Diff line number Diff line change @@ -161,18 +161,18 @@ module internal ChannelHelpers =
161161module 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -834,7 +834,7 @@ module SerializationTest =
834834 1 L <<< Feature.BasicMultiPartPayment.MandatoryBitPosition, false
835835 1 L <<< Feature.BasicMultiPartPayment.OptionalBitPosition, true
836836
837- 1 L <<< Feature.OptionSupportLargeChannel.MandatoryBitPosition, false
837+ 1 L <<< Feature.OptionSupportLargeChannel.MandatoryBitPosition, true
838838 1 L <<< 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
You can’t perform that action at this time.
0 commit comments