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

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

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

77.55
/chainntnfs/btcdnotify/btcd_dev.go
1
//go:build dev
2
// +build dev
3

4
package btcdnotify
5

6
import (
7
        "fmt"
8
        "time"
9

10
        "github.com/btcsuite/btcd/chaincfg/chainhash"
11
        "github.com/lightningnetwork/lnd/chainntnfs"
12
)
13

14
// UnsafeStart starts the notifier with a specified best height and optional
15
// best hash. Its bestBlock and txNotifier are initialized with bestHeight and
16
// optionally bestHash. The parameter generateBlocks is necessary for the
17
// bitcoind notifier to ensure we drain all notifications up to syncHeight,
18
// since if they are generated ahead of UnsafeStart the chainConn may start up
19
// with an outdated best block and miss sending ntfns. Used for testing.
20
func (b *BtcdNotifier) UnsafeStart(bestHeight int32, bestHash *chainhash.Hash,
21
        syncHeight int32, generateBlocks func() error) error {
3✔
22

3✔
23
        // Connect to btcd, and register for notifications on connected, and
3✔
24
        // disconnected blocks.
3✔
25
        if err := b.chainConn.Connect(20); err != nil {
3✔
26
                return err
×
27
        }
×
28
        if err := b.chainConn.NotifyBlocks(); err != nil {
3✔
29
                return err
×
30
        }
×
31

32
        b.txNotifier = chainntnfs.NewTxNotifier(
3✔
33
                uint32(bestHeight), chainntnfs.ReorgSafetyLimit,
3✔
34
                b.confirmHintCache, b.spendHintCache,
3✔
35
        )
3✔
36

3✔
37
        b.chainUpdates.Start()
3✔
38
        b.txUpdates.Start()
3✔
39

3✔
40
        if generateBlocks != nil {
5✔
41
                // Ensure no block notifications are pending when we start the
2✔
42
                // notification dispatcher goroutine.
2✔
43

2✔
44
                // First generate the blocks, then drain the notifications
2✔
45
                // for the generated blocks.
2✔
46
                if err := generateBlocks(); err != nil {
2✔
47
                        return err
×
48
                }
×
49

50
                timeout := time.After(60 * time.Second)
2✔
51
        loop:
2✔
52
                for {
22✔
53
                        select {
20✔
54
                        case ntfn := <-b.chainUpdates.ChanOut():
20✔
55
                                lastReceivedNtfn := ntfn.(*chainUpdate)
20✔
56
                                if lastReceivedNtfn.blockHeight >= syncHeight {
22✔
57
                                        break loop
2✔
58
                                }
59
                        case <-timeout:
×
60
                                return fmt.Errorf("unable to catch up to height %d",
×
61
                                        syncHeight)
×
62
                        }
63
                }
64
        }
65

66
        // Run notificationDispatcher after setting the notifier's best block
67
        // to avoid a race condition.
68
        b.bestBlock = chainntnfs.BlockEpoch{Height: bestHeight, Hash: bestHash}
3✔
69
        if bestHash == nil {
5✔
70
                hash, err := b.chainConn.GetBlockHash(int64(bestHeight))
2✔
71
                if err != nil {
2✔
72
                        return err
×
73
                }
×
74
                b.bestBlock.Hash = hash
2✔
75
        }
76

77
        b.wg.Add(1)
3✔
78
        go b.notificationDispatcher()
3✔
79

3✔
80
        return nil
3✔
81
}
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