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

lightningnetwork / lnd / 13558005087

27 Feb 2025 03:04AM UTC coverage: 58.834% (-0.001%) from 58.835%
13558005087

Pull #8453

github

Roasbeef
lnwallet/chancloser: increase test coverage of state machine
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

1079 of 1370 new or added lines in 23 files covered. (78.76%)

578 existing lines in 40 files now uncovered.

137063 of 232965 relevant lines covered (58.83%)

19205.84 hits per line

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

69.77
/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,
44
        msgSender flexMessageSender) *peerMsgSender {
1✔
45

1✔
46
        return &peerMsgSender{
1✔
47
                sender:  msgSender,
1✔
48
                peerPub: peerPub,
1✔
49
        }
1✔
50
}
1✔
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,
57
        msgs []lnwire.Message) error {
1✔
58

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

65
        return p.sender.SendMessage(true, msgs...)
1✔
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
// LinkNetworkController is an interface that represents an object capable of
76
// managing interactions with the active channel links from the PoV of the
77
// gossip network.
78
//
79
//nolint:iface
80
type LinkNetworkController interface {
81
        // RequestDisable disables a channel by its channel point.
82
        RequestDisable(wire.OutPoint, bool) error
83
}
84

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

91
        // TxBroadcaster is capable of broadcasting a transaction to the
92
        // network.
93
        TxBroadcaster TxBroadcaster
94

95
        // LinkNetworkControl is the primary interface for interacting with the
96
        // set of active channel links from the PoV of the network.
97
        LinkNetworkControl LinkNetworkController
98

99
        // ChainNotifier is capable of receiving notifications for on-chain
100
        // events.
101
        ChainNotifier chainntnfs.ChainNotifier
102
}
103

104
// LndDaemonAdapters is a struct that implements the protofsm.DaemonAdapters
105
// interface using common lnd abstractions.
106
type LndDaemonAdapters struct {
107
        cfg LndAdapterCfg
108
}
109

110
// NewLndDaemonAdapters creates a new instance of the lndDaemonAdapters struct.
111
func NewLndDaemonAdapters(cfg LndAdapterCfg) *LndDaemonAdapters {
1✔
112
        return &LndDaemonAdapters{
1✔
113
                cfg: cfg,
1✔
114
        }
1✔
115
}
1✔
116

117
// SendMessages sends the target set of messages to the target peer.
118
func (l *LndDaemonAdapters) SendMessages(pub btcec.PublicKey,
119
        msgs []lnwire.Message) error {
1✔
120

1✔
121
        return l.cfg.MsgSender.SendMessages(pub, msgs)
1✔
122
}
1✔
123

124
// BroadcastTransaction broadcasts a transaction with the target label.
125
func (l *LndDaemonAdapters) BroadcastTransaction(tx *wire.MsgTx,
126
        label string) error {
1✔
127

1✔
128
        return l.cfg.TxBroadcaster.PublishTransaction(tx, label)
1✔
129
}
1✔
130

131
// DisableChannel disables the target channel.
NEW
132
func (l *LndDaemonAdapters) DisableChannel(op wire.OutPoint) error {
×
NEW
133
        return l.cfg.LinkNetworkControl.RequestDisable(op, false)
×
NEW
134
}
×
135

136
// RegisterConfirmationsNtfn registers an intent to be notified once txid
137
// reaches numConfs confirmations.
138
func (l *LndDaemonAdapters) RegisterConfirmationsNtfn(txid *chainhash.Hash,
139
        pkScript []byte, numConfs, heightHint uint32,
140
        opts ...chainntnfs.NotifierOption,
NEW
141
) (*chainntnfs.ConfirmationEvent, error) {
×
NEW
142

×
NEW
143
        return l.cfg.ChainNotifier.RegisterConfirmationsNtfn(
×
NEW
144
                txid, pkScript, numConfs, heightHint, opts...,
×
NEW
145
        )
×
NEW
146
}
×
147

148
// RegisterSpendNtfn registers an intent to be notified once the target
149
// outpoint is successfully spent within a transaction.
150
func (l *LndDaemonAdapters) RegisterSpendNtfn(outpoint *wire.OutPoint,
151
        pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
1✔
152

1✔
153
        return l.cfg.ChainNotifier.RegisterSpendNtfn(
1✔
154
                outpoint, pkScript, heightHint,
1✔
155
        )
1✔
156
}
1✔
157

158
// A compile time check to ensure that lndDaemonAdapters fully implements the
159
// DaemonAdapters interface.
160
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