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

lightningnetwork / lnd / 13577134505

27 Feb 2025 10:29PM UTC coverage: 57.681%. First build
13577134505

Pull #9559

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #9559: multi: preliminary changes towards integrating the new RBF close protocol feature

58 of 253 new or added lines in 15 files covered. (22.92%)

103797 of 179949 relevant lines covered (57.68%)

24831.15 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
//
27
//nolint:unused
28
type flexMessageSender interface {
29
        // SendMessage sends a variadic number of high-priority messages to the
30
        // remote peer. The first argument denotes if the method should block
31
        // until the messages have been sent to the remote peer or an error is
32
        // returned, otherwise it returns immediately after queuing.
33
        SendMessage(sync bool, msgs ...lnwire.Message) error
34
}
35

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

46
// newPeerMsgSender creates a new instance of a peerMsgSender.
47
//
48
//nolint:unused
49
func newPeerMsgSender(peerPub btcec.PublicKey,
NEW
50
        msgSender flexMessageSender) *peerMsgSender {
×
NEW
51

×
NEW
52
        return &peerMsgSender{
×
NEW
53
                sender:  msgSender,
×
NEW
54
                peerPub: peerPub,
×
NEW
55
        }
×
NEW
56
}
×
57

58
// SendMessages sends the target set of messages to the target peer.
59
//
60
// TODO(roasbeef): current impl bound to single peer, need server pointer
61
// otherwise?
62
//
63
//nolint:unused
64
func (p *peerMsgSender) SendMessages(pub btcec.PublicKey,
NEW
65
        msgs []lnwire.Message) error {
×
NEW
66

×
NEW
67
        if !p.peerPub.IsEqual(&pub) {
×
NEW
68
                return fmt.Errorf("wrong peer pubkey: got %x, can only send "+
×
NEW
69
                        "to %x", pub.SerializeCompressed(),
×
NEW
70
                        p.peerPub.SerializeCompressed())
×
NEW
71
        }
×
72

NEW
73
        return p.sender.SendMessage(true, msgs...)
×
74
}
75

76
// TxBroadcaster is an interface that represents an object capable of
77
// broadcasting transactions to the network.
78
type TxBroadcaster interface {
79
        // PublishTransaction broadcasts a transaction to the network.
80
        PublishTransaction(*wire.MsgTx, string) error
81
}
82

83
// LndAdapterCfg is a struct that holds the configuration for the
84
// LndDaemonAdapters instance.
85
type LndAdapterCfg struct {
86
        // MsgSender is capable of sending messages to an arbitrary peer.
87
        MsgSender MessageSender
88

89
        // TxBroadcaster is capable of broadcasting a transaction to the
90
        // network.
91
        TxBroadcaster TxBroadcaster
92

93
        // ChainNotifier is capable of receiving notifications for on-chain
94
        // events.
95
        ChainNotifier chainntnfs.ChainNotifier
96
}
97

98
// LndDaemonAdapters is a struct that implements the protofsm.DaemonAdapters
99
// interface using common lnd abstractions.
100
type LndDaemonAdapters struct {
101
        cfg LndAdapterCfg
102
}
103

104
// NewLndDaemonAdapters creates a new instance of the lndDaemonAdapters struct.
NEW
105
func NewLndDaemonAdapters(cfg LndAdapterCfg) *LndDaemonAdapters {
×
NEW
106
        return &LndDaemonAdapters{
×
NEW
107
                cfg: cfg,
×
NEW
108
        }
×
NEW
109
}
×
110

111
// SendMessages sends the target set of messages to the target peer.
112
func (l *LndDaemonAdapters) SendMessages(pub btcec.PublicKey,
NEW
113
        msgs []lnwire.Message) error {
×
NEW
114

×
NEW
115
        return l.cfg.MsgSender.SendMessages(pub, msgs)
×
NEW
116
}
×
117

118
// BroadcastTransaction broadcasts a transaction with the target label.
119
func (l *LndDaemonAdapters) BroadcastTransaction(tx *wire.MsgTx,
NEW
120
        label string) error {
×
NEW
121

×
NEW
122
        return l.cfg.TxBroadcaster.PublishTransaction(tx, label)
×
NEW
123
}
×
124

125
// RegisterConfirmationsNtfn registers an intent to be notified once txid
126
// reaches numConfs confirmations.
127
func (l *LndDaemonAdapters) RegisterConfirmationsNtfn(txid *chainhash.Hash,
128
        pkScript []byte, numConfs, heightHint uint32,
129
        opts ...chainntnfs.NotifierOption,
NEW
130
) (*chainntnfs.ConfirmationEvent, error) {
×
NEW
131

×
NEW
132
        return l.cfg.ChainNotifier.RegisterConfirmationsNtfn(
×
NEW
133
                txid, pkScript, numConfs, heightHint, opts...,
×
NEW
134
        )
×
NEW
135
}
×
136

137
// RegisterSpendNtfn registers an intent to be notified once the target
138
// outpoint is successfully spent within a transaction.
139
func (l *LndDaemonAdapters) RegisterSpendNtfn(outpoint *wire.OutPoint,
NEW
140
        pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
×
NEW
141

×
NEW
142
        return l.cfg.ChainNotifier.RegisterSpendNtfn(
×
NEW
143
                outpoint, pkScript, heightHint,
×
NEW
144
        )
×
NEW
145
}
×
146

147
// A compile time check to ensure that lndDaemonAdapters fully implements the
148
// DaemonAdapters interface.
149
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