contractcourt: extend the ChainArbitratorConfig with IsOurAddress closure

In this commit, we add the IsOurAddress field into the config of the
chain arb. With this new function closure, the chain arb is able to
detect co-op on chain closes automatically.
This commit is contained in:
Olaoluwa Osuntokun 2018-01-19 17:17:14 -08:00
parent bdbb33344a
commit bbca53507f
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 17 additions and 1 deletions

@ -11,6 +11,7 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
"github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil"
)
// ResolutionMsg is a message sent by resolvers to outside sub-systems once an
@ -77,9 +78,14 @@ type ChainArbitratorConfig struct {
// ChannelArbitrator decides that it needs to go to chain in order to
// resolve contracts.
//
// TODO(Roasbeef): rename, routing based
// TODO(roasbeef): rename, routing based
MarkLinkInactive func(wire.OutPoint) error
// IsOurAddress is a function that returns true if the passed address
// is known to the underlying wallet. Otherwise, false should be
// returned.
IsOurAddress func(btcutil.Address) bool
// IncubateOutput sends either a incoming HTLC, an outgoing HTLC, or
// both to the utxo nursery. Once this function returns, the nursery
// should have safely persisted the outputs to disk, and should start
@ -323,6 +329,9 @@ func (c *ChainArbitrator) Start() error {
// to ensure that we detect any relevant on chain events.
chainWatcher, err := newChainWatcher(
channel, c.cfg.Notifier, c.cfg.PreimageDB, c.cfg.Signer,
c.cfg.IsOurAddress, func() error {
return c.resolveContract(channel.FundingOutpoint, nil)
},
)
if err != nil {
return err
@ -572,6 +581,9 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
// that we detect any relevant on chain events.
chainWatcher, err := newChainWatcher(
newChan, c.cfg.Notifier, c.cfg.PreimageDB, c.cfg.Signer,
c.cfg.IsOurAddress, func() error {
return c.resolveContract(chanPoint, nil)
},
)
if err != nil {
return err

@ -400,6 +400,10 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
return s.htlcSwitch.RemoveLink(chanID)
},
IsOurAddress: func(addr btcutil.Address) bool {
_, err := cc.wallet.GetPrivKey(addr)
return err == nil
},
}, chanDB)
s.breachArbiter = newBreachArbiter(&BreachConfig{