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

lightningnetwork / lnd / 12056196575

27 Nov 2024 06:23PM UTC coverage: 58.717% (-0.2%) from 58.921%
12056196575

Pull #9242

github

aakselrod
go.mod: update to latest btcwallet
Pull Request #9242: Reapply #8644

8 of 39 new or added lines in 3 files covered. (20.51%)

543 existing lines in 30 files now uncovered.

132924 of 226381 relevant lines covered (58.72%)

19504.16 hits per line

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

59.55
/config_builder.go
1
package lnd
2

3
import (
4
        "bytes"
5
        "context"
6
        "database/sql"
7
        "errors"
8
        "fmt"
9
        "net"
10
        "os"
11
        "path/filepath"
12
        "sort"
13
        "strconv"
14
        "strings"
15
        "sync/atomic"
16
        "time"
17

18
        "github.com/btcsuite/btcd/chaincfg"
19
        "github.com/btcsuite/btcd/chaincfg/chainhash"
20
        "github.com/btcsuite/btcd/wire"
21
        "github.com/btcsuite/btclog/v2"
22
        "github.com/btcsuite/btcwallet/chain"
23
        "github.com/btcsuite/btcwallet/waddrmgr"
24
        "github.com/btcsuite/btcwallet/wallet"
25
        "github.com/btcsuite/btcwallet/walletdb"
26
        proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
27
        "github.com/lightninglabs/neutrino"
28
        "github.com/lightninglabs/neutrino/blockntfns"
29
        "github.com/lightninglabs/neutrino/headerfs"
30
        "github.com/lightninglabs/neutrino/pushtx"
31
        "github.com/lightningnetwork/lnd/blockcache"
32
        "github.com/lightningnetwork/lnd/chainntnfs"
33
        "github.com/lightningnetwork/lnd/chainreg"
34
        "github.com/lightningnetwork/lnd/channeldb"
35
        "github.com/lightningnetwork/lnd/clock"
36
        "github.com/lightningnetwork/lnd/fn"
37
        "github.com/lightningnetwork/lnd/funding"
38
        "github.com/lightningnetwork/lnd/invoices"
39
        "github.com/lightningnetwork/lnd/keychain"
40
        "github.com/lightningnetwork/lnd/kvdb"
41
        "github.com/lightningnetwork/lnd/lncfg"
42
        "github.com/lightningnetwork/lnd/lnrpc"
43
        "github.com/lightningnetwork/lnd/lnwallet"
44
        "github.com/lightningnetwork/lnd/lnwallet/btcwallet"
45
        "github.com/lightningnetwork/lnd/lnwallet/chancloser"
46
        "github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
47
        "github.com/lightningnetwork/lnd/macaroons"
48
        "github.com/lightningnetwork/lnd/msgmux"
49
        "github.com/lightningnetwork/lnd/routing"
50
        "github.com/lightningnetwork/lnd/rpcperms"
51
        "github.com/lightningnetwork/lnd/signal"
52
        "github.com/lightningnetwork/lnd/sqldb"
53
        "github.com/lightningnetwork/lnd/sweep"
54
        "github.com/lightningnetwork/lnd/walletunlocker"
55
        "github.com/lightningnetwork/lnd/watchtower"
56
        "github.com/lightningnetwork/lnd/watchtower/wtclient"
57
        "github.com/lightningnetwork/lnd/watchtower/wtdb"
58
        "google.golang.org/grpc"
59
        "gopkg.in/macaroon-bakery.v2/bakery"
60
)
61

62
// GrpcRegistrar is an interface that must be satisfied by an external subserver
63
// that wants to be able to register its own gRPC server onto lnd's main
64
// grpc.Server instance.
65
type GrpcRegistrar interface {
66
        // RegisterGrpcSubserver is called for each net.Listener on which lnd
67
        // creates a grpc.Server instance. External subservers implementing this
68
        // method can then register their own gRPC server structs to the main
69
        // server instance.
70
        RegisterGrpcSubserver(*grpc.Server) error
71
}
72

73
// RestRegistrar is an interface that must be satisfied by an external subserver
74
// that wants to be able to register its own REST mux onto lnd's main
75
// proxy.ServeMux instance.
76
type RestRegistrar interface {
77
        // RegisterRestSubserver is called after lnd creates the main
78
        // proxy.ServeMux instance. External subservers implementing this method
79
        // can then register their own REST proxy stubs to the main server
80
        // instance.
81
        RegisterRestSubserver(context.Context, *proxy.ServeMux, string,
82
                []grpc.DialOption) error
83
}
84

85
// ExternalValidator is an interface that must be satisfied by an external
86
// macaroon validator.
87
type ExternalValidator interface {
88
        macaroons.MacaroonValidator
89

90
        // Permissions returns the permissions that the external validator is
91
        // validating. It is a map between the full HTTP URI of each RPC and its
92
        // required macaroon permissions. If multiple action/entity tuples are
93
        // specified per URI, they are all required. See rpcserver.go for a list
94
        // of valid action and entity values.
95
        Permissions() map[string][]bakery.Op
96
}
97

98
// DatabaseBuilder is an interface that must be satisfied by the implementation
99
// that provides lnd's main database backend instances.
100
type DatabaseBuilder interface {
101
        // BuildDatabase extracts the current databases that we'll use for
102
        // normal operation in the daemon. A function closure that closes all
103
        // opened databases is also returned.
104
        BuildDatabase(ctx context.Context) (*DatabaseInstances, func(), error)
105
}
106

107
// WalletConfigBuilder is an interface that must be satisfied by a custom wallet
108
// implementation.
109
type WalletConfigBuilder interface {
110
        // BuildWalletConfig is responsible for creating or unlocking and then
111
        // fully initializing a wallet.
112
        BuildWalletConfig(context.Context, *DatabaseInstances, *AuxComponents,
113
                *rpcperms.InterceptorChain,
114
                []*ListenerWithSignal) (*chainreg.PartialChainControl,
115
                *btcwallet.Config, func(), error)
116
}
117

118
// ChainControlBuilder is an interface that must be satisfied by a custom wallet
119
// implementation.
120
type ChainControlBuilder interface {
121
        // BuildChainControl is responsible for creating a fully populated chain
122
        // control instance from a wallet.
123
        BuildChainControl(*chainreg.PartialChainControl,
124
                *btcwallet.Config) (*chainreg.ChainControl, func(), error)
125
}
126

127
// ImplementationCfg is a struct that holds all configuration items for
128
// components that can be implemented outside lnd itself.
129
type ImplementationCfg struct {
130
        // GrpcRegistrar is a type that can register additional gRPC subservers
131
        // before the main gRPC server is started.
132
        GrpcRegistrar
133

134
        // RestRegistrar is a type that can register additional REST subservers
135
        // before the main REST proxy is started.
136
        RestRegistrar
137

138
        // ExternalValidator is a type that can provide external macaroon
139
        // validation.
140
        ExternalValidator
141

142
        // DatabaseBuilder is a type that can provide lnd's main database
143
        // backend instances.
144
        DatabaseBuilder
145

146
        // WalletConfigBuilder is a type that can provide a wallet configuration
147
        // with a fully loaded and unlocked wallet.
148
        WalletConfigBuilder
149

150
        // ChainControlBuilder is a type that can provide a custom wallet
151
        // implementation.
152
        ChainControlBuilder
153

154
        // AuxComponents is a set of auxiliary components that can be used by
155
        // lnd for certain custom channel types.
156
        AuxComponents
157
}
158

159
// AuxComponents is a set of auxiliary components that can be used by lnd for
160
// certain custom channel types.
161
type AuxComponents struct {
162
        // AuxLeafStore is an optional data source that can be used by custom
163
        // channels to fetch+store various data.
164
        AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
165

166
        // TrafficShaper is an optional traffic shaper that can be used to
167
        // control the outgoing channel of a payment.
168
        TrafficShaper fn.Option[routing.TlvTrafficShaper]
169

170
        // MsgRouter is an optional message router that if set will be used in
171
        // place of a new blank default message router.
172
        MsgRouter fn.Option[msgmux.Router]
173

174
        // AuxFundingController is an optional controller that can be used to
175
        // modify the way we handle certain custom channel types. It's also
176
        // able to automatically handle new custom protocol messages related to
177
        // the funding process.
178
        AuxFundingController fn.Option[funding.AuxFundingController]
179

180
        // AuxSigner is an optional signer that can be used to sign auxiliary
181
        // leaves for certain custom channel types.
182
        AuxSigner fn.Option[lnwallet.AuxSigner]
183

184
        // AuxDataParser is an optional data parser that can be used to parse
185
        // auxiliary data for certain custom channel types.
186
        AuxDataParser fn.Option[AuxDataParser]
187

188
        // AuxChanCloser is an optional channel closer that can be used to
189
        // modify the way a coop-close transaction is constructed.
190
        AuxChanCloser fn.Option[chancloser.AuxChanCloser]
191

192
        // AuxSweeper is an optional interface that can be used to modify the
193
        // way sweep transaction are generated.
194
        AuxSweeper fn.Option[sweep.AuxSweeper]
195

196
        // AuxContractResolver is an optional interface that can be used to
197
        // modify the way contracts are resolved.
198
        AuxContractResolver fn.Option[lnwallet.AuxContractResolver]
199
}
200

