From 10090a978d4346cb90dc0cc0017ca75ff8cbd18c Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Sun, 21 Oct 2018 20:40:02 -0700 Subject: [PATCH] contractcourt/chain_arbitrator: notify the ChannelNotifier on newly closed channels. --- contractcourt/chain_arbitrator.go | 26 +++++++++++++++----------- server.go | 5 +++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index a9c77234..76be7873 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -141,6 +141,10 @@ type ChainArbitratorConfig struct { // the given payment hash. ErrInvoiceNotFound is returned if an invoice // is not found. SettleInvoice func(lntypes.Hash, lnwire.MilliSatoshi) error + + // NotifyClosedChannel is a function closure that the ChainArbitrator + // will use to notify the ChannelNotifier about a newly closed channel. + NotifyClosedChannel func(wire.OutPoint) } // ChainArbitrator is a sub-system that oversees the on-chain resolution of all @@ -245,10 +249,16 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel, return chanMachine.ForceClose() }, MarkCommitmentBroadcasted: channel.MarkCommitmentBroadcasted, - MarkChannelClosed: channel.CloseChannel, - IsPendingClose: false, - ChainArbitratorConfig: c.cfg, - ChainEvents: chanEvents, + MarkChannelClosed: func(summary *channeldb.ChannelCloseSummary) error { + if err := channel.CloseChannel(summary); err != nil { + return err + } + c.cfg.NotifyClosedChannel(summary.ChanPoint) + return nil + }, + IsPendingClose: false, + ChainArbitratorConfig: c.cfg, + ChainEvents: chanEvents, } // The final component needed is an arbitrator log that the arbitrator @@ -719,13 +729,7 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error // SubscribeChannelEvents returns a new active subscription for the set of // possible on-chain events for a particular channel. The struct can be used by // callers to be notified whenever an event that changes the state of the -// channel on-chain occurs. If syncDispatch is true, then the sender of the -// notification will wait until an error is sent over the ProcessACK before -// modifying any database state. This allows callers to request a reliable hand -// off. -// -// TODO(roasbeef): can be used later to provide RPC hook for all channel -// lifetimes +// channel on-chain occurs. func (c *ChainArbitrator) SubscribeChannelEvents( chanPoint wire.OutPoint) (*ChainEventSubscription, error) { diff --git a/server.go b/server.go index 3be02cdd..38df7e34 100644 --- a/server.go +++ b/server.go @@ -742,8 +742,9 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, DisableChannel: func(op wire.OutPoint) error { return s.announceChanStatus(op, true) }, - Sweeper: s.sweeper, - SettleInvoice: s.invoices.SettleInvoice, + Sweeper: s.sweeper, + SettleInvoice: s.invoices.SettleInvoice, + NotifyClosedChannel: s.channelNotifier.NotifyClosedChannelEvent, }, chanDB) s.breachArbiter = newBreachArbiter(&BreachConfig{