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

lightningnetwork / lnd / 19924300449

04 Dec 2025 09:35AM UTC coverage: 53.479% (-1.9%) from 55.404%
19924300449

Pull #10419

github

web-flow
Merge f811805c6 into 20473482d
Pull Request #10419: [docs] Document use-native-sql=true for SQL migration step 2

110496 of 206616 relevant lines covered (53.48%)

21221.61 hits per line

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

25.53
/onionmessage/onion_endpoint.go
1
package onionmessage
2

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

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

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

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

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

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

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

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

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

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

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

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

71
        peer := msg.PeerPub.SerializeCompressed()
×
72

×
73
        logCtx := btclog.WithCtx(ctx,
×
74
                slog.String("peer", hex.EncodeToString(peer)),
×
75
                lnutils.LogPubKey("path_key", onionMsg.PathKey),
×
76
        )
×
77

×
78
        log.DebugS(logCtx, "OnionEndpoint received OnionMessage",
×
79
                btclog.HexN("onion_blob", onionMsg.OnionBlob, 10),
×
80
                slog.Int("blob_length", len(onionMsg.OnionBlob)))
×
81

×
82
        var peerArr [33]byte
×
83
        copy(peerArr[:], peer)
×
84

×
85
        // Convert path key []byte to [33]byte.
×
86
        pathKey := onionMsg.PathKey.SerializeCompressed()
×
87
        var pathKeyArr [33]byte
×
88
        copy(pathKeyArr[:], pathKey)
×
89

×
90
        err := o.onionMessageServer.SendUpdate(&OnionMessageUpdate{
×
91
                Peer:      peerArr,
×
92
                PathKey:   pathKeyArr,
×
93
                OnionBlob: onionMsg.OnionBlob,
×
94
        })
×
95
        if err != nil {
×
96
                log.ErrorS(logCtx, "Failed to send onion message update", err)
×
97
                return false
×
98
        }
×
99

100
        return true
×
101
}
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