peer+chancloser: tryLinkShutdown during cooperative close process

Adds a new Brontide struct method tryLinkShutdown that attempts to
fetch the target link and calls ShutdownIfChannelClean on it. This
allows the coop close process to guarantee atomicity of the underlying
channel state. Also removes the UnregisterChannel method from the
chancloser's config as the link is shut down before the chancloser
is created.
This commit is contained in:
eugene
2021-08-10 17:00:51 -04:00
parent 608d11dcbc
commit aeaa009e92
4 changed files with 110 additions and 49 deletions

View File

@@ -79,11 +79,6 @@ type ChanCloseCfg struct {
// Channel is the channel that should be closed.
Channel *lnwallet.LightningChannel
// UnregisterChannel is a function closure that allows the ChanCloser to
// unregister a channel. Once this has been done, no further HTLC's should
// be routed through the channel.
UnregisterChannel func(lnwire.ChannelID)
// BroadcastTx broadcasts the passed transaction to the network.
BroadcastTx func(*wire.MsgTx, string) error
@@ -212,8 +207,6 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) {
// closing script.
shutdown := lnwire.NewShutdown(c.cid, c.localDeliveryScript)
// TODO(roasbeef): err if channel has htlc's?
// Before closing, we'll attempt to send a disable update for the channel.
// We do so before closing the channel as otherwise the current edge policy
// won't be retrievable from the graph.
@@ -222,10 +215,6 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) {
c.chanPoint, err)
}
// Before returning the shutdown message, we'll unregister the channel to
// ensure that it isn't seen as usable within the system.
c.cfg.UnregisterChannel(c.cid)
// Before continuing, mark the channel as cooperatively closed with a nil
// txn. Even though we haven't negotiated the final txn, this guarantees
// that our listchannels rpc will be externally consistent, and reflect