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

lightningnetwork / lnd / 18340726508

08 Oct 2025 09:49AM UTC coverage: 66.653%. First build
18340726508

Pull #9868

github

web-flow
Merge a988f91c8 into 30decfc3c
Pull Request #9868: Basic structures for onion messages into LND

162 of 243 new or added lines in 11 files covered. (66.67%)

137441 of 206205 relevant lines covered (66.65%)

21298.55 hits per line

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

88.37
/onionmessage/onion_endpoint.go
1
package onionmessage
2

3
import (
4
        "context"
5
        "encoding/hex"
6
        "log/slog"
7

8
        "github.com/lightningnetwork/lnd/lnutils"
9
        "github.com/lightningnetwork/lnd/lnwire"
10
        "github.com/lightningnetwork/lnd/msgmux"
11
        "github.com/lightningnetwork/lnd/subscribe"
12
)
13

14
// OnionMessageUpdate is onion message update dispatched to any potential
15
// subscriber.
16
type OnionMessageUpdate struct {
17
        // Peer is the peer pubkey
18
        Peer [33]byte
19

20
        // PathKey is the route blinding ephemeral pubkey to be used for
21
        // the onion message.
22
        PathKey [33]byte
23

24
        // OnionBlob is the raw serialized mix header used to relay messages in
25
        // a privacy-preserving manner. This blob should be handled in the same
26
        // manner as onions used to route HTLCs, with the exception that it uses
27
        // blinded routes by default.
28
        OnionBlob []byte
29
}
30

31
// OnionEndpoint handles incoming onion messages.
32
type OnionEndpoint struct {
33
        // subscribe.Server is used for subscriptions to onion messages.
34
        onionMessageServer *subscribe.Server
35
}
36

37
// A compile-time check to ensure OnionEndpoint implements the Endpoint
38
// interface.
39
var _ msgmux.Endpoint = (*OnionEndpoint)(nil)
40

41
// NewOnionEndpoint creates a new OnionEndpoint.
42
func NewOnionEndpoint(messageServer *subscribe.Server) *OnionEndpoint {
6✔
43
        return &OnionEndpoint{
6✔
44
                onionMessageServer: messageServer,
6✔
45
        }
6✔
46
}
6✔
47

48
// Name returns the unique name of the endpoint.
49
func (o *OnionEndpoint) Name() string {
15✔
50
        return "OnionMessageHandler"
15✔
51
}
15✔
52

53
// CanHandle checks if the endpoint can handle the incoming message.
54
// It returns true if the message is an lnwire.OnionMessage.
55
func (o *OnionEndpoint) CanHandle(msg msgmux.PeerMsg) bool {
4✔
56
        _, ok := msg.Message.(*lnwire.OnionMessage)
4✔
57
        return ok
4✔
58
}
4✔
59

60
// SendMessage processes the incoming onion message.
61
// It returns true if the message was successfully processed.
62
func (o *OnionEndpoint) SendMessage(ctx context.Context,
63
        msg msgmux.PeerMsg) bool {
3✔
64

3✔
65
        onionMsg, ok := msg.Message.(*lnwire.OnionMessage)
3✔
66
        if !ok {
3✔
NEW
67
                return false
×
NEW
68
        }
×
69

70
        peer := msg.PeerPub.SerializeCompressed()
3✔
71
        log.DebugS(ctx, "OnionEndpoint received OnionMessage",
3✔
72
                slog.String("peer", hex.EncodeToString(peer)),
3✔
73
                lnutils.LogPubKey("path_key", onionMsg.PathKey),
3✔
74
                lnutils.LogBytesPreview("onion_blob", onionMsg.OnionBlob),
3✔
75
                slog.Int("blob length", len(onionMsg.OnionBlob)))
3✔
76

3✔
77
        var peerArr [33]byte
3✔
78
        copy(peerArr[:], peer)
3✔
79

3✔
80
        // Convert blinding point []byte to [33]byte.
3✔
81
        blinding := onionMsg.PathKey.SerializeCompressed()
3✔
82
        var blindingArr [33]byte
3✔
83
        copy(blindingArr[:], blinding)
3✔
84

3✔
85
        err := o.onionMessageServer.SendUpdate(&OnionMessageUpdate{
3✔
86
                Peer:      peerArr,
3✔
87
                PathKey:   blindingArr,
3✔
88
                OnionBlob: onionMsg.OnionBlob,
3✔
89
        })
3✔
90
        if err != nil {
3✔
NEW
91
                log.ErrorS(ctx, "Failed to send onion message update", err)
×
NEW
92
                return false
×
NEW
93
        }
×
94

95
        return true
3✔
96
}
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