lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.69k stars 2.08k forks source link

[bug]: Rebroadcaster - Tx is rebroadcasted although it was already doublespend (bad/missing inputs) #7600

Closed ziggie1984 closed 1 year ago

ziggie1984 commented 1 year ago

Since lnd 0.16.0 the rebroadcaster was implemented, though there might be a small inconvenient bug, filling the log files. In case the anchor output is spent by a third party we wanna make sure we back-propagate this info also to the rebroadcaster so that it removes the tx from its "rebroadcast-transaction". Currently the rebroadcaster registers a sweep and although the sweep (anchor-sweep) is already invalid the backend tries to rebroadcast it continuously (1min)

My analysis lead me to the following outcome:

The sweeper registers the sweep here:

https://github.com/lightningnetwork/lnd/blob/master/lnwallet/wallet.go#L480

https://github.com/lightninglabs/neutrino/blob/master/pushtx/broadcaster.go#L180

Then the rebroadcaster does its job here (after the timer kicks in):

https://github.com/lightninglabs/neutrino/blob/master/pushtx/broadcaster.go#L180

And now the problem lies here:

https://github.com/lightninglabs/neutrino/blob/master/pushtx/broadcaster.go#L213

We only remove transactions from the queue/array if they are confirmed:

https://github.com/lightninglabs/neutrino/blob/master/pushtx/broadcaster.go#L245

What I think is needed something like:

case IsBroadcastError(err, Invalid):

remove the TX from the rebroadcast transaction queue

Happy to hear your thought about my observation

Your environment

Example Log of lnd(repeating itself every DefaultRebroadcastInterval = time.Minute):

2023-04-15 07:02:20.013 [ERR] BTCN: Unable to rebroadcast transaction ea95a3b5a1e09e7c8229b27d73fb2a925df0bbf35f0412ee9f0ec0a3535024ec: -25: bad-txns-inputs-missingorspent
2023-04-15 07:02:20.027 [ERR] BTCN: Unable to rebroadcast transaction 3d74e9e32b4f694f62b0ae319649187c9e2e07098e57c289cc628b62cba96be9: -25: bad-txns-inputs-missingorspent
2023-04-15 07:02:20.039 [ERR] BTCN: Unable to rebroadcast transaction 6450aaadc40f286011c1da0e7cd9c75a85ae3c2c56b0cc0ae6a19fd2cfb7b0ff: -25: bad-txns-inputs-missingorspent
2023-04-15 07:02:20.044 [ERR] BTCN: Unable to rebroadcast transaction cf51dba1f2bc1cad6d9edd78fe35de93473717f5eadfe2de8675ebc82e8e387e: -25: bad-txns-inputs-missingorspent

Restarting lnd fixes the problem but would be cool to have the solution as presented above maybe?

guggero commented 1 year ago

See https://github.com/lightningnetwork/lnd/pull/7599.

saubyk commented 1 year ago

Hi @ziggie1984 can we close this issue?

ziggie1984 commented 1 year ago

closed with #7746