Commit Graph

275 Commits

Author SHA1 Message Date
Hampus Sjöberg
ada1bc701c signal: handle shutdown properly
This addresses issues related to the mobile lnd builds, where
calling `stopDaemon` and subsequently calling LndMobile's `Start`
results in crash.
2021-03-18 12:54:25 +01:00
Johan T. Halseth
9ef556624e
lnrpc: add StateService 2021-03-17 12:09:38 +01:00
Johan T. Halseth
ad6673c21d
lnd: close MacResponseChan when wallet is unlocked
After unification of the WalletUnlocker and RPC services on the same gRPC
server, the WalletUnlocker will no longer be shut down after the wallet
has been unlocked.

In case --no-macaroons was used, this lead to the caller getting stuck
after unlocking the wallet, since we would wait for a response on the
MacResponseChan. Earlier we would close the MacResponseChan always
when shutting down the WalletUnlocker, but this is no longer done.

To fix this we close this channel after the wallet is unlocked,
regardless of which combination of --no-macaroons and --noseedbackup
that is being used.
2021-03-16 14:47:02 +01:00
Johan T. Halseth
2877511fce
rpcperms+lnd: gate RPC calls on RPC state
This commit makes us gate the calls to the RPC servers according to the
current RPC state. This ensures we won't try to call the RPC server
before it has been fully initialized, and that we won't call the
walletUnlocker after the wallet already has been unlocked.
2021-03-11 13:05:24 +01:00
Johan T. Halseth
4bbf5c4b6d
rpcserver: use same grpc server for both services
This commit achieves what we have been building up to: running the
WalletUnlockerService and the LightningService on the same gRPC server
simultaneously!

To achieve this, we first create the RPC server in a "interface only"
way, only creating the struct and setting the dependencies we have
available before the wallet has been unlocked. After the wallet has been
unlocked and we have created all the subsystems we need, we add those to
the RPC server, and start the sub-servers.

This means that the WalletUnlockerService and the LightningService both
will be registered and available at all times on the gRPC server.
However, before the wallet has been unlocked, the LightningService
should not be used since the RPC server is not yet ready to handle the
calls. Similarly, after the wallet has been unlocked, the
WalletUnlockerService should not be used. This we will ensure in
following commits.
2021-03-11 13:05:24 +01:00
Johan T. Halseth
82fb22eda2
lnd+rpc: define external subserver config only once
We don't have to define the external subserver config more than once, so
it is not needed to be defined for every listener. Instead we move it to
the ListenerConfig.
2021-03-11 13:05:24 +01:00
Johan T. Halseth
3c81a5dd73
rpcperms: add RPC interceptor chain
This adds a new package rpcperms which houses the InterceptorChain
struct.  This is a central place where we'll craft interceptors to use
for the GRPC server, which includes macaroon enforcement.

