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

lightningnetwork / lnd / 13566028875

27 Feb 2025 12:09PM UTC coverage: 49.396% (-9.4%) from 58.748%
13566028875

Pull #9555

github

ellemouton
graph/db: populate the graph cache in Start instead of during construction

In this commit, we move the graph cache population logic out of the
ChannelGraph constructor and into its Start method instead.
Pull Request #9555: graph: extract cache from CRUD [6]

34 of 54 new or added lines in 4 files covered. (62.96%)

27464 existing lines in 436 files now uncovered.

101095 of 204664 relevant lines covered (49.4%)

1.54 hits per line

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

0.0
/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,
UNCOV
21
        syncHeight int32, generateBlocks func() error) error {
×
UNCOV
22

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

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

×
UNCOV
37
        b.chainUpdates.Start()
×
UNCOV
38
        b.txUpdates.Start()
×
UNCOV
39

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

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

UNCOV
50
                timeout := time.After(60 * time.Second)
×
UNCOV
51
        loop:
×
UNCOV
52
                for {
×
UNCOV
53
                        select {
×
UNCOV
54
                        case ntfn := <-b.chainUpdates.ChanOut():
×
UNCOV
55
                                lastReceivedNtfn := ntfn.(*chainUpdate)
×
UNCOV
56
                                if lastReceivedNtfn.blockHeight >= syncHeight {
×
UNCOV
57
                                        break loop
×
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.
UNCOV
68
        b.bestBlock = chainntnfs.BlockEpoch{Height: bestHeight, Hash: bestHash}
×
UNCOV
69
        if bestHash == nil {
×
UNCOV
70
                hash, err := b.chainConn.GetBlockHash(int64(bestHeight))
×
UNCOV
71
                if err != nil {
×
72
                        return err
×
73
                }
×
UNCOV
74
                b.bestBlock.Hash = hash
×
75
        }
76

UNCOV
77
        b.wg.Add(1)
×
UNCOV
78
        go b.notificationDispatcher()
×
UNCOV
79

×
UNCOV
80
        return nil
×
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