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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/channeldb/migration29/codec.go
1
package migration29
2

3
import (
4
        "encoding/binary"
5
        "encoding/hex"
6
        "io"
7

8
        "github.com/btcsuite/btcd/wire"
9
)
10

11
var (
12
        byteOrder = binary.BigEndian
13
)
14

15
// ChannelID is a series of 32-bytes that uniquely identifies all channels
16
// within the network. The ChannelID is computed using the outpoint of the
17
// funding transaction (the txid, and output index). Given a funding output the
18
// ChannelID can be calculated by XOR'ing the big-endian serialization of the
19
// txid and the big-endian serialization of the output index, truncated to
20
// 2 bytes.
21
type ChannelID [32]byte
22

23
// String returns the string representation of the ChannelID. This is just the
24
// hex string encoding of the ChannelID itself.
25
func (c ChannelID) String() string {
×
26
        return hex.EncodeToString(c[:])
×
27
}
×
28

29
// NewChanIDFromOutPoint converts a target OutPoint into a ChannelID that is
30
// usable within the network. In order to convert the OutPoint into a ChannelID,
31
// we XOR the lower 2-bytes of the txid within the OutPoint with the big-endian
32
// serialization of the Index of the OutPoint, truncated to 2-bytes.
UNCOV
33
func NewChanIDFromOutPoint(op *wire.OutPoint) ChannelID {
×
UNCOV
34
        // First we'll copy the txid of the outpoint into our channel ID slice.
×
UNCOV
35
        var cid ChannelID
×
UNCOV
36
        copy(cid[:], op.Hash[:])
×
UNCOV
37

×
UNCOV
38
        // With the txid copied over, we'll now XOR the lower 2-bytes of the
×
UNCOV
39
        // partial channelID with big-endian serialization of output index.
×
UNCOV
40
        xorTxid(&cid, uint16(op.Index))
×
UNCOV
41

×
UNCOV
42
        return cid
×
UNCOV
43
}
×
44

45
// xorTxid performs the transformation needed to transform an OutPoint into a
46
// ChannelID. To do this, we expect the cid parameter to contain the txid
47
// unaltered and the outputIndex to be the output index
UNCOV
48
func xorTxid(cid *ChannelID, outputIndex uint16) {
×
UNCOV
49
        var buf [2]byte
×
UNCOV
50
        binary.BigEndian.PutUint16(buf[:], outputIndex)
×
UNCOV
51

×
UNCOV
52
        cid[30] ^= buf[0]
×
UNCOV
53
        cid[31] ^= buf[1]
×
UNCOV
54
}
×
55

56
// readOutpoint reads an outpoint from the passed reader.
UNCOV
57
func readOutpoint(r io.Reader, o *wire.OutPoint) error {
×
UNCOV
58
        if _, err := io.ReadFull(r, o.Hash[:]); err != nil {
×
59
                return err
×
60
        }
×
UNCOV
61
        if err := binary.Read(r, byteOrder, &o.Index); err != nil {
×
62
                return err
×
63
        }
×
64

UNCOV
65
        return nil
×
66
}
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