201
// DefaultWalletImpl is the default implementation of our normal, btcwallet
202
// backed configuration.
203
type DefaultWalletImpl struct {
204
        cfg         *Config
205
        logger      btclog.Logger
206
        interceptor signal.Interceptor
207

208
        watchOnly        bool
209
        migrateWatchOnly bool
210
        pwService        *walletunlocker.UnlockerService
211
}
212

213
// NewDefaultWalletImpl creates a new default wallet implementation.
214
func NewDefaultWalletImpl(cfg *Config, logger btclog.Logger,
215
        interceptor signal.Interceptor, watchOnly bool) *DefaultWalletImpl {
2✔
216

2✔
217
        return &DefaultWalletImpl{
2✔
218
                cfg:         cfg,
2✔
219
                logger:      logger,
2✔
220
                interceptor: interceptor,
2✔
221
                watchOnly:   watchOnly,
2✔
222
                pwService:   createWalletUnlockerService(cfg),
2✔
223
        }
2✔
224
}
2✔
225

226
// RegisterRestSubserver is called after lnd creates the main proxy.ServeMux
227
// instance. External subservers implementing this method can then register
228
// their own REST proxy stubs to the main server instance.
229
//
230
// NOTE: This is part of the GrpcRegistrar interface.
231
func (d *DefaultWalletImpl) RegisterRestSubserver(ctx context.Context,
232
        mux *proxy.ServeMux, restProxyDest string,
233
        restDialOpts []grpc.DialOption) error {
2✔
234

2✔
235
        return lnrpc.RegisterWalletUnlockerHandlerFromEndpoint(
2✔
236
                ctx, mux, restProxyDest, restDialOpts,
2✔
237
        )
2✔
238
}
2✔
239

240
// RegisterGrpcSubserver is called for each net.Listener on which lnd creates a
241
// grpc.Server instance. External subservers implementing this method can then
242
// register their own gRPC server structs to the main server instance.
243
//
244
// NOTE: This is part of the GrpcRegistrar interface.
245
func (d *DefaultWalletImpl) RegisterGrpcSubserver(s *grpc.Server) error {
2✔
246
        lnrpc.RegisterWalletUnlockerServer(s, d.pwService)
2✔
247

2✔
248
        return nil
2✔
249
}
2✔
250

251
// ValidateMacaroon extracts the macaroon from the context's gRPC metadata,
252
// checks its signature, makes sure all specified permissions for the called
253
// method are contained within and finally ensures all caveat conditions are
254
// met. A non-nil error is returned if any of the checks fail.
255
//
256
// NOTE: This is part of the ExternalValidator interface.
257
func (d *DefaultWalletImpl) ValidateMacaroon(ctx context.Context,
258
        requiredPermissions []bakery.Op, fullMethod string) error {
×
259

×
260
        // Because the default implementation does not return any permissions,
×
261
        // we shouldn't be registered as an external validator at all and this
×
262
        // should never be invoked.
×
263
        return fmt.Errorf("default implementation does not support external " +
×
264
                "macaroon validation")
×
265
}
×
266

267
// Permissions returns the permissions that the external validator is
268
// validating. It is a map between the full HTTP URI of each RPC and its
269
// required macaroon permissions. If multiple action/entity tuples are specified
270
// per URI, they are all required. See rpcserver.go for a list of valid action
271
// and entity values.
272
//
273
// NOTE: This is part of the ExternalValidator interface.
274
func (d *DefaultWalletImpl) Permissions() map[string][]bakery.Op {
2✔
275
        return nil
2✔
276
}
2✔
277

278
// BuildWalletConfig is responsible for creating or unlocking and then
279
// fully initializing a wallet.
280
//
281
// NOTE: This is part of the WalletConfigBuilder interface.
282
func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
283
        dbs *DatabaseInstances, aux *AuxComponents,
284
        interceptorChain *rpcperms.InterceptorChain,
