From 7e68cae8bd152a14b57365aed4f0a0d7b37ba5ce Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 9 Aug 2021 13:55:31 +0200 Subject: [PATCH] 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. --- contractcourt/chain_arbitrator.go | 17 +++++++++++++++++ server.go | 1 + 2 files changed, 18 insertions(+) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 453f292b6..f653ebcad 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -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) } diff --git a/server.go b/server.go index 358e4f70a..8e0498f81 100644 --- a/server.go +++ b/server.go @@ -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,