contractcourt: use MarkChannelResolved for coop channel closures
In this commit, we alter cooperative channel closures to also use MarkChannelResolved in order to unify the logic for the different types of channel closures.
This commit is contained in:
parent
4578eec8a1
commit
d26050f711
@ -342,23 +342,6 @@ func (c *ChainArbitrator) Start() error {
|
|||||||
pCache: c.cfg.PreimageDB,
|
pCache: c.cfg.PreimageDB,
|
||||||
signer: c.cfg.Signer,
|
signer: c.cfg.Signer,
|
||||||
isOurAddr: c.cfg.IsOurAddress,
|
isOurAddr: c.cfg.IsOurAddress,
|
||||||
notifyChanClosed: func() error {
|
|
||||||
c.Lock()
|
|
||||||
delete(c.activeChannels, chanPoint)
|
|
||||||
|
|
||||||
chainWatcher, ok := c.activeWatchers[chanPoint]
|
|
||||||
if ok {
|
|
||||||
// Since the chainWatcher is
|
|
||||||
// calling notifyChanClosed, we
|
|
||||||
// must stop it in a goroutine
|
|
||||||
// to not deadlock.
|
|
||||||
go chainWatcher.Stop()
|
|
||||||
}
|
|
||||||
delete(c.activeWatchers, chanPoint)
|
|
||||||
c.Unlock()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
|
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
|
||||||
return c.cfg.ContractBreach(chanPoint, retInfo)
|
return c.cfg.ContractBreach(chanPoint, retInfo)
|
||||||
},
|
},
|
||||||
@ -697,22 +680,6 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
|
|||||||
pCache: c.cfg.PreimageDB,
|
pCache: c.cfg.PreimageDB,
|
||||||
signer: c.cfg.Signer,
|
signer: c.cfg.Signer,
|
||||||
isOurAddr: c.cfg.IsOurAddress,
|
isOurAddr: c.cfg.IsOurAddress,
|
||||||
notifyChanClosed: func() error {
|
|
||||||
c.Lock()
|
|
||||||
delete(c.activeChannels, chanPoint)
|
|
||||||
|
|
||||||
chainWatcher, ok := c.activeWatchers[chanPoint]
|
|
||||||
if ok {
|
|
||||||
// Since the chainWatcher is calling
|
|
||||||
// notifyChanClosed, we must stop it in
|
|
||||||
// a goroutine to not deadlock.
|
|
||||||
go chainWatcher.Stop()
|
|
||||||
}
|
|
||||||
delete(c.activeWatchers, chanPoint)
|
|
||||||
c.Unlock()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
|
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
|
||||||
return c.cfg.ContractBreach(chanPoint, retInfo)
|
return c.cfg.ContractBreach(chanPoint, retInfo)
|
||||||
},
|
},
|
||||||
|
@ -78,13 +78,6 @@ type chainWatcherConfig struct {
|
|||||||
// machine.
|
// machine.
|
||||||
signer lnwallet.Signer
|
signer lnwallet.Signer
|
||||||
|
|
||||||
// notifyChanClosed is a method that will be called by the watcher when
|
|
||||||
// it has detected a close on-chain and performed all necessary
|
|
||||||
// actions, like marking the channel closed in the database and
|
|
||||||
// notified all its subcribers. It lets the chain arbitrator know that
|
|
||||||
// the chain watcher chan be stopped.
|
|
||||||
notifyChanClosed func() error
|
|
||||||
|
|
||||||
// contractBreach is a method that will be called by the watcher if it
|
// contractBreach is a method that will be called by the watcher if it
|
||||||
// detects that a contract breach transaction has been confirmed. Only
|
// detects that a contract breach transaction has been confirmed. Only
|
||||||
// when this method returns with a non-nil error it will be safe to mark
|
// when this method returns with a non-nil error it will be safe to mark
|
||||||
@ -492,16 +485,7 @@ func (c *chainWatcher) dispatchCooperativeClose(commitSpend *chainntnfs.SpendDet
|
|||||||
}
|
}
|
||||||
c.Unlock()
|
c.Unlock()
|
||||||
|
|
||||||
// Now notify the ChainArbitrator that the watcher's job is done, such
|
|
||||||
// that it can shut it down and clean up.
|
|
||||||
if err := c.cfg.notifyChanClosed(); err != nil {
|
|
||||||
log.Errorf("unable to notify channel closed for "+
|
|
||||||
"ChannelPoint(%v): %v",
|
|
||||||
c.cfg.chanState.FundingOutpoint, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dispatchLocalForceClose processes a unilateral close by us being confirmed.
|
// dispatchLocalForceClose processes a unilateral close by us being confirmed.
|
||||||
|
@ -1364,10 +1364,16 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// We've cooperatively closed the channel, so we're no longer
|
// We've cooperatively closed the channel, so we're no longer
|
||||||
// needed.
|
// needed. We'll mark the channel as resolved and exit.
|
||||||
case <-c.cfg.ChainEvents.CooperativeClosure:
|
case <-c.cfg.ChainEvents.CooperativeClosure:
|
||||||
log.Infof("ChannelArbitrator(%v) closing due to co-op "+
|
log.Infof("ChannelArbitrator(%v) closing due to co-op "+
|
||||||
"closure", c.cfg.ChanPoint)
|
"closure", c.cfg.ChanPoint)
|
||||||
|
|
||||||
|
if err := c.cfg.MarkChannelResolved(); err != nil {
|
||||||
|
log.Errorf("Unable to mark contract "+
|
||||||
|
"resolved: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
// We have broadcasted our commitment, and it is now confirmed
|
// We have broadcasted our commitment, and it is now confirmed
|
||||||
|
Loading…
Reference in New Issue
Block a user