285
        grpcListeners []*ListenerWithSignal) (*chainreg.PartialChainControl,
286
        *btcwallet.Config, func(), error) {
2✔
287

2✔
288
        // Keep track of our various cleanup functions. We use a defer function
2✔
289
        // as well to not repeat ourselves with every return statement.
2✔
290
        var (
2✔
291
                cleanUpTasks []func()
2✔
292
                earlyExit    = true
2✔
293
                cleanUp      = func() {
4✔
294
                        for _, fn := range cleanUpTasks {
4✔
295
                                if fn == nil {
2✔
296
                                        continue
×
297
                                }
298

299
                                fn()
2✔
300
                        }
301
                }
302
        )
303
        defer func() {
4✔
304
                if earlyExit {
2✔
305
                        cleanUp()
×
306
                }
×
307
        }()
308

309
        // Initialize a new block cache.
310
        blockCache := blockcache.NewBlockCache(d.cfg.BlockCacheSize)
2✔
311

2✔
312
        // Before starting the wallet, we'll create and start our Neutrino
2✔
313
        // light client instance, if enabled, in order to allow it to sync
2✔
314
        // while the rest of the daemon continues startup.
2✔
315
        mainChain := d.cfg.Bitcoin
2✔
316
        var neutrinoCS *neutrino.ChainService
2✔
317
        if mainChain.Node == "neutrino" {
2✔
UNCOV
318
                neutrinoBackend, neutrinoCleanUp, err := initNeutrinoBackend(
×
UNCOV
319
                        ctx, d.cfg, mainChain.ChainDir, blockCache,
×
UNCOV
320
                )
×
UNCOV
321
                if err != nil {
×
322
                        err := fmt.Errorf("unable to initialize neutrino "+
×
323
                                "backend: %v", err)
×
324
                        d.logger.Error(err)
×
325
                        return nil, nil, nil, err
×
326
                }
×
UNCOV
327
                cleanUpTasks = append(cleanUpTasks, neutrinoCleanUp)
×
UNCOV
328
                neutrinoCS = neutrinoBackend
×
329
        }
330

331
        var (
2✔
332
                walletInitParams = walletunlocker.WalletUnlockParams{
2✔
333
                        // In case we do auto-unlock, we need to be able to send
2✔
334
                        // into the channel without blocking so we buffer it.
2✔
335
                        MacResponseChan: make(chan []byte, 1),
2✔
336
                }
2✔
337
                privateWalletPw = lnwallet.DefaultPrivatePassphrase
2✔
338
                publicWalletPw  = lnwallet.DefaultPublicPassphrase
2✔
339
        )
2✔
340

2✔
341
        // If the user didn't request a seed, then we'll manually assume a
2✔
342
        // wallet birthday of now, as otherwise the seed would've specified
2✔
343
        // this information.
2✔
344
        walletInitParams.Birthday = time.Now()
2✔
345

2✔
346
        d.pwService.SetLoaderOpts([]btcwallet.LoaderOption{dbs.WalletDB})
2✔
347
        d.pwService.SetMacaroonDB(dbs.MacaroonDB)
2✔
348
        walletExists, err := d.pwService.WalletExists()
2✔
349
        if err != nil {
2✔
350
                return nil, nil, nil, err
×
351
        }
×
352

353
        if !walletExists {
4✔
354
                interceptorChain.SetWalletNotCreated()
2✔
355
        } else {
4✔
356
                interceptorChain.SetWalletLocked()
2✔
357
        }
2✔
358

359
        // If we've started in auto unlock mode, then a wallet should already
360
        // exist because we don't want to enable the RPC unlocker in that case
361
        // for security reasons (an attacker could inject their seed since the
362
        // RPC is unauthenticated). Only if the user explicitly wants to allow
363
        // wallet creation we don't error out here.
364
        if d.cfg.WalletUnlockPasswordFile != "" && !walletExists &&
2✔
365
                !d.cfg.WalletUnlockAllowCreate {
2✔
366

×
367
                return nil, nil, nil, fmt.Errorf("wallet unlock password file " +
×
368
                        "was specified but wallet does not exist; initialize " +
×
369
                        "the wallet before using auto unlocking")
×
370
        }
×
371

372
        // What wallet mode are we running in? We've already made sure the no
373
        // seed backup and auto unlock aren't both set during config parsing.
374
        switch {
2✔
375
        // No seed backup means we're also using the default password.
376
        case d.cfg.NoSeedBackup:
2✔
377
                // We continue normally, the default password has already been
378
                // set above.
379

380
        // A password for unlocking is provided in a file.
381
        case d.cfg.WalletUnlockPasswordFile != "" && walletExists:
×
382
                d.logger.Infof("Attempting automatic wallet unlock with " +
×
383
                        "password provided in file")
×
384
                pwBytes, err := os.ReadFile(d.cfg.WalletUnlockPasswordFile)
×
385
                if err != nil {
×
386
                        return nil, nil, nil, fmt.Errorf("error reading "+
×
387
                                "password from file %s: %v",
×
388
                                d.cfg.WalletUnlockPasswordFile, err)
×
389
                }
×
390

391
                // Remove any newlines at the end of the file. The lndinit tool
392
                // won't ever write a newline but maybe the file was provisioned
393
                // by another process or user.
394
                pwBytes = bytes.TrimRight(pwBytes, "\r\n")
×
395

×
396
                // We have the password now, we can ask the unlocker service to
×
397
                // do the unlock for us.
×
398
                unlockedWallet, unloadWalletFn, err := d.pwService.LoadAndUnlock(
×
399
                        pwBytes, 0,
×
400
                )
×
401
                if err != nil {
×
402
                        return nil, nil, nil, fmt.Errorf("error unlocking "+
×
403
                                "wallet with password from file: %v", err)
×
404
                }
×
405

406
                cleanUpTasks = append(cleanUpTasks, func() {
×
407
                        if err := unloadWalletFn(); err != nil {
×
408
                                d.logger.Errorf("Could not unload wallet: %v",
×
409
                                        err)
×
410
                        }
×
411
                })
412

413
                privateWalletPw = pwBytes
×
414
                publicWalletPw = pwBytes
×
415
                walletInitParams.Wallet = unlockedWallet
×
416
                walletInitParams.UnloadWallet = unloadWalletFn
×
417

418
        // If none of the automatic startup options are selected, we fall back
419
        // to the default behavior of waiting for the wallet creation/unlocking
420
        // over RPC.
421
        default:
2✔
422
                if err := d.interceptor.Notifier.NotifyReady(false); err != nil {
2✔
423
                        return nil, nil, nil, err
×
424
                }
×
425

426
                params, err := waitForWalletPassword(
2✔
427
                        d.cfg, d.pwService, []btcwallet.LoaderOption{dbs.WalletDB},
2✔
428
                        d.interceptor.ShutdownChannel(),
2✔
429
                )
2✔
430
                if err != nil {
2✔
431
                        err := fmt.Errorf("unable to set up wallet password "+
×
432
                                "listeners: %v", err)
×
433
                        d.logger.Error(err)
×
434
                        return nil, nil, nil, err
×
435
                }
×
436

437
                walletInitParams = *params
2✔
438
                privateWalletPw = walletInitParams.Password
2✔
439
                publicWalletPw = walletInitParams.Password
2✔
440
                cleanUpTasks = append(cleanUpTasks, func() {
4✔
441
                        if err := walletInitParams.UnloadWallet(); err != nil {
2✔
442
                                d.logger.Errorf("Could not unload wallet: %v",
×
443
                                        err)
×
444
                        }
×
445
                })
446

447
                if walletInitParams.RecoveryWindow > 0 {
4✔
448
                        d.logger.Infof("Wallet recovery mode enabled with "+
2✔
449
                                "address lookahead of %d addresses",
2✔
450
                                walletInitParams.RecoveryWindow)
2✔
451
                }
2✔
452
        }
453

454
        var macaroonService *macaroons.Service
2✔
455
        if !d.cfg.NoMacaroons {
4✔
456
                // Create the macaroon authentication/authorization service.
2✔
457
                rootKeyStore, err := macaroons.NewRootKeyStorage(dbs.MacaroonDB)
2✔
458
                if err != nil {
2✔
459
                        return nil, nil, nil, err
×
460
                }
×
461
                macaroonService, err = macaroons.NewService(
2✔
462
                        rootKeyStore, "lnd", walletInitParams.StatelessInit,
2✔
463
                        macaroons.IPLockChecker,
2✔
464
                        macaroons.CustomChecker(interceptorChain),
2✔
465
                )
2✔
466
                if err != nil {
2✔
467
                        err := fmt.Errorf("unable to set up macaroon "+
×
468
                                "authentication: %v", err)
×
469
                        d.logger.Error(err)
×
470
                        return nil, nil, nil, err
×
471
                }
×
472
                cleanUpTasks = append(cleanUpTasks, func() {
4✔
473
                        if err := macaroonService.Close(); err != nil {
2✔
474
                                d.logger.Errorf("Could not close macaroon "+
×
475
                                        "service: %v", err)
×
476
                        }
×
477
                })
478

479
                // Try to unlock the macaroon store with the private password.
480
                // Ignore ErrAlreadyUnlocked since it could be unlocked by the
481
                // wallet unlocker.
482
                err = macaroonService.CreateUnlock(&privateWalletPw)
2✔
483
                if err != nil && err != macaroons.ErrAlreadyUnlocked {
2✔
484
                        err := fmt.Errorf("unable to unlock macaroons: %w", err)
×
485
                        d.logger.Error(err)
×
486
                        return nil, nil, nil, err
×
487
                }
×
488

489
                // If we have a macaroon root key from the init wallet params,
490
                // set the root key before baking any macaroons.
491
                if len(walletInitParams.MacRootKey) > 0 {
2✔
492
                        err := macaroonService.SetRootKey(
×
493
                                walletInitParams.MacRootKey,
×
494
                        )
×
495
                        if err != nil {
×
496
                                return nil, nil, nil, err
×
497
                        }
×
498
                }
499

500
                // Send an admin macaroon to all our listeners that requested
501
                // one by setting a non-nil macaroon channel.
502
                adminMacBytes, err := bakeMacaroon(
2✔
503
                        ctx, macaroonService, adminPermissions(),
2✔
504
                )
2✔
505
                if err != nil {
2✔
506
                        return nil, nil, nil, err
×
507
                }
×
508
                for _, lis := range grpcListeners {
4✔
509
                        if lis.MacChan != nil {
2✔
510
                                lis.MacChan <- adminMacBytes
×
511
                        }
×
512
                }
513

514
                // In case we actually needed to unlock the wallet, we now need
515
                // to create an instance of the admin macaroon and send it to
516
                // the unlocker so it can forward it to the user. In no seed
517
                // backup mode, there's nobody listening on the channel and we'd
518
                // block here forever.
519
                if !d.cfg.NoSeedBackup {
4✔
520
                        // The channel is buffered by one element so writing
2✔
521
                        // should not block here.
2✔
522
                        walletInitParams.MacResponseChan <- adminMacBytes
2✔
523
                }
2✔
524

525
                // If the user requested a stateless initialization, no macaroon
526
                // files should be created.
527
                if !walletInitParams.StatelessInit {
4✔
528
                        // Create default macaroon files for lncli to use if
2✔
529
                        // they don't exist.
2✔
530
                        err = genDefaultMacaroons(
2✔
531
                                ctx, macaroonService, d.cfg.AdminMacPath,
2✔
532
                                d.cfg.ReadMacPath, d.cfg.InvoiceMacPath,
2✔
533
                        )
2✔
534
                        if err != nil {
2✔
535
                                err := fmt.Errorf("unable to create macaroons "+
×
536
                                        "%v", err)
×
537
                                d.logger.Error(err)
×
538
                                return nil, nil, nil, err
×
539
                        }
×
540
                }
541

542
                // As a security service to the user, if they requested
543
                // stateless initialization and there are macaroon files on disk
544
                // we log a warning.
545
                if walletInitParams.StatelessInit {
4✔
546
                        msg := "Found %s macaroon on disk (%s) even though " +
2✔
547
                                "--stateless_init was requested. Unencrypted " +
2✔
548
                                "state is accessible by the host system. You " +
2✔
549
                                "should change the password and use " +
2✔
550
                                "--new_mac_root_key with --stateless_init to " +
2✔
551
                                "clean up and invalidate old macaroons."
2✔
552

2✔
553
                        if lnrpc.FileExists(d.cfg.AdminMacPath) {
2✔
554
                                d.logger.Warnf(msg, "admin", d.cfg.AdminMacPath)
×
555
                        }
×
556
                        if lnrpc.FileExists(d.cfg.ReadMacPath) {
2✔
557
                                d.logger.Warnf(msg, "readonly", d.cfg.ReadMacPath)
×
558
                        }
×
559
                        if lnrpc.FileExists(d.cfg.InvoiceMacPath) {
2✔
560
                                d.logger.Warnf(msg, "invoice", d.cfg.InvoiceMacPath)
×
561
                        }
×
562
                }
563

564
                // We add the macaroon service to our RPC interceptor. This
565
                // will start checking macaroons against permissions on every
566
                // RPC invocation.
567
                interceptorChain.AddMacaroonService(macaroonService)
2✔
568
        }
569

570
        // Now that the wallet password has been provided, transition the RPC
571
        // state into Unlocked.
572
        interceptorChain.SetWalletUnlocked()
2✔
573

2✔
574
        // Since calls to the WalletUnlocker service wait for a response on the
2✔
575
        // macaroon channel, we close it here to make sure they return in case
2✔
576
        // we did not return the admin macaroon above. This will be the case if
2✔
577
        // --no-macaroons is used.
2✔
578
        close(walletInitParams.MacResponseChan)
2✔
579

2✔
580
        // We'll also close all the macaroon channels since lnd is done sending
2✔
581
        // macaroon data over it.
2✔
582
        for _, lis := range grpcListeners {
4✔
583
                if lis.MacChan != nil {
2✔
584
                        close(lis.MacChan)
×
585
                }
×
586
        }
587

588
        // With the information parsed from the configuration, create valid
589
        // instances of the pertinent interfaces required to operate the
590
        // Lightning Network Daemon.
591
        //
592
        // When we create the chain control, we need storage for the height
593
        // hints and also the wallet itself, for these two we want them to be
594
        // replicated, so we'll pass in the remote channel DB instance.
595
        chainControlCfg := &chainreg.Config{
2✔
596
                Bitcoin:                     d.cfg.Bitcoin,
2✔
597
                HeightHintCacheQueryDisable: d.cfg.HeightHintCacheQueryDisable,
2✔
598
                NeutrinoMode:                d.cfg.NeutrinoMode,
2✔
599
                BitcoindMode:                d.cfg.BitcoindMode,
2✔
600
                BtcdMode:                    d.cfg.BtcdMode,
2✔
601
                HeightHintDB:                dbs.HeightHintDB,
2✔
602
                ChanStateDB:                 dbs.ChanStateDB.ChannelStateDB(),
2✔
603
                NeutrinoCS:                  neutrinoCS,
2✔
604
                AuxLeafStore:                aux.AuxLeafStore,
2✔
605
                AuxSigner:                   aux.AuxSigner,
2✔
606
                ActiveNetParams:             d.cfg.ActiveNetParams,
2✔
607
                FeeURL:                      d.cfg.FeeURL,
2✔
608
                Fee: &lncfg.Fee{
2✔
609
                        URL:              d.cfg.Fee.URL,
2✔
610
                        MinUpdateTimeout: d.cfg.Fee.MinUpdateTimeout,
2✔
611
                        MaxUpdateTimeout: d.cfg.Fee.MaxUpdateTimeout,
2✔
612
                },
2✔
613
                Dialer: func(addr string) (net.Conn, error) {
2✔
614
                        return d.cfg.net.Dial(
×
615
                                "tcp", addr, d.cfg.ConnectionTimeout,
×
616
                        )
×
617
                },
×
618
                BlockCache:         blockCache,
619
                WalletUnlockParams: &walletInitParams,
620
        }
621

622
        // Let's go ahead and create the partial chain control now that is only
623
        // dependent on our configuration and doesn't require any wallet
624
        // specific information.
625
        partialChainControl, pccCleanup, err := chainreg.NewPartialChainControl(
2✔
626
                chainControlCfg,
2✔
627
        )
2✔
628
        cleanUpTasks = append(cleanUpTasks, pccCleanup)
2✔
629
        if err != nil {
2✔
630
                err := fmt.Errorf("unable to create partial chain control: %w",
×
631
                        err)
×
632
                d.logger.Error(err)
×
633
                return nil, nil, nil, err
×
634
        }
×
635

636
        walletConfig := &btcwallet.Config{
2✔
637
                PrivatePass:      privateWalletPw,
2✔
638
                PublicPass:       publicWalletPw,
2✔
639
                Birthday:         walletInitParams.Birthday,
2✔
640
                RecoveryWindow:   walletInitParams.RecoveryWindow,
2✔
641
                NetParams:        d.cfg.ActiveNetParams.Params,
2✔
642
                CoinType:         d.cfg.ActiveNetParams.CoinType,
2✔
643
                Wallet:           walletInitParams.Wallet,
2✔
644
                LoaderOptions:    []btcwallet.LoaderOption{dbs.WalletDB},
2✔
645
                ChainSource:      partialChainControl.ChainSource,
2✔
646
                WatchOnly:        d.watchOnly,
2✔
647
                MigrateWatchOnly: d.migrateWatchOnly,
2✔
648
        }
2✔
649

2✔
650
        // Parse coin selection strategy.
2✔
651
        switch d.cfg.CoinSelectionStrategy {
2✔
652
        case "largest":
2✔
653
                walletConfig.CoinSelectionStrategy = wallet.CoinSelectionLargest
2✔
654

655
        case "random":
×
656
                walletConfig.CoinSelectionStrategy = wallet.CoinSelectionRandom
×
657

658
        default:
×
659
                return nil, nil, nil, fmt.Errorf("unknown coin selection "+
×
660
                        "strategy %v", d.cfg.CoinSelectionStrategy)
×
661
        }
662

663
        earlyExit = false
2✔
664
        return partialChainControl, walletConfig, cleanUp, nil
2✔
665
}
666

