Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept remote's closing fee when we have nothing at stake #1633

Merged
merged 3 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,14 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
// if we are fundee and we were waiting for them to send their first closing_signed, we don't have a lastLocalClosingFee, so we compute a firstClosingFee
val lastLocalClosingFee = d.closingTxProposed.last.lastOption.map(_.localClosingSigned.feeSatoshis)
val nextClosingFee = Closing.nextClosingFee(
localClosingFee = lastLocalClosingFee.getOrElse(Closing.firstClosingFee(d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nodeParams.onChainFeeConf.feeEstimator, nodeParams.onChainFeeConf.feeTargets)),
localClosingFee = lastLocalClosingFee.getOrElse {
t-bast marked this conversation as resolved.
Show resolved Hide resolved
if (d.commitments.localCommit.spec.toLocal == 0.msat) {
t-bast marked this conversation as resolved.
Show resolved Hide resolved
// if we have nothing at stake there is no need to negotiate and we accept their fee right away
remoteClosingFee
} else {
Closing.firstClosingFee(d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nodeParams.onChainFeeConf.feeEstimator, nodeParams.onChainFeeConf.feeTargets)
}
},
remoteClosingFee = remoteClosingFee)
val (closingTx, closingSigned) = Closing.makeClosingTx(keyManager, d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nextClosingFee)
if (lastLocalClosingFee.contains(nextClosingFee)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ class NegotiatingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike
testFeeConverge(f)
}

test("recv ClosingSigned (nothing at stake)", Tag("no_push_msat")) { f =>
import f._
val aliceCloseFee = alice2bob.expectMsgType[ClosingSigned].feeSatoshis
alice2bob.forward(bob)
val bobCloseFee = bob2alice.expectMsgType[ClosingSigned].feeSatoshis
assert(aliceCloseFee === bobCloseFee)
val mutualCloseTx = bob2blockchain.expectMsgType[PublishAsap].tx
assert(bob.stateData.asInstanceOf[DATA_CLOSING].mutualClosePublished == List(mutualCloseTx))
assert(bob2blockchain.expectMsgType[WatchConfirmed].event === BITCOIN_TX_CONFIRMED(mutualCloseTx))
alice ! WatchEventSpent(BITCOIN_FUNDING_SPENT, mutualCloseTx)
t-bast marked this conversation as resolved.
Show resolved Hide resolved
}

test("recv ClosingSigned (fee too high)") { f =>
import f._
val aliceCloseSig = alice2bob.expectMsgType[ClosingSigned]
Expand Down