server+contractcourt: signal channel fully resolved

We might want to react to a channel being fully resolved after being
involved in a force close. For this we add a new callback and invoke it
where appropriate.
This commit is contained in:
Oliver Gugger 2021-08-09 13:55:31 +02:00
parent dcff9e5e26
commit 7e68cae8bd
No known key found for this signature in database
GPG key ID: 8E4256593F177720
2 changed files with 18 additions and 0 deletions

View file

@ -158,6 +158,15 @@ type ChainArbitratorConfig struct {
// will use to notify the ChannelNotifier about a newly closed channel.
NotifyClosedChannel func(wire.OutPoint)
// NotifyFullyResolvedChannel is a function closure that the
// ChainArbitrator will use to notify the ChannelNotifier about a newly
// resolved channel. The main difference to NotifyClosedChannel is that
// in case of a local force close the NotifyClosedChannel is called when
// the published commitment transaction confirms while
// NotifyFullyResolvedChannel is only called when the channel is fully
// resolved (which includes sweeping any time locked funds).
NotifyFullyResolvedChannel func(point wire.OutPoint)
// OnionProcessor is used to decode onion payloads for on-chain
// resolution.
OnionProcessor OnionProcessor
@ -366,6 +375,10 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel,
}
arbCfg.MarkChannelResolved = func() error {
if c.cfg.NotifyFullyResolvedChannel != nil {
c.cfg.NotifyFullyResolvedChannel(chanPoint)
}
return c.ResolveContract(chanPoint)
}
@ -566,6 +579,10 @@ func (c *ChainArbitrator) Start() error {
return err
}
arbCfg.MarkChannelResolved = func() error {
if c.cfg.NotifyFullyResolvedChannel != nil {
c.cfg.NotifyFullyResolvedChannel(chanPoint)
}
return c.ResolveContract(chanPoint)
}

View file

@ -1004,6 +1004,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
Sweeper: s.sweeper,
Registry: s.invoices,
NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent,
NotifyFullyResolvedChannel: s.channelNotifier.NotifyFullyResolvedChannelEvent,
OnionProcessor: s.sphinx,
PaymentsExpirationGracePeriod: cfg.PaymentsExpirationGracePeriod,
IsForwardedHTLC: s.htlcSwitch.IsForwardedHTLC,