• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 11170835610

03 Oct 2024 10:41PM UTC coverage: 49.188% (-9.6%) from 58.738%
11170835610

push

github

web-flow
Merge pull request #9154 from ziggie1984/master

multi: bump btcd version.

3 of 6 new or added lines in 6 files covered. (50.0%)

26110 existing lines in 428 files now uncovered.

97359 of 197934 relevant lines covered (49.19%)

1.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/htlcswitch/mock.go
1
package htlcswitch
2

3
import (
4
        "bytes"
5
        "context"
6
        "crypto/sha256"
7
        "encoding/binary"
8
        "fmt"
9
        "io"
10
        "net"
11
        "os"
12
        "path/filepath"
13
        "sync"
14
        "sync/atomic"
15
        "testing"
16
        "time"
17

18
        "github.com/btcsuite/btcd/btcec/v2"
19
        "github.com/btcsuite/btcd/btcec/v2/ecdsa"
20
        "github.com/btcsuite/btcd/btcutil"
21
        "github.com/btcsuite/btcd/wire"
22
        "github.com/go-errors/errors"
23
        sphinx "github.com/lightningnetwork/lightning-onion"
24
        "github.com/lightningnetwork/lnd/chainntnfs"
25
        "github.com/lightningnetwork/lnd/channeldb"
26
        "github.com/lightningnetwork/lnd/channeldb/models"
27
        "github.com/lightningnetwork/lnd/clock"
28
        "github.com/lightningnetwork/lnd/contractcourt"
29
        "github.com/lightningnetwork/lnd/fn"
30
        "github.com/lightningnetwork/lnd/htlcswitch/hop"
31
        "github.com/lightningnetwork/lnd/invoices"
32
        "github.com/lightningnetwork/lnd/lnpeer"
33
        "github.com/lightningnetwork/lnd/lntest/mock"
34
        "github.com/lightningnetwork/lnd/lntypes"
35
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
36
        "github.com/lightningnetwork/lnd/lnwire"
37
        "github.com/lightningnetwork/lnd/ticker"
38
        "github.com/lightningnetwork/lnd/tlv"
39
)
40

UNCOV
41
func isAlias(scid lnwire.ShortChannelID) bool {
×
UNCOV
42
        return scid.BlockHeight >= 16_000_000 && scid.BlockHeight < 16_250_000
×
UNCOV
43
}
×
44

45
type mockPreimageCache struct {
46
        sync.Mutex
47
        preimageMap map[lntypes.Hash]lntypes.Preimage
48
}
49

UNCOV
50
func newMockPreimageCache() *mockPreimageCache {
×
UNCOV
51
        return &mockPreimageCache{
×
UNCOV
52
                preimageMap: make(map[lntypes.Hash]lntypes.Preimage),
×
UNCOV
53
        }
×
UNCOV
54
}
×
55

56
func (m *mockPreimageCache) LookupPreimage(
UNCOV
57
        hash lntypes.Hash) (lntypes.Preimage, bool) {
×
UNCOV
58

×
UNCOV
59
        m.Lock()
×
UNCOV
60
        defer m.Unlock()
×
UNCOV
61

×
UNCOV
62
        p, ok := m.preimageMap[hash]
×
UNCOV
63
        return p, ok
×
UNCOV
64
}
×
65

UNCOV
66
func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error {
×
UNCOV
67
        m.Lock()
×
UNCOV
68
        defer m.Unlock()
×
UNCOV
69

×
UNCOV
70
        for _, preimage := range preimages {
×
UNCOV
71
                m.preimageMap[preimage.Hash()] = preimage
×
UNCOV
72
        }
×
73

UNCOV
74
        return nil
×
75
}
76

77
func (m *mockPreimageCache) SubscribeUpdates(
78
        chanID lnwire.ShortChannelID, htlc *channeldb.HTLC,
79
        payload *hop.Payload,
80
        nextHopOnionBlob []byte) (*contractcourt.WitnessSubscription, error) {
×
81

×
82
        return nil, nil
×
83
}
×
84

85
// TODO(yy): replace it with chainfee.MockEstimator.
86
type mockFeeEstimator struct {
87
        byteFeeIn chan chainfee.SatPerKWeight
88
        relayFee  chan chainfee.SatPerKWeight
89

90
        quit chan struct{}
91
}
92

UNCOV
93
func newMockFeeEstimator() *mockFeeEstimator {
×
UNCOV
94
        return &mockFeeEstimator{
×
UNCOV
95
                byteFeeIn: make(chan chainfee.SatPerKWeight),
×
UNCOV
96
                relayFee:  make(chan chainfee.SatPerKWeight),
×
UNCOV
97
                quit:      make(chan struct{}),
×
UNCOV
98
        }
×
UNCOV
99
}
×
100

101
func (m *mockFeeEstimator) EstimateFeePerKW(
UNCOV
102
        numBlocks uint32) (chainfee.SatPerKWeight, error) {
×
UNCOV
103

×
UNCOV
104
        select {
×
UNCOV
105
        case feeRate := <-m.byteFeeIn:
×
UNCOV
106
                return feeRate, nil
×
107
        case <-m.quit:
×
108
                return 0, fmt.Errorf("exiting")
×
109
        }
110
}
111

UNCOV
112
func (m *mockFeeEstimator) RelayFeePerKW() chainfee.SatPerKWeight {
×
UNCOV
113
        select {
×
UNCOV
114
        case feeRate := <-m.relayFee:
×
UNCOV
115
                return feeRate
×
116
        case <-m.quit:
×
117
                return 0
×
118
        }
119
}
120

121
func (m *mockFeeEstimator) Start() error {
×
122
        return nil
×
123
}
×
UNCOV
124
func (m *mockFeeEstimator) Stop() error {
×
UNCOV
125
        close(m.quit)
×
UNCOV
126
        return nil
×
UNCOV
127
}
×
128

129
var _ chainfee.Estimator = (*mockFeeEstimator)(nil)
130

131
type mockForwardingLog struct {
132
        sync.Mutex
133

134
        events map[time.Time]channeldb.ForwardingEvent
135
}
136

UNCOV
137
func (m *mockForwardingLog) AddForwardingEvents(events []channeldb.ForwardingEvent) error {
×
UNCOV
138
        m.Lock()
×
UNCOV
139
        defer m.Unlock()
×
UNCOV
140

×
UNCOV
141
        for _, event := range events {
×
UNCOV
142
                m.events[event.Timestamp] = event
×
UNCOV
143
        }
×
144

UNCOV
145
        return nil
×
146
}
147

