htlcswitch/test: move preimage cache to server level

In this commit the preimage cache is instantiated on the mock server
level where it belongs. Previously it was a cache shared across all mock
servers.
This commit is contained in:
Joost Jager 2019-02-09 17:22:32 +01:00
parent c4263e7061
commit 9643b45dbc
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 8 additions and 6 deletions

@ -131,6 +131,7 @@ type mockServer struct {
htlcSwitch *Switch htlcSwitch *Switch
registry *mockInvoiceRegistry registry *mockInvoiceRegistry
pCache *mockPreimageCache
interceptorFuncs []messageInterceptor interceptorFuncs []messageInterceptor
} }
@ -186,19 +187,24 @@ func newMockServer(t testing.TB, name string, startingHeight uint32,
h := sha256.Sum256([]byte(name)) h := sha256.Sum256([]byte(name))
copy(id[:], h[:]) copy(id[:], h[:])
pCache := newMockPreimageCache()
htlcSwitch, err := initSwitchWithDB(startingHeight, db) htlcSwitch, err := initSwitchWithDB(startingHeight, db)
if err != nil { if err != nil {
return nil, err return nil, err
} }
registry := newMockRegistry(defaultDelta)
return &mockServer{ return &mockServer{
t: t, t: t,
id: id, id: id,
name: name, name: name,
messages: make(chan lnwire.Message, 3000), messages: make(chan lnwire.Message, 3000),
quit: make(chan struct{}), quit: make(chan struct{}),
registry: newMockRegistry(defaultDelta), registry: registry,
htlcSwitch: htlcSwitch, htlcSwitch: htlcSwitch,
pCache: pCache,
interceptorFuncs: make([]messageInterceptor, 0), interceptorFuncs: make([]messageInterceptor, 0),
}, nil }, nil
} }

@ -971,7 +971,6 @@ type hopNetwork struct {
feeEstimator *mockFeeEstimator feeEstimator *mockFeeEstimator
globalPolicy ForwardingPolicy globalPolicy ForwardingPolicy
obfuscator ErrorEncrypter obfuscator ErrorEncrypter
pCache *mockPreimageCache
defaultDelta uint32 defaultDelta uint32
} }
@ -979,8 +978,6 @@ type hopNetwork struct {
func newHopNetwork() *hopNetwork { func newHopNetwork() *hopNetwork {
defaultDelta := uint32(6) defaultDelta := uint32(6)
pCache := newMockPreimageCache()
globalPolicy := ForwardingPolicy{ globalPolicy := ForwardingPolicy{
MinHTLC: lnwire.NewMSatFromSatoshis(5), MinHTLC: lnwire.NewMSatFromSatoshis(5),
BaseFee: lnwire.NewMSatFromSatoshis(1), BaseFee: lnwire.NewMSatFromSatoshis(1),
@ -997,7 +994,6 @@ func newHopNetwork() *hopNetwork {
feeEstimator: feeEstimator, feeEstimator: feeEstimator,
globalPolicy: globalPolicy, globalPolicy: globalPolicy,
obfuscator: obfuscator, obfuscator: obfuscator,
pCache: pCache,
defaultDelta: defaultDelta, defaultDelta: defaultDelta,
} }
} }
@ -1028,7 +1024,7 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer,
FetchLastChannelUpdate: mockGetChanUpdateMessage, FetchLastChannelUpdate: mockGetChanUpdateMessage,
Registry: server.registry, Registry: server.registry,
FeeEstimator: h.feeEstimator, FeeEstimator: h.feeEstimator,
PreimageCache: h.pCache, PreimageCache: server.pCache,
UpdateContractSignals: func(*contractcourt.ContractSignals) error { UpdateContractSignals: func(*contractcourt.ContractSignals) error {
return nil return nil
}, },