From 6c6e353597dfc0eae752f8ace3abd52b61c0e491 Mon Sep 17 00:00:00 2001 From: eugene Date: Tue, 3 Aug 2021 14:49:17 -0400 Subject: [PATCH] htlcswitch+peer: pass BestHeight to ChannelLinkConfig This allows non-test usages of ChannelLinkConfig to omit the raw htlcswitch.Switch pointer. --- htlcswitch/link.go | 5 ++++- htlcswitch/link_test.go | 2 ++ htlcswitch/test_utils.go | 1 + peer/brontide.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 304b2d8a4..883dbbdb6 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -134,6 +134,9 @@ type ChannelLinkConfig struct { // TODO(conner): remove after refactoring htlcswitch testing framework. Switch *Switch + // BestHeight returns the best known height. + BestHeight func() uint32 + // ForwardPackets attempts to forward the batch of htlcs through the // switch. The function returns and error in case it fails to send one or // more packets. The link's quit signal should be provided to allow @@ -2677,7 +2680,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, continue } - heightNow := l.cfg.Switch.BestHeight() + heightNow := l.cfg.BestHeight() pld, err := chanIterator.HopPayload() if err != nil { diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 6a0603d7f..cf62a77a4 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1951,6 +1951,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) ( FwrdingPolicy: globalPolicy, Peer: alicePeer, Switch: aliceSwitch, + BestHeight: aliceSwitch.BestHeight, Circuits: aliceSwitch.CircuitModifier(), ForwardPackets: aliceSwitch.ForwardPackets, DecodeHopIterators: decoder.DecodeHopIterators, @@ -4454,6 +4455,7 @@ func (h *persistentLinkHarness) restartLink( FwrdingPolicy: globalPolicy, Peer: alicePeer, Switch: aliceSwitch, + BestHeight: aliceSwitch.BestHeight, Circuits: aliceSwitch.CircuitModifier(), ForwardPackets: aliceSwitch.ForwardPackets, DecodeHopIterators: decoder.DecodeHopIterators, diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index cfdadd969..d33daff8f 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -1119,6 +1119,7 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer, link := NewChannelLink( ChannelLinkConfig{ Switch: server.htlcSwitch, + BestHeight: server.htlcSwitch.BestHeight, FwrdingPolicy: h.globalPolicy, Peer: peer, Circuits: server.htlcSwitch.CircuitModifier(), diff --git a/peer/brontide.go b/peer/brontide.go index 8d52cdbe3..b54eac4be 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -813,7 +813,7 @@ func (p *Brontide) addLink(chanPoint *wire.OutPoint, FetchLastChannelUpdate: p.cfg.FetchLastChanUpdate, HodlMask: p.cfg.Hodl.Mask(), Registry: p.cfg.Invoices, - Switch: p.cfg.Switch, + BestHeight: p.cfg.Switch.BestHeight, Circuits: p.cfg.Switch.CircuitModifier(), ForwardPackets: p.cfg.InterceptSwitch.ForwardPackets, FwrdingPolicy: *forwardingPolicy,