148
type mockServer struct {
149
        started  int32 // To be used atomically.
150
        shutdown int32 // To be used atomically.
151
        wg       sync.WaitGroup
152
        quit     chan struct{}
153

154
        t testing.TB
155

156
        name     string
157
        messages chan lnwire.Message
158

159
        id         [33]byte
160
        htlcSwitch *Switch
161

162
        registry         *mockInvoiceRegistry
163
        pCache           *mockPreimageCache
164
        interceptorFuncs []messageInterceptor
165
}
166

167
var _ lnpeer.Peer = (*mockServer)(nil)
168

UNCOV
169
func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) {
×
UNCOV
170
        signAliasUpdate := func(u *lnwire.ChannelUpdate1) (*ecdsa.Signature,
×
UNCOV
171
                error) {
×
UNCOV
172

×
UNCOV
173
                return testSig, nil
×
UNCOV
174
        }
×
175

UNCOV
176
        cfg := Config{
×
UNCOV
177
                DB:                   db,
×
UNCOV
178
                FetchAllOpenChannels: db.ChannelStateDB().FetchAllOpenChannels,
×
UNCOV
179
                FetchAllChannels:     db.ChannelStateDB().FetchAllChannels,
×
UNCOV
180
                FetchClosedChannels:  db.ChannelStateDB().FetchClosedChannels,
×
UNCOV
181
                SwitchPackager:       channeldb.NewSwitchPackager(),
×
UNCOV
182
                FwdingLog: &mockForwardingLog{
×
UNCOV
183
                        events: make(map[time.Time]channeldb.ForwardingEvent),
×
UNCOV
184
                },
×
UNCOV
185
                FetchLastChannelUpdate: func(scid lnwire.ShortChannelID) (
×
UNCOV
186
                        *lnwire.ChannelUpdate1, error) {
×
UNCOV
187

×
UNCOV
188
                        return &lnwire.ChannelUpdate1{
×
UNCOV
189
                                ShortChannelID: scid,
×
UNCOV
190
                        }, nil
×
UNCOV
191
                },
×
192
                Notifier: &mock.ChainNotifier{
193
                        SpendChan: make(chan *chainntnfs.SpendDetail),
194
                        EpochChan: make(chan *chainntnfs.BlockEpoch),
195
                        ConfChan:  make(chan *chainntnfs.TxConfirmation),
196
                },
197
                FwdEventTicker: ticker.NewForce(
198
                        DefaultFwdEventInterval,
199
                ),
200
                LogEventTicker:         ticker.NewForce(DefaultLogInterval),
201
                AckEventTicker:         ticker.NewForce(DefaultAckInterval),
202
                HtlcNotifier:           &mockHTLCNotifier{},
203
                Clock:                  clock.NewDefaultClock(),
204
                MailboxDeliveryTimeout: time.Hour,
205
                MaxFeeExposure:         DefaultMaxFeeExposure,
206
                SignAliasUpdate:        signAliasUpdate,
207
                IsAlias:                isAlias,
208
        }
209

UNCOV
210
        return New(cfg, startingHeight)
×
211
}
212

213
func initSwitchWithTempDB(t testing.TB, startingHeight uint32) (*Switch,
UNCOV
214
        error) {
×
UNCOV
215

×
UNCOV
216
        tempPath := filepath.Join(t.TempDir(), "switchdb")
×
UNCOV
217
        db, err := channeldb.Open(tempPath)
×
UNCOV
218
        if err != nil {
×
219
                return nil, err
×
220
        }
×
UNCOV
221
        t.Cleanup(func() { db.Close() })
×
222

UNCOV
223
        s, err := initSwitchWithDB(startingHeight, db)
×
UNCOV
224
        if err != nil {
×
225
                return nil, err
×
226
        }
×
227

UNCOV
228
        return s, nil
×
229
}
230

231
func newMockServer(t testing.TB, name string, startingHeight uint32,
UNCOV
232
        db *channeldb.DB, defaultDelta uint32) (*mockServer, error) {
×
UNCOV
233

×
UNCOV
234
        var id [33]byte
×
UNCOV
235
        h := sha256.Sum256([]byte(name))
×
UNCOV
236
        copy(id[:], h[:])
×
UNCOV
237

×
UNCOV
238
        pCache := newMockPreimageCache()
×
UNCOV
239

×
UNCOV
240
        var (
×
UNCOV
241
                htlcSwitch *Switch
×
UNCOV
242
                err        error
×
UNCOV
243
        )
×
UNCOV
244
        if db == nil {
×
UNCOV
245
                htlcSwitch, err = initSwitchWithTempDB(t, startingHeight)
×
UNCOV
246
        } else {
×
UNCOV
247
                htlcSwitch, err = initSwitchWithDB(startingHeight, db)
×
UNCOV
248
        }
×
UNCOV
249
        if err != nil {
×
250
                return nil, err
×
251
        }
×
252

UNCOV
253
        t.Cleanup(func() { _ = htlcSwitch.Stop() })
×
254

UNCOV
255
        registry := newMockRegistry(defaultDelta)
×
UNCOV
256

×
UNCOV
257
        t.Cleanup(func() { registry.cleanup() })
×
258

UNCOV
259
        return &mockServer{
×
UNCOV
260
                t:                t,
×
UNCOV
261
                id:               id,
×
UNCOV
262
                name:             name,
×
UNCOV
263
                messages:         make(chan lnwire.Message, 3000),
×
UNCOV
264
                quit:             make(chan struct{}),
×
UNCOV
265
                registry:         registry,
×
UNCOV
266
                htlcSwitch:       htlcSwitch,
×
UNCOV
267
                pCache:           pCache,
×
UNCOV
268
                interceptorFuncs: make([]messageInterceptor, 0),
×
UNCOV
269
        }, nil
×
270
}
271

