mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-07 13:39:46 +02:00
peer: rewrite handleCloseMsg in terms of new ChanCloser methods
This commit is contained in:
parent
7b08899cdb
commit
f81e7ada4c
@ -3621,13 +3621,8 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, we'll process the next message using the target state machine.
|
handleErr := func(err error) {
|
||||||
// We'll either continue negotiation, or halt.
|
err = fmt.Errorf("unable to process close msg: %w", err)
|
||||||
msgs, closeFin, err := chanCloser.ProcessCloseMsg(
|
|
||||||
msg.msg,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("unable to process close msg: %v", err)
|
|
||||||
p.log.Error(err)
|
p.log.Error(err)
|
||||||
|
|
||||||
// As the negotiations failed, we'll reset the channel state machine to
|
// As the negotiations failed, we'll reset the channel state machine to
|
||||||
@ -3638,18 +3633,52 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
|
|||||||
chanCloser.CloseRequest().Err <- err
|
chanCloser.CloseRequest().Err <- err
|
||||||
}
|
}
|
||||||
delete(p.activeChanCloses, msg.cid)
|
delete(p.activeChanCloses, msg.cid)
|
||||||
return
|
|
||||||
|
p.Disconnect(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue any messages to the remote peer that need to be sent as a part of
|
// Next, we'll process the next message using the target state machine.
|
||||||
// this latest round of negotiations.
|
// We'll either continue negotiation, or halt.
|
||||||
for _, msg := range msgs {
|
switch typed := msg.msg.(type) {
|
||||||
p.queueMsg(msg, nil)
|
case *lnwire.Shutdown:
|
||||||
|
oShutdown, err := chanCloser.ReceiveShutdown(*typed)
|
||||||
|
if err != nil {
|
||||||
|
handleErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oShutdown.WhenSome(func(msg lnwire.Shutdown) {
|
||||||
|
p.queueMsg(&msg, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
oClosingSigned, err := chanCloser.BeginNegotiation()
|
||||||
|
if err != nil {
|
||||||
|
handleErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oClosingSigned.WhenSome(func(msg lnwire.ClosingSigned) {
|
||||||
|
p.queueMsg(&msg, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
case *lnwire.ClosingSigned:
|
||||||
|
oClosingSigned, err := chanCloser.ReceiveClosingSigned(*typed)
|
||||||
|
if err != nil {
|
||||||
|
handleErr(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oClosingSigned.WhenSome(func(msg lnwire.ClosingSigned) {
|
||||||
|
p.queueMsg(&msg, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic("impossible closeMsg type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we haven't finished close negotiations, then we'll continue as we
|
// If we haven't finished close negotiations, then we'll continue as we
|
||||||
// can't yet finalize the closure.
|
// can't yet finalize the closure.
|
||||||
if !closeFin {
|
if _, err := chanCloser.ClosingTx(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user