• 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
/build/handler_sets.go
1
package build
2

3
import (
4
        "context"
5
        "log/slog"
6

7
        btclogv1 "github.com/btcsuite/btclog"
8
        "github.com/btcsuite/btclog/v2"
9
)
10

11
// handlerSet is an implementation of Handler that abstracts away multiple
12
// Handlers.
13
type handlerSet struct {
14
        level btclogv1.Level
15
        set   []btclog.Handler
16
}
17

18
// newHandlerSet constructs a new HandlerSet.
UNCOV
19
func newHandlerSet(level btclogv1.Level, set ...btclog.Handler) *handlerSet {
×
UNCOV
20
        h := &handlerSet{
×
UNCOV
21
                set:   set,
×
UNCOV
22
                level: level,
×
UNCOV
23
        }
×
UNCOV
24
        h.SetLevel(level)
×
UNCOV
25

×
UNCOV
26
        return h
×
UNCOV
27
}
×
28

29
// Enabled reports whether the handler handles records at the given level.
30
//
31
// NOTE: this is part of the slog.Handler interface.
UNCOV
32
func (h *handlerSet) Enabled(ctx context.Context, level slog.Level) bool {
×
UNCOV
33
        for _, handler := range h.set {
×
UNCOV
34
                if !handler.Enabled(ctx, level) {
×
UNCOV
35
                        return false
×
UNCOV
36
                }
×
37
        }
38

UNCOV
39
        return true
×
40
}
41

42
// Handle handles the Record.
43
//
44
// NOTE: this is part of the slog.Handler interface.
UNCOV
45
func (h *handlerSet) Handle(ctx context.Context, record slog.Record) error {
×
UNCOV
46
        for _, handler := range h.set {
×
UNCOV
47
                if err := handler.Handle(ctx, record); err != nil {
×
48
                        return err
×
49
                }
×
50
        }
51

UNCOV
52
        return nil
×
53
}
54

55
// WithAttrs returns a new Handler whose attributes consist of both the
56
// receiver's attributes and the arguments.
57
//
58
// NOTE: this is part of the slog.Handler interface.
59
func (h *handlerSet) WithAttrs(attrs []slog.Attr) slog.Handler {
×
60
        newSet := &reducedSet{set: make([]slog.Handler, len(h.set))}
×
61
        for i, handler := range h.set {
×
62
                newSet.set[i] = handler.WithAttrs(attrs)
×
63
        }
×
64

65
        return newSet
×
66
}
67

68
// WithGroup returns a new Handler with the given group appended to the
69
// receiver's existing groups.
70
//
71
// NOTE: this is part of the slog.Handler interface.
72
func (h *handlerSet) WithGroup(name string) slog.Handler {
×
73
        newSet := &reducedSet{set: make([]slog.Handler, len(h.set))}
×
74
        for i, handler := range h.set {
×
75
                newSet.set[i] = handler.WithGroup(name)
×
76
        }
×
77

78
        return newSet
×
79
}
80

81
// SubSystem creates a new Handler with the given sub-system tag.
82
//
83
// NOTE: this is part of the Handler interface.
UNCOV
84
func (h *handlerSet) SubSystem(tag string) btclog.Handler {
×
UNCOV
85
        newSet := &handlerSet{set: make([]btclog.Handler, len(h.set))}
×
UNCOV
86
        for i, handler := range h.set {
×
UNCOV
87
                newSet.set[i] = handler.SubSystem(tag)
×
UNCOV
88
        }
×
89

UNCOV
90
        return newSet
×
91
}
92

93
// SetLevel changes the logging level of the Handler to the passed
94
// level.
95
//
96
// NOTE: this is part of the btclog.Handler interface.
UNCOV
97
func (h *handlerSet) SetLevel(level btclogv1.Level) {
×
UNCOV
98
        for _, handler := range h.set {
×
UNCOV
99
                handler.SetLevel(level)
×
UNCOV
100
        }
×
UNCOV
101
        h.level = level
×
102
}
103

104
// Level returns the current logging level of the Handler.
105
//
106
// NOTE: this is part of the btclog.Handler interface.
UNCOV
107
func (h *handlerSet) Level() btclogv1.Level {
×
UNCOV
108
        return h.level
×
UNCOV
109
}
×
110

