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

lightningnetwork / lnd / 14096782012

27 Mar 2025 01:21AM UTC coverage: 69.035% (-0.008%) from 69.043%
14096782012

Pull #9651

github

web-flow
Merge bcacc6976 into 193d2a658
Pull Request #9651: chainreg: send dummy epoch in `no_chain_backend`

0 of 12 new or added lines in 1 file covered. (0.0%)

86 existing lines in 19 files now uncovered.

133295 of 193084 relevant lines covered (69.03%)

22159.13 hits per line

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

0.0
/chainreg/no_chain_backend.go
1
package chainreg
2

3
import (
4
        "errors"
5
        "time"
6

7
        "github.com/btcsuite/btcd/btcjson"
8
        "github.com/btcsuite/btcd/btcutil"
9
        "github.com/btcsuite/btcd/chaincfg/chainhash"
10
        "github.com/btcsuite/btcd/wire"
11
        "github.com/btcsuite/btcwallet/chain"
12
        "github.com/btcsuite/btcwallet/waddrmgr"
13
        "github.com/lightningnetwork/lnd/chainntnfs"
14
        graphdb "github.com/lightningnetwork/lnd/graph/db"
15
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
16
        "github.com/lightningnetwork/lnd/routing/chainview"
17
)
18

19
var (
20
        // defaultFee is the fee that is returned by NoChainBackend.
21
        defaultFee = chainfee.FeePerKwFloor
22

23
        // noChainBackendName is the backend name returned by NoChainBackend.
24
        noChainBackendName = "nochainbackend"
25

26
        // errNotImplemented is the error that is returned by NoChainBackend for
27
        // any operation that is not supported by it. Such paths should in
28
        // practice never been hit, so seeing this error either means a remote
29
        // signing instance was used for an unsupported purpose or a previously
30
        // forgotten edge case path was hit.
31
        errNotImplemented = errors.New("not implemented in nochainbackend " +
32
                "mode")
33

34
        // noChainBackendBestHash is the chain hash of the chain tip that is
35
        // returned by NoChainBackend.
36
        noChainBackendBestHash = &chainhash.Hash{0x01}
37

38
        // noChainBackendBestHeight is the best height that is returned by
39
        // NoChainBackend.
40
        noChainBackendBestHeight int32 = 1
41
)
42

43
// NoChainBackend is a mock implementation of the following interfaces:
44
//   - chainview.FilteredChainView
45
//   - chainntnfs.ChainNotifier
46
//   - chainfee.Estimator
47
type NoChainBackend struct {
48
}
49

50
func (n *NoChainBackend) EstimateFeePerKW(uint32) (chainfee.SatPerKWeight,
51
        error) {
×
52

×
53
        return defaultFee, nil
×
54
}
×
55

56
func (n *NoChainBackend) RelayFeePerKW() chainfee.SatPerKWeight {
×
57
        return defaultFee
×
58
}
×
59

60
func (n *NoChainBackend) RegisterConfirmationsNtfn(*chainhash.Hash, []byte,
61
        uint32, uint32,
62
        ...chainntnfs.NotifierOption) (*chainntnfs.ConfirmationEvent, error) {
×
63

×
64
        return nil, errNotImplemented
×
65
}
×
66

67
func (n *NoChainBackend) RegisterSpendNtfn(*wire.OutPoint, []byte,
68
        uint32) (*chainntnfs.SpendEvent, error) {
×
69

×
70
        return nil, errNotImplemented
×
71
}
×
72

73
func (n *NoChainBackend) RegisterBlockEpochNtfn(
74
        *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error) {
×
75

×
NEW
76
        epochChan := make(chan *chainntnfs.BlockEpoch, 1)
×
NEW
77

×
NEW
78
        blockHeader := &wire.BlockHeader{
×
NEW
79
                Nonce: 1,
×
NEW
80
        }
×
NEW
81
        block := &chainntnfs.BlockEpoch{
×
NEW
82
                BlockHeader: blockHeader,
×
NEW
83
                Hash:   noChainBackendBestHash,
×
NEW
84
                Height: noChainBackendBestHeight,
×
NEW
85
        }
×
NEW
86
        epochChan <- block
×
NEW
87

×
88
        return &chainntnfs.BlockEpochEvent{
×
89
                Epochs: epochChan,
×
90
                Cancel: func() {
×
91
                        close(epochChan)
×
92
                },
×
93
        }, nil
94
}
95

96
func (n *NoChainBackend) Started() bool {
×
97
        return true
×
98
}
×
99

100
func (n *NoChainBackend) FilteredBlocks() <-chan *chainview.FilteredBlock {
×
101
        return make(chan *chainview.FilteredBlock)
×
102
}
×
103

