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

lightningnetwork / lnd / 12286237218

11 Dec 2024 10:48PM UTC coverage: 49.653% (-0.04%) from 49.696%
12286237218

Pull #9313

github

aakselrod
docs: update release-notes for 0.19.0
Pull Request #9313: Reapply 8644 on 9260

6 of 27 new or added lines in 2 files covered. (22.22%)

105 existing lines in 12 files now uncovered.

100294 of 201991 relevant lines covered (49.65%)

1.55 hits per line

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

90.14
/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 {
3✔
28
        r := &breachResolver{
3✔
29
                contractResolverKit: *newContractResolverKit(resCfg),
3✔
30
                replyChan:           make(chan struct{}),
3✔
31
        }
3✔
32

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

3✔
35
        return r
3✔
36
}
3✔
37

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

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

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

64
                // Prevent duplicate subscriptions.
65
                b.subscribed = true
3✔
66
        }
67

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

76
        case <-b.quit:
3✔
77
        }
78

79
        return nil, errResolverShuttingDown
3✔
80
}
81

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

88
// SupplementState adds additional state to the breachResolver.
89
func (b *breachResolver) SupplementState(_ *channeldb.OpenChannel) {
3✔
90
}
3✔
91

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

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

3✔
102
        b := &breachResolver{
3✔
103
                contractResolverKit: *newContractResolverKit(resCfg),
3✔
104
                replyChan:           make(chan struct{}),
3✔
105
        }
3✔
106

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

115
        b.initLogger(fmt.Sprintf("%T(%v)", b, b.ChanPoint))
3✔
116

3✔
117
        return b, nil
3✔
118
}
119

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

124
// TODO(yy): implement it once the outputs are offered to the sweeper.
125
func (b *breachResolver) Launch() error {
3✔
126
        if b.isLaunched() {
6✔
127
                b.log.Tracef("already launched")
3✔
128
                return nil
3✔
129
        }
3✔
130

131
        b.log.Debugf("launching resolver...")
3✔
132
        b.markLaunched()
3✔
133

3✔
134
        return nil
3✔
135
}
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