• 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

89.55
/chainntnfs/neutrinonotify/neutrino_dev.go
1
//go:build dev
2
// +build dev
3

4
package neutrinonotify
5

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

10
        "github.com/btcsuite/btcd/chaincfg/chainhash"
11
        "github.com/btcsuite/btcd/rpcclient"
12
        "github.com/lightninglabs/neutrino"
13
        "github.com/lightningnetwork/lnd/chainntnfs"
14
)
15

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

2✔
26
        // We'll obtain the latest block height of the p2p node. We'll
2✔
27
        // start the auto-rescan from this point. Once a caller actually wishes
2✔
28
        // to register a chain view, the rescan state will be rewound
2✔
29
        // accordingly.
2✔
30
        startingPoint, err := n.p2pNode.BestBlock()
2✔
31
        if err != nil {
2✔
32
                return err
×
33
        }
×
34

35
        // Next, we'll create our set of rescan options. Currently it's
36
        // required that a user MUST set an addr/outpoint/txid when creating a
37
        // rescan. To get around this, we'll add a "zero" outpoint, that won't
38
        // actually be matched.
39
        var zeroInput neutrino.InputWithScript
2✔
40
        rescanOptions := []neutrino.RescanOption{
2✔
41
                neutrino.StartBlock(startingPoint),
2✔
42
                neutrino.QuitChan(n.quit),
2✔
43
                neutrino.NotificationHandlers(
2✔
44
                        rpcclient.NotificationHandlers{
2✔
45
                                OnFilteredBlockConnected:    n.onFilteredBlockConnected,
2✔
46
                                OnFilteredBlockDisconnected: n.onFilteredBlockDisconnected,
2✔
47
                        },
2✔
48
                ),
2✔
49
                neutrino.WatchInputs(zeroInput),
2✔
50
        }
2✔
51

2✔
52
        n.txNotifier = chainntnfs.NewTxNotifier(
2✔
53
                uint32(bestHeight), chainntnfs.ReorgSafetyLimit,
2✔
54
                n.confirmHintCache, n.spendHintCache,
2✔
55
        )
2✔
56

2✔
57
        // Finally, we'll create our rescan struct, start it, and launch all
2✔
58
        // the goroutines we need to operate this ChainNotifier instance.
2✔
59
        n.chainView = neutrino.NewRescan(
2✔
60
                &neutrino.RescanChainSource{
2✔
61
                        ChainService: n.p2pNode,
2✔
62
                },
2✔
63
                rescanOptions...,
2✔
64
        )
2✔
65
        n.rescanErr = n.chainView.Start()
2✔
66

2✔
67
        n.txUpdates.Start()
2✔
68

2✔
69
        if generateBlocks != nil {
4✔
70
                // Ensure no block notifications are pending when we start the
2✔
71
                // notification dispatcher goroutine.
2✔
72

2✔
73
                // First generate the blocks, then drain the notifications
2✔
74
                // for the generated blocks.
2✔
75
                if err := generateBlocks(); err != nil {
2✔
76
                        return err
×
77
                }
×
78

79
                timeout := time.After(60 * time.Second)
2✔
80
        loop:
2✔
81
                for {
23✔
82
                        select {
21✔
83
                        case ntfn := <-n.chainUpdates:
21✔
84
                                lastReceivedNtfn := ntfn
21✔
85
                                if lastReceivedNtfn.height >= uint32(syncHeight) {
23✔
86
                                        break loop
2✔
87
                                }
88
                        case <-timeout:
×
89
                                return fmt.Errorf("unable to catch up to height %d",
×
90
                                        syncHeight)
×
91
                        }
92
                }
93
        }
94

95
        // Run notificationDispatcher after setting the notifier's best height
96
        // to avoid a race condition.
97
        n.bestBlock.Hash = bestHash
2✔
98
        n.bestBlock.Height = bestHeight
2✔
99

2✔
100
        n.wg.Add(1)
2✔
101
        go n.notificationDispatcher()
2✔
102

2✔
103
        return nil
2✔
104
}
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