104
func (n *NoChainBackend) DisconnectedBlocks() <-chan *chainview.FilteredBlock {
×
105
        return make(chan *chainview.FilteredBlock)
×
106
}
×
107

108
func (n *NoChainBackend) UpdateFilter([]graphdb.EdgePoint, uint32) error {
×
109
        return nil
×
110
}
×
111

112
func (n *NoChainBackend) FilterBlock(*chainhash.Hash) (*chainview.FilteredBlock,
113
        error) {
×
114

×
115
        return nil, errNotImplemented
×
116
}
×
117

118
func (n *NoChainBackend) Start() error {
×
119
        return nil
×
120
}
×
121

122
func (n *NoChainBackend) Stop() error {
×
123
        return nil
×
124
}
×
125

126
var _ chainview.FilteredChainView = (*NoChainBackend)(nil)
127
var _ chainntnfs.ChainNotifier = (*NoChainBackend)(nil)
128
var _ chainfee.Estimator = (*NoChainBackend)(nil)
129

130
// NoChainSource is a mock implementation of chain.Interface.
131
// The mock is designed to return static values where necessary to make any
132
// caller believe the chain is fully synced to virtual block height 1 (hash
133
// 0x0000..0001). That should avoid calls to other methods completely since they
134
// are only used for advancing the chain forward.
135
type NoChainSource struct {
136
        notifChan chan interface{}
137

138
        BestBlockTime time.Time
139
}
140

141
func (n *NoChainSource) Start() error {
×
142
        n.notifChan = make(chan interface{})
×
143

×
144
        go func() {
×
145
                n.notifChan <- &chain.RescanFinished{
×
146
                        Hash:   noChainBackendBestHash,
×
147
                        Height: noChainBackendBestHeight,
×
148
                        Time:   n.BestBlockTime,
×
149
                }
×
150
        }()
×
151

152
        return nil
×
153
}
154

155
func (n *NoChainSource) Stop() {
×
156
}
×
157

158
func (n *NoChainSource) WaitForShutdown() {
×
159
}
×
160

161
func (n *NoChainSource) GetBestBlock() (*chainhash.Hash, int32, error) {
×
162
        return noChainBackendBestHash, noChainBackendBestHeight, nil
×
163
}
×
164

165
func (n *NoChainSource) GetBlock(*chainhash.Hash) (*wire.MsgBlock, error) {
×
166
        return &wire.MsgBlock{
×
167
                Header: wire.BlockHeader{
×
168
                        Timestamp: n.BestBlockTime,
×
169
                },
×
170
                Transactions: []*wire.MsgTx{},
×
171
        }, nil
×
172
}
×
173

174
func (n *NoChainSource) GetBlockHash(int64) (*chainhash.Hash, error) {
×
175
        return noChainBackendBestHash, nil
×
176
}
×
177

178
func (n *NoChainSource) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader,
179
        error) {
×
180

×
181
        return &wire.BlockHeader{
×
182
                Timestamp: n.BestBlockTime,
×
183
        }, nil
×
184
}
×
185

186
func (n *NoChainSource) IsCurrent() bool {
×
187
        return true
×
188
}
×
189

190
func (n *NoChainSource) FilterBlocks(
191
        *chain.FilterBlocksRequest) (*chain.FilterBlocksResponse, error) {
×
192

×
193
        return nil, errNotImplemented
×
194
}
×
195

196
func (n *NoChainSource) BlockStamp() (*waddrmgr.BlockStamp, error) {
×
197
        return nil, errNotImplemented
×
198
}
×
199

200
func (n *NoChainSource) SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash,
201
        error) {
×
202

×
203
        return nil, errNotImplemented
×
204
}
×
205

206
func (n *NoChainSource) Rescan(*chainhash.Hash, []btcutil.Address,
207
        map[wire.OutPoint]btcutil.Address) error {
×
208

×
209
        return nil
×
210
}
×
211

212
func (n *NoChainSource) NotifyReceived([]btcutil.Address) error {
×
213
        return nil
×
214
}
×
215

216
func (n *NoChainSource) NotifyBlocks() error {
×
217
        return nil
×
218
}
×
219

220
func (n *NoChainSource) Notifications() <-chan interface{} {
×
221
        return n.notifChan
×
222
}
×
223

224
func (n *NoChainSource) BackEnd() string {
×
225
        return noChainBackendName
×
226
}
×
227

228
func (n *NoChainSource) TestMempoolAccept([]*wire.MsgTx,
229
        float64) ([]*btcjson.TestMempoolAcceptResult, error) {
×
230

×
231
        return nil, nil
×
232
}
×
233

234
func (n *NoChainSource) MapRPCErr(err error) error {
×
235
        return err
×
236
}
×
237

238
var _ chain.Interface = (*NoChainSource)(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