mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-26 22:17:51 +01:00
funding+server: ensure we cancel all reservations when a peer disconnects
In this commit, we fix an existing issue that could at times cause an inconsistent view between the set of total coins, and the set of segwit coins in the wallet of the node. This could be caused by initiating a funding flow, but then the funding negotiation breaking down somewhere along the lines. In this case, us or the other peer will disconnect. When we initiate funding flows, we lock coins exclusively, to ensure that concurrent funding flows don’t end up double spending the same coin. Before this commit, we wouldn’t ever unlock those coins. As a result, our view of available coins would be skewed. The walletbalance call would show all the coins, but when adding the —witness_only flag, some coins would be missing, or gone all together. This is because the former call actually scans the txstore and manually tallies the amount of available coins, while the latter looks at the sent of available outputs, which is filtered based on which coins are locked. To remedy this, we now ensure that when a peer disconnects, we wipe all existing reservations which will return any locked outputs to the set of available outputs for funding flows.
This commit is contained in:
@@ -1036,6 +1036,12 @@ func (s *server) peerTerminationWatcher(p *peer) {
|
||||
return
|
||||
}
|
||||
|
||||
// Next, we'll cancel all pending funding reservations with this node.
|
||||
// If we tried to initiate any funding flows that haven't yet finished,
|
||||
// then we need to unlock those committed outputs so they're still
|
||||
// available for use.
|
||||
s.fundingMgr.CancelPeerReservations(p.PubKey())
|
||||
|
||||
// Tell the switch to remove all links associated with this peer.
|
||||
// Passing nil as the target link indicates that all links associated
|
||||
// with this interface should be closed.
|
||||
|
||||
Reference in New Issue
Block a user