• 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

80.0
/record/mpp.go
1
package record
2

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

7
        "github.com/lightningnetwork/lnd/lnwire"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
// MPPOnionType is the type used in the onion to reference the MPP fields:
12
// total_amt and payment_addr.
13
const MPPOnionType tlv.Type = 8
14

15
// MPP is a record that encodes the fields necessary for multi-path payments.
16
type MPP struct {
17
        // paymentAddr is a random, receiver-generated value used to avoid
18
        // collisions with concurrent payers.
19
        paymentAddr [32]byte
20

21
        // totalMsat is the total value of the payment, potentially spread
22
        // across more than one HTLC.
23
        totalMsat lnwire.MilliSatoshi
24
}
25

26
// NewMPP generates a new MPP record with the given total and payment address.
27
func NewMPP(total lnwire.MilliSatoshi, addr [32]byte) *MPP {
480✔
28
        return &MPP{
480✔
29
                paymentAddr: addr,
480✔
30
                totalMsat:   total,
480✔
31
        }
480✔
32
}
480✔
33

34
// PaymentAddr returns the payment address contained in the MPP record.
35
func (r *MPP) PaymentAddr() [32]byte {
2,421✔
36
        return r.paymentAddr
2,421✔
37
}
2,421✔
38

39
// TotalMsat returns the total value of an MPP payment in msats.
40
func (r *MPP) TotalMsat() lnwire.MilliSatoshi {
781✔
41
        return r.totalMsat
781✔
42
}
781✔
43

44
// MPPEncoder writes the MPP record to the provided io.Writer.
45
func MPPEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
74✔
46
        if v, ok := val.(*MPP); ok {
148✔
47
                err := tlv.EBytes32(w, &v.paymentAddr, buf)
74✔
48
                if err != nil {
74✔
49
                        return err
×
50
                }
×
51

52
                return tlv.ETUint64T(w, uint64(v.totalMsat), buf)
74✔
53
        }
54
        return tlv.NewTypeForEncodingErr(val, "MPP")
×
55
}
56

57
const (
58
        // minMPPLength is the minimum length of a serialized MPP TLV record,
59
        // which occurs when the truncated encoding of total_amt_msat takes 0
60
        // bytes, leaving only the payment_addr.
61
        minMPPLength = 32
62

63
        // maxMPPLength is the maximum length of a serialized MPP TLV record,
64
        // which occurs when the truncated encoding of total_amt_msat takes 8
65
        // bytes.
66
        maxMPPLength = 40
67
)
68

69
// MPPDecoder reads the MPP record to the provided io.Reader.
70
func MPPDecoder(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
676✔
71
        if v, ok := val.(*MPP); ok && minMPPLength <= l && l <= maxMPPLength {
1,352✔
72
                if err := tlv.DBytes32(r, &v.paymentAddr, buf, 32); err != nil {
676✔
73
                        return err
×
74
                }
×
75

76
                var total uint64
676✔
77
                if err := tlv.DTUint64(r, &total, buf, l-32); err != nil {
676✔
78
                        return err
×
79
                }
×
80
                v.totalMsat = lnwire.MilliSatoshi(total)
676✔
81

676✔
82
                return nil
676✔
83
        }
84
        return tlv.NewTypeForDecodingErr(val, "MPP", l, maxMPPLength)
×
85
}
86

87
// Record returns a tlv.Record that can be used to encode or decode this record.
88
func (r *MPP) Record() tlv.Record {
800✔
89
        // Fixed-size, 32 byte payment address followed by truncated 64-bit
800✔
90
        // total msat.
800✔
91
        size := func() uint64 {
810✔
92
                return 32 + tlv.SizeTUint64(uint64(r.totalMsat))
10✔
93
        }
10✔
94

95
        return tlv.MakeDynamicRecord(
800✔
96
                MPPOnionType, r, size, MPPEncoder, MPPDecoder,
800✔
97
        )
800✔
98
}
99

100
// PayloadSize returns the size this record takes up in encoded form.
101
func (r *MPP) PayloadSize() uint64 {
52✔
102
        return 32 + tlv.SizeTUint64(uint64(r.totalMsat))
52✔
103
}
52✔
104

105
// String returns a human-readable representation of the mpp payload field.
106
func (r *MPP) String() string {
1✔
107
        if r == nil {
1✔
UNCOV
108
                return "<nil>"
×
UNCOV
109
        }
×
110

111
        return fmt.Sprintf("total=%v, addr=%x", r.totalMsat, r.paymentAddr)
1✔
112
}
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