contractcourt/chain_arbitrator: notify the ChannelNotifier on newly closed channels.

This commit is contained in:
Valentine Wallace 2018-10-21 20:40:02 -07:00 committed by Valentine Wallace
parent bdd8ce14c9
commit 10090a978d
2 changed files with 18 additions and 13 deletions

@ -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) {

@ -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{