htlcswitch+peer: pass BestHeight to ChannelLinkConfig

This allows non-test usages of ChannelLinkConfig to omit the raw
htlcswitch.Switch pointer.
This commit is contained in:
eugene 2021-08-03 14:49:17 -04:00
parent 90db8de6fe
commit 6c6e353597
No known key found for this signature in database
GPG Key ID: 118759E83439A9B1
4 changed files with 8 additions and 2 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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(),

View File

@ -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,