Commit Graph

52 Commits

Author SHA1 Message Date
Oliver Gugger
648fb22f63
multi: wrap all errors 2024-04-11 15:04:03 +02:00
Oliver Gugger
2086f09489
walletunlocker: fix unit test flake by closing DB
This fixes a unit test flake that occurred sometimes if the temporary
directory was attempted to be deleted but the wallet or macaroon DB
hasn't been closed yet.

````
--- FAIL: TestChangeWalletPasswordNewRootkey (1.63s)
    testing.go:1097: TempDir RemoveAll cleanup: unlinkat /tmp/TestChangeWalletPasswordNewRootkey3063283009/001/mainnet: directory not empty
FAIL
FAIL	github.com/lightningnetwork/lnd/walletunlocker	6.171s
FAIL
````
2023-02-06 14:08:08 +01:00
Oliver Gugger
ad0dbb1c15
walletunlocker: re-create loader after unloading wallet
Because the wallet loader sets its internal database reference to nil
when unloading a wallet, it cannot be loaded again in case of a remote
DB such as etcd or postgres. To avoid running into a nil pointer panic
we just re-create the loader as well before opening the wallet.
2022-12-09 11:09:05 +01:00
Eng Zer Jun
05c0dd7c91
walletunlocker: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 09:03:05 +08:00
Daniel McNally
86e5f9d0db
lnrpc: add macaroon_root_key to InitWalletRequest
This adds a field for specifying the macaroon root key to use during the
wallet initialization process instead of having lnd generate a random
macaroon root key itself.
2022-08-12 10:30:32 -04:00
Olaoluwa Osuntokun
e073b1d343
macaroons: futher abstract NewService from root key store impl
In this commit, we modify the `macaroons.NewService` consturctor to
accept the main interface rather than the raw DB. This allows us to use
other backends other than bolt or the kvdb interface to store the
macaroon root keys.

