diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 696ddeb26..6100758a0 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -375,6 +375,7 @@ func (c *ChainArbitrator) Start() error { contractBreach: func(retInfo *lnwallet.BreachRetribution) error { return c.cfg.ContractBreach(chanPoint, retInfo) }, + extractStateNumHint: lnwallet.GetStateNumHint, }, ) if err != nil { @@ -710,6 +711,7 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error contractBreach: func(retInfo *lnwallet.BreachRetribution) error { return c.cfg.ContractBreach(chanPoint, retInfo) }, + extractStateNumHint: lnwallet.GetStateNumHint, }, ) if err != nil { diff --git a/contractcourt/chain_watcher.go b/contractcourt/chain_watcher.go index 719b2068c..a658d0236 100644 --- a/contractcourt/chain_watcher.go +++ b/contractcourt/chain_watcher.go @@ -105,6 +105,11 @@ type chainWatcherConfig struct { // isOurAddr is a function that returns true if the passed address is // known to us. isOurAddr func(btcutil.Address) bool + + // extractStateNumHint extracts the encoded state hint using the passed + // obfuscater. This is used by the chain watcher to identify which + // state was broadcast and confirmed on-chain. + extractStateNumHint func(*wire.MsgTx, [lnwallet.StateHintSize]byte) uint64 } // chainWatcher is a system that's assigned to every active channel. The duty @@ -350,10 +355,9 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) { "ChannelPoint(%v) ", c.cfg.chanState.FundingOutpoint) // Decode the state hint encoded within the commitment - // transaction to determine if this is a revoked state - // or not. + // transaction to determine if this is a revoked state or not. obfuscator := c.stateHintObfuscator - broadcastStateNum := lnwallet.GetStateNumHint( + broadcastStateNum := c.cfg.extractStateNumHint( commitTxBroadcast, obfuscator, ) remoteStateNum := remoteCommit.CommitHeight @@ -418,6 +422,7 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) { // point, there's not much we can do other than wait // for us to retrieve it. We will attempt to retrieve // it from the peer each time we connect to it. + // // TODO(halseth): actively initiate re-connection to // the peer? var commitPoint *btcec.PublicKey @@ -458,6 +463,7 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) { // state, we'll just pass an empty commitment. Note // that this means we won't be able to recover any HTLC // funds. + // // TODO(halseth): can we try to recover some HTLCs? err = c.dispatchRemoteForceClose( commitSpend, channeldb.ChannelCommitment{},