667
// proxyBlockEpoch proxies a block epoch subsections to the underlying neutrino
668
// rebroadcaster client.
669
func proxyBlockEpoch(
670
        notifier chainntnfs.ChainNotifier) func() (*blockntfns.Subscription,
671
        error) {
2✔
672

2✔
673
        return func() (*blockntfns.Subscription, error) {
4✔
674
                blockEpoch, err := notifier.RegisterBlockEpochNtfn(
2✔
675
                        nil,
2✔
676
                )
2✔
677
                if err != nil {
2✔
678
                        return nil, err
×
679
                }
×
680

681
                sub := blockntfns.Subscription{
2✔
682
                        Notifications: make(chan blockntfns.BlockNtfn, 6),
2✔
683
                        Cancel:        blockEpoch.Cancel,
2✔
684
                }
2✔
685
                go func() {
4✔
686
                        for blk := range blockEpoch.Epochs {
4✔
687
                                ntfn := blockntfns.NewBlockConnected(
2✔
688
                                        *blk.BlockHeader,
2✔
689
                                        uint32(blk.Height),
2✔
690
                                )
2✔
691

2✔
692
                                sub.Notifications <- ntfn
2✔
693
                        }
2✔
694
                }()
695

696
                return &sub, nil
2✔
697
        }
698
}
699

700
// walletReBroadcaster is a simple wrapper around the pushtx.Broadcaster
701
// interface to adhere to the expanded lnwallet.Rebroadcaster interface.
702
type walletReBroadcaster struct {
703
        started atomic.Bool
704

705
        *pushtx.Broadcaster
706
}
707

708
// newWalletReBroadcaster creates a new instance of the walletReBroadcaster.
709
func newWalletReBroadcaster(
710
        broadcaster *pushtx.Broadcaster) *walletReBroadcaster {
2✔
711

2✔
712
        return &walletReBroadcaster{
2✔
713
                Broadcaster: broadcaster,
2✔
714
        }
2✔
715
}
2✔
716

717
// Start launches all goroutines the rebroadcaster needs to operate.
718
func (w *walletReBroadcaster) Start() error {
2✔
719
        defer w.started.Store(true)
2✔
720

2✔
721
        return w.Broadcaster.Start()
2✔
722
}
2✔
723

724
// Started returns true if the broadcaster is already active.
725
func (w *walletReBroadcaster) Started() bool {
2✔
726
        return w.started.Load()
2✔
727
}
2✔
728

729
// BuildChainControl is responsible for creating a fully populated chain
730
// control instance from a wallet.
731
//
732
// NOTE: This is part of the ChainControlBuilder interface.
733
func (d *DefaultWalletImpl) BuildChainControl(
734
        partialChainControl *chainreg.PartialChainControl,
735
        walletConfig *btcwallet.Config) (*chainreg.ChainControl, func(), error) {
2✔
736

2✔
737
        walletController, err := btcwallet.New(
2✔
738
                *walletConfig, partialChainControl.Cfg.BlockCache,
2✔
739
        )
2✔
740
        if err != nil {
2✔
741
                err := fmt.Errorf("unable to create wallet controller: %w", err)
×
742
                d.logger.Error(err)
×
743
                return nil, nil, err
×
744
        }
×
745

746
        keyRing := keychain.NewBtcWalletKeyRing(
2✔
747
                walletController.InternalWallet(), walletConfig.CoinType,
2✔
748
        )
2✔
749

2✔
750
        // Create, and start the lnwallet, which handles the core payment
2✔
751
        // channel logic, and exposes control via proxy state machines.
2✔
752
        lnWalletConfig := lnwallet.Config{
2✔
753
                Database:              partialChainControl.Cfg.ChanStateDB,
2✔
754
                Notifier:              partialChainControl.ChainNotifier,
2✔
755
                WalletController:      walletController,
2✔
756
                Signer:                walletController,
2✔
757
                FeeEstimator:          partialChainControl.FeeEstimator,
2✔
758
                SecretKeyRing:         keyRing,
2✔
759
                ChainIO:               walletController,
2✔
760
                NetParams:             *walletConfig.NetParams,
2✔
761
                CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
2✔
762
                AuxLeafStore:          partialChainControl.Cfg.AuxLeafStore,
2✔
763
                AuxSigner:             partialChainControl.Cfg.AuxSigner,
2✔
764
        }
2✔
765

2✔
766
        // The broadcast is already always active for neutrino nodes, so we
2✔
767
        // don't want to create a rebroadcast loop.
2✔
768
        if partialChainControl.Cfg.NeutrinoCS == nil {
4✔
769
                cs := partialChainControl.ChainSource
2✔
770
                broadcastCfg := pushtx.Config{
2✔
771
                        Broadcast: func(tx *wire.MsgTx) error {
4✔
772
                                _, err := cs.SendRawTransaction(
2✔
773
                                        tx, true,
2✔
774
                                )
2✔
775

2✔
776
                                return err
2✔
777
                        },
2✔
778
                        SubscribeBlocks: proxyBlockEpoch(
779
                                partialChainControl.ChainNotifier,
780
                        ),
781
                        RebroadcastInterval: pushtx.DefaultRebroadcastInterval,
782
                        // In case the backend is different from neutrino we
783
                        // make sure that broadcast backend errors are mapped
784
                        // to the neutrino broadcastErr.
785
                        MapCustomBroadcastError: func(err error) error {
2✔
786
                                rpcErr := cs.MapRPCErr(err)
2✔
787
                                return broadcastErrorMapper(rpcErr)
2✔
788
                        },
2✔
789
                }
790

791
                lnWalletConfig.Rebroadcaster = newWalletReBroadcaster(
2✔
792
                        pushtx.NewBroadcaster(&broadcastCfg),
2✔
793
                )
2✔
794
        }
795

796
        // We've created the wallet configuration now, so we can finish
797
        // initializing the main chain control.
798
        activeChainControl, cleanUp, err := chainreg.NewChainControl(
2✔
799
                lnWalletConfig, walletController, partialChainControl,
2✔
800
        )
2✔
801
        if err != nil {
2✔
802
                err := fmt.Errorf("unable to create chain control: %w", err)
×
803
                d.logger.Error(err)
×
804
                return nil, nil, err
×
805
        }
×
806

807
        return activeChainControl, cleanUp, nil
2✔
808
}
809