111
// WithPrefix returns a copy of the Handler but with the given string prefixed
112
// to each log message.
113
//
114
// NOTE: this is part of the btclog.Handler interface.
UNCOV
115
func (h *handlerSet) WithPrefix(prefix string) btclog.Handler {
×
UNCOV
116
        newSet := &handlerSet{set: make([]btclog.Handler, len(h.set))}
×
UNCOV
117
        for i, handler := range h.set {
×
UNCOV
118
                newSet.set[i] = handler.WithPrefix(prefix)
×
UNCOV
119
        }
×
120

UNCOV
121
        return newSet
×
122
}
123

124
// A compile-time check to ensure that handlerSet implements btclog.Handler.
125
var _ btclog.Handler = (*handlerSet)(nil)
126

127
// reducedSet is an implementation of the slog.Handler interface which is
128
// itself backed by multiple slog.Handlers. This is used by the handlerSet
129
// WithGroup and WithAttrs methods so that we can apply the WithGroup and
130
// WithAttrs to the underlying handlers in the set. These calls, however,
131
// produce slog.Handlers and not btclog.Handlers. So the reducedSet represents
132
// the resulting set produced.
133
type reducedSet struct {
134
        set []slog.Handler
135
}
136

137
// Enabled reports whether the handler handles records at the given level.
138
//
139
// NOTE: this is part of the slog.Handler interface.
140
func (r *reducedSet) Enabled(ctx context.Context, level slog.Level) bool {
×
141
        for _, handler := range r.set {
×
142
                if !handler.Enabled(ctx, level) {
×
143
                        return false
×
144
                }
×
145
        }
146

147
        return true
×
148
}
149

150
// Handle handles the Record.
151
//
152
// NOTE: this is part of the slog.Handler interface.
153
func (r *reducedSet) Handle(ctx context.Context, record slog.Record) error {
×
154
        for _, handler := range r.set {
×
155
                if err := handler.Handle(ctx, record); err != nil {
×
156
                        return err
×
157
                }
×
158
        }
159

160
        return nil
×
161
}
162

163
// WithAttrs returns a new Handler whose attributes consist of both the
164
// receiver's attributes and the arguments.
165
//
166
// NOTE: this is part of the slog.Handler interface.
167
func (r *reducedSet) WithAttrs(attrs []slog.Attr) slog.Handler {
×
168
        newSet := &reducedSet{set: make([]slog.Handler, len(r.set))}
×
169
        for i, handler := range r.set {
×
170
                newSet.set[i] = handler.WithAttrs(attrs)
×
171
        }
×
172

173
        return newSet
×
174
}
175

176
// WithGroup returns a new Handler with the given group appended to the
177
// receiver's existing groups.
178
//
179
// NOTE: this is part of the slog.Handler interface.
180
func (r *reducedSet) WithGroup(name string) slog.Handler {
×
181
        newSet := &reducedSet{set: make([]slog.Handler, len(r.set))}
×
182
        for i, handler := range r.set {
×
183
                newSet.set[i] = handler.WithGroup(name)
×
184
        }
×
185

186
        return newSet
×
187
}
188

189
// A compile-time check to ensure that handlerSet implements slog.Handler.
190
var _ slog.Handler = (*reducedSet)(nil)
191

192
// subLogGenerator implements the SubLogCreator backed by a Handler.
193
type subLogGenerator struct {
194
        handler btclog.Handler
195
}
196

197
// newSubLogGenerator constructs a new subLogGenerator from a Handler.
UNCOV
198
func newSubLogGenerator(handler btclog.Handler) *subLogGenerator {
×
UNCOV
199
        return &subLogGenerator{
×
UNCOV
200
                handler: handler,
×
UNCOV
201
        }
×
UNCOV
202
}
×
203

204
// Logger returns a new logger for a particular sub-system.
205
//
206
// NOTE: this is part of the SubLogCreator interface.
UNCOV
207
func (b *subLogGenerator) Logger(subsystemTag string) btclog.Logger {
×
UNCOV
208
        handler := b.handler.SubSystem(subsystemTag)
×
UNCOV
209

×
UNCOV
210
        return btclog.NewSLogger(handler)
×
UNCOV
211
}
×
212

213
// A compile-time check to ensure that handlerSet implements slog.Handler.
214
var _ SubLogCreator = (*subLogGenerator)(nil)
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