link+peer: thread anchor tower client to link

This commit is contained in:
Conner Fromknecht 2020-11-25 15:06:46 -08:00
parent 094ce09644
commit 0d0f22aacb
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 25 additions and 19 deletions

@ -256,7 +256,7 @@ type ChannelLinkConfig struct {
// TowerClient is an optional engine that manages the signing, // TowerClient is an optional engine that manages the signing,
// encrypting, and uploading of justice transactions to the daemon's // encrypting, and uploading of justice transactions to the daemon's
// configured set of watchtowers. // configured set of watchtowers for legacy channels.
TowerClient TowerClient TowerClient TowerClient
// MaxOutgoingCltvExpiry is the maximum outgoing timelock that the link // 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 // If the config supplied watchtower client, ensure the channel is
// registered before trying to use it during operation. // registered before trying to use it during operation.
// TODO(halseth): support anchor types for watchtower. if l.cfg.TowerClient != nil {
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() {
err := l.cfg.TowerClient.RegisterChannel(l.ChanID()) err := l.cfg.TowerClient.RegisterChannel(l.ChanID())
if err != nil { if err != nil {
return err return err
@ -1835,14 +1830,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
return return
} }
// If we have a tower client, we'll proceed in backing up the // If we have a tower client for this channel type, we'll
// state that was just revoked. if l.cfg.TowerClient != nil {
// TODO(halseth): support anchor types for watchtower. state := l.channel.State()
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() {
breachInfo, err := lnwallet.NewBreachRetribution( breachInfo, err := lnwallet.NewBreachRetribution(
state, state.RemoteCommitment.CommitHeight-1, 0, state, state.RemoteCommitment.CommitHeight-1, 0,
) )
@ -1852,10 +1842,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
return return
} }
chanType := l.channel.State().ChanType
chanID := l.ChanID() chanID := l.ChanID()
err = l.cfg.TowerClient.BackupState( err = l.cfg.TowerClient.BackupState(
&chanID, breachInfo, chanType, &chanID, breachInfo, state.ChanType,
) )
if err != nil { if err != nil {
l.fail(LinkFailureError{code: ErrInternalError}, l.fail(LinkFailureError{code: ErrInternalError},

@ -248,9 +248,13 @@ type Config struct {
// HtlcNotifier is used when creating a ChannelLink. // HtlcNotifier is used when creating a ChannelLink.
HtlcNotifier *htlcswitch.HtlcNotifier HtlcNotifier *htlcswitch.HtlcNotifier
// TowerClient is used when creating a ChannelLink. // TowerClient is used by legacy channels to backup revoked states.
TowerClient wtclient.Client 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 // DisconnectPeer is used to disconnect this peer if the cooperative close
// process fails. // process fails.
DisconnectPeer func(*btcec.PublicKey) error DisconnectPeer func(*btcec.PublicKey) error
@ -757,6 +761,18 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint,
return p.cfg.ChainArb.UpdateContractSignals(*chanPoint, signals) 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{ linkCfg := htlcswitch.ChannelLinkConfig{
Peer: p, Peer: p,
DecodeHopIterators: p.cfg.Sphinx.DecodeHopIterators, DecodeHopIterators: p.cfg.Sphinx.DecodeHopIterators,
@ -782,7 +798,7 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint,
MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout, MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout,
MaxFeeUpdateTimeout: htlcswitch.DefaultMaxLinkFeeUpdateTimeout, MaxFeeUpdateTimeout: htlcswitch.DefaultMaxLinkFeeUpdateTimeout,
OutgoingCltvRejectDelta: p.cfg.OutgoingCltvRejectDelta, OutgoingCltvRejectDelta: p.cfg.OutgoingCltvRejectDelta,
TowerClient: p.cfg.TowerClient, TowerClient: towerClient,
MaxOutgoingCltvExpiry: p.cfg.MaxOutgoingCltvExpiry, MaxOutgoingCltvExpiry: p.cfg.MaxOutgoingCltvExpiry,
MaxFeeAllocation: p.cfg.MaxChannelFeeAllocation, MaxFeeAllocation: p.cfg.MaxChannelFeeAllocation,
NotifyActiveLink: p.cfg.ChannelNotifier.NotifyActiveLinkEvent, NotifyActiveLink: p.cfg.ChannelNotifier.NotifyActiveLinkEvent,

@ -3077,6 +3077,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
ChannelNotifier: s.channelNotifier, ChannelNotifier: s.channelNotifier,
HtlcNotifier: s.htlcNotifier, HtlcNotifier: s.htlcNotifier,
TowerClient: s.towerClient, TowerClient: s.towerClient,
AnchorTowerClient: s.anchorTowerClient,
DisconnectPeer: s.DisconnectPeer, DisconnectPeer: s.DisconnectPeer,
GenNodeAnnouncement: s.genNodeAnnouncement, GenNodeAnnouncement: s.genNodeAnnouncement,