Skip to content

Commit 711c52a

Browse files
authored
Avoid negative on-the-fly funding fee (#3189)
Since we don't have access to channel params in the `Peer` actor, we don't know the remote `htlc_minimum` when receiving a splice. This may lead to cases where we later fail because we end up with a negative funding fee, which doesn't make any sense. To avoid those failures, we hard-code the `htlc_minimum` value used by Phoenix (which is the only consumer of this protocol so far) and use the max with our local `htlc_minimum`.
1 parent 0baddd9 commit 711c52a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,11 @@ class Peer(val nodeParams: NodeParams,
467467
case Event(msg: SpliceInit, d: ConnectedData) =>
468468
d.channels.get(FinalChannelId(msg.channelId)) match {
469469
case Some(_) if msg.usesOnTheFlyFunding && !d.fundingFeerateOk(msg.feerate) =>
470-
log.info("rejecting open_channel2: feerate too low ({} < {})", msg.feerate, d.currentFeerates.fundingFeerate)
470+
log.info("rejecting splice_init: feerate too low ({} < {})", msg.feerate, d.currentFeerates.fundingFeerate)
471471
self ! Peer.OutgoingMessage(TxAbort(msg.channelId, FundingFeerateTooLow(msg.channelId, msg.feerate, d.currentFeerates.fundingFeerate).getMessage), d.peerConnection)
472472
case Some(channel) =>
473-
OnTheFlyFunding.validateSplice(nodeParams.onTheFlyFundingConfig, msg, nodeParams.channelConf.htlcMinimum, pendingOnTheFlyFunding, feeCredit.getOrElse(0 msat)) match {
473+
// We don't have access to the remote htlc_minimum here, so we hard-code the value Phoenix uses (1000 msat).
474+
OnTheFlyFunding.validateSplice(nodeParams.onTheFlyFundingConfig, msg, nodeParams.channelConf.htlcMinimum.max(1000 msat), pendingOnTheFlyFunding, feeCredit.getOrElse(0 msat)) match {
474475
case reject: OnTheFlyFunding.ValidationResult.Reject =>
475476
log.warning("rejecting on-the-fly splice: {}", reject.cancel.toAscii)
476477
self ! Peer.OutgoingMessage(reject.cancel, d.peerConnection)

eclair-core/src/main/scala/fr/acinq/eclair/payment/relay/OnTheFlyFunding.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object OnTheFlyFunding {
9191
/** An on-the-fly funding proposal sent to our peer. */
9292
case class Proposal(htlc: WillAddHtlc, upstream: Upstream.Hot, onionSharedSecrets: Seq[Sphinx.SharedSecret]) {
9393
/** Maximum fees that can be collected from this HTLC. */
94-
def maxFees(htlcMinimum: MilliSatoshi): MilliSatoshi = htlc.amount - htlcMinimum
94+
def maxFees(htlcMinimum: MilliSatoshi): MilliSatoshi = (htlc.amount - htlcMinimum).max(0 msat)
9595

9696
/** Create commands to fail all upstream HTLCs. */
9797
def createFailureCommands(failure_opt: Option[FailureReason])(implicit log: LoggingAdapter): Seq[(ByteVector32, CMD_FAIL_HTLC)] = upstream match {

0 commit comments

Comments
 (0)