@@ -320,7 +320,7 @@ case class Commitment(fundingTxIndex: Long,
320320 val remoteCommit1 = nextRemoteCommit_opt.map(_.commit).getOrElse(remoteCommit)
321321 val reduced = CommitmentSpec .reduce(remoteCommit1.spec, changes.remoteChanges.acked, changes.localChanges.proposed)
322322 val balanceNoFees = (reduced.toRemote - localChannelReserve(params)).max(0 msat)
323- if (localParams.isInitiator ) {
323+ if (localParams.payCommitTxFees ) {
324324 // The initiator always pays the on-chain fees, so we must subtract that from the amount we can send.
325325 val commitFees = commitTxTotalCostMsat(remoteParams.dustLimit, reduced, commitmentFormat)
326326 // the initiator needs to keep a "funder fee buffer" (see explanation above)
@@ -347,7 +347,7 @@ case class Commitment(fundingTxIndex: Long,
347347 import params ._
348348 val reduced = CommitmentSpec .reduce(localCommit.spec, changes.localChanges.acked, changes.remoteChanges.proposed)
349349 val balanceNoFees = (reduced.toRemote - remoteChannelReserve(params)).max(0 msat)
350- if (localParams.isInitiator ) {
350+ if (localParams.payCommitTxFees ) {
351351 // The non-initiator doesn't pay on-chain fees so we don't take those into account when receiving.
352352 balanceNoFees
353353 } else {
@@ -456,12 +456,12 @@ case class Commitment(fundingTxIndex: Long,
456456 val funderFeeBuffer = commitTxTotalCostMsat(params.remoteParams.dustLimit, reduced.copy(commitTxFeerate = reduced.commitTxFeerate * 2 ), params.commitmentFormat) + htlcOutputFee(reduced.commitTxFeerate * 2 , params.commitmentFormat)
457457 // NB: increasing the feerate can actually remove htlcs from the commit tx (if they fall below the trim threshold)
458458 // which may result in a lower commit tx fee; this is why we take the max of the two.
459- val missingForSender = reduced.toRemote - localChannelReserve(params) - (if (params.localParams.isInitiator ) fees.max(funderFeeBuffer.truncateToSatoshi) else 0 .sat)
460- val missingForReceiver = reduced.toLocal - remoteChannelReserve(params) - (if (params.localParams.isInitiator ) 0 .sat else fees)
459+ val missingForSender = reduced.toRemote - localChannelReserve(params) - (if (params.localParams.payCommitTxFees ) fees.max(funderFeeBuffer.truncateToSatoshi) else 0 .sat)
460+ val missingForReceiver = reduced.toLocal - remoteChannelReserve(params) - (if (params.localParams.payCommitTxFees ) 0 .sat else fees)
461461 if (missingForSender < 0 .msat) {
462- return Left (InsufficientFunds (params.channelId, amount = amount, missing = - missingForSender.truncateToSatoshi, reserve = localChannelReserve(params), fees = if (params.localParams.isInitiator ) fees else 0 .sat))
462+ return Left (InsufficientFunds (params.channelId, amount = amount, missing = - missingForSender.truncateToSatoshi, reserve = localChannelReserve(params), fees = if (params.localParams.payCommitTxFees ) fees else 0 .sat))
463463 } else if (missingForReceiver < 0 .msat) {
464- if (params.localParams.isInitiator ) {
464+ if (params.localParams.payCommitTxFees ) {
465465 // receiver is not the channel initiator; it is ok if it can't maintain its channel_reserve for now, as long as its balance is increasing, which is the case if it is receiving a payment
466466 } else if (reduced.toLocal > fees && reduced.htlcs.size < 5 && fundingTxIndex > 0 ) {
467467 // Receiver is the channel initiator; we usually don't want to let them dip into their channel reserve, because
@@ -527,15 +527,15 @@ case class Commitment(fundingTxIndex: Long,
527527 val fees = commitTxTotalCost(params.localParams.dustLimit, reduced, params.commitmentFormat)
528528 // NB: we don't enforce the funderFeeReserve (see sendAdd) because it would confuse a remote initiator that doesn't have this mitigation in place
529529 // We could enforce it once we're confident a large portion of the network implements it.
530- val missingForSender = reduced.toRemote - remoteChannelReserve(params) - (if (params.localParams.isInitiator ) 0 .sat else fees)
530+ val missingForSender = reduced.toRemote - remoteChannelReserve(params) - (if (params.localParams.payCommitTxFees ) 0 .sat else fees)
531531 // Note that Bolt 2 requires to also meet our channel reserve requirement, but we're more lenient than that because
532532 // as long as we're able to pay the commit tx fee, it's ok if we dip into our channel reserve: we're receiving an
533533 // HTLC, which means our balance will increase and meet the channel reserve again.
534- val missingForReceiver = reduced.toLocal - (if (params.localParams.isInitiator ) fees else 0 .sat)
534+ val missingForReceiver = reduced.toLocal - (if (params.localParams.payCommitTxFees ) fees else 0 .sat)
535535 if (missingForSender < 0 .sat) {
536- return Left (InsufficientFunds (params.channelId, amount = amount, missing = - missingForSender.truncateToSatoshi, reserve = remoteChannelReserve(params), fees = if (params.localParams.isInitiator ) 0 .sat else fees))
536+ return Left (InsufficientFunds (params.channelId, amount = amount, missing = - missingForSender.truncateToSatoshi, reserve = remoteChannelReserve(params), fees = if (params.localParams.payCommitTxFees ) 0 .sat else fees))
537537 } else if (missingForReceiver < 0 .sat) {
538- if (params.localParams.isInitiator ) {
538+ if (params.localParams.payCommitTxFees ) {
539539 return Left (CannotAffordFees (params.channelId, missing = - missingForReceiver.truncateToSatoshi, reserve = localChannelReserve(params), fees = fees))
540540 } else {
541541 // receiver is not the channel initiator; it is ok if it can't maintain its channel_reserve for now, as long as its balance is increasing, which is the case if it is receiving a payment
@@ -699,8 +699,8 @@ object Commitment {
699699 val remoteHtlcPubkey = Generators .derivePubKey(remoteParams.htlcBasepoint, localPerCommitmentPoint)
700700 val localRevocationPubkey = Generators .revocationPubKey(remoteParams.revocationBasepoint, localPerCommitmentPoint)
701701 val localPaymentBasepoint = localParams.walletStaticPaymentBasepoint.getOrElse(keyManager.paymentPoint(channelKeyPath).publicKey)
702- val outputs = makeCommitTxOutputs(localParams.isInitiator , localParams.dustLimit, localRevocationPubkey, remoteParams.toSelfDelay, localDelayedPaymentPubkey, remotePaymentPubkey, localHtlcPubkey, remoteHtlcPubkey, localFundingPubkey, remoteFundingPubKey, spec, channelFeatures.commitmentFormat)
703- val commitTx = makeCommitTx(commitmentInput, commitTxNumber, localPaymentBasepoint, remoteParams.paymentBasepoint, localParams.isInitiator , outputs)
702+ val outputs = makeCommitTxOutputs(localParams.payCommitTxFees , localParams.dustLimit, localRevocationPubkey, remoteParams.toSelfDelay, localDelayedPaymentPubkey, remotePaymentPubkey, localHtlcPubkey, remoteHtlcPubkey, localFundingPubkey, remoteFundingPubKey, spec, channelFeatures.commitmentFormat)
703+ val commitTx = makeCommitTx(commitmentInput, commitTxNumber, localPaymentBasepoint, remoteParams.paymentBasepoint, localParams.isChannelOpener , outputs)
704704 val htlcTxs = makeHtlcTxs(commitTx.tx, localParams.dustLimit, localRevocationPubkey, remoteParams.toSelfDelay, localDelayedPaymentPubkey, spec.htlcTxFeerate(channelFeatures.commitmentFormat), outputs, channelFeatures.commitmentFormat)
705705 (commitTx, htlcTxs)
706706 }
@@ -728,8 +728,8 @@ object Commitment {
728728 val remoteDelayedPaymentPubkey = Generators .derivePubKey(remoteParams.delayedPaymentBasepoint, remotePerCommitmentPoint)
729729 val remoteHtlcPubkey = Generators .derivePubKey(remoteParams.htlcBasepoint, remotePerCommitmentPoint)
730730 val remoteRevocationPubkey = Generators .revocationPubKey(keyManager.revocationPoint(channelKeyPath).publicKey, remotePerCommitmentPoint)
731- val outputs = makeCommitTxOutputs(! localParams.isInitiator , remoteParams.dustLimit, remoteRevocationPubkey, localParams.toSelfDelay, remoteDelayedPaymentPubkey, localPaymentPubkey, remoteHtlcPubkey, localHtlcPubkey, remoteFundingPubKey, localFundingPubkey, spec, channelFeatures.commitmentFormat)
732- val commitTx = makeCommitTx(commitmentInput, commitTxNumber, remoteParams.paymentBasepoint, localPaymentBasepoint, ! localParams.isInitiator , outputs)
731+ val outputs = makeCommitTxOutputs(! localParams.payCommitTxFees , remoteParams.dustLimit, remoteRevocationPubkey, localParams.toSelfDelay, remoteDelayedPaymentPubkey, localPaymentPubkey, remoteHtlcPubkey, localHtlcPubkey, remoteFundingPubKey, localFundingPubkey, spec, channelFeatures.commitmentFormat)
732+ val commitTx = makeCommitTx(commitmentInput, commitTxNumber, remoteParams.paymentBasepoint, localPaymentBasepoint, ! localParams.isChannelOpener , outputs)
733733 val htlcTxs = makeHtlcTxs(commitTx.tx, remoteParams.dustLimit, remoteRevocationPubkey, localParams.toSelfDelay, remoteDelayedPaymentPubkey, spec.htlcTxFeerate(channelFeatures.commitmentFormat), outputs, channelFeatures.commitmentFormat)
734734 (commitTx, htlcTxs)
735735 }
@@ -960,7 +960,7 @@ case class Commitments(params: ChannelParams,
960960 }
961961
962962 def sendFee (cmd : CMD_UPDATE_FEE , feeConf : OnChainFeeConf ): Either [ChannelException , (Commitments , UpdateFee )] = {
963- if (! params.localParams.isInitiator ) {
963+ if (! params.localParams.payCommitTxFees ) {
964964 Left (NonInitiatorCannotSendUpdateFee (channelId))
965965 } else {
966966 val fee = UpdateFee (channelId, cmd.feeratePerKw)
@@ -976,7 +976,7 @@ case class Commitments(params: ChannelParams,
976976 }
977977
978978 def receiveFee (fee : UpdateFee , feerates : FeeratesPerKw , feeConf : OnChainFeeConf )(implicit log : LoggingAdapter ): Either [ChannelException , Commitments ] = {
979- if (params.localParams.isInitiator ) {
979+ if (params.localParams.payCommitTxFees ) {
980980 Left (NonInitiatorCannotSendUpdateFee (channelId))
981981 } else if (fee.feeratePerKw < FeeratePerKw .MinimumFeeratePerKw ) {
982982 Left (FeerateTooSmall (channelId, remoteFeeratePerKw = fee.feeratePerKw))
0 commit comments