UNCOV
272
func (s *mockServer) Start() error {
×
UNCOV
273
        if !atomic.CompareAndSwapInt32(&s.started, 0, 1) {
×
274
                return errors.New("mock server already started")
×
275
        }
×
276

UNCOV
277
        if err := s.htlcSwitch.Start(); err != nil {
×
278
                return err
×
279
        }
×
280

UNCOV
281
        s.wg.Add(1)
×
UNCOV
282
        go func() {
×
UNCOV
283
                defer s.wg.Done()
×
UNCOV
284

×
UNCOV
285
                defer func() {
×
UNCOV
286
                        s.htlcSwitch.Stop()
×
UNCOV
287
                }()
×
288

UNCOV
289
                for {
×
UNCOV
290
                        select {
×
UNCOV
291
                        case msg := <-s.messages:
×
UNCOV
292
                                var shouldSkip bool
×
UNCOV
293

×
UNCOV
294
                                for _, interceptor := range s.interceptorFuncs {
×
UNCOV
295
                                        skip, err := interceptor(msg)
×
UNCOV
296
                                        if err != nil {
×
297
                                                s.t.Fatalf("%v: error in the "+
×
298
                                                        "interceptor: %v", s.name, err)
×
299
                                                return
×
300
                                        }
×
UNCOV
301
                                        shouldSkip = shouldSkip || skip
×
302
                                }
303

UNCOV
304
                                if shouldSkip {
×
UNCOV
305
                                        continue
×
306
                                }
307

UNCOV
308
                                if err := s.readHandler(msg); err != nil {
×
309
                                        s.t.Fatal(err)
×
310
                                        return
×
311
                                }
×
UNCOV
312
                        case <-s.quit:
×
UNCOV
313
                                return
×
314
                        }
315
                }
316
        }()
317

UNCOV
318
        return nil
×
319
}
320

321
func (s *mockServer) QuitSignal() <-chan struct{} {
×
322
        return s.quit
×
323
}
×
324

325
// mockHopIterator represents the test version of hop iterator which instead
326
// of encrypting the path in onion blob just stores the path as a list of hops.
327
type mockHopIterator struct {
328
        hops []*hop.Payload
329
}
330

UNCOV
331
func newMockHopIterator(hops ...*hop.Payload) hop.Iterator {
×
UNCOV
332
        return &mockHopIterator{hops: hops}
×
UNCOV
333
}
×
334

UNCOV
335
func (r *mockHopIterator) HopPayload() (*hop.Payload, hop.RouteRole, error) {
×
UNCOV
336
        h := r.hops[0]
×
UNCOV
337
        r.hops = r.hops[1:]
×
UNCOV
338
        return h, hop.RouteRoleCleartext, nil
×
UNCOV
339
}
×
340

341
func (r *mockHopIterator) ExtraOnionBlob() []byte {
×
342
        return nil
×
343
}
×
344

345
func (r *mockHopIterator) ExtractErrorEncrypter(
346
        extracter hop.ErrorEncrypterExtracter, _ bool) (hop.ErrorEncrypter,
UNCOV
347
        lnwire.FailCode) {
×
UNCOV
348

×
UNCOV
349
        return extracter(nil)
×
UNCOV
350
}
×
351

UNCOV
352
func (r *mockHopIterator) EncodeNextHop(w io.Writer) error {
×
UNCOV
353
        var hopLength [4]byte
×
UNCOV
354
        binary.BigEndian.PutUint32(hopLength[:], uint32(len(r.hops)))
×
UNCOV
355

×
UNCOV
356
        if _, err := w.Write(hopLength[:]); err != nil {
×
357
                return err
×
358
        }
×
359

UNCOV
360
        for _, hop := range r.hops {
×
UNCOV
361
                fwdInfo := hop.ForwardingInfo()
×
UNCOV
362
                if err := encodeFwdInfo(w, &fwdInfo); err != nil {
×
363
                        return err
×
364
                }
×
365
        }
366

UNCOV
367
        return nil
×
368
}
369

UNCOV
370
func encodeFwdInfo(w io.Writer, f *hop.ForwardingInfo) error {
×
UNCOV
371
        if err := binary.Write(w, binary.BigEndian, f.NextHop); err != nil {
×
372
                return err
×
373
        }
×
374

UNCOV
375
        if err := binary.Write(w, binary.BigEndian, f.AmountToForward); err != nil {
×
376
                return err
×
377
        }
×
378

UNCOV
379
        if err := binary.Write(w, binary.BigEndian, f.OutgoingCTLV); err != nil {
×
380
                return err
×
381
        }
×
382

UNCOV
383
        return nil
×
384
}
385

386
var _ hop.Iterator = (*mockHopIterator)(nil)
387

388
// mockObfuscator mock implementation of the failure obfuscator which only
389
// encodes the failure and do not makes any onion obfuscation.
390
type mockObfuscator struct {
391
        ogPacket *sphinx.OnionPacket
392
        failure  lnwire.FailureMessage
393
}
394

395
// NewMockObfuscator initializes a dummy mockObfuscator used for testing.
UNCOV
396
func NewMockObfuscator() hop.ErrorEncrypter {
×
UNCOV
397
        return &mockObfuscator{}
×
UNCOV
398
}
×
399

400
func (o *mockObfuscator) OnionPacket() *sphinx.OnionPacket {
×
401
        return o.ogPacket
×
402
}
×
403

UNCOV
404
func (o *mockObfuscator) Type() hop.EncrypterType {
×
UNCOV
405
        return hop.EncrypterTypeMock
×
UNCOV
406
}
×
407

UNCOV
408
func (o *mockObfuscator) Encode(w io.Writer) error {
×
UNCOV
409
        return nil
×
UNCOV
410
}
×
411

UNCOV
412
func (o *mockObfuscator) Decode(r io.Reader) error {
×
UNCOV
413
        return nil
×
UNCOV
414
}
×
415

416
func (o *mockObfuscator) Reextract(
UNCOV
417
        extracter hop.ErrorEncrypterExtracter) error {
×
UNCOV
418

×
UNCOV
419
        return nil
×
UNCOV
420
}
×
421

422
var fakeHmac = []byte("hmachmachmachmachmachmachmachmac")
423

424
func (o *mockObfuscator) EncryptFirstHop(failure lnwire.FailureMessage) (
UNCOV
425
        lnwire.OpaqueReason, error) {
×
UNCOV
426

×
UNCOV
427
        o.failure = failure
×
UNCOV
428

×
UNCOV
429
        var b bytes.Buffer
×
UNCOV
430
        b.Write(fakeHmac)
×
UNCOV
431

×
UNCOV
432
        if err := lnwire.EncodeFailure(&b, failure, 0); err != nil {
×
433
                return nil, err
×
434
        }
×
UNCOV
435
        return b.Bytes(), nil
×
436
}
437

UNCOV
438
func (o *mockObfuscator) IntermediateEncrypt(reason lnwire.OpaqueReason) lnwire.OpaqueReason {
×
UNCOV
439
        return reason
×
UNCOV
440
}
×
441

UNCOV
442
func (o *mockObfuscator) EncryptMalformedError(reason lnwire.OpaqueReason) lnwire.OpaqueReason {
×
UNCOV
443
        var b bytes.Buffer
×
UNCOV
444
        b.Write(fakeHmac)
×
UNCOV
445

×
UNCOV
446
        b.Write(reason)
×
UNCOV
447

×
UNCOV
448
        return b.Bytes()
×
UNCOV
449
}
×
450

