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

lightningnetwork / lnd / 12343072627

15 Dec 2024 11:09PM UTC coverage: 57.504% (-1.1%) from 58.636%
12343072627

Pull #9315

github

yyforyongyu
contractcourt: offer outgoing htlc one block earlier before its expiry

We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
Pull Request #9315: Implement `blockbeat`

1445 of 2007 new or added lines in 26 files covered. (72.0%)

19246 existing lines in 249 files now uncovered.

102342 of 177975 relevant lines covered (57.5%)

24772.24 hits per line

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

0.0
/peernotifier/peernotifier.go
1
package peernotifier
2

3
import (
4
        "sync"
5

6
        "github.com/lightningnetwork/lnd/subscribe"
7
)
8

9
// PeerNotifier is a subsystem which observes peer offline and online events.
10
// It takes subscriptions for its events, and whenever it observes a new event
11
// it notifies its subscribers over the proper channel.
12
type PeerNotifier struct {
13
        started sync.Once
14
        stopped sync.Once
15

16
        ntfnServer *subscribe.Server
17
}
18

19
// PeerOnlineEvent represents a new event where a peer comes online.
20
type PeerOnlineEvent struct {
21
        // PubKey is the peer's compressed public key.
22
        PubKey [33]byte
23
}
24

25
// PeerOfflineEvent represents a new event where a peer goes offline.
26
type PeerOfflineEvent struct {
27
        // PubKey is the peer's compressed public key.
28
        PubKey [33]byte
29
}
30

31
// New creates a new peer notifier which notifies clients of peer online
32
// and offline events.
UNCOV
33
func New() *PeerNotifier {
×
UNCOV
34
        return &PeerNotifier{
×
UNCOV
35
                ntfnServer: subscribe.NewServer(),
×
UNCOV
36
        }
×
UNCOV
37
}
×
38

39
// Start starts the PeerNotifier's subscription server.
UNCOV
40
func (p *PeerNotifier) Start() error {
×
UNCOV
41
        var err error
×
UNCOV
42

×
UNCOV
43
        p.started.Do(func() {
×
UNCOV
44
                log.Info("PeerNotifier starting")
×
UNCOV
45
                err = p.ntfnServer.Start()
×
UNCOV
46
        })
×
47

UNCOV
48
        return err
×
49
}
50

51
// Stop signals the notifier for a graceful shutdown.
UNCOV
52
func (p *PeerNotifier) Stop() error {
×
UNCOV
53
        var err error
×
UNCOV
54
        p.stopped.Do(func() {
×
UNCOV
55
                log.Info("PeerNotifier shutting down...")
×
UNCOV
56
                defer log.Debug("PeerNotifier shutdown complete")
×
UNCOV
57

×
UNCOV
58
                err = p.ntfnServer.Stop()
×
UNCOV
59
        })
×
UNCOV
60
        return err
×
61
}
62

63
// SubscribePeerEvents returns a subscribe.Client that will receive updates
64
// any time the Server is informed of a peer event.
UNCOV
65
func (p *PeerNotifier) SubscribePeerEvents() (*subscribe.Client, error) {
×
UNCOV
66
        return p.ntfnServer.Subscribe()
×
UNCOV
67
}
×
68

69
// NotifyPeerOnline sends a peer online event to all clients subscribed to the
70
// peer notifier.
UNCOV
71
func (p *PeerNotifier) NotifyPeerOnline(pubKey [33]byte) {
×
UNCOV
72
        event := PeerOnlineEvent{PubKey: pubKey}
×
UNCOV
73

×
UNCOV
74
        log.Debugf("PeerNotifier notifying peer: %x online", pubKey)
×
UNCOV
75

×
UNCOV
76
        if err := p.ntfnServer.SendUpdate(event); err != nil {
×
77
                log.Warnf("Unable to send peer online update: %v", err)
×
78
        }
×
79
}
80

81
// NotifyPeerOffline sends a peer offline event to all the clients subscribed
82
// to the peer notifier.
UNCOV
83
func (p *PeerNotifier) NotifyPeerOffline(pubKey [33]byte) {
×
UNCOV
84
        event := PeerOfflineEvent{PubKey: pubKey}
×
UNCOV
85

×
UNCOV
86
        log.Debugf("PeerNotifier notifying peer: %x offline", pubKey)
×
UNCOV
87

×
UNCOV
88
        if err := p.ntfnServer.SendUpdate(event); err != nil {
×
89
                log.Warnf("Unable to send peer offline update: %v", err)
×
90
        }
×
91
}
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