From 0d0f22aacbda539fc0437ab1eb84cfd936edc613 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 25 Nov 2020 15:06:46 -0800 Subject: [PATCH] link+peer: thread anchor tower client to link --- htlcswitch/link.go | 23 ++++++----------------- peer/brontide.go | 20 ++++++++++++++++++-- server.go | 1 + 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 3b0e923c..6a7c3128 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -256,7 +256,7 @@ type ChannelLinkConfig struct { // TowerClient is an optional engine that manages the signing, // encrypting, and uploading of justice transactions to the daemon's - // configured set of watchtowers. + // configured set of watchtowers for legacy channels. TowerClient TowerClient // MaxOutgoingCltvExpiry is the maximum outgoing timelock that the link @@ -435,12 +435,7 @@ func (l *channelLink) Start() error { // If the config supplied watchtower client, ensure the channel is // registered before trying to use it during operation. - // TODO(halseth): support anchor types for watchtower. - state := l.channel.State() - if l.cfg.TowerClient != nil && state.ChanType.HasAnchors() { - l.log.Warnf("Skipping tower registration for anchor " + - "channel type") - } else if l.cfg.TowerClient != nil && !state.ChanType.HasAnchors() { + if l.cfg.TowerClient != nil { err := l.cfg.TowerClient.RegisterChannel(l.ChanID()) if err != nil { return err @@ -1835,14 +1830,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { return } - // If we have a tower client, we'll proceed in backing up the - // state that was just revoked. - // TODO(halseth): support anchor types for watchtower. - state := l.channel.State() - if l.cfg.TowerClient != nil && state.ChanType.HasAnchors() { - l.log.Warnf("Skipping tower backup for anchor " + - "channel type") - } else if l.cfg.TowerClient != nil && !state.ChanType.HasAnchors() { + // If we have a tower client for this channel type, we'll + if l.cfg.TowerClient != nil { + state := l.channel.State() breachInfo, err := lnwallet.NewBreachRetribution( state, state.RemoteCommitment.CommitHeight-1, 0, ) @@ -1852,10 +1842,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) { return } - chanType := l.channel.State().ChanType chanID := l.ChanID() err = l.cfg.TowerClient.BackupState( - &chanID, breachInfo, chanType, + &chanID, breachInfo, state.ChanType, ) if err != nil { l.fail(LinkFailureError{code: ErrInternalError}, diff --git a/peer/brontide.go b/peer/brontide.go index 164bbdf4..578d7133 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -248,9 +248,13 @@ type Config struct { // HtlcNotifier is used when creating a ChannelLink. HtlcNotifier *htlcswitch.HtlcNotifier - // TowerClient is used when creating a ChannelLink. + // TowerClient is used by legacy channels to backup revoked states. TowerClient wtclient.Client + // AnchorTowerClient is used by anchor channels to backup revoked + // states. + AnchorTowerClient wtclient.Client + // DisconnectPeer is used to disconnect this peer if the cooperative close // process fails. DisconnectPeer func(*btcec.PublicKey) error @@ -757,6 +761,18 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, return p.cfg.ChainArb.UpdateContractSignals(*chanPoint, signals) } + chanType := lnChan.State().ChanType + + // Select the appropriate tower client based on the channel type. It's + // okay if the clients are disabled altogether and these values are nil, + // as the link will check for nilness before using either. + var towerClient htlcswitch.TowerClient + if chanType.HasAnchors() { + towerClient = p.cfg.AnchorTowerClient + } else { + towerClient = p.cfg.TowerClient + } + linkCfg := htlcswitch.ChannelLinkConfig{ Peer: p, DecodeHopIterators: p.cfg.Sphinx.DecodeHopIterators, @@ -782,7 +798,7 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout, MaxFeeUpdateTimeout: htlcswitch.DefaultMaxLinkFeeUpdateTimeout, OutgoingCltvRejectDelta: p.cfg.OutgoingCltvRejectDelta, - TowerClient: p.cfg.TowerClient, + TowerClient: towerClient, MaxOutgoingCltvExpiry: p.cfg.MaxOutgoingCltvExpiry, MaxFeeAllocation: p.cfg.MaxChannelFeeAllocation, NotifyActiveLink: p.cfg.ChannelNotifier.NotifyActiveLinkEvent, diff --git a/server.go b/server.go index e725538a..c7d2f350 100644 --- a/server.go +++ b/server.go @@ -3077,6 +3077,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq, ChannelNotifier: s.channelNotifier, HtlcNotifier: s.htlcNotifier, TowerClient: s.towerClient, + AnchorTowerClient: s.anchorTowerClient, DisconnectPeer: s.DisconnectPeer, GenNodeAnnouncement: s.genNodeAnnouncement,