This let us add the interceptor chain to the GRPC server before the
macaroon service is ready, allowing us to avoid tearing down the GRPC
server after the wallet has been unlocked.
2021-03-11 13:05:23 +01:00
Oliver Gugger
03a21367d3
lnd+walletunlocker: move history drop to unlocker
Apparently dropping the wallet transaction history only fully takes
effect after opening the wallet from scratch again. To do this cleanly,
we need to do it in the unlocker instead of lnd.
2020-12-15 21:34:12 +01:00
Yong
582b164c46
kvdb: add timeout options for bbolt (#4787)
* mod: bump btcwallet version to accept db timeout

* btcwallet: add DBTimeOut in config

* kvdb: add database timeout option for bbolt

This commit adds a DBTimeout option in bbolt config. The relevant
functions walletdb.Open/Create are updated to use this config. In
addition, the bolt compacter also applies the new timeout option.

* channeldb: add DBTimeout in db options

This commit adds the DBTimeout option for channeldb. A new unit
test file is created to test the default options. In addition,
the params used in kvdb.Create inside channeldb_test is updated
with a DefaultDBTimeout value.

* contractcourt+routing: use DBTimeout in kvdb

This commit touches multiple test files in contractcourt and routing.
The call of function kvdb.Create and kvdb.Open are now updated with
the new param DBTimeout, using the default value kvdb.DefaultDBTimeout.

* lncfg: add DBTimeout option in db config

The DBTimeout option is added to db config. A new unit test is
added to check the default DB config is created as expected.

* migration: add DBTimeout param in kvdb.Create/kvdb.Open

* keychain: update tests to use DBTimeout param

* htlcswitch+chainreg: add DBTimeout option

* macaroons: support DBTimeout config in creation

This commit adds the DBTimeout during the creation of macaroons.db.
The usage of kvdb.Create and kvdb.Open in its tests are updated with
a timeout value using kvdb.DefaultDBTimeout.

* walletunlocker: add dbTimeout option in UnlockerService

This commit adds a new param, dbTimeout, during the creation of
UnlockerService. This param is then passed to wallet.NewLoader
inside various service calls, specifying a timeout value to be
used when opening the bbolt. In addition, the macaroonService
is also called with this dbTimeout param.

* watchtower/wtdb: add dbTimeout param during creation

This commit adds the dbTimeout param for the creation of both
watchtower.db and wtclient.db.

* multi: add db timeout param for walletdb.Create

This commit adds the db timeout param for the function call
walletdb.Create. It touches only the test files found in chainntnfs,
lnwallet, and routing.

* lnd: pass DBTimeout config to relevant services

This commit enables lnd to pass the DBTimeout config to the following
services/config/functions,
  - chainControlConfig
  - walletunlocker
  - wallet.NewLoader
  - macaroons
  - watchtower
In addition, the usage of wallet.Create is updated too.

* sample-config: add dbtimeout option
2020-12-07 15:31:49 -08:00
Conner Fromknecht
e9b5b2d767
Merge pull request #4793 from murtyjones/cosmetic/add-newline-to-log
Cosmetic: Add newline to end of log statement
2020-12-01 16:44:24 -08:00
Oliver Gugger
76d2c49a17
lnd: fix Onion v2 support for Neutrino backends
With this commit we make it possible to use an Onion v2 hidden service
address as the Neutrino backend.
This failed before because an .onion address cannot be looked up and
converted into an IP address through the normal DNS resolving process,
even when using a Tor socks proxy.
Instead, we turn any v2 .onion address into a fake IPv6 representation
before giving it to Neutrino's address manager and turn it back into an
Onion host address when actually dialing.
2020-11-30 22:42:57 +01:00
Conner Fromknecht
82a238317c
lncfg+itest: expose configurable batch-commit-interval
This will permit a greater degree of tuning or customization depending
on various hardware/environmental factors.
2020-11-25 16:45:25 -08:00
Marty Jones
b06e0c648e Add newline to end of log statement 2020-11-23 08:37:42 -05:00
Oliver Gugger
f8907fdb47
multi: add AutoCompact option to bolt backend
With this commit we thread the new AutoCompact flags all the way through
to the bolt backend.
2020-11-13 10:19:49 +01:00
carla
61777c41e4
lnd: return missing shutdown parameter 2020-11-12 09:12:32 +02:00
Olaoluwa Osuntokun
58f72df94a
Merge pull request #4715 from guggero/reset-wallet
Implement btcwallet's "dropwtxmgr" command as --reset-wallet-transactions flag
2020-11-11 19:50:21 -08:00
Johan T. Halseth
5be7e710c7
RPC: Add --notls to disable TLS for RPC endpoints
Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
2020-11-11 09:37:52 +01:00
Johan T. Halseth
a2a924e1e5
rpcserver: move TLS listen config to closure 2020-11-11 09:37:52 +01:00
Oliver Gugger
e7aa9256ab
walletunlocker+lnd: implement stateless wallet initialization 2020-11-07 11:24:34 +01:00
Oliver Gugger
b685a97fcd
lnd: shutdown wallet unlocker after macaroon creation
Because we'll need to return the macaroon through the wallet unlocker
we cannot shut down its service before we have done so, otherwise
we'll end up in a deadlock. That's why we collect all shutdown
tasks and return them as a function that can be called after we've
initialized the macaroon service.
2020-11-07 11:24:34 +01:00
Oliver Gugger
71ba2a8e60
lnd: prepare for proper wallet unlocker cleanup
As a preparation for the next commit where we add proper wallet unlocker
shutdown handling, we move the calls that require cleanup down after the
creation of the wallet unlocker service itself.
2020-11-07 11:24:33 +01:00
Oliver Gugger
294cb4a966
macaroons: remember stateless init
To make sure no macaroons are created anywhere if the stateless
initialization was requested, we keep the requested initialization mode
in the memory of the macaroon service.
2020-11-07 11:24:33 +01:00
Oliver Gugger
a7c81eb595
lnd: drop wallet transactions if flag is set
To force a full chain rescan, the wallet can now be instructed to drop
its full transaction history on startup.
2020-11-04 09:12:24 +01:00
Eugene
bebe258e2d chainregistry+lnd: moving chainregistry+chainparams to new package 2020-10-29 15:24:14 -04:00
Eugene
46ef212de4 lnd+lncfg: move normalizeNetwork to lncfg 2020-10-29 15:20:00 -04:00
Eugene
4d238cfa2f lnd: export ChainControl, ChainRegistry 2020-10-29 15:20:00 -04:00
Eugene
f4fe76aaf1 chainreg: add Config, move chainparams.go
Creates a Config that initializes the chainregistry struct in the
lnd package. Also moves all of chainparams.go to the chainreg
package.
2020-10-29 15:19:58 -04:00
Eugene
933b959aa8 chainreg: export ChainCode to new pkg
Moves chainCode from the lnd package to the chainreg package,
where it is exported and can be used by other packages.
2020-10-29 15:19:57 -04:00
eugene
afb6ad295e lnd: move initNeutrinoBackend to lnd.go 2020-10-29 15:19:56 -04:00
MrManPew
72e4eab3b9
Update lnd.go 2020-10-01 18:02:16 -04:00
MrManPew
f5e0922c31
Show debug level at startup
I think it is efficient to also show the debug level at the startup. To verify that indeed the correct settings of the debuglevel started correctly. Especially when trying to capture rare bugs.
2020-09-27 12:39:20 -04:00
Oliver Gugger
00cb6fcc5d
lnd+config: allow Let's Encrypt listen IP to be set
To make it possible to request a Let's Encrypt certificate by using a
different IP address where the port 80 might still be free, we add the
IP part to its configuration as well instead of just the port.
This makes it possible to use an IPv6 address for the ACME request if
all available IPv4 addresses already have their port 80 occupied.
2020-09-17 09:54:23 +02:00
Johan T. Halseth
b8eb41f947
Merge pull request #4591 from hsjoberg/walletloader-unload
lnd: Call loader.UnloadWallet on shutdown
2020-09-15 13:54:46 +02:00
Joost Jager
403d72b468
lnrpc: lets encrypt
This commit enables lnd to request and renew a Let's Encrypt
certificate. This certificate is used both for the grpc as well as the
rest listeners. It allows clients to connect without having a copy of
the (public) server certificate.

Co-authored-by: Vegard Engen <vegard@engen.priv.no>
2020-09-15 09:59:09 +02:00
Joost Jager
999ffffa37
lnd: join imports to form three groups
In line with https://github.com/pavius/impi
2020-09-14 14:52:07 +02:00
Hampus Sjöberg
6dd1555e66 lnd: Call loader.UnloadWallet on shutdown
This is required to make restart work for LndMobile builds.
Not calling UnloadWallet would make `UnlockWallet` stall forever as
the file is already opened.
2020-09-14 12:32:48 +02:00
Oliver Gugger
8988a01d7e
lnd+rpcserver: allow external subservers to specify macaroon validator
Give the external subservers the possibility to also use their own
validator to check any macaroons attached to calls to their registered
gRPC URIs.
This allows them to have their own root key ID database and permission
entities.
2020-09-10 10:24:10 +02:00
Oliver Gugger
d4c4cf01f0
lnd+macaroons: specify location when creating macaroon service
To allow the macaroon service to be used in other projects, we want the
location to be passed in as a parameter instead of being hard coded.
2020-09-10 10:24:08 +02:00
Oliver Gugger
fac3c84806
Merge pull request #4551 from gkrizek/cors
lnd: Add CORS support to the WalletUnlocker proxy
2020-08-25 09:31:40 +02:00
Graham Krizek
3f944dd337
lnd: Add CORS support to the WalletUnlocker proxy
This commit adds the same CORS functionality that's currently in the main gRPC proxy to the WalletUnlocker proxy. This ensures the CORS configuration is carried through all API endpoints
2020-08-24 14:29:31 -05:00
Olaoluwa Osuntokun
bd18f9acf5
Merge pull request #4427 from yyforyongyu/customize-root-key-id
macaroons: customize root key ID
2020-08-21 19:34:15 -07:00
Olaoluwa Osuntokun
d14aa9feaa
Merge pull request #4421 from gkrizek/tls-disable-autofill
tls: add --tlsdisableautofill flag to prevent sensitive data leaks
2020-08-21 19:32:24 -07:00
yyforyongyu
c0e2513350
lnrpc+rpcserver: support list/delete on marcaroon IDs 2020-08-14 12:33:13 +08:00
Graham Krizek
86a0609ecf
config+lnd+cert: add --tlsdisableautofill to prevent information leaks.
This adds in a new boolean flag that when set, prevents LND from writing the system hostname and network interface IPs to the TLS certificate. This will ensure privacy for those that don't want private IP addresses to be exposed on a public facing LND node.
2020-08-13 09:24:39 -05:00
nsa
3791c9efcb lnd: removing activeNetParams global, passed around instead via configs
This commit removes the activeNetParams global in chainparams.go. This
is necessary to isolate code from the lnd package so we can import it
for use in tests, other projects, etc.
2020-08-11 11:41:24 -04:00
Olaoluwa Osuntokun
f58b00ef55
multi: split database storage into remote and local instances
In this commit, we split the database storage into two classes: remote
and local data. If etcd isn't active, then everything is actually just
local though we use two pointers everywhere. If etcd is active, then
everything but the graph goes into the remote database.
2020-08-07 18:44:02 -07:00
Olaoluwa Osuntokun
7355c8ba3a
lncfg: add new GetBackends which returns active DB backends
In this commit, we modify the existing `GetBackend` method to now be
called `GetBackends`. This new method will populate a new `RemoteDB`
attribute based on if the replicated backend is active or not. As is,
the local backend is used everywhere. An upcoming commit will once again
re-enable the remote backend, in a hybrid manner.
2020-08-07 18:44:00 -07:00
Olaoluwa Osuntokun
19f68d2538
lnd: log bbolt freelist sync config value on start up 2020-08-04 18:55:02 -07:00
Olaoluwa Osuntokun
675c1b95c9
lnd: don't set freelist value when creating channeldb
This value actually isn't read anywhere, since it's no longer used.
Instead, `cfg.Db.Bolt.NoSyncFreeList` is what's evaluated when we go to
open the DB.
2020-08-04 18:54:59 -07:00
Andras Banki-Horvath
3e5e60cac4 lnd+kvdb: pass LND abort context to etcd 2020-06-03 17:44:44 +02:00