• 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

57.45
/lnwire/custom.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "io"
7
        "sync"
8
)
9

10
// CustomTypeStart is the start of the custom type range for peer messages as
11
// defined in BOLT 01.
12
const CustomTypeStart MessageType = 32768
13

14
var (
15
        // customTypeOverride contains a set of message types < CustomTypeStart
16
        // that lnd allows to be treated as custom messages. This allows us to
17
        // override messages reserved for the protocol level and treat them as
18
        // custom messages. This set of message types is stored as a global so
19
        // that we do not need to pass around state when accounting for this
20
        // set of messages in message creation.
21
        //
22
        // Note: This global is protected by the customTypeOverride mutex.
23
        customTypeOverride map[MessageType]struct{}
24

25
        // customTypeOverrideMtx manages concurrent access to
26
        // customTypeOverride.
27
        customTypeOverrideMtx sync.RWMutex
28
)
29

30
// SetCustomOverrides validates that the set of override types are outside of
31
// the custom message range (there's no reason to override messages that are
32
// already within the range), and updates the customTypeOverride global to hold
33
// this set of message types. Note that this function will completely overwrite
34
// the set of overrides, so should be called with the full set of types.
UNCOV
35
func SetCustomOverrides(overrideTypes []uint16) error {
×
UNCOV
36
        customTypeOverrideMtx.Lock()
×
UNCOV
37
        defer customTypeOverrideMtx.Unlock()
×
UNCOV
38

×
UNCOV
39
        customTypeOverride = make(map[MessageType]struct{}, len(overrideTypes))
×
UNCOV
40

×
UNCOV
41
        for _, t := range overrideTypes {
×
UNCOV
42
                msgType := MessageType(t)
×
UNCOV
43

×
UNCOV
44
                if msgType >= CustomTypeStart {
×
45
                        return fmt.Errorf("can't override type: %v, already "+
×
46
                                "in custom range", t)
×
47
                }
×
48

UNCOV
49
                customTypeOverride[msgType] = struct{}{}
×
50
        }
51

UNCOV
52
        return nil
×
53
}
54

55
// IsCustomOverride returns a bool indicating whether the message type is one
56
// of the protocol messages that we override for custom use.
57
func IsCustomOverride(t MessageType) bool {
1✔
58
        customTypeOverrideMtx.RLock()
1✔
59
        defer customTypeOverrideMtx.RUnlock()
1✔
60

1✔
61
        _, ok := customTypeOverride[t]
1✔
62

1✔
63
        return ok
1✔
64
}
1✔
65

66
// Custom represents an application-defined wire message.
67
type Custom struct {
68
        Type MessageType
69
        Data []byte
70
}
71

72
// A compile time check to ensure FundingCreated implements the lnwire.Message
73
// interface.
74
var _ Message = (*Custom)(nil)
75

76
// NewCustom instantiates a new custom message.
77
func NewCustom(msgType MessageType, data []byte) (*Custom, error) {
2✔
78
        if msgType < CustomTypeStart && !IsCustomOverride(msgType) {
2✔
UNCOV
79
                return nil, fmt.Errorf("msg type: %d not in custom range: %v "+
×
UNCOV
80
                        "and not overridden", msgType, CustomTypeStart)
×
UNCOV
81
        }
×
82

83
        return &Custom{
2✔
84
                Type: msgType,
2✔
85
                Data: data,
2✔
86
        }, nil
2✔
87
}
88

89
// Encode serializes the target Custom message into the passed io.Writer
90
// implementation.
91
//
92
// This is part of the lnwire.Message interface.
93
func (c *Custom) Encode(b *bytes.Buffer, pver uint32) error {
5✔
94
        _, err := b.Write(c.Data)
5✔
95
        return err
5✔
96
}
5✔
97

98
// Decode deserializes the serialized Custom message stored in the passed
99
// io.Reader into the target Custom message.
100
//
101
// This is part of the lnwire.Message interface.
102
func (c *Custom) Decode(r io.Reader, pver uint32) error {
9✔
103
        var b bytes.Buffer
9✔
104
        if _, err := io.Copy(&b, r); err != nil {
9✔
105
                return err
×
106
        }
×
107

108
        c.Data = b.Bytes()
9✔
109

9✔
110
        return nil
9✔
111
}
112

113
// MsgType returns the uint32 code which uniquely identifies this message as a
114
// Custom message on the wire.
115
//
116
// This is part of the lnwire.Message interface.
117
func (c *Custom) MsgType() MessageType {
5✔
118
        return c.Type
5✔
119
}
5✔
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