810
// RPCSignerWalletImpl is a wallet implementation that uses a remote signer over
811
// an RPC interface.
812
type RPCSignerWalletImpl struct {
813
        // DefaultWalletImpl is the embedded instance of the default
814
        // implementation that the remote signer uses as its watch-only wallet
815
        // for keeping track of addresses and UTXOs.
816
        *DefaultWalletImpl
817
}
818

819
// NewRPCSignerWalletImpl creates a new instance of the remote signing wallet
820
// implementation.
821
func NewRPCSignerWalletImpl(cfg *Config, logger btclog.Logger,
822
        interceptor signal.Interceptor,
823
        migrateWatchOnly bool) *RPCSignerWalletImpl {
2✔
824

2✔
825
        return &RPCSignerWalletImpl{
2✔
826
                DefaultWalletImpl: &DefaultWalletImpl{
2✔
827
                        cfg:              cfg,
2✔
828
                        logger:           logger,
2✔
829
                        interceptor:      interceptor,
2✔
830
                        watchOnly:        true,
2✔
831
                        migrateWatchOnly: migrateWatchOnly,
2✔
832
                        pwService:        createWalletUnlockerService(cfg),
2✔
833
                },
2✔
834
        }
2✔
835
}
2✔
836

837
// BuildChainControl is responsible for creating or unlocking and then fully
838
// initializing a wallet and returning it as part of a fully populated chain
839
// control instance.
840
//
841
// NOTE: This is part of the ChainControlBuilder interface.
842
func (d *RPCSignerWalletImpl) BuildChainControl(
843
        partialChainControl *chainreg.PartialChainControl,
844
        walletConfig *btcwallet.Config) (*chainreg.ChainControl, func(), error) {
2✔
845

2✔
846
        walletController, err := btcwallet.New(
2✔
847
                *walletConfig, partialChainControl.Cfg.BlockCache,
2✔
848
        )
2✔
849
        if err != nil {
2✔
850
                err := fmt.Errorf("unable to create wallet controller: %w", err)
×
851
                d.logger.Error(err)
×
852
                return nil, nil, err
×
853
        }
×
854

855
        baseKeyRing := keychain.NewBtcWalletKeyRing(
2✔
856
                walletController.InternalWallet(), walletConfig.CoinType,
2✔
857
        )
2✔
858

2✔
859
        rpcKeyRing, err := rpcwallet.NewRPCKeyRing(
2✔
860
                baseKeyRing, walletController,
2✔
861
                d.DefaultWalletImpl.cfg.RemoteSigner, walletConfig.NetParams,
2✔
862
        )
2✔
863
        if err != nil {
2✔
864
                err := fmt.Errorf("unable to create RPC remote signing wallet "+
×
865
                        "%v", err)
×
866
                d.logger.Error(err)
×
867
                return nil, nil, err
×
868
        }
×
869

870
        // Create, and start the lnwallet, which handles the core payment
871
        // channel logic, and exposes control via proxy state machines.
872
        lnWalletConfig := lnwallet.Config{
2✔
873
                Database:              partialChainControl.Cfg.ChanStateDB,
2✔
874
                Notifier:              partialChainControl.ChainNotifier,
2✔
875
                WalletController:      rpcKeyRing,
2✔
876
                Signer:                rpcKeyRing,
2✔
877
                FeeEstimator:          partialChainControl.FeeEstimator,
2✔
878
                SecretKeyRing:         rpcKeyRing,
2✔
879
                ChainIO:               walletController,
2✔
880
                NetParams:             *walletConfig.NetParams,
2✔
881
                CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
2✔
882
        }
2✔
883

2✔
884
        // We've created the wallet configuration now, so we can finish
2✔
885
        // initializing the main chain control.
2✔
886
        activeChainControl, cleanUp, err := chainreg.NewChainControl(
2✔
887
                lnWalletConfig, rpcKeyRing, partialChainControl,
2✔
888
        )
2✔
889
        if err != nil {
2✔
890
                err := fmt.Errorf("unable to create chain control: %w", err)
×
891
                d.logger.Error(err)
×
892
                return nil, nil, err
×
893
        }
×
894

895
        return activeChainControl, cleanUp, nil
2✔
896
}
897

898
// DatabaseInstances is a struct that holds all instances to the actual
899
// databases that are used in lnd.
900
type DatabaseInstances struct {
901
        // GraphDB is the database that stores the channel graph used for path
902
        // finding.
903
        //
904
        // NOTE/TODO: This currently _needs_ to be the same instance as the
905
        // ChanStateDB below until the separation of the two databases is fully
906
        // complete!
907
        GraphDB *channeldb.DB
908

909
        // ChanStateDB is the database that stores all of our node's channel
910
        // state.
911
        //
912
        // NOTE/TODO: This currently _needs_ to be the same instance as the
913
        // GraphDB above until the separation of the two databases is fully
914
        // complete!
915
        ChanStateDB *channeldb.DB
916

917
        // HeightHintDB is the database that stores height hints for spends.
918
        HeightHintDB kvdb.Backend
919

920
        // InvoiceDB is the database that stores information about invoices.
921
        InvoiceDB invoices.InvoiceDB
922

923
        // MacaroonDB is the database that stores macaroon root keys.
924
        MacaroonDB kvdb.Backend
925

926
        // DecayedLogDB is the database that stores p2p related encryption
927
        // information.
928
        DecayedLogDB kvdb.Backend
929

930
        // TowerClientDB is the database that stores the watchtower client's
931
        // configuration.
932
        TowerClientDB wtclient.DB
933

934
        // TowerServerDB is the database that stores the watchtower server's
935
        // configuration.
936
        TowerServerDB watchtower.DB
937

938
        // WalletDB is the configuration for loading the wallet database using
939
        // the btcwallet's loader.
940
        WalletDB btcwallet.LoaderOption
941

942
        // NativeSQLStore is a pointer to a native SQL store that can be used
943
        // for native SQL queries for tables that already support it. This may
944
        // be nil if the use-native-sql flag was not set.
945
        NativeSQLStore *sqldb.BaseDB
946
}
947

948
// DefaultDatabaseBuilder is a type that builds the default database backends
949
// for lnd, using the given configuration to decide what actual implementation
950
// to use.
951
type DefaultDatabaseBuilder struct {
952
        cfg    *Config
953
        logger btclog.Logger
954
}
955

956
// NewDefaultDatabaseBuilder returns a new instance of the default database
957
// builder.
958
func NewDefaultDatabaseBuilder(cfg *Config,
959
        logger btclog.Logger) *DefaultDatabaseBuilder {
2✔
960

2✔
961
        return &DefaultDatabaseBuilder{
2✔
962
                cfg:    cfg,
2✔
963
                logger: logger,
2✔
964
        }
2✔
965
}
2✔
966

