@@ -195,15 +195,15 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
195
195
startWith(WAIT_FOR_INIT_INTERNAL , Nothing )
196
196
197
197
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 ) =>
199
199
context.system.eventStream.publish(ChannelCreated (self, peer, remoteNodeId, isFunder = true , temporaryChannelId, initialFeeratePerKw, Some (fundingTxFeeratePerKw)))
200
200
activeConnection = remote
201
201
txPublisher ! SetChannelId (remoteNodeId, temporaryChannelId)
202
202
val fundingPubKey = keyManager.fundingPublicKey(localParams.fundingKeyPath).publicKey
203
203
val channelKeyPath = keyManager.keyPath(localParams, channelConfig)
204
204
// In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script if this feature is not used
205
205
// 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
207
207
val open = OpenChannel (nodeParams.chainHash,
208
208
temporaryChannelId = temporaryChannelId,
209
209
fundingSatoshis = fundingSatoshis,
@@ -222,7 +222,10 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
222
222
htlcBasepoint = keyManager.htlcPoint(channelKeyPath).publicKey,
223
223
firstPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, 0 ),
224
224
channelFlags = channelFlags,
225
- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript)))
225
+ tlvStream = TlvStream (
226
+ ChannelTlv .UpfrontShutdownScriptTlv (localShutdownScript),
227
+ ChannelTlv .ChannelTypeTlv (channelType)
228
+ ))
226
229
goto(WAIT_FOR_ACCEPT_CHANNEL ) using DATA_WAIT_FOR_ACCEPT_CHANNEL (initFunder, open) sending open
227
230
228
231
case Event (inputFundee@ INPUT_INIT_FUNDEE (_, localParams, remote, _, _, _), Nothing ) if ! localParams.isFunder =>
@@ -337,18 +340,17 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
337
340
})
338
341
339
342
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 {
343
+ case Event (open : OpenChannel , d@ DATA_WAIT_FOR_OPEN_CHANNEL (INPUT_INIT_FUNDEE (_, localParams, _, remoteInit, channelConfig, channelType))) =>
344
+ Helpers .validateParamsFundee(nodeParams, channelType, localParams.initFeatures, open, remoteNodeId, remoteInit.features) match {
343
345
case Left (t) => handleLocalError(t, d, Some (open))
344
- case Right (remoteShutdownScript) =>
346
+ case Right ((channelFeatures, remoteShutdownScript) ) =>
345
347
context.system.eventStream.publish(ChannelCreated (self, peer, remoteNodeId, isFunder = false , open.temporaryChannelId, open.feeratePerKw, None ))
346
348
val fundingPubkey = keyManager.fundingPublicKey(localParams.fundingKeyPath).publicKey
347
349
val channelKeyPath = keyManager.keyPath(localParams, channelConfig)
348
350
val minimumDepth = Helpers .minDepthForFunding(nodeParams, open.fundingSatoshis)
349
351
// In order to allow TLV extensions and keep backwards-compatibility, we include an empty upfront_shutdown_script if this feature is not used.
350
352
// See https://github.com/lightningnetwork/lightning-rfc/pull/714.
351
- val localShutdownScript = if (channelFeatures.hasFeature( Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
353
+ val localShutdownScript = if (Features .canUseFeature(localParams.initFeatures, remoteInit.features, Features .OptionUpfrontShutdownScript )) localParams.defaultFinalScriptPubKey else ByteVector .empty
352
354
val accept = AcceptChannel (temporaryChannelId = open.temporaryChannelId,
353
355
dustLimitSatoshis = localParams.dustLimit,
354
356
maxHtlcValueInFlightMsat = localParams.maxHtlcValueInFlightMsat,
@@ -363,7 +365,10 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
363
365
delayedPaymentBasepoint = keyManager.delayedPaymentPoint(channelKeyPath).publicKey,
364
366
htlcBasepoint = keyManager.htlcPoint(channelKeyPath).publicKey,
365
367
firstPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, 0 ),
366
- tlvStream = TlvStream (ChannelTlv .UpfrontShutdownScript (localShutdownScript)))
368
+ tlvStream = TlvStream (
369
+ ChannelTlv .UpfrontShutdownScriptTlv (localShutdownScript),
370
+ ChannelTlv .ChannelTypeTlv (channelType)
371
+ ))
367
372
val remoteParams = RemoteParams (
368
373
nodeId = remoteNodeId,
369
374
dustLimit = open.dustLimitSatoshis,
@@ -391,11 +396,10 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
391
396
})
392
397
393
398
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 {
399
+ case Event (accept : AcceptChannel , d@ DATA_WAIT_FOR_ACCEPT_CHANNEL (INPUT_INIT_FUNDER (temporaryChannelId, fundingSatoshis, pushMsat, initialFeeratePerKw, fundingTxFeeratePerKw, localParams, _, remoteInit, _, channelConfig, channelType), open)) =>
400
+ Helpers .validateParamsFunder(nodeParams, channelType, localParams.initFeatures, remoteInit.features, open, accept) match {
397
401
case Left (t) => handleLocalError(t, d, Some (accept))
398
- case Right (remoteShutdownScript) =>
402
+ case Right ((channelFeatures, remoteShutdownScript) ) =>
399
403
val remoteParams = RemoteParams (
400
404
nodeId = remoteNodeId,
401
405
dustLimit = accept.dustLimitSatoshis,
@@ -889,7 +893,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
889
893
case Event (remoteShutdown@ Shutdown (_, remoteScriptPubKey, _), d : DATA_NORMAL ) =>
890
894
d.commitments.getRemoteShutdownScript(remoteScriptPubKey) match {
891
895
case Left (e) =>
892
- log.warning(" they sent an invalid closing script" )
896
+ log.warning(s " they sent an invalid closing script: ${e.getMessage} " )
893
897
context.system.scheduler.scheduleOnce(2 second, peer, Peer .Disconnect (remoteNodeId))
894
898
stay() sending Warning (d.channelId, " invalid closing script" )
895
899
case Right (remoteShutdownScript) =>
@@ -1681,7 +1685,7 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
1681
1685
val shutdownInProgress = d.localShutdown.nonEmpty || d.remoteShutdown.nonEmpty
1682
1686
if (d.commitments.localParams.isFunder && ! shutdownInProgress) {
1683
1687
val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
1684
- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, None )
1688
+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, None )
1685
1689
if (nodeParams.onChainFeeConf.shouldUpdateFee(currentFeeratePerKw, networkFeeratePerKw)) {
1686
1690
self ! CMD_UPDATE_FEE (networkFeeratePerKw, commit = true )
1687
1691
}
@@ -1972,11 +1976,11 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
1972
1976
}
1973
1977
1974
1978
private def handleCurrentFeerate (c : CurrentFeerates , d : HasCommitments ) = {
1975
- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, Some (c))
1979
+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, Some (c))
1976
1980
val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
1977
1981
val shouldUpdateFee = d.commitments.localParams.isFunder && nodeParams.onChainFeeConf.shouldUpdateFee(currentFeeratePerKw, networkFeeratePerKw)
1978
1982
val shouldClose = ! d.commitments.localParams.isFunder &&
1979
- nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelFeatures , networkFeeratePerKw, currentFeeratePerKw) &&
1983
+ nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelType , networkFeeratePerKw, currentFeeratePerKw) &&
1980
1984
d.commitments.hasPendingOrProposedHtlcs // we close only if we have HTLCs potentially at risk
1981
1985
if (shouldUpdateFee) {
1982
1986
self ! CMD_UPDATE_FEE (networkFeeratePerKw, commit = true )
@@ -1996,11 +2000,11 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
1996
2000
* @return
1997
2001
*/
1998
2002
private def handleOfflineFeerate (c : CurrentFeerates , d : HasCommitments ) = {
1999
- val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelFeatures , d.commitments.capacity, Some (c))
2003
+ val networkFeeratePerKw = nodeParams.onChainFeeConf.getCommitmentFeerate(remoteNodeId, d.commitments.channelType , d.commitments.capacity, Some (c))
2000
2004
val currentFeeratePerKw = d.commitments.localCommit.spec.feeratePerKw
2001
2005
// if the network fees are too high we risk to not be able to confirm our current commitment
2002
2006
val shouldClose = networkFeeratePerKw > currentFeeratePerKw &&
2003
- nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelFeatures , networkFeeratePerKw, currentFeeratePerKw) &&
2007
+ nodeParams.onChainFeeConf.feerateToleranceFor(d.commitments.remoteNodeId).isFeeDiffTooHigh(d.commitments.channelType , networkFeeratePerKw, currentFeeratePerKw) &&
2004
2008
d.commitments.hasPendingOrProposedHtlcs // we close only if we have HTLCs potentially at risk
2005
2009
if (shouldClose) {
2006
2010
if (nodeParams.onChainFeeConf.closeOnOfflineMismatch) {
0 commit comments