451
// mockDeobfuscator mock implementation of the failure deobfuscator which
452
// only decodes the failure do not makes any onion obfuscation.
453
type mockDeobfuscator struct{}
454

UNCOV
455
func newMockDeobfuscator() ErrorDecrypter {
×
UNCOV
456
        return &mockDeobfuscator{}
×
UNCOV
457
}
×
458

459
func (o *mockDeobfuscator) DecryptError(reason lnwire.OpaqueReason) (
UNCOV
460
        *ForwardingError, error) {
×
UNCOV
461

×
UNCOV
462
        if !bytes.Equal(reason[:32], fakeHmac) {
×
463
                return nil, errors.New("fake decryption error")
×
464
        }
×
UNCOV
465
        reason = reason[32:]
×
UNCOV
466

×
UNCOV
467
        r := bytes.NewReader(reason)
×
UNCOV
468
        failure, err := lnwire.DecodeFailure(r, 0)
×
UNCOV
469
        if err != nil {
×
470
                return nil, err
×
471
        }
×
472

UNCOV
473
        return NewForwardingError(failure, 1), nil
×
474
}
475

476
var _ ErrorDecrypter = (*mockDeobfuscator)(nil)
477

478
// mockIteratorDecoder test version of hop iterator decoder which decodes the
479
// encoded array of hops.
480
type mockIteratorDecoder struct {
481
        mu sync.RWMutex
482

483
        responses map[[32]byte][]hop.DecodeHopIteratorResponse
484

485
        decodeFail bool
486
}
487

UNCOV
488
func newMockIteratorDecoder() *mockIteratorDecoder {
×
UNCOV
489
        return &mockIteratorDecoder{
×
UNCOV
490
                responses: make(map[[32]byte][]hop.DecodeHopIteratorResponse),
×
UNCOV
491
        }
×
UNCOV
492
}
×
493

494
func (p *mockIteratorDecoder) DecodeHopIterator(r io.Reader, rHash []byte,
UNCOV
495
        cltv uint32) (hop.Iterator, lnwire.FailCode) {
×
UNCOV
496

×
UNCOV
497
        var b [4]byte
×
UNCOV
498
        _, err := r.Read(b[:])
×
UNCOV
499
        if err != nil {
×
500
                return nil, lnwire.CodeTemporaryChannelFailure
×
501
        }
×
UNCOV
502
        hopLength := binary.BigEndian.Uint32(b[:])
×
UNCOV
503

×
UNCOV
504
        hops := make([]*hop.Payload, hopLength)
×
UNCOV
505
        for i := uint32(0); i < hopLength; i++ {
×
UNCOV
506
                var f hop.ForwardingInfo
×
UNCOV
507
                if err := decodeFwdInfo(r, &f); err != nil {
×
508
                        return nil, lnwire.CodeTemporaryChannelFailure
×
509
                }
×
510

UNCOV
511
                var nextHopBytes [8]byte
×
UNCOV
512
                binary.BigEndian.PutUint64(nextHopBytes[:], f.NextHop.ToUint64())
×
UNCOV
513

×
UNCOV
514
                hops[i] = hop.NewLegacyPayload(&sphinx.HopData{
×
UNCOV
515
                        Realm:         [1]byte{}, // hop.BitcoinNetwork
×
UNCOV
516
                        NextAddress:   nextHopBytes,
×
UNCOV
517
                        ForwardAmount: uint64(f.AmountToForward),
×
UNCOV
518
                        OutgoingCltv:  f.OutgoingCTLV,
×
UNCOV
519
                })
×
520
        }
521

UNCOV
522
        return newMockHopIterator(hops...), lnwire.CodeNone
×
523
}
524

525
func (p *mockIteratorDecoder) DecodeHopIterators(id []byte,
526
        reqs []hop.DecodeHopIteratorRequest) (
UNCOV
527
        []hop.DecodeHopIteratorResponse, error) {
×
UNCOV
528

×
UNCOV
529
        idHash := sha256.Sum256(id)
×
UNCOV
530

×
UNCOV
531
        p.mu.RLock()
×
UNCOV
532
        if resps, ok := p.responses[idHash]; ok {
×
533
                p.mu.RUnlock()
×
534
                return resps, nil
×
535
        }
×
UNCOV
536
        p.mu.RUnlock()
×
UNCOV
537

×
UNCOV
538
        batchSize := len(reqs)
×
UNCOV
539

×
UNCOV
540
        resps := make([]hop.DecodeHopIteratorResponse, 0, batchSize)
×
UNCOV
541
        for _, req := range reqs {
×
UNCOV
542
                iterator, failcode := p.DecodeHopIterator(
×
UNCOV
543
                        req.OnionReader, req.RHash, req.IncomingCltv,
×
UNCOV
544
                )
×
UNCOV
545

×
UNCOV
546
                if p.decodeFail {
×
UNCOV
547
                        failcode = lnwire.CodeTemporaryChannelFailure
×
UNCOV
548
                }
×
549

UNCOV
550
                resp := hop.DecodeHopIteratorResponse{
×
UNCOV
551
                        HopIterator: iterator,
×
UNCOV
552
                        FailCode:    failcode,
×
UNCOV
553
                }
×
UNCOV
554
                resps = append(resps, resp)
×
555
        }
556

UNCOV
557
        p.mu.Lock()
×
UNCOV
558
        p.responses[idHash] = resps
×
UNCOV
559
        p.mu.Unlock()
×
UNCOV
560

×
UNCOV
561
        return resps, nil
×
562
}
563

UNCOV
564
func decodeFwdInfo(r io.Reader, f *hop.ForwardingInfo) error {
×
UNCOV
565
        if err := binary.Read(r, binary.BigEndian, &f.NextHop); err != nil {
×
566
                return err
×
567
        }
×
568

UNCOV
569
        if err := binary.Read(r, binary.BigEndian, &f.AmountToForward); err != nil {
×
570
                return err
×
571
        }
×
572

UNCOV
573
        if err := binary.Read(r, binary.BigEndian, &f.OutgoingCTLV); err != nil {
×
574
                return err
×
575
        }
×
576

UNCOV
577
        return nil
×
578
}
579

580
// messageInterceptor is function that handles the incoming peer messages and
581
// may decide should the peer skip the message or not.
582
type messageInterceptor func(m lnwire.Message) (bool, error)
583

584
// Record is used to set the function which will be triggered when new
585
// lnwire message was received.
UNCOV
586
func (s *mockServer) intersect(f messageInterceptor) {
×
UNCOV
587
        s.interceptorFuncs = append(s.interceptorFuncs, f)
×
UNCOV
588
}
×
589

