@@ -195,15 +195,15 @@ 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, channelFeatures ), Nothing ) =>
198+ case Event (initFunder@ INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, localParams, remote, remoteInit , channelFlags, channelConfig, channelType ), Nothing ) =>
199199 context.system.eventStream.publish(ChannelCreated (self, peer, remoteNodeId, isFunder = true , temporaryChannelId, initialFeeratePerKw, Some (fundingTxFeeratePerKw)))
200200 activeConnection = remote
201201 txPublisher ! SetChannelId (remoteNodeId, temporaryChannelId)
202202 val fundingPubKey = keyManager.fundingPublicKey(localParams.fundingKeyPath).publicKey
203203 val channelKeyPath = keyManager.keyPath(localParams, channelConfig)
204204 // In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script if this feature is not used
205205 // See https://github.com/lightningnetwork/lightning-rfc/pull/714.
206- val localShutdownScript = if (channelFeatures.hasFeature( Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
206+ val localShutdownScript = if (Features .canUseFeature(localParams.initFeatures, remoteInit.features, Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
207207 val open = OpenChannel (nodeParams.chainHash,
208208 temporaryChannelId = temporaryChannelId,
209209 fundingSatoshis = fundingSatoshis,
@@ -222,7 +222,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
222222 htlcBasepoint = keyManager.htlcPoint(channelKeyPath).publicKey,
223223 firstPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, 0 ),
224224 channelFlags = channelFlags,
225- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript)))
225+ tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript), ChannelTlv . ChannelType (channelType.features) ))
226226 goto(WAIT_FOR_ACCEPT_CHANNEL ) using DATA_WAIT_FOR_ACCEPT_CHANNEL (initFunder, open) sending open
227227
228228 case Event (inputFundee@ INPUT_INIT_FUNDEE (_, localParams, remote, _, _, _), Nothing ) if ! localParams.isFunder =>
@@ -337,18 +337,17 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
337337 })
338338
339339 when(WAIT_FOR_OPEN_CHANNEL )(handleExceptions {
340- case Event (open : OpenChannel , d@ DATA_WAIT_FOR_OPEN_CHANNEL (INPUT_INIT_FUNDEE (_, localParams, _, remoteInit, channelConfig, channelFeatures))) =>
341- log.info(" received OpenChannel={}" , open)
342- Helpers .validateParamsFundee(nodeParams, localParams.initFeatures, channelFeatures, open, remoteNodeId) match {
340+ case Event (open : OpenChannel , d@ DATA_WAIT_FOR_OPEN_CHANNEL (INPUT_INIT_FUNDEE (_, localParams, _, remoteInit, channelConfig, channelType))) =>
341+ Helpers .validateParamsFundee(nodeParams, localParams.initFeatures, channelType, open, remoteNodeId, remoteInit.features) match {
343342 case Left (t) => handleLocalError(t, d, Some (open))
344- case Right (remoteShutdownScript) =>
343+ case Right ((channelFeatures, remoteShutdownScript) ) =>
345344 context.system.eventStream.publish(ChannelCreated (self, peer, remoteNodeId, isFunder = false , open.temporaryChannelId, open.feeratePerKw, None ))
346345 val fundingPubkey = keyManager.fundingPublicKey(localParams.fundingKeyPath).publicKey
347346 val channelKeyPath = keyManager.keyPath(localParams, channelConfig)
348347 val minimumDepth = Helpers .minDepthForFunding(nodeParams, open.fundingSatoshis)
349348 // In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script if this feature is not used.
350349 // See https://github.com/lightningnetwork/lightning-rfc/pull/714.
351- val localShutdownScript = if (channelFeatures.hasFeature( Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
350+ val localShutdownScript = if (Features .canUseFeature(localParams.initFeatures, remoteInit.features, Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
352351 val accept = AcceptChannel (temporaryChannelId = open.temporaryChannelId,
353352 dustLimitSatoshis = localParams.dustLimit,
354353 maxHtlcValueInFlightMsat = localParams.maxHtlcValueInFlightMsat,
@@ -363,7 +362,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
363362 delayedPaymentBasepoint = keyManager.delayedPaymentPoint(channelKeyPath).publicKey,
364363 htlcBasepoint = keyManager.htlcPoint(channelKeyPath).publicKey,
365364 firstPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, 0 ),
366- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript)))
365+ tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript), ChannelTlv . ChannelType (channelType.features) ))
367366 val remoteParams = RemoteParams (
368367 nodeId = remoteNodeId,
369368 dustLimit = open.dustLimitSatoshis,
@@ -391,11 +390,10 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
391390 })
392391
393392 when(WAIT_FOR_ACCEPT_CHANNEL )(handleExceptions {
394- case Event (accept : AcceptChannel , d@ DATA_WAIT_FOR_ACCEPT_CHANNEL (INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, localParams, _, remoteInit, _, channelConfig, channelFeatures), open)) =>
395- log.info(s " received AcceptChannel= $accept" )
396- Helpers .validateParamsFunder(nodeParams, channelFeatures, open, accept) match {
393+ case Event (accept : AcceptChannel , d@ DATA_WAIT_FOR_ACCEPT_CHANNEL (INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, localParams, _, remoteInit, _, channelConfig, channelType), open)) =>
394+ Helpers .validateParamsFunder(nodeParams, channelType, localParams.initFeatures, remoteInit.features, open, accept) match {
397395 case Left (t) => handleLocalError(t, d, Some (accept))
398- case Right (remoteShutdownScript) =>
396+ case Right ((channelFeatures, remoteShutdownScript) ) =>
399397 val remoteParams = RemoteParams (
400398 nodeId = remoteNodeId,
401399 dustLimit = accept.dustLimitSatoshis,
@@ -1681,7 +1679,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
16811679 val shutdownInProgress = d.localShutdown.nonEmpty || d.remoteShutdown.nonEmpty
16821680 if (d.commitments.localParams.isFunder && ! shutdownInProgress) {
16831681 val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
1684- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, None )
1682+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, None )
16851683 if (nodeParams.onChainFeeConf.shouldUpdateFee(currentFeeratePerKw, networkFeeratePerKw)) {
16861684 self ! CMD_UPDATE_FEE (networkFeeratePerKw, commit = true )
16871685 }
@@ -1972,11 +1970,11 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
19721970 }
19731971
19741972 private def handleCurrentFeerate (c : CurrentFeerates , d : HasCommitments ) = {
1975- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, Some (c))
1973+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, Some (c))
19761974 val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
19771975 val shouldUpdateFee = d.commitments.localParams.isFunder && nodeParams.onChainFeeConf.shouldUpdateFee(currentFeeratePerKw, networkFeeratePerKw)
19781976 val shouldClose = ! d.commitments.localParams.isFunder &&
1979- nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelFeatures , networkFeeratePerKw, currentFeeratePerKw) &&
1977+ nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelType , networkFeeratePerKw, currentFeeratePerKw) &&
19801978 d.commitments.hasPendingOrProposedHtlcs // we close only if we have HTLCs potentially at risk
19811979 if (shouldUpdateFee) {
19821980 self ! CMD_UPDATE_FEE (networkFeeratePerKw, commit = true )
@@ -1996,11 +1994,11 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
19961994 * @return
19971995 */
19981996 private def handleOfflineFeerate (c : CurrentFeerates , d : HasCommitments ) = {
1999- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, Some (c))
1997+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, Some (c))
20001998 val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
20011999 // if the network fees are too high we risk to not be able to confirm our current commitment
20022000 val shouldClose = networkFeeratePerKw > currentFeeratePerKw &&
2003- nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelFeatures , networkFeeratePerKw, currentFeeratePerKw) &&
2001+ nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelType , networkFeeratePerKw, currentFeeratePerKw) &&
20042002 d.commitments.hasPendingOrProposedHtlcs // we close only if we have HTLCs potentially at risk
20052003 if (shouldClose) {
20062004 if (nodeParams.onChainFeeConf.closeOnOfflineMismatch) {
0 commit comments