We also create a new ExtendedRootKeyStore interface that implements some
of the more advanced features we use such as macaroon encryption and
password rotation.
2022-07-06 18:59:50 -07:00
Oliver Gugger
51a480129b
walletunlocker+keychain+config_builder: use new aezeed version 2022-05-12 12:49:14 +02:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
ceb31f9034
multi: allow watch-only wallet creation 2021-10-14 15:42:55 +02:00
Oliver Gugger
47f1b81a51
walletunlocker+lnd: move WalletUnlockParams
As a preparation for adding the wallet unlock params to the chain
control, we first need to move them out of the main package.
2021-10-08 12:06:54 +02:00
Oliver Gugger
2835cebe90
Merge pull request #5659 from guggero/unit-test-race-fix
multi: fix unit test for high CPU load envs
2021-08-24 15:16:28 +02:00
Oliver Gugger
1f3a6e101d
multi: fix unit test for high CPU load envs
It seems that the GitHub CI runners share a CPU and therefore only have
very few ressources available. This causes the wallet unlocker and breach
arbiter tests to fail if we don't give them enough time to complete.
2021-08-24 13:03:21 +02:00
Oliver Gugger
aa9435be84
lnd+walletunlocker: allow creating wallet from extended key
In addition to creating a new wallet from an aezeed, we allow specifying
an exteded master root key as the main wallet key directly.
Because an exteded key (xprv) doesn't contain any information about the
creation time of the wallet, we must assume a birthday to start scanning
the chain from (if the user doesn't provide an explicit value). Since
lnd only uses SegWit addresses, it makes sense to
choose the date that corresponds to the first mainnet block that
contained SegWit transactions.
Restoring a wallet from an extended master root key will result in a
significantly longer initial wallet rescan time if the default value is
used.
2021-08-24 10:37:32 +02:00
Oliver Gugger
f7b17df452
multi: make macaroon DB remote compatible
The macaroon root keys should also be stored to the remote database if a
replicated backend such as etcd is used.
This commit refactors the macaroons service and wallet unlocker to
accept a kvdb backend directly instead of creating the bolt instance
automatically.
2021-08-04 14:55:52 +02:00
Oliver Gugger
ad061b73e3
walletunlocker: remove unnecessary conversions 2021-08-04 14:55:49 +02:00
Oliver Gugger
dd749fe580
lnrpc: update grpc-gateway library to v2 2021-07-27 13:09:59 +02:00
Olaoluwa Osuntokun
7ab5906093
Merge pull request #5245 from bhandras/kvdb_module
kvdb: make kvdb a top level submodule to allow dependency in other projects
2021-05-13 15:59:20 -07:00
Andras Banki-Horvath
14c851c8fc
kvdb: move channeldb/kvdb to top level 2021-05-07 14:18:56 +02:00
Oliver Gugger
8224de599b
walletunlocker: extract LoadAndUnlock
As a preparation to do auto-unlock without the unlock RPC, we extract
the relevant part into its own method in the unlocker service.
2021-05-06 10:07:00 +02:00
Andras Banki-Horvath
5e215a7a66
lnrpc: add "waiting to start" state to state service
This commit adds a new "waiting to start" state which may be used to
query if we're still waiting to become the cluster leader. Once leader
we advance the state to "wallet not exist" or "wallet locked" given
wallet availablity.
2021-05-04 17:33:11 +02:00
Andras Banki-Horvath
b6a620e6b2
misc: add ability to store the wallet in the remote DB 2021-05-04 17:33:11 +02:00
Andras Banki-Horvath
08be03367a
walletunlocker: extract method to create the Loader 2021-05-04 17:33:10 +02:00
Johan T. Halseth
0d7763fb96
walletunlocker: expose WalletExists 2021-03-11 13:05:24 +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
Oliver Gugger
0c6cc71f86
walletunlocker: use noFreeListSync param 2020-12-15 21:21:29 +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
Oliver Gugger
e7aa9256ab
walletunlocker+lnd: implement stateless wallet initialization 2020-11-07 11:24:34 +01:00
Oliver Gugger
4b0b20c98b
walletunlocker: use require library, fix linter issues
To prepare for new tests to be added, we first rewrite the existing
tests to use the require library and get rid of some smaller linter
issues.
2020-11-07 11:24:34 +01: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
3f45fb3781
walletunlocker: use fast scrypt options for unit tests 2020-01-24 14:02:40 +01:00
Wilmer Paulino
194a9dea81
multi: support sync freelist option within btcwallet 2019-10-04 12:19:40 -04:00
Lars Lehtonen
bd2e4d6c42
walletunlocker: stdlib context 2019-09-28 15:45:41 -07:00
Joost Jager
3d7de2ad39
multi: remove dead code 2019-09-10 17:21:59 +02:00
Olaoluwa Osuntokun
f0e9a1f753
walletunlock: exend the Init and Unlock methods to also return optional SCB's
In this commit, we we extend the Init and Unlock methods to also parse
out and return optional SCB instances. With this change, when the user
creates their node, if they have an existing seed and also a set of SCBs
(either single or multi), they'll be able to recover both their on-chain
balance, and also any funds that were settled within their existing
channels.
2019-03-28 17:53:23 -07:00
Francisco Calderón
9e920f12c9
Add password length validation on create CLI
In this commit we add this validation importing
the walletunlocker.ValidatePassword function on
create wallet command.
2019-03-05 20:58:46 -03:00
Conner Fromknecht
d75a01ec83
walletunlocker/service: change noencryptwallet reference to noseedbackup 2018-09-04 20:52:43 -07:00
Wilmer Paulino
b3edc5c257
walletunlocker: avoid returning error if macaroon files don't exist
In this commit, we fix a bug where it's possible that changing the
wallet's password fails due to not being able to remove non-existent
macaroon files. Since it's possible to run lnd without creating them,
changing the wallet's password would always result in a failure.
2018-08-16 16:17:54 -07:00
Conner Fromknecht
1ded697e8d
multi: sort import paths with gofmt 2018-08-02 18:20:49 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Oliver Gugger
cd8a21c4b8 walletunlocker: pass unlocked wallet back to lnd to avoid double unlock 2018-06-12 19:27:57 -07:00
Wilmer Paulino
58a3419283
lnd+walletunlocker: implement ChangePassword RPC 2018-05-31 17:24:00 -07:00
Wilmer Paulino
b32e0ced45
lnd+walletunlocker: remove macaroon dependency from UnlockerService 2018-05-31 17:23:57 -07:00
yohei okada
a15c6e5b04 walletunlocker: use KeyDerivationVersion for generating cipher seed
Replace hard coded internal version with KeyDerivationVersion specified
in keychain package.
2018-05-22 17:39:14 +09:00
Conner Fromknecht
3cb87f377f
walletunlocker/service_test: check recovery window is threaded 2018-04-26 16:03:09 -07:00
Conner Fromknecht
f8c0357770
walletunlocker: accept recovery window from InitWallet 2018-04-26 16:03:09 -07:00
Olaoluwa Osuntokun
428693cb6e
walletunlocker: modify service to implement new 2-step wallet creation
In this commit, we extend the UnlockerService to account for the new
changes in the lnrpc definition. Setting up the daemon for the first
time is now two step process: first the user will generate a new seed
via the GenSeed method, then the user will present this new seed (and
optional pass) to the InitWallet method which then will finalize the
wallet creation.

This two step process ensures that we don't commit the wallet changes
in the case that the user doesn't actually "ACK" the new seed.

In the case that the user already has an existing seed, they can
re-enter it and skip straight to the InitWallet step.

We also update the tests to account for the new API changes.
2018-03-05 11:07:06 -05:00
Alex
de6efbd1a1 multi: macaroon root key encryption 2018-02-05 21:44:06 -08:00
Alex
21c29c33d7 multi: upgrade macaroons to v2, replace per-method auth with interceptors
This commit reworks the macaroon authentication framework to use the
v2 macaroon format and bakery API. It also replaces the code in each
RPC method which calls the macaroon verifier with interceptors which
call the macaroon verifier instead. In addition, the operation
permissions are reworked to fit the new format of "allow" commands
(specifically, entity/operation permissions instead of method
permissions).
2018-01-31 17:14:49 -08:00
johan
92f4f4fbda
walletunlocker: check that password is at least 8 characters 2017-11-29 17:30:56 +01:00