UNCOV
590
func (s *mockServer) SendMessage(sync bool, msgs ...lnwire.Message) error {
×
UNCOV
591

×
UNCOV
592
        for _, msg := range msgs {
×
UNCOV
593
                select {
×
UNCOV
594
                case s.messages <- msg:
×
UNCOV
595
                case <-s.quit:
×
UNCOV
596
                        return errors.New("server is stopped")
×
597
                }
598
        }
599

UNCOV
600
        return nil
×
601
}
602

603
func (s *mockServer) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
×
604
        panic("not implemented")
×
605
}
606

UNCOV
607
func (s *mockServer) readHandler(message lnwire.Message) error {
×
UNCOV
608
        var targetChan lnwire.ChannelID
×
UNCOV
609

×
UNCOV
610
        switch msg := message.(type) {
×
UNCOV
611
        case *lnwire.UpdateAddHTLC:
×
UNCOV
612
                targetChan = msg.ChanID
×
UNCOV
613
        case *lnwire.UpdateFulfillHTLC:
×
UNCOV
614
                targetChan = msg.ChanID
×
UNCOV
615
        case *lnwire.UpdateFailHTLC:
×
UNCOV
616
                targetChan = msg.ChanID
×
UNCOV
617
        case *lnwire.UpdateFailMalformedHTLC:
×
UNCOV
618
                targetChan = msg.ChanID
×
UNCOV
619
        case *lnwire.RevokeAndAck:
×
UNCOV
620
                targetChan = msg.ChanID
×
UNCOV
621
        case *lnwire.CommitSig:
×
UNCOV
622
                targetChan = msg.ChanID
×
UNCOV
623
        case *lnwire.ChannelReady:
×
UNCOV
624
                // Ignore
×
UNCOV
625
                return nil
×
UNCOV
626
        case *lnwire.ChannelReestablish:
×
UNCOV
627
                targetChan = msg.ChanID
×
UNCOV
628
        case *lnwire.UpdateFee:
×
UNCOV
629
                targetChan = msg.ChanID
×
630
        default:
×
631
                return fmt.Errorf("unknown message type: %T", msg)
×
632
        }
633

634
        // Dispatch the commitment update message to the proper channel link
635
        // dedicated to this channel. If the link is not found, we will discard
636
        // the message.
UNCOV
637
        link, err := s.htlcSwitch.GetLink(targetChan)
×
UNCOV
638
        if err != nil {
×
639
                return nil
×
640
        }
×
641

642
        // Create goroutine for this, in order to be able to properly stop
643
        // the server when handler stacked (server unavailable)
UNCOV
644
        link.HandleChannelUpdate(message)
×
UNCOV
645

×
UNCOV
646
        return nil
×
647
}
648

UNCOV
649
func (s *mockServer) PubKey() [33]byte {
×
UNCOV
650
        return s.id
×
UNCOV
651
}
×
652

653
func (s *mockServer) IdentityKey() *btcec.PublicKey {
×
654
        pubkey, _ := btcec.ParsePubKey(s.id[:])
×
655
        return pubkey
×
656
}
×
657

658
func (s *mockServer) Address() net.Addr {
×
659
        return nil
×
660
}
×
661

662
func (s *mockServer) AddNewChannel(channel *lnpeer.NewChannel,
663
        cancel <-chan struct{}) error {
×
664

×
665
        return nil
×
666
}
×
667

668
func (s *mockServer) AddPendingChannel(_ lnwire.ChannelID,
669
        cancel <-chan struct{}) error {
×
670

×
671
        return nil
×
672
}
×
673

674
func (s *mockServer) RemovePendingChannel(_ lnwire.ChannelID) error {
×
675
        return nil
×
676
}
×
677

678
func (s *mockServer) WipeChannel(*wire.OutPoint) {}
×
679

680
func (s *mockServer) LocalFeatures() *lnwire.FeatureVector {
×
681
        return nil
×
682
}
×
683

684
func (s *mockServer) RemoteFeatures() *lnwire.FeatureVector {
×
685
        return nil
×
686
}
×
687

688
func (s *mockServer) Disconnect(err error) {}
×
689

UNCOV
690
func (s *mockServer) Stop() error {
×
UNCOV
691
        if !atomic.CompareAndSwapInt32(&s.shutdown, 0, 1) {
×
UNCOV
692
                return nil
×
UNCOV
693
        }
×
694

UNCOV
695
        close(s.quit)
×
UNCOV
696
        s.wg.Wait()
×
UNCOV
697

×
UNCOV
698
        return nil
×
699
}
700

701
func (s *mockServer) String() string {
×
702
        return s.name
×
703
}
×
704

705
type mockChannelLink struct {
706
        htlcSwitch *Switch
707

708
        shortChanID lnwire.ShortChannelID
709

710
        // Only used for zero-conf channels.
711
        realScid lnwire.ShortChannelID
712

713
        aliases []lnwire.ShortChannelID
714

715
        chanID lnwire.ChannelID
716

717
        peer lnpeer.Peer
718

719
        mailBox MailBox
720

721
        packets chan *htlcPacket
722

723
        eligible bool
724

725
        unadvertised bool
726

727
        zeroConf bool
728

729
        optionFeature bool
730

731
        htlcID uint64
732

733
        checkHtlcTransitResult *LinkError
734

735
        checkHtlcForwardResult *LinkError
736

737
        failAliasUpdate func(sid lnwire.ShortChannelID,
738
                incoming bool) *lnwire.ChannelUpdate1
739

740
        confirmedZC bool
741
}
742

743
// completeCircuit is a helper method for adding the finalized payment circuit
744
// to the switch's circuit map. In testing, this should be executed after
745
// receiving an htlc from the downstream packets channel.
UNCOV
746
func (f *mockChannelLink) completeCircuit(pkt *htlcPacket) error {
×
UNCOV
747
        switch htlc := pkt.htlc.(type) {
×
UNCOV
748
        case *lnwire.UpdateAddHTLC:
×
UNCOV
749
                pkt.outgoingChanID = f.shortChanID
×
UNCOV
750
                pkt.outgoingHTLCID = f.htlcID
×
UNCOV
751
                htlc.ID = f.htlcID
×
UNCOV
752

×
UNCOV
753
                keystone := Keystone{pkt.inKey(), pkt.outKey()}
×
UNCOV
754
                err := f.htlcSwitch.circuits.OpenCircuits(keystone)
×
UNCOV
755
                if err != nil {
×
756
                        return err
×
757
                }
×
758

UNCOV
759
                f.htlcID++
×
760

UNCOV
761
        case *lnwire.UpdateFulfillHTLC, *lnwire.UpdateFailHTLC:
×
UNCOV
762
                if pkt.circuit != nil {
×
UNCOV
763
                        err := f.htlcSwitch.teardownCircuit(pkt)
×
UNCOV
764
                        if err != nil {
×
765
                                return err
×
766
                        }
×
767
                }
768
        }
769

UNCOV
770
        f.mailBox.AckPacket(pkt.inKey())
×
UNCOV
771

×
UNCOV
772
        return nil
×
773
}
774

