contractcourt/chain_arbitrator: make breachArbiter handoff a function closure

This commit adds the new function closure option ContractBreach to the
ChainArbitrator config, a closure that is again used by the ChainWatcher
to reliably handoff a breach event to the breachArbiter.
This commit is contained in:
Johan T. Halseth 2018-04-18 13:41:49 +02:00
parent 3fdc04dff0
commit f06797ab00
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -81,6 +81,13 @@ type ChainArbitratorConfig struct {
// TODO(roasbeef): rename, routing based
MarkLinkInactive func(wire.OutPoint) error
// ContractBreach is a function closure that the ChainArbitrator will
// use to notify the breachArbiter about a contract breach. It should
// only return a non-nil error when the breachArbiter has preserved the
// necessary breach info for this channel point, and it is safe to mark
// the channel as pending close in the database.
ContractBreach func(wire.OutPoint, *lnwallet.BreachRetribution) error
// IsOurAddress is a function that returns true if the passed address
// is known to the underlying wallet. Otherwise, false should be
// returned.
@ -337,6 +344,9 @@ func (c *ChainArbitrator) Start() error {
// TODO(roasbeef): also need to pass in log?
return c.resolveContract(chanPoint, nil)
},
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
return c.cfg.ContractBreach(chanPoint, retInfo)
},
},
)
if err != nil {
@ -345,7 +355,7 @@ func (c *ChainArbitrator) Start() error {
c.activeWatchers[chanPoint] = chainWatcher
channelArb, err := newActiveChannelArbitrator(
channel, c, chainWatcher.SubscribeChannelEvents(false),
channel, c, chainWatcher.SubscribeChannelEvents(),
)
if err != nil {
return err
@ -669,6 +679,9 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
markChanClosed: func() error {
return c.resolveContract(chanPoint, nil)
},
contractBreach: func(retInfo *lnwallet.BreachRetribution) error {
return c.cfg.ContractBreach(chanPoint, retInfo)
},
},
)
if err != nil {
@ -680,7 +693,7 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
// We'll also create a new channel arbitrator instance using this new
// channel, and our internal state.
channelArb, err := newActiveChannelArbitrator(
newChan, c, chainWatcher.SubscribeChannelEvents(false),
newChan, c, chainWatcher.SubscribeChannelEvents(),
)
if err != nil {
return err
@ -708,7 +721,7 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
// TODO(roasbeef): can be used later to provide RPC hook for all channel
// lifetimes
func (c *ChainArbitrator) SubscribeChannelEvents(
chanPoint wire.OutPoint, syncDispatch bool) (*ChainEventSubscription, error) {
chanPoint wire.OutPoint) (*ChainEventSubscription, error) {
// First, we'll attempt to look up the active watcher for this channel.
// If we can't find it, then we'll return an error back to the caller.
@ -720,7 +733,7 @@ func (c *ChainArbitrator) SubscribeChannelEvents(
// With the watcher located, we'll request for it to create a new chain
// event subscription client.
return watcher.SubscribeChannelEvents(syncDispatch), nil
return watcher.SubscribeChannelEvents(), nil
}
// BeginCoopChanClose allows the initiator or responder to a cooperative