mirror of
https://github.com/ACINQ/eclair.git
synced 2025-03-15 04:11:33 +01:00
Accept remote's closing fee when we have nothing at stake (#1633)
If we have nothing at stake there is no need to negotiate and we accept their fee right away.
This commit is contained in:
parent
addc7a4ab4
commit
ac8dd4d29f
2 changed files with 25 additions and 4 deletions
|
@ -1186,9 +1186,14 @@ class Channel(val nodeParams: NodeParams, val wallet: EclairWallet, remoteNodeId
|
||||||
case Success(signedClosingTx) =>
|
case Success(signedClosingTx) =>
|
||||||
// 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
|
// 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 lastLocalClosingFee = d.closingTxProposed.last.lastOption.map(_.localClosingSigned.feeSatoshis)
|
||||||
val nextClosingFee = Closing.nextClosingFee(
|
val nextClosingFee = if (d.commitments.localCommit.spec.toLocal == 0.msat) {
|
||||||
localClosingFee = lastLocalClosingFee.getOrElse(Closing.firstClosingFee(d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nodeParams.onChainFeeConf.feeEstimator, nodeParams.onChainFeeConf.feeTargets)),
|
// if we have nothing at stake there is no need to negotiate and we accept their fee right away
|
||||||
remoteClosingFee = remoteClosingFee)
|
remoteClosingFee
|
||||||
|
} else {
|
||||||
|
Closing.nextClosingFee(
|
||||||
|
localClosingFee = lastLocalClosingFee.getOrElse(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)
|
val (closingTx, closingSigned) = Closing.makeClosingTx(keyManager, d.commitments, d.localShutdown.scriptPubKey, d.remoteShutdown.scriptPubKey, nextClosingFee)
|
||||||
if (lastLocalClosingFee.contains(nextClosingFee)) {
|
if (lastLocalClosingFee.contains(nextClosingFee)) {
|
||||||
// next computed fee is the same than the one we previously sent (probably because of rounding), let's close now
|
// next computed fee is the same than the one we previously sent (probably because of rounding), let's close now
|
||||||
|
|
|
@ -50,7 +50,7 @@ class NegotiatingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike
|
||||||
val setup = init()
|
val setup = init()
|
||||||
import setup._
|
import setup._
|
||||||
within(30 seconds) {
|
within(30 seconds) {
|
||||||
reachNormal(setup)
|
reachNormal(setup, test.tags)
|
||||||
val sender = TestProbe()
|
val sender = TestProbe()
|
||||||
// alice initiates a closing
|
// alice initiates a closing
|
||||||
if (test.tags.contains("fee2")) {
|
if (test.tags.contains("fee2")) {
|
||||||
|
@ -131,6 +131,22 @@ class NegotiatingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike
|
||||||
testFeeConverge(f)
|
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)
|
||||||
|
bob2alice.forward(alice)
|
||||||
|
val mutualCloseTxAlice = alice2blockchain.expectMsgType[PublishAsap].tx
|
||||||
|
val mutualCloseTxBob = bob2blockchain.expectMsgType[PublishAsap].tx
|
||||||
|
assert(mutualCloseTxAlice === mutualCloseTxBob)
|
||||||
|
assert(alice2blockchain.expectMsgType[WatchConfirmed].event === BITCOIN_TX_CONFIRMED(mutualCloseTxAlice))
|
||||||
|
assert(bob2blockchain.expectMsgType[WatchConfirmed].event === BITCOIN_TX_CONFIRMED(mutualCloseTxBob))
|
||||||
|
assert(alice.stateData.asInstanceOf[DATA_CLOSING].mutualClosePublished == List(mutualCloseTxAlice))
|
||||||
|
assert(bob.stateData.asInstanceOf[DATA_CLOSING].mutualClosePublished == List(mutualCloseTxBob))
|
||||||
|
}
|
||||||
|
|
||||||
test("recv ClosingSigned (fee too high)") { f =>
|
test("recv ClosingSigned (fee too high)") { f =>
|
||||||
import f._
|
import f._
|
||||||
val aliceCloseSig = alice2bob.expectMsgType[ClosingSigned]
|
val aliceCloseSig = alice2bob.expectMsgType[ClosingSigned]
|
||||||
|
|
Loading…
Add table
Reference in a new issue