967
// BuildDatabase extracts the current databases that we'll use for normal
968
// operation in the daemon. A function closure that closes all opened databases
969
// is also returned.
970
func (d *DefaultDatabaseBuilder) BuildDatabase(
971
        ctx context.Context) (*DatabaseInstances, func(), error) {
2✔
972

2✔
973
        d.logger.Infof("Opening the main database, this might take a few " +
2✔
974
                "minutes...")
2✔
975

2✔
976
        cfg := d.cfg
2✔
977
        if cfg.DB.Backend == lncfg.BoltBackend {
4✔
978
                d.logger.Infof("Opening bbolt database, sync_freelist=%v, "+
2✔
979
                        "auto_compact=%v", !cfg.DB.Bolt.NoFreelistSync,
2✔
980
                        cfg.DB.Bolt.AutoCompact)
2✔
981
        }
2✔
982

983
        startOpenTime := time.Now()
2✔
984

2✔
985
        databaseBackends, err := cfg.DB.GetBackends(
2✔
986
                ctx, cfg.graphDatabaseDir(), cfg.networkDir, filepath.Join(
2✔
987
                        cfg.Watchtower.TowerDir, BitcoinChainName,
2✔
988
                        lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
2✔
989
                ), cfg.WtClient.Active, cfg.Watchtower.Active, d.logger,
2✔
990
        )
2✔
991
        if err != nil {
2✔
992
                return nil, nil, fmt.Errorf("unable to obtain database "+
×
993
                        "backends: %v", err)
×
994
        }
×
995

996
        // With the full remote mode we made sure both the graph and channel
997
        // state DB point to the same local or remote DB and the same namespace
998
        // within that DB.
999
        dbs := &DatabaseInstances{
2✔
1000
                HeightHintDB:   databaseBackends.HeightHintDB,
2✔
1001
                MacaroonDB:     databaseBackends.MacaroonDB,
2✔
1002
                DecayedLogDB:   databaseBackends.DecayedLogDB,
2✔
1003
                WalletDB:       databaseBackends.WalletDB,
2✔
1004
                NativeSQLStore: databaseBackends.NativeSQLStore,
2✔
1005
        }
2✔
1006
        cleanUp := func() {
4✔
1007
                // We can just close the returned close functions directly. Even
2✔
1008
                // if we decorate the channel DB with an additional struct, its
2✔
1009
                // close function still just points to the kvdb backend.
2✔
1010
                for name, closeFunc := range databaseBackends.CloseFuncs {
4✔
1011
                        if err := closeFunc(); err != nil {
2✔
1012
                                d.logger.Errorf("Error closing %s "+
×
1013
                                        "database: %v", name, err)
×
1014
                        }
×
1015
                }
1016
        }
1017
        if databaseBackends.Remote {
2✔
1018
                d.logger.Infof("Using remote %v database! Creating "+
×
1019
                        "graph and channel state DB instances", cfg.DB.Backend)
×
1020
        } else {
2✔
1021
                d.logger.Infof("Creating local graph and channel state DB " +
2✔
1022
                        "instances")
2✔
1023
        }
2✔
1024

1025
        dbOptions := []channeldb.OptionModifier{
2✔
1026
                channeldb.OptionSetRejectCacheSize(cfg.Caches.RejectCacheSize),
2✔
1027
                channeldb.OptionSetChannelCacheSize(
2✔
1028
                        cfg.Caches.ChannelCacheSize,
2✔
1029
                ),
2✔
1030
                channeldb.OptionSetBatchCommitInterval(
2✔
1031
                        cfg.DB.BatchCommitInterval,
2✔
1032
                ),
2✔
1033
                channeldb.OptionDryRunMigration(cfg.DryRunMigration),
2✔
1034
                channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
2✔
1035
                channeldb.OptionKeepFailedPaymentAttempts(
2✔
1036
                        cfg.KeepFailedPaymentAttempts,
2✔
1037
                ),
2✔
1038
                channeldb.OptionStoreFinalHtlcResolutions(
2✔
1039
                        cfg.StoreFinalHtlcResolutions,
2✔
1040
                ),
2✔
1041
                channeldb.OptionPruneRevocationLog(cfg.DB.PruneRevocation),
2✔
1042
                channeldb.OptionNoRevLogAmtData(cfg.DB.NoRevLogAmtData),
2✔
1043
        }
2✔
1044

2✔
1045
        // We want to pre-allocate the channel graph cache according to what we
2✔
1046
        // expect for mainnet to speed up memory allocation.
2✔
1047
        if cfg.ActiveNetParams.Name == chaincfg.MainNetParams.Name {
2✔
1048
                dbOptions = append(
×
1049
                        dbOptions, channeldb.OptionSetPreAllocCacheNumNodes(
×
1050
                                channeldb.DefaultPreAllocCacheNumNodes,
×
1051
                        ),
×
1052
                )
×
1053
        }
×
1054

1055
        // Otherwise, we'll open two instances, one for the state we only need
1056
        // locally, and the other for things we want to ensure are replicated.
1057
        dbs.GraphDB, err = channeldb.CreateWithBackend(
2✔
1058
                databaseBackends.GraphDB, dbOptions...,
2✔
1059
        )
2✔
1060
        switch {
2✔
1061
        // Give the DB a chance to dry run the migration. Since we know that
1062
        // both the channel state and graph DBs are still always behind the same
1063
        // backend, we know this would be applied to both of those DBs.
1064
        case err == channeldb.ErrDryRunMigrationOK:
×
1065
                d.logger.Infof("Graph DB dry run migration successful")
×
1066
                return nil, nil, err
×
1067

1068
        case err != nil:
×
1069
                cleanUp()
×
1070

×
1071
                err := fmt.Errorf("unable to open graph DB: %w", err)
×
1072
                d.logger.Error(err)
×
1073
                return nil, nil, err
×
1074
        }
1075

1076
        // For now, we don't _actually_ split the graph and channel state DBs on
1077
        // the code level. Since they both are based upon the *channeldb.DB
1078
        // struct it will require more refactoring to fully separate them. With
1079
        // the full remote mode we at least know for now that they both point to
1080
        // the same DB backend (and also namespace within that) so we only need
1081
        // to apply any migration once.
1082
        //
1083
        // TODO(guggero): Once the full separation of anything graph related
1084
        // from the channeldb.DB is complete, the decorated instance of the
1085
        // channel state DB should be created here individually instead of just
1086
        // using the same struct (and DB backend) instance.
1087
        dbs.ChanStateDB = dbs.GraphDB
2✔
1088

2✔
1089
        // Instantiate a native SQL invoice store if the flag is set.
2✔
1090
        if d.cfg.DB.UseNativeSQL {
2✔
1091
                // KV invoice db resides in the same database as the graph and
×
1092
                // channel state DB. Let's query the database to see if we have
×
1093
                // any invoices there. If we do, we won't allow the user to
×
1094
                // start lnd with native SQL enabled, as we don't currently
×
1095
                // migrate the invoices to the new database schema.
×
1096
                invoiceSlice, err := dbs.GraphDB.QueryInvoices(
×
1097
                        ctx, invoices.InvoiceQuery{
×
1098
                                NumMaxInvoices: 1,
×
1099
                        },
×
1100
                )
×
1101
                if err != nil {
×
1102
                        cleanUp()
×
1103
                        d.logger.Errorf("Unable to query KV invoice DB: %v",
×
1104
                                err)
×
1105

×
1106
                        return nil, nil, err
×
1107
                }
×
1108

1109
                if len(invoiceSlice.Invoices) > 0 {
×
1110
                        cleanUp()
×
1111
                        err := fmt.Errorf("found invoices in the KV invoice " +
×
1112
                                "DB, migration to native SQL is not yet " +
×
1113
                                "supported")
×
1114
                        d.logger.Error(err)
×
1115

×
1116
                        return nil, nil, err
×
1117
                }
×
1118

1119
                executor := sqldb.NewTransactionExecutor(
×
1120
                        dbs.NativeSQLStore,
×
1121
                        func(tx *sql.Tx) invoices.SQLInvoiceQueries {
×
1122
                                return dbs.NativeSQLStore.WithTx(tx)
×
1123
                        },
×
1124
                )
1125

1126
                dbs.InvoiceDB = invoices.NewSQLStore(
×
1127
                        executor, clock.NewDefaultClock(),
×
1128
                )
×
1129
        } else {
2✔
1130
                dbs.InvoiceDB = dbs.GraphDB
2✔
1131
        }
2✔
1132

1133
        // Wrap the watchtower client DB and make sure we clean up.
1134
        if cfg.WtClient.Active {
4✔
1135
                dbs.TowerClientDB, err = wtdb.OpenClientDB(
2✔
1136
                        databaseBackends.TowerClientDB,
2✔
1137
                )
2✔
1138
                if err != nil {
2✔
1139
                        cleanUp()
×
1140

×
1141
                        err := fmt.Errorf("unable to open %s database: %w",
×
1142
                                lncfg.NSTowerClientDB, err)
×
1143
                        d.logger.Error(err)
×
1144
                        return nil, nil, err
×
1145
                }
×
1146
        }
1147

1148
        // Wrap the watchtower server DB and make sure we clean up.
1149
        if cfg.Watchtower.Active {
4✔
1150
                dbs.TowerServerDB, err = wtdb.OpenTowerDB(
2✔
1151
                        databaseBackends.TowerServerDB,
2✔
1152
                )
2✔
1153
                if err != nil {
2✔
1154
                        cleanUp()
×
1155

×
1156
                        err := fmt.Errorf("unable to open %s database: %w",
×
1157
                                lncfg.NSTowerServerDB, err)
×
1158
                        d.logger.Error(err)
×
1159
                        return nil, nil, err
×
1160
                }
×
1161
        }
1162

1163
        openTime := time.Since(startOpenTime)
2✔
1164
        d.logger.Infof("Database(s) now open (time_to_open=%v)!", openTime)
2✔
1165

2✔
1166
        return dbs, cleanUp, nil
2✔
1167
}
1168

