mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
lnwallet+peer: add new ResetState method to channel state machine
In this commit, we add a new ResetState method to the channel state machine which will reset the state of the channel to `channelOpen`. We add this as before this commit, it was possible for a channel to shift into the closing state, the closing negotiation be cancelled for whatever reason, resulting the the channel held by the breachArbiter unable to act to potential on-chain events.
This commit is contained in:
parent
923cbe62a0
commit
39295dc5aa
2 changed files with 23 additions and 3 deletions
|
@ -1382,6 +1382,13 @@ func (lc *LightningChannel) CancelObserver() {
|
||||||
close(lc.observerQuit)
|
close(lc.observerQuit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ResetState resets the state of the channel back to the default state. This
|
||||||
|
// ensures that any active goroutines which need to act based on on-chain
|
||||||
|
// events do so properly.
|
||||||
|
func (lc *LightningChannel) ResetState() {
|
||||||
|
lc.Lock()
|
||||||
|
lc.status = channelOpen
|
||||||
|
lc.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// logUpdateToPayDesc converts a LogUpdate into a matching PaymentDescriptor
|
// logUpdateToPayDesc converts a LogUpdate into a matching PaymentDescriptor
|
||||||
|
|
19
peer.go
19
peer.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1273,6 +1272,10 @@ out:
|
||||||
"msg: %v", err)
|
"msg: %v", err)
|
||||||
peerLog.Error(err)
|
peerLog.Error(err)
|
||||||
|
|
||||||
|
// As the negotiations failed, we'll reset the
|
||||||
|
// channel state to ensure we act to on-chain
|
||||||
|
// events as normal.
|
||||||
|
chanCloser.cfg.channel.ResetState()
|
||||||
|
|
||||||
if chanCloser.CloseRequest() != nil {
|
if chanCloser.CloseRequest() != nil {
|
||||||
chanCloser.CloseRequest().Err <- err
|
chanCloser.CloseRequest().Err <- err
|
||||||
|
@ -1299,9 +1302,16 @@ out:
|
||||||
// relevant sub-systems and launching a goroutine to
|
// relevant sub-systems and launching a goroutine to
|
||||||
// wait for close tx conf.
|
// wait for close tx conf.
|
||||||
p.finalizeChanClosure(chanCloser)
|
p.finalizeChanClosure(chanCloser)
|
||||||
}
|
|
||||||
|
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
|
|
||||||
|
// As, we've been signalled to exit, we'll reset all
|
||||||
|
// our active channel back to their default state.
|
||||||
|
p.activeChanMtx.Lock()
|
||||||
|
for _, channel := range p.activeChannels {
|
||||||
|
channel.ResetState()
|
||||||
|
}
|
||||||
|
p.activeChanMtx.Unlock()
|
||||||
|
|
||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1440,6 +1450,9 @@ func (p *peer) handleLocalCloseReq(req *htlcswitch.ChanClose) {
|
||||||
req.Err <- err
|
req.Err <- err
|
||||||
delete(p.activeChanCloses, chanID)
|
delete(p.activeChanCloses, chanID)
|
||||||
|
|
||||||
|
// As we were unable to shutdown the channel, we'll
|
||||||
|
// return it back to its normal state.
|
||||||
|
channel.ResetState()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue