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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

63.46
/chanacceptor/merge.go
1
package chanacceptor
2

3
import (
4
        "bytes"
5
        "fmt"
6

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
)
10

11
const (
12
        // We use field names in our errors for more readable errors. Create
13
        // consts for them here so that we can exactly match in our unit tests.
14
        fieldCSV             = "csv delay"
15
        fieldHtlcLimit       = "htlc limit"
16
        fieldMinDep          = "min depth"
17
        fieldReserve         = "reserve"
18
        fieldMinIn           = "min htlc in"
19
        fieldInFlightTotal   = "in flight total"
20
        fieldUpfrontShutdown = "upfront shutdown"
21
)
22

23
var (
24
        errZeroConf = fmt.Errorf("zero-conf set with non-zero min-depth")
25
)
26

27
// fieldMismatchError returns a merge error for a named field when we get two
28
// channel acceptor responses which have different values set.
29
func fieldMismatchError(name string, current, newValue interface{}) error {
×
30
        return fmt.Errorf("multiple values set for: %v, %v and %v",
×
31
                name, current, newValue)
×
32
}
×
33

34
// mergeBool merges two boolean values.
35
func mergeBool(current, newValue bool) bool {
3✔
36
        // If either is true, return true. It is not possible to have different
3✔
37
        // "non-zero" values like the other cases.
3✔
38
        return current || newValue
3✔
39
}
3✔
40

41
// mergeInt64 merges two int64 values, failing if they have different non-zero
42
// values.
43
func mergeInt64(name string, current, newValue int64) (int64, error) {
3✔
44
        switch {
3✔
45
        case current == 0:
3✔
46
                return newValue, nil
3✔
47

48
        case newValue == 0:
×
49
                return current, nil
×
50

51
        case current != newValue:
×
52
                return 0, fieldMismatchError(name, current, newValue)
×
53

54
        default:
×
55
                return newValue, nil
×
56
        }
57
}
58

59
// mergeMillisatoshi merges two msat values, failing if they have different
60
// non-zero values.
61
func mergeMillisatoshi(name string, current,
62
        newValue lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) {
3✔
63

3✔
64
        switch {
3✔
65
        case current == 0:
3✔
66
                return newValue, nil
3✔
67

68
        case newValue == 0:
×
69
                return current, nil
×
70

71
        case current != newValue:
×
72
                return 0, fieldMismatchError(name, current, newValue)
×
73

74
        default:
×
75
                return newValue, nil
×
76
        }
77
}
78

79
// mergeDeliveryAddress merges two delivery address values, failing if they have
80
// different non-zero values.
81
func mergeDeliveryAddress(name string, current,
82
        newValue lnwire.DeliveryAddress) (lnwire.DeliveryAddress, error) {
3✔
83

3✔
84
        switch {
3✔
85
        case current == nil:
3✔
86
                return newValue, nil
3✔
87

88
        case newValue == nil:
×
89
                return current, nil
×
90

91
        case !bytes.Equal(current, newValue):
×
92
                return nil, fieldMismatchError(name, current, newValue)
×
93

94
        default:
×
95
                return newValue, nil
×
96
        }
97
}
98

99
// mergeResponse takes two channel accept responses, and attempts to merge their
100
// fields, failing if any fields conflict (are non-zero and not equal). It
101
// returns a new response that has all the merged fields in it.
102
func mergeResponse(current,
103
        newValue ChannelAcceptResponse) (ChannelAcceptResponse, error) {
3✔
104

3✔
105
        csv, err := mergeInt64(
3✔
106
                fieldCSV, int64(current.CSVDelay), int64(newValue.CSVDelay),
3✔
107
        )
3✔
108
        if err != nil {
3✔
109
                return current, err
×
110
        }
×
111
        current.CSVDelay = uint16(csv)
3✔
112

3✔
113
        htlcLimit, err := mergeInt64(
3✔
114
                fieldHtlcLimit, int64(current.HtlcLimit),
3✔
115
                int64(newValue.HtlcLimit),
3✔
116
        )
3✔
117
        if err != nil {
3✔
118
                return current, err
×
119
        }
×
120
        current.HtlcLimit = uint16(htlcLimit)
3✔
121

3✔
122
        minDepth, err := mergeInt64(
3✔
123
                fieldMinDep, int64(current.MinAcceptDepth),
3✔
124
                int64(newValue.MinAcceptDepth),
3✔
125
        )
3✔
126
        if err != nil {
3✔
127
                return current, err
×
128
        }
×
129
        current.MinAcceptDepth = uint16(minDepth)
3✔
130

3✔
131
        current.ZeroConf = mergeBool(current.ZeroConf, newValue.ZeroConf)
3✔
132

3✔
133
        // Assert that if zero-conf is set, min-depth is zero.
3✔
134
        if current.ZeroConf && current.MinAcceptDepth != 0 {
3✔
135
                return current, errZeroConf
×
136
        }
×
137

138
        reserve, err := mergeInt64(
3✔
139
                fieldReserve, int64(current.Reserve), int64(newValue.Reserve),
3✔
140
        )
3✔
141
        if err != nil {
3✔
142
                return current, err
×
143
        }
×
144
        current.Reserve = btcutil.Amount(reserve)
3✔
145

3✔
146
        current.MinHtlcIn, err = mergeMillisatoshi(
3✔
147
                fieldMinIn, current.MinHtlcIn, newValue.MinHtlcIn,
3✔
148
        )
3✔
149
        if err != nil {
3✔
150
                return current, err
×
151
        }
×
152

153
        current.InFlightTotal, err = mergeMillisatoshi(
3✔
154
                fieldInFlightTotal, current.InFlightTotal,
3✔
155
                newValue.InFlightTotal,
3✔
156
        )
3✔
157
        if err != nil {
3✔
158
                return current, err
×
159
        }
×
160

161
        current.UpfrontShutdown, err = mergeDeliveryAddress(
3✔
162
                fieldUpfrontShutdown, current.UpfrontShutdown,
3✔
163
                newValue.UpfrontShutdown,
3✔
164
        )
3✔
165
        if err != nil {
3✔
166
                return current, err
×
167
        }
×
168

169
        return current, nil
3✔
170
}
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