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

lightningnetwork / lnd / 13558005087

27 Feb 2025 03:04AM UTC coverage: 58.834% (-0.001%) from 58.835%
13558005087

Pull #8453

github

Roasbeef
lnwallet/chancloser: increase test coverage of state machine
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

1079 of 1370 new or added lines in 23 files covered. (78.76%)

578 existing lines in 40 files now uncovered.

137063 of 232965 relevant lines covered (58.83%)

19205.84 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 {
5✔
40
        key := newResolverID(b.ChanPoint)
5✔
41
        return key[:]
5✔
42
}
5✔
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) {
3✔
51
        if !b.subscribed {
6✔
52
                complete, err := b.SubscribeBreachComplete(
3✔
53
                        &b.ChanPoint, b.replyChan,
3✔
54
                )
3✔
55
                if err != nil {
3✔
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 {
3✔
UNCOV
62
                        b.markResolved()
×
UNCOV
63
                        return nil, b.Checkpoint(b)
×
UNCOV
64
                }
×
65

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

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

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

81
        return nil, errResolverShuttingDown
1✔
82
}
83

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

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

94
// Encode encodes the breachResolver to the passed writer.
95
func (b *breachResolver) Encode(w io.Writer) error {
1✔
96
        return binary.Write(w, endian, b.IsResolved())
1✔
97
}
1✔
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) {
1✔
103

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

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

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

1✔
119
        return b, nil
1✔
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 {
3✔
133
        if b.isLaunched() {
4✔
134
                b.log.Tracef("already launched")
1✔
135
                return nil
1✔
136
        }
1✔
137

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

3✔
141
        return nil
3✔
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