1169
// waitForWalletPassword blocks until a password is provided by the user to
1170
// this RPC server.
1171
func waitForWalletPassword(cfg *Config,
1172
        pwService *walletunlocker.UnlockerService,
1173
        loaderOpts []btcwallet.LoaderOption, shutdownChan <-chan struct{}) (
1174
        *walletunlocker.WalletUnlockParams, error) {
2✔
1175

2✔
1176
        // Wait for user to provide the password.
2✔
1177
        ltndLog.Infof("Waiting for wallet encryption password. Use `lncli " +
2✔
1178
                "create` to create a wallet, `lncli unlock` to unlock an " +
2✔
1179
                "existing wallet, or `lncli changepassword` to change the " +
2✔
1180
                "password of an existing wallet and unlock it.")
2✔
1181

2✔
1182
        // We currently don't distinguish between getting a password to be used
2✔
1183
        // for creation or unlocking, as a new wallet db will be created if
2✔
1184
        // none exists when creating the chain control.
2✔
1185
        select {
2✔
1186
        // The wallet is being created for the first time, we'll check to see
1187
        // if the user provided any entropy for seed creation. If so, then
1188
        // we'll create the wallet early to load the seed.
1189
        case initMsg := <-pwService.InitMsgs:
2✔
1190
                password := initMsg.Passphrase
2✔
1191
                cipherSeed := initMsg.WalletSeed
2✔
1192
                extendedKey := initMsg.WalletExtendedKey
2✔
1193
                watchOnlyAccounts := initMsg.WatchOnlyAccounts
2✔
1194
                recoveryWindow := initMsg.RecoveryWindow
2✔
1195

2✔
1196
                // Before we proceed, we'll check the internal version of the
2✔
1197
                // seed. If it's greater than the current key derivation
2✔
1198
                // version, then we'll return an error as we don't understand
2✔
1199
                // this.
2✔
1200
                if cipherSeed != nil &&
2✔
1201
                        !keychain.IsKnownVersion(cipherSeed.InternalVersion) {
2✔
1202

×
1203
                        return nil, fmt.Errorf("invalid internal "+
×
1204
                                "seed version %v, current max version is %v",
×
1205
                                cipherSeed.InternalVersion,
×
1206
                                keychain.CurrentKeyDerivationVersion)
×
1207
                }
×
1208

1209
                loader, err := btcwallet.NewWalletLoader(
2✔
1210
                        cfg.ActiveNetParams.Params, recoveryWindow,
2✔
1211
                        loaderOpts...,
2✔
1212
                )
2✔
1213
                if err != nil {
2✔
1214
                        return nil, err
×
1215
                }
×
1216

1217
                // With the seed, we can now use the wallet loader to create
1218
                // the wallet, then pass it back to avoid unlocking it again.
1219
                var (
2✔
1220
                        birthday  time.Time
2✔
1221
                        newWallet *wallet.Wallet
2✔
1222
                )
2✔
1223
                switch {
2✔
1224
                // A normal cipher seed was given, use the birthday encoded in
1225
                // it and create the wallet from that.
1226
                case cipherSeed != nil:
2✔
1227
                        birthday = cipherSeed.BirthdayTime()
2✔
1228
                        newWallet, err = loader.CreateNewWallet(
2✔
1229
                                password, password, cipherSeed.Entropy[:],
2✔
1230
                                birthday,
2✔
1231
                        )
2✔
1232

1233
                // No seed was given, we're importing a wallet from its extended
1234
                // private key.
1235
                case extendedKey != nil:
2✔
1236
                        birthday = initMsg.ExtendedKeyBirthday
2✔
1237
                        newWallet, err = loader.CreateNewWalletExtendedKey(
2✔
1238
                                password, password, extendedKey, birthday,
2✔
1239
                        )
2✔
1240

1241
                // Neither seed nor extended private key was given, so maybe the
1242
                // third option was chosen, the watch-only initialization. In
1243
                // this case we need to import each of the xpubs individually.
1244
                case watchOnlyAccounts != nil:
2✔
1245
                        if !cfg.RemoteSigner.Enable {
2✔
1246
                                return nil, fmt.Errorf("cannot initialize " +
×
1247
                                        "watch only wallet with remote " +
×
1248
                                        "signer config disabled")
×
1249
                        }
×
1250

1251
                        birthday = initMsg.WatchOnlyBirthday
2✔
1252
                        newWallet, err = loader.CreateNewWatchingOnlyWallet(
2✔
1253
                                password, birthday,
2✔
1254
                        )
2✔
1255
                        if err != nil {
2✔
1256
                                break
×
1257
                        }
1258

1259
                        err = importWatchOnlyAccounts(newWallet, initMsg)
2✔
1260

1261
                default:
×
1262
                        // The unlocker service made sure either the cipher seed
×
1263
                        // or the extended key is set so, we shouldn't get here.
×
1264
                        // The default case is just here for readability and
×
1265
                        // completeness.
×
1266
                        err = fmt.Errorf("cannot create wallet, neither seed " +
×
1267
                                "nor extended key was given")
×
1268
                }
1269
                if err != nil {
2✔
1270
                        // Don't leave the file open in case the new wallet
×
1271
                        // could not be created for whatever reason.
×
1272
                        if err := loader.UnloadWallet(); err != nil {
×
1273
                                ltndLog.Errorf("Could not unload new "+
×
1274
                                        "wallet: %v", err)
×
1275
                        }
×
1276
                        return nil, err
×
1277
                }
1278

1279
                // For new wallets, the ResetWalletTransactions flag is a no-op.
1280
                if cfg.ResetWalletTransactions {
4✔
1281
                        ltndLog.Warnf("Ignoring reset-wallet-transactions " +
2✔
1282
                                "flag for new wallet as it has no effect")
2✔
1283
                }
2✔
1284

1285
                return &walletunlocker.WalletUnlockParams{
2✔
1286
                        Password:        password,
2✔
1287
                        Birthday:        birthday,
2✔
1288
                        RecoveryWindow:  recoveryWindow,
2✔
1289
                        Wallet:          newWallet,
2✔
1290
                        ChansToRestore:  initMsg.ChanBackups,
2✔
1291
                        UnloadWallet:    loader.UnloadWallet,
2✔
1292
                        StatelessInit:   initMsg.StatelessInit,
2✔
1293
                        MacResponseChan: pwService.MacResponseChan,
2✔
1294
                        MacRootKey:      initMsg.MacRootKey,
2✔
1295
                }, nil
2✔
1296

1297
        // The wallet has already been created in the past, and is simply being
1298
        // unlocked. So we'll just return these passphrases.
1299
        case unlockMsg := <-pwService.UnlockMsgs:
2✔
1300
                // Resetting the transactions is something the user likely only
2✔
1301
                // wants to do once so we add a prominent warning to the log to
2✔
1302
                // remind the user to turn off the setting again after
2✔
1303
                // successful completion.
2✔
1304
                if cfg.ResetWalletTransactions {
4✔
1305
                        ltndLog.Warnf("Dropped all transaction history from " +
2✔
1306
                                "on-chain wallet. Remember to disable " +
2✔
1307
                                "reset-wallet-transactions flag for next " +
2✔
1308
                                "start of lnd")
2✔
1309
                }
2✔
1310

1311
                return &walletunlocker.WalletUnlockParams{
2✔
1312
                        Password:        unlockMsg.Passphrase,
2✔
1313
                        RecoveryWindow:  unlockMsg.RecoveryWindow,
2✔
1314
                        Wallet:          unlockMsg.Wallet,
2✔
1315
                        ChansToRestore:  unlockMsg.ChanBackups,
2✔
1316
                        UnloadWallet:    unlockMsg.UnloadWallet,
2✔
1317
                        StatelessInit:   unlockMsg.StatelessInit,
2✔
1318
                        MacResponseChan: pwService.MacResponseChan,
2✔
1319
                }, nil
2✔
1320

1321
        // If we got a shutdown signal we just return with an error immediately
1322
        case <-shutdownChan:
×
1323
                return nil, fmt.Errorf("shutting down")
×
1324
        }
1325
}
1326

1327
// importWatchOnlyAccounts imports all individual account xpubs into our wallet
1328
// which we created as watch-only.
1329
func importWatchOnlyAccounts(wallet *wallet.Wallet,
1330
        initMsg *walletunlocker.WalletInitMsg) error {
2✔
1331

2✔
1332
        scopes := make([]waddrmgr.ScopedIndex, 0, len(initMsg.WatchOnlyAccounts))
2✔
1333
        for scope := range initMsg.WatchOnlyAccounts {
4✔
1334
                scopes = append(scopes, scope)
2✔
1335
        }
2✔
1336

1337
        // We need to import the accounts in the correct order, otherwise the
1338
        // indices will be incorrect.
1339
        sort.Slice(scopes, func(i, j int) bool {
4✔
1340
                return scopes[i].Scope.Purpose < scopes[j].Scope.Purpose ||
2✔
1341
                        scopes[i].Index < scopes[j].Index
2✔
1342
        })
2✔
1343

1344
        for _, scope := range scopes {
4✔
1345
                addrSchema := waddrmgr.ScopeAddrMap[waddrmgr.KeyScopeBIP0084]
2✔
1346

2✔
1347
                // We want witness pubkey hash by default, except for BIP49
2✔
1348
                // where we want mixed and BIP86 where we want taproot address
2✔
1349
                // formats.
2✔
1350
                switch scope.Scope.Purpose {
2✔
1351
                case waddrmgr.KeyScopeBIP0049Plus.Purpose,
1352
                        waddrmgr.KeyScopeBIP0086.Purpose:
2✔
1353

2✔
1354
                        addrSchema = waddrmgr.ScopeAddrMap[scope.Scope]
2✔
1355
                }
1356

1357
                // We want a human-readable account name. But for the default
1358
                // on-chain wallet we actually need to call it "default" to make
1359
                // sure everything works correctly.
1360
                name := fmt.Sprintf("%s/%d'", scope.Scope.String(), scope.Index)
2✔
1361
                if scope.Index == 0 {
4✔
1362
                        name = "default"
2✔
1363
                }
2✔
1364

1365
                _, err := wallet.ImportAccountWithScope(
2✔
1366
                        name, initMsg.WatchOnlyAccounts[scope],
2✔
1367
                        initMsg.WatchOnlyMasterFingerprint, scope.Scope,
2✔
1368
                        addrSchema,
2✔
1369
                )
2✔
1370
                if err != nil {
2✔
1371
                        return fmt.Errorf("could not import account %v: %w",
×
1372
                                name, err)
×
1373
                }
×
1374
        }
1375

1376
        return nil
2✔
1377
}
1378