UNCOV
775
func (f *mockChannelLink) deleteCircuit(pkt *htlcPacket) error {
×
UNCOV
776
        return f.htlcSwitch.circuits.DeleteCircuits(pkt.inKey())
×
UNCOV
777
}
×
778

779
func newMockChannelLink(htlcSwitch *Switch, chanID lnwire.ChannelID,
780
        shortChanID, realScid lnwire.ShortChannelID, peer lnpeer.Peer,
781
        eligible, unadvertised, zeroConf, optionFeature bool,
UNCOV
782
) *mockChannelLink {
×
UNCOV
783

×
UNCOV
784
        aliases := make([]lnwire.ShortChannelID, 0)
×
UNCOV
785
        var realConfirmed bool
×
UNCOV
786

×
UNCOV
787
        if zeroConf {
×
UNCOV
788
                aliases = append(aliases, shortChanID)
×
UNCOV
789
        }
×
790

UNCOV
791
        if realScid != hop.Source {
×
UNCOV
792
                realConfirmed = true
×
UNCOV
793
        }
×
794

UNCOV
795
        return &mockChannelLink{
×
UNCOV
796
                htlcSwitch:    htlcSwitch,
×
UNCOV
797
                chanID:        chanID,
×
UNCOV
798
                shortChanID:   shortChanID,
×
UNCOV
799
                realScid:      realScid,
×
UNCOV
800
                peer:          peer,
×
UNCOV
801
                eligible:      eligible,
×
UNCOV
802
                unadvertised:  unadvertised,
×
UNCOV
803
                zeroConf:      zeroConf,
×
UNCOV
804
                optionFeature: optionFeature,
×
UNCOV
805
                aliases:       aliases,
×
UNCOV
806
                confirmedZC:   realConfirmed,
×
UNCOV
807
        }
×
808
}
809

810
// addAlias is not part of any interface method.
UNCOV
811
func (f *mockChannelLink) addAlias(alias lnwire.ShortChannelID) {
×
UNCOV
812
        f.aliases = append(f.aliases, alias)
×
UNCOV
813
}
×
814

UNCOV
815
func (f *mockChannelLink) handleSwitchPacket(pkt *htlcPacket) error {
×
UNCOV
816
        f.mailBox.AddPacket(pkt)
×
UNCOV
817
        return nil
×
UNCOV
818
}
×
819

820
func (f *mockChannelLink) getDustSum(whoseCommit lntypes.ChannelParty,
UNCOV
821
        dryRunFee fn.Option[chainfee.SatPerKWeight]) lnwire.MilliSatoshi {
×
UNCOV
822

×
UNCOV
823
        return 0
×
UNCOV
824
}
×
825

UNCOV
826
func (f *mockChannelLink) getFeeRate() chainfee.SatPerKWeight {
×
UNCOV
827
        return 0
×
UNCOV
828
}
×
829

UNCOV
830
func (f *mockChannelLink) getDustClosure() dustClosure {
×
UNCOV
831
        dustLimit := btcutil.Amount(400)
×
UNCOV
832
        return dustHelper(
×
UNCOV
833
                channeldb.SingleFunderTweaklessBit, dustLimit, dustLimit,
×
UNCOV
834
        )
×
UNCOV
835
}
×
836

837
func (f *mockChannelLink) getCommitFee(remote bool) btcutil.Amount {
×
838
        return 0
×
839
}
×
840

841
func (f *mockChannelLink) HandleChannelUpdate(lnwire.Message) {
×
842
}
×
843

844
func (f *mockChannelLink) UpdateForwardingPolicy(_ models.ForwardingPolicy) {
×
845
}
×
846
func (f *mockChannelLink) CheckHtlcForward([32]byte, lnwire.MilliSatoshi,
847
        lnwire.MilliSatoshi, uint32, uint32, models.InboundFee, uint32,
UNCOV
848
        lnwire.ShortChannelID) *LinkError {
×
UNCOV
849

×
UNCOV
850
        return f.checkHtlcForwardResult
×
UNCOV
851
}
×
852

853
func (f *mockChannelLink) CheckHtlcTransit(payHash [32]byte,
854
        amt lnwire.MilliSatoshi, timeout uint32,
UNCOV
855
        heightNow uint32) *LinkError {
×
UNCOV
856

×
UNCOV
857
        return f.checkHtlcTransitResult
×
UNCOV
858
}
×
859

860
func (f *mockChannelLink) Stats() (
UNCOV
861
        uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi) {
×
UNCOV
862

×
UNCOV
863
        return 0, 0, 0
×
UNCOV
864
}
×
865

UNCOV
866
func (f *mockChannelLink) AttachMailBox(mailBox MailBox) {
×
UNCOV
867
        f.mailBox = mailBox
×
UNCOV
868
        f.packets = mailBox.PacketOutBox()
×
UNCOV
869
        mailBox.SetDustClosure(f.getDustClosure())
×
UNCOV
870
}
×
871

872
func (f *mockChannelLink) attachFailAliasUpdate(closure func(
UNCOV
873
        sid lnwire.ShortChannelID, incoming bool) *lnwire.ChannelUpdate1) {
×
UNCOV
874

×
UNCOV
875
        f.failAliasUpdate = closure
×
UNCOV
876
}
×
877

UNCOV
878
func (f *mockChannelLink) getAliases() []lnwire.ShortChannelID {
×
UNCOV
879
        return f.aliases
×
UNCOV
880
}
×
881

UNCOV
882
func (f *mockChannelLink) isZeroConf() bool {
×
UNCOV
883
        return f.zeroConf
×
UNCOV
884
}
×
885

UNCOV
886
func (f *mockChannelLink) negotiatedAliasFeature() bool {
×
UNCOV
887
        return f.optionFeature
×
UNCOV
888
}
×
889

UNCOV
890
func (f *mockChannelLink) confirmedScid() lnwire.ShortChannelID {
×
UNCOV
891
        return f.realScid
×
UNCOV
892
}
×
893

