@@ -195,7 +195,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
195195 startWith(WAIT_FOR_INIT_INTERNAL , Nothing )
196196
197197 when(WAIT_FOR_INIT_INTERNAL )(handleExceptions {
198- case Event (initFunder@ INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, _, localParams, remote, _, channelFlags, channelConfig, _ ), Nothing ) =>
198+ case Event (initFunder@ INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, _, localParams, remote, _, channelFlags, channelConfig, channelFeatures ), Nothing ) =>
199199 context.system.eventStream.publish(ChannelCreated (self, peer, remoteNodeId, isFunder = true , temporaryChannelId, initialFeeratePerKw, Some (fundingTxFeeratePerKw)))
200200 activeConnection = remote
201201 txPublisher ! SetChannelId (remoteNodeId, temporaryChannelId)
@@ -221,7 +221,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
221221 channelFlags = channelFlags,
222222 // In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script.
223223 // See https://github.com/lightningnetwork/lightning-rfc/pull/714.
224- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (ByteVector .empty)))
224+ tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (ByteVector .empty), ChannelTlv . ChannelType (channelFeatures.channelType.features) ))
225225 goto(WAIT_FOR_ACCEPT_CHANNEL ) using DATA_WAIT_FOR_ACCEPT_CHANNEL (initFunder, open) sending open
226226
227227 case Event (inputFundee@ INPUT_INIT_FUNDEE (_, localParams, remote, _, _, _), Nothing ) if ! localParams.isFunder =>
@@ -362,7 +362,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
362362 firstPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, 0 ),
363363 // In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script.
364364 // See https://github.com/lightningnetwork/lightning-rfc/pull/714.
365- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (ByteVector .empty)))
365+ tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (ByteVector .empty), ChannelTlv . ChannelType (channelFeatures.channelType.features) ))
366366 val remoteParams = RemoteParams (
367367 nodeId = remoteNodeId,
368368 dustLimit = open.dustLimitSatoshis,
@@ -395,26 +395,40 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
395395 Helpers .validateParamsFunder(nodeParams, open, accept) match {
396396 case Left (t) => handleLocalError(t, d, Some (accept))
397397 case _ =>
398- val remoteParams = RemoteParams (
399- nodeId = remoteNodeId,
400- dustLimit = accept.dustLimitSatoshis,
401- maxHtlcValueInFlightMsat = accept.maxHtlcValueInFlightMsat,
402- channelReserve = accept.channelReserveSatoshis, // remote requires local to keep this much satoshis as direct payment
403- htlcMinimum = accept.htlcMinimumMsat,
404- toSelfDelay = accept.toSelfDelay,
405- maxAcceptedHtlcs = accept.maxAcceptedHtlcs,
406- fundingPubKey = accept.fundingPubkey,
407- revocationBasepoint = accept.revocationBasepoint,
408- paymentBasepoint = accept.paymentBasepoint,
409- delayedPaymentBasepoint = accept.delayedPaymentBasepoint,
410- htlcBasepoint = accept.htlcBasepoint,
411- features = remoteInit.features,
412- shutdownScript = None )
413- log.debug(" remote params: {}" , remoteParams)
414- val localFundingPubkey = keyManager.fundingPublicKey(localParams.fundingKeyPath)
415- val fundingPubkeyScript = Script .write(Script .pay2wsh(Scripts .multiSig2of2(localFundingPubkey.publicKey, remoteParams.fundingPubKey)))
416- wallet.makeFundingTx(fundingPubkeyScript, fundingSatoshis, fundingTxFeeratePerKw).pipeTo(self)
417- goto(WAIT_FOR_FUNDING_INTERNAL ) using DATA_WAIT_FOR_FUNDING_INTERNAL (temporaryChannelId, localParams, remoteParams, fundingSatoshis, pushMsat, initialFeeratePerKw, initialRelayFees_opt, accept.firstPerCommitmentPoint, channelConfig, channelFeatures, open)
398+ // If we have overridden the default channel type, but they didn't support explicit channel type negotiation,
399+ // we need to abort because they expect a different channel type than what we offered.
400+ val channelTypeOk = (open.channelType_opt, accept.channelType_opt) match {
401+ case (Some (proposedChannelType), None ) =>
402+ val channelTypeTheyExpect = ChannelTypes .pickChannelType(localParams.features, remoteInit.features)
403+ channelTypeTheyExpect.features == proposedChannelType
404+ case _ => true
405+ }
406+ if (! channelTypeOk) {
407+ log.warning(" open channel cancelled, peer doesn't support explicit channel type negotiation" )
408+ channelOpenReplyToUser(Left (LocalError (new RuntimeException (" open channel cancelled, peer doesn't support explicit channel type negotiation" ))))
409+ goto(CLOSED ) sending Error (accept.temporaryChannelId, " explicit channel type negotiation not supported" )
410+ } else {
411+ val remoteParams = RemoteParams (
412+ nodeId = remoteNodeId,
413+ dustLimit = accept.dustLimitSatoshis,
414+ maxHtlcValueInFlightMsat = accept.maxHtlcValueInFlightMsat,
415+ channelReserve = accept.channelReserveSatoshis, // remote requires local to keep this much satoshis as direct payment
416+ htlcMinimum = accept.htlcMinimumMsat,
417+ toSelfDelay = accept.toSelfDelay,
418+ maxAcceptedHtlcs = accept.maxAcceptedHtlcs,
419+ fundingPubKey = accept.fundingPubkey,
420+ revocationBasepoint = accept.revocationBasepoint,
421+ paymentBasepoint = accept.paymentBasepoint,
422+ delayedPaymentBasepoint = accept.delayedPaymentBasepoint,
423+ htlcBasepoint = accept.htlcBasepoint,
424+ features = remoteInit.features,
425+ shutdownScript = None )
426+ log.debug(" remote params: {}" , remoteParams)
427+ val localFundingPubkey = keyManager.fundingPublicKey(localParams.fundingKeyPath)
428+ val fundingPubkeyScript = Script .write(Script .pay2wsh(Scripts .multiSig2of2(localFundingPubkey.publicKey, remoteParams.fundingPubKey)))
429+ wallet.makeFundingTx(fundingPubkeyScript, fundingSatoshis, fundingTxFeeratePerKw).pipeTo(self)
430+ goto(WAIT_FOR_FUNDING_INTERNAL ) using DATA_WAIT_FOR_FUNDING_INTERNAL (temporaryChannelId, localParams, remoteParams, fundingSatoshis, pushMsat, initialFeeratePerKw, initialRelayFees_opt, accept.firstPerCommitmentPoint, channelConfig, channelFeatures, open)
431+ }
418432 }
419433
420434 case Event (c : CloseCommand , d : DATA_WAIT_FOR_ACCEPT_CHANNEL ) =>
0 commit comments