peer.go: handleCloseMsg function for channelManager goroutine
This commit is contained in:
parent
1a91013c14
commit
e1632dd172
125
peer.go
125
peer.go
@ -2071,69 +2071,7 @@ out:
|
|||||||
// message from the remote peer, we'll use this message to
|
// message from the remote peer, we'll use this message to
|
||||||
// advance the chan closer state machine.
|
// advance the chan closer state machine.
|
||||||
case closeMsg := <-p.chanCloseMsgs:
|
case closeMsg := <-p.chanCloseMsgs:
|
||||||
// We'll now fetch the matching closing state machine
|
p.handleCloseMsg(closeMsg)
|
||||||
// in order to continue, or finalize the channel
|
|
||||||
// closure process.
|
|
||||||
chanCloser, err := p.fetchActiveChanCloser(closeMsg.cid)
|
|
||||||
if err != nil {
|
|
||||||
// If the channel is not known to us, we'll
|
|
||||||
// simply ignore this message.
|
|
||||||
if err == ErrChannelNotFound {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
peerLog.Errorf("Unable to respond to remote "+
|
|
||||||
"close msg: %v", err)
|
|
||||||
|
|
||||||
errMsg := &lnwire.Error{
|
|
||||||
ChanID: closeMsg.cid,
|
|
||||||
Data: lnwire.ErrorData(err.Error()),
|
|
||||||
}
|
|
||||||
p.queueMsg(errMsg, nil)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, we'll process the next message using the
|
|
||||||
// target state machine. We'll either continue
|
|
||||||
// negotiation, or halt.
|
|
||||||
msgs, closeFin, err := chanCloser.ProcessCloseMsg(
|
|
||||||
closeMsg.msg,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("unable to process close "+
|
|
||||||
"msg: %v", 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.Channel().ResetState()
|
|
||||||
|
|
||||||
if chanCloser.CloseRequest() != nil {
|
|
||||||
chanCloser.CloseRequest().Err <- err
|
|
||||||
}
|
|
||||||
delete(p.activeChanCloses, closeMsg.cid)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queue any messages to the remote peer that need to
|
|
||||||
// be sent as a part of this latest round of
|
|
||||||
// negotiations.
|
|
||||||
for _, msg := range msgs {
|
|
||||||
p.queueMsg(msg, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we haven't finished close negotiations, then
|
|
||||||
// we'll continue as we can't yet finalize the closure.
|
|
||||||
if !closeFin {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, we've agreed on a closing fee! In this
|
|
||||||
// case, we'll wrap up the channel closure by notifying
|
|
||||||
// relevant sub-systems and launching a goroutine to
|
|
||||||
// wait for close tx conf.
|
|
||||||
p.finalizeChanClosure(chanCloser)
|
|
||||||
|
|
||||||
// The channel reannounce delay has elapsed, broadcast the
|
// The channel reannounce delay has elapsed, broadcast the
|
||||||
// reenabled channel updates to the network. This should only
|
// reenabled channel updates to the network. This should only
|
||||||
@ -2858,6 +2796,67 @@ func (p *peer) StartTime() time.Time {
|
|||||||
return p.startTime
|
return p.startTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleCloseMsg is called when a new cooperative channel closure related
|
||||||
|
// message is received from the remote peer. We'll use this message to advance
|
||||||
|
// the chan closer state machine.
|
||||||
|
func (p *peer) handleCloseMsg(msg *closeMsg) {
|
||||||
|
// We'll now fetch the matching closing state machine in order to continue,
|
||||||
|
// or finalize the channel closure process.
|
||||||
|
chanCloser, err := p.fetchActiveChanCloser(msg.cid)
|
||||||
|
if err != nil {
|
||||||
|
// If the channel is not known to us, we'll simply ignore this message.
|
||||||
|
if err == ErrChannelNotFound {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
peerLog.Errorf("Unable to respond to remote close msg: %v", err)
|
||||||
|
|
||||||
|
errMsg := &lnwire.Error{
|
||||||
|
ChanID: msg.cid,
|
||||||
|
Data: lnwire.ErrorData(err.Error()),
|
||||||
|
}
|
||||||
|
p.queueMsg(errMsg, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next, we'll process the next message using the target state machine.
|
||||||
|
// We'll either continue negotiation, or halt.
|
||||||
|
msgs, closeFin, err := chanCloser.ProcessCloseMsg(
|
||||||
|
msg.msg,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("unable to process close msg: %v", err)
|
||||||
|
peerLog.Error(err)
|
||||||
|
|
||||||
|
// As the negotiations failed, we'll reset the channel state machine to
|
||||||
|
// ensure we act to on-chain events as normal.
|
||||||
|
chanCloser.Channel().ResetState()
|
||||||
|
|
||||||
|
if chanCloser.CloseRequest() != nil {
|
||||||
|
chanCloser.CloseRequest().Err <- err
|
||||||
|
}
|
||||||
|
delete(p.activeChanCloses, msg.cid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue any messages to the remote peer that need to be sent as a part of
|
||||||
|
// this latest round of negotiations.
|
||||||
|
for _, msg := range msgs {
|
||||||
|
p.queueMsg(msg, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we haven't finished close negotiations, then we'll continue as we
|
||||||
|
// can't yet finalize the closure.
|
||||||
|
if !closeFin {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, we've agreed on a closing fee! In this case, we'll wrap up
|
||||||
|
// the channel closure by notifying relevant sub-systems and launching a
|
||||||
|
// goroutine to wait for close tx conf.
|
||||||
|
p.finalizeChanClosure(chanCloser)
|
||||||
|
}
|
||||||
|
|
||||||
// LinkUpdater is an interface implemented by most messages in BOLT 2 that are
|
// LinkUpdater is an interface implemented by most messages in BOLT 2 that are
|
||||||
// allowed to update the channel state.
|
// allowed to update the channel state.
|
||||||
type LinkUpdater interface {
|
type LinkUpdater interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user