UNCOV
894
func (f *mockChannelLink) zeroConfConfirmed() bool {
×
UNCOV
895
        return f.confirmedZC
×
UNCOV
896
}
×
897

UNCOV
898
func (f *mockChannelLink) Start() error {
×
UNCOV
899
        f.mailBox.ResetMessages()
×
UNCOV
900
        f.mailBox.ResetPackets()
×
UNCOV
901
        return nil
×
UNCOV
902
}
×
903

UNCOV
904
func (f *mockChannelLink) ChanID() lnwire.ChannelID {
×
UNCOV
905
        return f.chanID
×
UNCOV
906
}
×
907

UNCOV
908
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID {
×
UNCOV
909
        return f.shortChanID
×
UNCOV
910
}
×
911

912
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi {
×
913
        return 99999999
×
914
}
×
915

UNCOV
916
func (f *mockChannelLink) PeerPubKey() [33]byte {
×
UNCOV
917
        return f.peer.PubKey()
×
UNCOV
918
}
×
919

920
func (f *mockChannelLink) ChannelPoint() wire.OutPoint {
×
921
        return wire.OutPoint{}
×
922
}
×
923

UNCOV
924
func (f *mockChannelLink) Stop()                                        {}
×
UNCOV
925
func (f *mockChannelLink) EligibleToForward() bool                      { return f.eligible }
×
926
func (f *mockChannelLink) MayAddOutgoingHtlc(lnwire.MilliSatoshi) error { return nil }
×
927
func (f *mockChannelLink) setLiveShortChanID(sid lnwire.ShortChannelID) { f.shortChanID = sid }
×
UNCOV
928
func (f *mockChannelLink) IsUnadvertised() bool                         { return f.unadvertised }
×
UNCOV
929
func (f *mockChannelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
×
UNCOV
930
        f.eligible = true
×
UNCOV
931
        return f.shortChanID, nil
×
UNCOV
932
}
×
933

934
func (f *mockChannelLink) EnableAdds(linkDirection LinkDirection) bool {
×
935
        // TODO(proofofkeags): Implement
×
936
        return true
×
937
}
×
938

939
func (f *mockChannelLink) DisableAdds(linkDirection LinkDirection) bool {
×
940
        // TODO(proofofkeags): Implement
×
941
        return true
×
942
}
×
943
func (f *mockChannelLink) IsFlushing(linkDirection LinkDirection) bool {
×
944
        // TODO(proofofkeags): Implement
×
945
        return false
×
946
}
×
947
func (f *mockChannelLink) OnFlushedOnce(func()) {
×
948
        // TODO(proofofkeags): Implement
×
949
}
×
950
func (f *mockChannelLink) OnCommitOnce(LinkDirection, func()) {
×
951
        // TODO(proofofkeags): Implement
×
952
}
×
953

954
func (f *mockChannelLink) FundingCustomBlob() fn.Option[tlv.Blob] {
×
955
        return fn.None[tlv.Blob]()
×
956
}
×
957

958
func (f *mockChannelLink) CommitmentCustomBlob() fn.Option[tlv.Blob] {
×
959
        return fn.None[tlv.Blob]()
×
960
}
×
961

962
var _ ChannelLink = (*mockChannelLink)(nil)
963

UNCOV
964
func newDB() (*channeldb.DB, func(), error) {
×
UNCOV
965
        // First, create a temporary directory to be used for the duration of
×
UNCOV
966
        // this test.
×
UNCOV
967
        tempDirName, err := os.MkdirTemp("", "channeldb")
×
UNCOV
968
        if err != nil {
×
969
                return nil, nil, err
×
970
        }
×
971

972
        // Next, create channeldb for the first time.
UNCOV
973
        cdb, err := channeldb.Open(tempDirName)
×
UNCOV
974
        if err != nil {
×
975
                os.RemoveAll(tempDirName)
×
976
                return nil, nil, err
×
977
        }
×
978

UNCOV
979
        cleanUp := func() {
×
UNCOV
980
                cdb.Close()
×
UNCOV
981
                os.RemoveAll(tempDirName)
×
UNCOV
982
        }
×
983

UNCOV
984
        return cdb, cleanUp, nil
×
985
}
986

987
const testInvoiceCltvExpiry = 6
988

989
type mockInvoiceRegistry struct {
990
        settleChan chan lntypes.Hash
991

992
        registry *invoices.InvoiceRegistry
993

994
        cleanup func()
995
}
996

997
type mockChainNotifier struct {
998
        chainntnfs.ChainNotifier
999
}
1000

1001
// RegisterBlockEpochNtfn mocks a successful call to register block
1002
// notifications.
1003
func (m *mockChainNotifier) RegisterBlockEpochNtfn(*chainntnfs.BlockEpoch) (
UNCOV
1004
        *chainntnfs.BlockEpochEvent, error) {
×
UNCOV
1005

×
UNCOV
1006
        return &chainntnfs.BlockEpochEvent{
×
UNCOV
1007
                Cancel: func() {},
×
1008
        }, nil
1009
}
1010

UNCOV
1011
func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
×
UNCOV
1012
        cdb, cleanup, err := newDB()
×
UNCOV
1013
        if err != nil {
×
1014
                panic(err)
×
1015
        }
1016

UNCOV
1017
        modifierMock := &invoices.MockHtlcModifier{}
×
UNCOV
1018
        registry := invoices.NewRegistry(
×
UNCOV
1019
                cdb,
×
UNCOV
1020
                invoices.NewInvoiceExpiryWatcher(
×
UNCOV
1021
                        clock.NewDefaultClock(), 0, 0, nil,
×
UNCOV
1022
                        &mockChainNotifier{},
×
UNCOV
1023
                ),
×
UNCOV
1024
                &invoices.RegistryConfig{
×
UNCOV
1025
                        FinalCltvRejectDelta: 5,
×
UNCOV
1026
                        HtlcInterceptor:      modifierMock,
×
UNCOV
1027
                },
×
UNCOV
1028
        )
×
UNCOV
1029
        registry.Start()
×
UNCOV
1030

×
UNCOV
1031
        return &mockInvoiceRegistry{
×
UNCOV
1032
                registry: registry,
×
UNCOV
1033
                cleanup:  cleanup,
×
UNCOV
1034
        }
×
1035
}
1036

1037
func (i *mockInvoiceRegistry) LookupInvoice(ctx context.Context,
UNCOV
1038
        rHash lntypes.Hash) (invoices.Invoice, error) {
×
UNCOV
1039

×
UNCOV
1040
        return i.registry.LookupInvoice(ctx, rHash)
×
UNCOV
1041
}
×
1042

