Skip to content

Commit

Permalink
Use min fee instead of tx propagation check
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Aug 31, 2021
1 parent b6a6a73 commit fccdd7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1301,14 +1301,12 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
case Some(ClosingSignedTlv.FeeRange(minFee, maxFee)) if !d.commitments.localParams.isFunder =>
// if we are fundee and they proposed a fee range, we pick a value in that range and they should accept it without further negotiation
// we don't care much about the closing fee since they're paying it (not us) and we can use CPFP if we want to speed up confirmation
// but we need to ensure it's high enough to at least propagate across the network
val txPropagationFeerate = nodeParams.onChainFeeConf.feeEstimator.getFeeratePerKw(1008)
val txPropagationMinFee = Transactions.weight2fee(txPropagationFeerate, signedClosingTx.tx.weight())
if (maxFee < txPropagationMinFee) {
log.warning("their highest closing fee is below our tx propagation threshold (feerate={}): {} < {}", txPropagationFeerate, maxFee, txPropagationMinFee)
stay() sending Warning(d.channelId, s"closing fee range must not be below $txPropagationMinFee ($txPropagationFeerate)")
val localClosingFees = Closing.firstClosingFee(d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nodeParams.onChainFeeConf.feeEstimator, nodeParams.onChainFeeConf.feeTargets)
if (maxFee < localClosingFees.min) {
log.warning("their highest closing fee is below our minimum fee: {} < {}", maxFee, localClosingFees.min)
stay() sending Warning(d.channelId, s"closing fee range must not be below ${localClosingFees.min}")
} else {
val closingFee = Closing.firstClosingFee(d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nodeParams.onChainFeeConf.feeEstimator, nodeParams.onChainFeeConf.feeTargets) match {
val closingFee = localClosingFees match {
case ClosingFees(preferred, _, _) if preferred > maxFee => maxFee
// if we underestimate the fee, then we're happy with whatever they propose (it will confirm more quickly and we're not paying it)
case ClosingFees(preferred, _, _) if preferred < remoteClosingFee => remoteClosingFee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,10 @@ object Helpers {
// we "MUST set fee_satoshis less than or equal to the base fee of the final commitment transaction"
requestedFeerate.min(commitments.localCommit.spec.feeratePerKw)
}
firstClosingFee(commitments, localScriptPubkey, remoteScriptPubkey, ClosingFeerates(preferredFeerate, preferredFeerate / 2, preferredFeerate * 2))
// NB: we choose a minimum fee that ensures the tx will easily propagate while allowing low fees since we can
// always use CPFP to speed up confirmation if necessary.
val closingFeerates = ClosingFeerates(preferredFeerate, preferredFeerate.min(feeEstimator.getFeeratePerKw(1008)), preferredFeerate * 2)
firstClosingFee(commitments, localScriptPubkey, remoteScriptPubkey, closingFeerates)
}

def nextClosingFee(localClosingFee: Satoshi, remoteClosingFee: Satoshi): Satoshi = ((localClosingFee + remoteClosingFee) / 4) * 2
Expand Down

0 comments on commit fccdd7b

Please sign in to comment.