link+peer: thread anchor tower client to link
This commit is contained in:
parent
094ce09644
commit
0d0f22aacb
@ -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.
|
||||
// If we have a tower client for this channel type, we'll
|
||||
if l.cfg.TowerClient != nil {
|
||||
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(
|
||||
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},
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user