1043
func (i *mockInvoiceRegistry) SettleHodlInvoice(
UNCOV
1044
        ctx context.Context, preimage lntypes.Preimage) error {
×
UNCOV
1045

×
UNCOV
1046
        return i.registry.SettleHodlInvoice(ctx, preimage)
×
UNCOV
1047
}
×
1048

1049
func (i *mockInvoiceRegistry) NotifyExitHopHtlc(rhash lntypes.Hash,
1050
        amt lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
1051
        circuitKey models.CircuitKey, hodlChan chan<- interface{},
1052
        wireCustomRecords lnwire.CustomRecords,
UNCOV
1053
        payload invoices.Payload) (invoices.HtlcResolution, error) {
×
UNCOV
1054

×
UNCOV
1055
        event, err := i.registry.NotifyExitHopHtlc(
×
UNCOV
1056
                rhash, amt, expiry, currentHeight, circuitKey,
×
UNCOV
1057
                hodlChan, wireCustomRecords, payload,
×
UNCOV
1058
        )
×
UNCOV
1059
        if err != nil {
×
1060
                return nil, err
×
1061
        }
×
UNCOV
1062
        if i.settleChan != nil {
×
UNCOV
1063
                i.settleChan <- rhash
×
UNCOV
1064
        }
×
1065

UNCOV
1066
        return event, nil
×
1067
}
1068

1069
func (i *mockInvoiceRegistry) CancelInvoice(ctx context.Context,
UNCOV
1070
        payHash lntypes.Hash) error {
×
UNCOV
1071

×
UNCOV
1072
        return i.registry.CancelInvoice(ctx, payHash)
×
UNCOV
1073
}
×
1074

1075
func (i *mockInvoiceRegistry) AddInvoice(ctx context.Context,
UNCOV
1076
        invoice invoices.Invoice, paymentHash lntypes.Hash) error {
×
UNCOV
1077

×
UNCOV
1078
        _, err := i.registry.AddInvoice(ctx, &invoice, paymentHash)
×
UNCOV
1079
        return err
×
UNCOV
1080
}
×
1081

1082
func (i *mockInvoiceRegistry) HodlUnsubscribeAll(
UNCOV
1083
        subscriber chan<- interface{}) {
×
UNCOV
1084

×
UNCOV
1085
        i.registry.HodlUnsubscribeAll(subscriber)
×
UNCOV
1086
}
×
1087

1088
var _ InvoiceDatabase = (*mockInvoiceRegistry)(nil)
1089

1090
type mockCircuitMap struct {
1091
        lookup chan *PaymentCircuit
1092
}
1093

1094
var _ CircuitMap = (*mockCircuitMap)(nil)
1095

1096
func (m *mockCircuitMap) OpenCircuits(...Keystone) error {
×
1097
        return nil
×
1098
}
×
1099

1100
func (m *mockCircuitMap) TrimOpenCircuits(chanID lnwire.ShortChannelID,
1101
        start uint64) error {
×
1102
        return nil
×
1103
}
×
1104

1105
func (m *mockCircuitMap) DeleteCircuits(inKeys ...CircuitKey) error {
×
1106
        return nil
×
1107
}
×
1108

1109
func (m *mockCircuitMap) CommitCircuits(
1110
        circuit ...*PaymentCircuit) (*CircuitFwdActions, error) {
×
1111

×
1112
        return nil, nil
×
1113
}
×
1114

1115
func (m *mockCircuitMap) CloseCircuit(outKey CircuitKey) (*PaymentCircuit,
1116
        error) {
×
1117
        return nil, nil
×
1118
}
×
1119

1120
func (m *mockCircuitMap) FailCircuit(inKey CircuitKey) (*PaymentCircuit,
1121
        error) {
×
1122
        return nil, nil
×
1123
}
×
1124

UNCOV
1125
func (m *mockCircuitMap) LookupCircuit(inKey CircuitKey) *PaymentCircuit {
×
UNCOV
1126
        return <-m.lookup
×
UNCOV
1127
}
×
1128

1129
func (m *mockCircuitMap) LookupOpenCircuit(outKey CircuitKey) *PaymentCircuit {
×
1130
        return nil
×
1131
}
×
1132

1133
func (m *mockCircuitMap) LookupByPaymentHash(hash [32]byte) []*PaymentCircuit {
×
1134
        return nil
×
1135
}
×
1136

1137
func (m *mockCircuitMap) NumPending() int {
×
1138
        return 0
×
1139
}
×
1140

1141
func (m *mockCircuitMap) NumOpen() int {
×
1142
        return 0
×
1143
}
×
1144

1145
type mockOnionErrorDecryptor struct {
1146
        sourceIdx int
1147
        message   []byte
1148
        err       error
1149
}
1150

1151
func (m *mockOnionErrorDecryptor) DecryptError(encryptedData []byte) (
UNCOV
1152
        *sphinx.DecryptedError, error) {
×
UNCOV
1153

×
UNCOV
1154
        return &sphinx.DecryptedError{
×
UNCOV
1155
                SenderIdx: m.sourceIdx,
×
UNCOV
1156
                Message:   m.message,
×
UNCOV
1157
        }, m.err
×
UNCOV
1158
}
×
1159

1160
var _ htlcNotifier = (*mockHTLCNotifier)(nil)
1161

1162
type mockHTLCNotifier struct {
1163
        htlcNotifier //nolint:unused
1164
}
1165

1166
func (h *mockHTLCNotifier) NotifyForwardingEvent(key HtlcKey, info HtlcInfo,
UNCOV
1167
        eventType HtlcEventType) {
×
UNCOV
1168

×
UNCOV
1169
}
×
1170

1171
func (h *mockHTLCNotifier) NotifyLinkFailEvent(key HtlcKey, info HtlcInfo,
1172
        eventType HtlcEventType, linkErr *LinkError,
UNCOV
1173
        incoming bool) {
×
UNCOV
1174

×
UNCOV
1175
}
×
1176

1177
func (h *mockHTLCNotifier) NotifyForwardingFailEvent(key HtlcKey,
UNCOV
1178
        eventType HtlcEventType) {
×
UNCOV
1179

×
UNCOV
1180
}
×
1181

1182
func (h *mockHTLCNotifier) NotifySettleEvent(key HtlcKey,
UNCOV
1183
        preimage lntypes.Preimage, eventType HtlcEventType) {
×
UNCOV
1184

×
UNCOV
1185
}
×
1186

1187
func (h *mockHTLCNotifier) NotifyFinalHtlcEvent(key models.CircuitKey,
UNCOV
1188
        info channeldb.FinalHtlcInfo) {
×
UNCOV
1189

×
UNCOV
1190
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc