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

lightningnetwork / lnd / 13567496470

27 Feb 2025 01:26PM UTC coverage: 58.757% (-0.1%) from 58.858%
13567496470

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]

40 of 54 new or added lines in 4 files covered. (74.07%)

307 existing lines in 27 files now uncovered.

136396 of 232137 relevant lines covered (58.76%)

19208.99 hits per line

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

87.32
/contractcourt/breach_resolver.go
1
package contractcourt
2

3
import (
4
        "encoding/binary"
5
        "fmt"
6
        "io"
7

8
        "github.com/lightningnetwork/lnd/channeldb"
9
)
10

11
// breachResolver is a resolver that will handle breached closes. In the
12
// future, this will likely take over the duties the current BreachArbitrator
13
// has.
14
type breachResolver struct {
15
        // subscribed denotes whether or not the breach resolver has subscribed
16
        // to the BreachArbitrator for breach resolution.
17
        subscribed bool
18

19
        // replyChan is closed when the breach arbiter has completed serving
20
        // justice.
21
        replyChan chan struct{}
22

23
        contractResolverKit
24
}
25

26
// newBreachResolver instantiates a new breach resolver.
27
func newBreachResolver(resCfg ResolverConfig) *breachResolver {
4✔
28
        r := &breachResolver{
4✔
29
                contractResolverKit: *newContractResolverKit(resCfg),
4✔
30
                replyChan:           make(chan struct{}),
4✔
31
        }
4✔
32

4✔
33
        r.initLogger(fmt.Sprintf("%T(%v)", r, r.ChanPoint))
4✔
34

4✔
35
        return r
4✔
36
}
4✔
37

38
// ResolverKey returns the unique identifier for this resolver.
39
func (b *breachResolver) ResolverKey() []byte {
6✔
40
        key := newResolverID(b.ChanPoint)
6✔
41
        return key[:]
6✔
42
}
6✔
43

44
// Resolve queries the BreachArbitrator to see if the justice transaction has
45
// been broadcast.
46
//
47
// NOTE: Part of the ContractResolver interface.
48
//
49
// TODO(yy): let sweeper handle the breach inputs.
50
func (b *breachResolver) Resolve() (ContractResolver, error) {
4✔
51
        if !b.subscribed {
8✔
52
                complete, err := b.SubscribeBreachComplete(
4✔
53
                        &b.ChanPoint, b.replyChan,
4✔
54
                )
4✔
55
                if err != nil {
4✔
56
                        return nil, err
×
57
                }
×
58

59
                // If the breach resolution process is already complete, then
60
                // we can cleanup and checkpoint the resolved state.
61
                if complete {
4✔
UNCOV
62
                        b.markResolved()
×
UNCOV
63
                        return nil, b.Checkpoint(b)
×
UNCOV
64
                }
×
65

66
                // Prevent duplicate subscriptions.
67
                b.subscribed = true
4✔
68
        }
69

70
        select {
4✔
71
        case <-b.replyChan:
4✔
72
                // The replyChan has been closed, signalling that the breach
4✔
73
                // has been fully resolved. Checkpoint the resolved state and
4✔
74
                // exit.
4✔
75
                b.markResolved()
4✔
76
                return nil, b.Checkpoint(b)
4✔
77

78
        case <-b.quit:
2✔
79
        }
80

81
        return nil, errResolverShuttingDown
2✔
82
}
83

84
// Stop signals the breachResolver to stop.
85
func (b *breachResolver) Stop() {
4✔
86
        b.log.Debugf("stopping...")
4✔
87
        close(b.quit)
4✔
88
}
4✔
89

90
// SupplementState adds additional state to the breachResolver.
91
func (b *breachResolver) SupplementState(_ *channeldb.OpenChannel) {
2✔
92
}
2✔
93

94
// Encode encodes the breachResolver to the passed writer.
95
func (b *breachResolver) Encode(w io.Writer) error {
2✔
96
        return binary.Write(w, endian, b.IsResolved())
2✔
97
}
2✔
98

99
// newBreachResolverFromReader attempts to decode an encoded breachResolver
100
// from the passed Reader instance, returning an active breachResolver.
101
func newBreachResolverFromReader(r io.Reader, resCfg ResolverConfig) (
102
        *breachResolver, error) {
2✔
103

2✔
104
        b := &breachResolver{
2✔
105
                contractResolverKit: *newContractResolverKit(resCfg),
2✔
106
                replyChan:           make(chan struct{}),
2✔
107
        }
2✔
108

2✔
109
        var resolved bool
2✔
110
        if err := binary.Read(r, endian, &resolved); err != nil {
2✔
111
                return nil, err
×
112
        }
×
113
        if resolved {
2✔
UNCOV
114
                b.markResolved()
×
UNCOV
115
        }
×
116

117
        b.initLogger(fmt.Sprintf("%T(%v)", b, b.ChanPoint))
2✔
118

2✔
119
        return b, nil
2✔
120
}
121

122
// A compile time assertion to ensure breachResolver meets the ContractResolver
123
// interface.
124
var _ ContractResolver = (*breachResolver)(nil)
125

126
// Launch offers the breach outputs to the sweeper - currently it's a NOOP as
127
// the outputs here are not offered to the sweeper.
128
//
129
// NOTE: Part of the ContractResolver interface.
130
//
131
// TODO(yy): implement it once the outputs are offered to the sweeper.
132
func (b *breachResolver) Launch() error {
4✔
133
        if b.isLaunched() {
6✔
134
                b.log.Tracef("already launched")
2✔
135
                return nil
2✔
136
        }
2✔
137

138
        b.log.Debugf("launching resolver...")
4✔
139
        b.markLaunched()
4✔
140

4✔
141
        return nil
4✔
142
}
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