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

lightningnetwork / lnd / 13725358077

07 Mar 2025 04:51PM UTC coverage: 58.224% (-10.4%) from 68.615%
13725358077

Pull #9458

github

web-flow
Merge bf4c6625f into ab2dc09eb
Pull Request #9458: multi+server.go: add initial permissions for some peers

346 of 549 new or added lines in 10 files covered. (63.02%)

27466 existing lines in 443 files now uncovered.

94609 of 162492 relevant lines covered (58.22%)

1.81 hits per line

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

0.0
/chainntnfs/bitcoindnotify/bitcoind_dev.go
1
//go:build dev
2
// +build dev
3

4
package bitcoindnotify
5

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

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

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

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

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

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

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

UNCOV
48
                timeout := time.After(60 * time.Second)
×
UNCOV
49
        loop:
×
UNCOV
50
                for {
×
UNCOV
51
                        select {
×
UNCOV
52
                        case ntfn := <-b.chainConn.Notifications():
×
UNCOV
53
                                switch update := ntfn.(type) {
×
UNCOV
54
                                case chain.BlockConnected:
×
UNCOV
55
                                        if update.Height >= syncHeight {
×
UNCOV
56
                                                break loop
×
57
                                        }
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