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

lightningnetwork / lnd / 15871518718

25 Jun 2025 08:37AM UTC coverage: 55.595% (-12.2%) from 67.8%
15871518718

Pull #9991

github

web-flow
Merge 43edfeb10 into 33e6f2854
Pull Request #9991: routerrpc: add log line for probing the invoice request

2 of 12 new or added lines in 1 file covered. (16.67%)

23714 existing lines in 287 files now uncovered.

108233 of 194681 relevant lines covered (55.6%)

22511.42 hits per line

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

0.0
/peer/daemon_adapters.go
1
package peer
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/btcec/v2"
7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
        "github.com/btcsuite/btcd/wire"
9
        "github.com/lightningnetwork/lnd/chainntnfs"
10
        "github.com/lightningnetwork/lnd/lnwire"
11
        "github.com/lightningnetwork/lnd/protofsm"
12
)
13

14
// MessageSender is an interface that represents an object capable of sending
15
// p2p messages to a destination.
16
type MessageSender interface {
17
        // SendMessages sends the target set of messages to the target peer.
18
        //
19
        // TODO(roasbeef): current impl bound to single peer, need server
20
        // pointer otherwise
21
        SendMessages(btcec.PublicKey, []lnwire.Message) error
22
}
23

24
// flexMessageSender is a message sender-like interface that is aware of
25
// sync/async semantics, and is bound to a single peer.
26
type flexMessageSender interface {
27
        // SendMessage sends a variadic number of high-priority messages to the
28
        // remote peer. The first argument denotes if the method should block
29
        // until the messages have been sent to the remote peer or an error is
30
        // returned, otherwise it returns immediately after queuing.
31
        SendMessage(sync bool, msgs ...lnwire.Message) error
32
}
33

34
// peerMsgSender implements the MessageSender interface for a single peer.
35
// It'll return an error if the target public isn't equal to public key of the
36
// backing peer.
37
type peerMsgSender struct {
38
        sender  flexMessageSender
39
        peerPub btcec.PublicKey
40
}
41

42
// newPeerMsgSender creates a new instance of a peerMsgSender.
43
func newPeerMsgSender(peerPub btcec.PublicKey,
UNCOV
44
        msgSender flexMessageSender) *peerMsgSender {
×
UNCOV
45

×
UNCOV
46
        return &peerMsgSender{
×
UNCOV
47
                sender:  msgSender,
×
UNCOV
48
                peerPub: peerPub,
×
UNCOV
49
        }
×
UNCOV
50
}
×
51

52
// SendMessages sends the target set of messages to the target peer.
53
//
54
// TODO(roasbeef): current impl bound to single peer, need server pointer
55
// otherwise?
56
func (p *peerMsgSender) SendMessages(pub btcec.PublicKey,
UNCOV
57
        msgs []lnwire.Message) error {
×
UNCOV
58

×
UNCOV
59
        if !p.peerPub.IsEqual(&pub) {
×
60
                return fmt.Errorf("wrong peer pubkey: got %x, can only send "+
×
61
                        "to %x", pub.SerializeCompressed(),
×
62
                        p.peerPub.SerializeCompressed())
×
63
        }
×
64

UNCOV
65
        return p.sender.SendMessage(true, msgs...)
×
66
}
67

68
// TxBroadcaster is an interface that represents an object capable of
69
// broadcasting transactions to the network.
70
type TxBroadcaster interface {
71
        // PublishTransaction broadcasts a transaction to the network.
72
        PublishTransaction(*wire.MsgTx, string) error
73
}
74

75
// LndAdapterCfg is a struct that holds the configuration for the
76
// LndDaemonAdapters instance.
77
type LndAdapterCfg struct {
78
        // MsgSender is capable of sending messages to an arbitrary peer.
79
        MsgSender MessageSender
80

81
        // TxBroadcaster is capable of broadcasting a transaction to the
82
        // network.
83
        TxBroadcaster TxBroadcaster
84

85
        // ChainNotifier is capable of receiving notifications for on-chain
86
        // events.
87
        ChainNotifier chainntnfs.ChainNotifier
88
}
89

90
// LndDaemonAdapters is a struct that implements the protofsm.DaemonAdapters
91
// interface using common lnd abstractions.
92
type LndDaemonAdapters struct {
93
        cfg LndAdapterCfg
94
}
95

96
// NewLndDaemonAdapters creates a new instance of the lndDaemonAdapters struct.
UNCOV
97
func NewLndDaemonAdapters(cfg LndAdapterCfg) *LndDaemonAdapters {
×
UNCOV
98
        return &LndDaemonAdapters{
×
UNCOV
99
                cfg: cfg,
×
UNCOV
100
        }
×
UNCOV
101
}
×
102

103
// SendMessages sends the target set of messages to the target peer.
104
func (l *LndDaemonAdapters) SendMessages(pub btcec.PublicKey,
UNCOV
105
        msgs []lnwire.Message) error {
×
UNCOV
106

×
UNCOV
107
        return l.cfg.MsgSender.SendMessages(pub, msgs)
×
UNCOV
108
}
×
109

110
// BroadcastTransaction broadcasts a transaction with the target label.
111
func (l *LndDaemonAdapters) BroadcastTransaction(tx *wire.MsgTx,
UNCOV
112
        label string) error {
×
UNCOV
113

×
UNCOV
114
        return l.cfg.TxBroadcaster.PublishTransaction(tx, label)
×
UNCOV
115
}
×
116

117
// RegisterConfirmationsNtfn registers an intent to be notified once txid
118
// reaches numConfs confirmations.
119
func (l *LndDaemonAdapters) RegisterConfirmationsNtfn(txid *chainhash.Hash,
120
        pkScript []byte, numConfs, heightHint uint32,
121
        opts ...chainntnfs.NotifierOption,
122
) (*chainntnfs.ConfirmationEvent, error) {
×
123

×
124
        return l.cfg.ChainNotifier.RegisterConfirmationsNtfn(
×
125
                txid, pkScript, numConfs, heightHint, opts...,
×
126
        )
×
127
}
×
128

129
// RegisterSpendNtfn registers an intent to be notified once the target
130
// outpoint is successfully spent within a transaction.
131
func (l *LndDaemonAdapters) RegisterSpendNtfn(outpoint *wire.OutPoint,
UNCOV
132
        pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
×
UNCOV
133

×
UNCOV
134
        return l.cfg.ChainNotifier.RegisterSpendNtfn(
×
UNCOV
135
                outpoint, pkScript, heightHint,
×
UNCOV
136
        )
×
UNCOV
137
}
×
138

139
// A compile time check to ensure that lndDaemonAdapters fully implements the
140
// DaemonAdapters interface.
141
var _ protofsm.DaemonAdapters = (*LndDaemonAdapters)(nil)
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