lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.65k stars 2.07k forks source link

coop close does not work with agreed fees (may be due to Taproot) #6953

Closed BhaagBoseDK closed 1 year ago

BhaagBoseDK commented 2 years ago

Background

A peer tried to coop close with my node. The negotiation ended with 183 fees but than broadcast transaction failed. The channel got stuck in closing with no txn in mempool. It had to be force closed later.

closing negotiation

2022-09-28 07:47:12.286 [INF] HSWC: ChannelLink(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): exited
2022-09-28 07:47:12.286 [INF] HSWC: ChannelLink(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): stopping
2022-09-28 07:47:12.287 [INF] HSWC: Removing channel link with ChannelID(c0376aea6113eb4070f0c94bf8162cfd367a552d8f78ec939926f3192269f237)
2022-09-28 07:47:12.300 [INF] PEER: Peer(032e65c456441da55db4c9b3ea863e60a154afc4bac2bdc96dbb25336779257b38): Delivery addr for channel close: bc1pxxxxxxxx -> taproot address
2022-09-28 07:47:12.313 [INF] CHCL: Ideal fee for closure of ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0) is: 183 sat
2022-09-28 07:47:12.313 [INF] NANN: Announcing channel(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0) disabled [requested]
2022-09-28 07:47:12.336 [INF] CHCL: ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): sending shutdown message
2022-09-28 07:47:12.336 [INF] CHCL: ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): responding to shutdown
2022-09-28 07:47:12.720 [INF] CHCL: ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): computing fee compromise, ideal=183, last_sent=0, remote_offer=183
2022-09-28 07:47:12.723 [INF] CHCL: ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0): proposing fee of 183 sat to close chan
2022-09-28 07:47:12.723 [INF] CHCL: ChannelPoint(37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0) fee of 0.00000183 BTC accepted, ending negotiation
2022-09-28 07:47:12.731 [INF] CHCL: Broadcasting cooperative close tx: (*wire.MsgTx)(0x4020869180)({
 Version: (int32) 2,
 TxIn: ([]*wire.TxIn) (len=1 cap=15) {
  (*wire.TxIn)(0x407d6954a0)({
   PreviousOutPoint: (wire.OutPoint) 37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0,
   SignatureScript: ([]uint8) <nil>,
   Witness: (wire.TxWitness) (len=4 cap=4) {
    ([]uint8) <nil>,
    ([]uint8) (len=71 cap=144) {
     00000000  30 44 02 20 1f 02 46 27  89 62 99 6b 68 df 36 c2  |0D. ..F'.b.kh.6.|

however failure to broadcast as expected fees was 193 (may be due to taproot)

2022-09-28 07:47:12.740 [ERR] LNWL: Notifying unmined tx notification (ad702fc910e166ca03f60c7f04cb69319eb5f22af144bed8b52a5b1c2401940a) while creating notification for blocks
2022-09-28 07:47:12.804 [INF] LNWL: Removed invalid transaction: (*wire.MsgTx)(0x4020869180)({
 Version: (int32) 2,
 TxIn: ([]*wire.TxIn) (len=1 cap=15) {
  (*wire.TxIn)(0x407d6954a0)({
   PreviousOutPoint: (wire.OutPoint) 37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0,
   SignatureScript: ([]uint8) <nil>,
   Witness: (wire.TxWitness) (len=4 cap=4) {
    ([]uint8) <nil>,
    ([]uint8) (len=71 cap=144) {
     00000000  30 44 02 20 1f 02 46 27  89 62 99 6b 68 df 36 c2  |0D. ..F'.b.kh.6.|
--
  })
 },
 LockTime: (uint32) 0
})

2022-09-28 07:47:12.806 [ERR] PEER: Peer(032e65c456441da55db4c9b3ea863e60a154afc4bac2bdc96dbb25336779257b38): unable to process close msg: unmatched backend error: -26: min relay fee not met, 184 < 193

Your environment

* which operating system (`uname -a` on *Nix)
`Linux umbrel 5.10.17-v8+ #1421 SMP PREEMPT Thu May 27 14:01:37 BST 2021 aarch64 GNU/Linux`
* version of `btcd`, `bitcoind`, or other backend

umbrel@umbrel:~/umbrel/bin $ ./bitcoin-cli -getinfo Chain: main Blocks: 756058 Headers: 756058 Verification progress: 99.9999% Difficulty: 31360548173144.85

Network: in 1, out 10, total 11 Version: 230000 Time offset (s): -1 Proxies: 10.21.21.11:9050 (ipv4, ipv6, onion, cjdns) Min tx relay fee rate (BTC/kvB): 0.00001000


* any other relevant environment details

### Steps to reproduce

May be try coop closing channel with ECONOMICAL fees.

### Expected behaviour

If minimum relay fees is 193 then 193 should have been proposed.

### Actual behaviour

Channel did not close and had to be force closed later.
Crypt-iQ commented 2 years ago

Was this channel a static-remote-key channel without anchors? Do you happen to know the script your counterparty was using here - it doesn't say in the logs? I'm guessing CalcFee was used to set the idealFee based on the channel, which has a P2WPKH output. Then the P2WPKH script was replaced with a P2WSH or P2TR script during the coop flow, giving a higher weight at the same fee

BhaagBoseDK commented 2 years ago

Was this channel a static-remote-key channel without anchors?

YES

Do you happen to know the script your counterparty was using here - it doesn't say in the logs? I'm guessing CalcFee was used to set the idealFee based on the channel, which has a P2WPKH output. Then the P2WPKH script was replaced with a P2WSH or P2TR script during the coop flow, giving a higher weight at the same fee

I have no idea about that but I have provided this gitub case to my peer and they can comment.

However, shouldn't my node propose a fee considering P2TR script during coop flow to nudge the negotiation higher? Why was my node also proposing 183?

apogiffa commented 2 years ago

Was this channel a static-remote-key channel without anchors? Do you happen to know the script your counterparty was using here - it doesn't say in the logs? I'm guessing CalcFee was used to set the idealFee based on the channel, which has a P2WPKH output. Then the P2WPKH script was replaced with a P2WSH or P2TR script during the coop flow, giving a higher weight at the same fee

I'm the peer who encountered these problems. In total I had 12/35 coop-closed channels with no closing_txid which I then had to force close. If you tell me what command to paste into terminal I'll gladly provide the infos you want to know.

Crypt-iQ commented 2 years ago

@BhaagBoseDK you can look at the outputs in the invalid transaction that was removed to determine the type of the outputs (p2wsh, p2wkh, p2tr, etc)

BhaagBoseDK commented 2 years ago

@BhaagBoseDK you can look at the outputs in the invalid transaction that was removed to determine the type of the outputs (p2wsh, p2wkh, p2tr, etc)

As I already mentioned, the "invalid" transaction had output as P2TR

This implies that fees are calculated on P2WSH while not realising that 0.15.0 onwards P2TR is also supported (and might require higher fees).

[INF] PEER: Peer(032e65c456441da55db4c9b3ea863e60a154afc4bac2bdc96dbb25336779257b38): Delivery addr for channel close: bc1pxxxxxxxx -> taproot address

apogiffa commented 2 years ago

Other plebs in the noderunners-TG-group also encountered "closing_txid": "" and mentioned that a simple restart of LND resulted in a successful renegotiation. So that might help to avoid having to FC the channels.

Crypt-iQ commented 2 years ago

As I already mentioned, the "invalid" transaction had output as P2TR

Yes I understand, what about the other output?

BhaagBoseDK commented 2 years ago

As I already mentioned, the "invalid" transaction had output as P2TR

Yes I understand, what about the other output?

how do I find it, the txn is not in mempool nor can I find the details from log. But most likely that was also P2TR because the peer is also on lnd 0.15.x

Crypt-iQ commented 2 years ago

It would be the un-truncated log here:

2022-09-28 07:47:12.804 [INF] LNWL: Removed invalid transaction: (*wire.MsgTx)(0x4020869180)({
 Version: (int32) 2,
 TxIn: ([]*wire.TxIn) (len=1 cap=15) {
  (*wire.TxIn)(0x407d6954a0)({
   PreviousOutPoint: (wire.OutPoint) 37f2692219f3269993ec788f2d557a36fd2c16f84bc9f07040eb1361ea6a37c0:0,
   SignatureScript: ([]uint8) <nil>,
   Witness: (wire.TxWitness) (len=4 cap=4) {
    ([]uint8) <nil>,
    ([]uint8) (len=71 cap=144) {
     00000000  30 44 02 20 1f 02 46 27  89 62 99 6b 68 df 36 c2  |0D. ..F'.b.kh.6.|
--
  })
 },
 LockTime: (uint32) 0
})
bota87 commented 1 year ago

I had this issue with 0.15.2, just updated to 0.15.3 to see if get fixed but I still see the same error, I have to force close or there is another way?

Crypt-iQ commented 1 year ago

the tx is persisted to the db and you won't be able to coop close that channel anymore, so you need to force close