1379
// initNeutrinoBackend inits a new instance of the neutrino light client
1380
// backend given a target chain directory to store the chain state.
1381
func initNeutrinoBackend(ctx context.Context, cfg *Config, chainDir string,
1382
        blockCache *blockcache.BlockCache) (*neutrino.ChainService,
UNCOV
1383
        func(), error) {
×
UNCOV
1384

×
UNCOV
1385
        // Both channel validation flags are false by default but their meaning
×
UNCOV
1386
        // is the inverse of each other. Therefore both cannot be true. For
×
UNCOV
1387
        // every other case, the neutrino.validatechannels overwrites the
×
UNCOV
1388
        // routing.assumechanvalid value.
×
UNCOV
1389
        if cfg.NeutrinoMode.ValidateChannels && cfg.Routing.AssumeChannelValid {
×
1390
                return nil, nil, fmt.Errorf("can't set both " +
×
1391
                        "neutrino.validatechannels and routing." +
×
1392
                        "assumechanvalid to true at the same time")
×
1393
        }
×
UNCOV
1394
        cfg.Routing.AssumeChannelValid = !cfg.NeutrinoMode.ValidateChannels
×
UNCOV
1395

×
UNCOV
1396
        // First we'll open the database file for neutrino, creating the
×
UNCOV
1397
        // database if needed. We append the normalized network name here to
×
UNCOV
1398
        // match the behavior of btcwallet.
×
UNCOV
1399
        dbPath := filepath.Join(
×
UNCOV
1400
                chainDir, lncfg.NormalizeNetwork(cfg.ActiveNetParams.Name),
×
UNCOV
1401
        )
×
UNCOV
1402

×
UNCOV
1403
        // Ensure that the neutrino db path exists.
×
UNCOV
1404
        if err := os.MkdirAll(dbPath, 0700); err != nil {
×
1405
                return nil, nil, err
×
1406
        }
×
1407

UNCOV
1408
        var (
×
UNCOV
1409
                db  walletdb.DB
×
UNCOV
1410
                err error
×
UNCOV
1411
        )
×
UNCOV
1412
        switch {
×
1413
        case cfg.DB.Backend == kvdb.SqliteBackendName:
×
1414
                sqliteConfig := lncfg.GetSqliteConfigKVDB(cfg.DB.Sqlite)
×
1415
                db, err = kvdb.Open(
×
1416
                        kvdb.SqliteBackendName, ctx, sqliteConfig, dbPath,
×
1417
                        lncfg.SqliteNeutrinoDBName, lncfg.NSNeutrinoDB,
×
1418
                )
×
1419

UNCOV
1420
        default:
×
UNCOV
1421
                dbName := filepath.Join(dbPath, "neutrino.db")
×
UNCOV
1422
                db, err = walletdb.Create(
×
UNCOV
1423
                        "bdb", dbName, !cfg.SyncFreelist, cfg.DB.Bolt.DBTimeout,
×
UNCOV
1424
                )
×
1425
        }
UNCOV
1426
        if err != nil {
×
1427
                return nil, nil, fmt.Errorf("unable to create "+
×
1428
                        "neutrino database: %v", err)
×
1429
        }
×
1430

UNCOV
1431
        headerStateAssertion, err := parseHeaderStateAssertion(
×
UNCOV
1432
                cfg.NeutrinoMode.AssertFilterHeader,
×
UNCOV
1433
        )
×
UNCOV
1434
        if err != nil {
×
1435
                db.Close()
×
1436
                return nil, nil, err
×
1437
        }
×
1438

1439
        // With the database open, we can now create an instance of the
1440
        // neutrino light client. We pass in relevant configuration parameters
1441
        // required.
UNCOV
1442
        config := neutrino.Config{
×
UNCOV
1443
                DataDir:      dbPath,
×
UNCOV
1444
                Database:     db,
×
UNCOV
1445
                ChainParams:  *cfg.ActiveNetParams.Params,
×
UNCOV
1446
                AddPeers:     cfg.NeutrinoMode.AddPeers,
×
UNCOV
1447
                ConnectPeers: cfg.NeutrinoMode.ConnectPeers,
×
UNCOV
1448
                Dialer: func(addr net.Addr) (net.Conn, error) {
×
UNCOV
1449
                        return cfg.net.Dial(
×
UNCOV
1450
                                addr.Network(), addr.String(),
×
UNCOV
1451
                                cfg.ConnectionTimeout,
×
UNCOV
1452
                        )
×
UNCOV
1453
                },
×
UNCOV
1454
                NameResolver: func(host string) ([]net.IP, error) {
×
UNCOV
1455
                        addrs, err := cfg.net.LookupHost(host)
×
UNCOV
1456
                        if err != nil {
×
1457
                                return nil, err
×
1458
                        }
×
1459

UNCOV
1460
                        ips := make([]net.IP, 0, len(addrs))
×
UNCOV
1461
                        for _, strIP := range addrs {
×
UNCOV
1462
                                ip := net.ParseIP(strIP)
×
UNCOV
1463
                                if ip == nil {
×
1464
                                        continue
×
1465
                                }
1466

UNCOV
1467
                                ips = append(ips, ip)
×
1468
                        }
1469

UNCOV
1470
                        return ips, nil
×
1471
                },
1472
                AssertFilterHeader: headerStateAssertion,
1473
                BlockCache:         blockCache.Cache,
1474
                BroadcastTimeout:   cfg.NeutrinoMode.BroadcastTimeout,
1475
                PersistToDisk:      cfg.NeutrinoMode.PersistFilters,
1476
        }
1477

UNCOV
1478
        neutrino.MaxPeers = 8
×
UNCOV
1479
        neutrino.BanDuration = time.Hour * 48
×
UNCOV
1480
        neutrino.UserAgentName = cfg.NeutrinoMode.UserAgentName
×
UNCOV
1481
        neutrino.UserAgentVersion = cfg.NeutrinoMode.UserAgentVersion
×
UNCOV
1482

×
UNCOV
1483
        neutrinoCS, err := neutrino.NewChainService(config)
×
UNCOV
1484
        if err != nil {
×
1485
                db.Close()
×
1486
                return nil, nil, fmt.Errorf("unable to create neutrino light "+
×
1487
                        "client: %v", err)
×
1488
        }
×
1489

UNCOV
1490
        if err := neutrinoCS.Start(); err != nil {
×
1491
                db.Close()
×
1492
                return nil, nil, err
×
1493
        }
×
1494

UNCOV
1495
        cleanUp := func() {
×
UNCOV
1496
                if err := neutrinoCS.Stop(); err != nil {
×
1497
                        ltndLog.Infof("Unable to stop neutrino light client: "+
×
1498
                                "%v", err)
×
1499
                }
×
UNCOV
1500
                db.Close()
×
1501
        }
1502

UNCOV
1503
        return neutrinoCS, cleanUp, nil
×
1504
}
1505

1506
// parseHeaderStateAssertion parses the user-specified neutrino header state
1507
// into a headerfs.FilterHeader.
UNCOV
1508
func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) {
×
UNCOV
1509
        if len(state) == 0 {
×
UNCOV
1510
                return nil, nil
×
UNCOV
1511
        }
×
1512

1513
        split := strings.Split(state, ":")
×
1514
        if len(split) != 2 {
×
1515
                return nil, fmt.Errorf("header state assertion %v in "+
×
1516
                        "unexpected format, expected format height:hash", state)
×
1517
        }
×
1518

1519
        height, err := strconv.ParseUint(split[0], 10, 32)
×
1520
        if err != nil {
×
1521
                return nil, fmt.Errorf("invalid filter header height: %w", err)
×
1522
        }
×
1523

1524
        hash, err := chainhash.NewHashFromStr(split[1])
×
1525
        if err != nil {
×
1526
                return nil, fmt.Errorf("invalid filter header hash: %w", err)
×
1527
        }
×
1528

1529
        return &headerfs.FilterHeader{
×
1530
                Height:     uint32(height),
×
1531
                FilterHash: *hash,
×
1532
        }, nil
×
1533
}
1534

1535
// broadcastErrorMapper maps errors from bitcoin backends other than neutrino to
1536
// the neutrino BroadcastError which allows the Rebroadcaster which currently
1537
// resides in the neutrino package to use all of its functionalities.
1538
func broadcastErrorMapper(err error) error {
2✔
1539
        var returnErr error
2✔
1540

2✔
1541
        // We only filter for specific backend errors which are relevant for the
2✔
1542
        // Rebroadcaster.
2✔
1543
        switch {
2✔
1544
        // This makes sure the tx is removed from the rebroadcaster once it is
1545
        // confirmed.
1546
        case errors.Is(err, chain.ErrTxAlreadyKnown),
1547
                errors.Is(err, chain.ErrTxAlreadyConfirmed):
2✔
1548

2✔
1549
                returnErr = &pushtx.BroadcastError{
2✔
1550
                        Code:   pushtx.Confirmed,
2✔
1551
                        Reason: err.Error(),
2✔
1552
                }
2✔
1553

1554
        // Transactions which are still in mempool but might fall out because
1555
        // of low fees are rebroadcasted despite of their backend error.
1556
        case errors.Is(err, chain.ErrTxAlreadyInMempool):
×
1557
                returnErr = &pushtx.BroadcastError{
×
1558
                        Code:   pushtx.Mempool,
×
1559
                        Reason: err.Error(),
×
1560
                }
×
1561

1562
        // Transactions which are not accepted into mempool because of low fees
1563
        // in the first place are rebroadcasted despite of their backend error.
1564
        // Mempool conditions change over time so it makes sense to retry
1565
        // publishing the transaction. Moreover we log the detailed error so the
1566
        // user can intervene and increase the size of his mempool.
1567
        case errors.Is(err, chain.ErrMempoolMinFeeNotMet):
×
1568
                ltndLog.Warnf("Error while broadcasting transaction: %v", err)
×
1569

×
1570
                returnErr = &pushtx.BroadcastError{
×
1571
                        Code:   pushtx.Mempool,
×
1572
                        Reason: err.Error(),
×
1573
                }
×
1574
        }
1575

1576
        return returnErr
2✔
1577
}
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