Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btcwallet: don't initialize wallet namespace if scrypt derivation fails due to low memory #6210

Open
callebtc opened this issue Jan 27, 2022 · 5 comments
Labels
bug Unintended code behaviour P2 should be fixed if one has time resource usage Software resource usage improvements/issues

Comments

@callebtc
Copy link

callebtc commented Jan 27, 2022

Background

lnd is killed at wallet creation.

Your environment

  • Hardware: Raspberry Pi Zero 2 W
  • version of lnd: Version: 0.14.1-beta commit=v0.14.1-beta,
  • Linux 5.10.63-v7+ #\1459 SMP Wed Oct 6 16:41:10 BST 2021 armv7l GNU/Linu
  • using neutrino backend

Steps to reproduce

I start with a fresh lnd with the Raspibolt config except that I use the neutrino backend. I use the ARMv7 binary since I'm running this on a Rpi Zero 2 W.

I start lnd and it does it's thing, waiting for me to create a wallet. In another session, I run lncli create. I see this:

x@y:~/.lnd $ lncli create
Input wallet password:
Confirm password:

Do you have an existing cipher seed mnemonic or extended master root key you want to use?
Enter 'y' to use an existing cipher seed mnemonic, 'x' to use an extended master root key
or 'n' to create a new seed (Enter y/x/n): n

Your cipher seed can optionally be encrypted.
Input your passphrase if you wish to encrypt it (or press enter to proceed without a cipher seed passphrase):

Generating fresh cipher seed...

!!!YOU MUST WRITE DOWN THIS SEED TO BE ABLE TO RESTORE THE WALLET!!!

---------------BEGIN LND CIPHER SEED---------------
 1. abandon    2. erupt   3. club       4. motion
 5. cabbage    6. leaf    7. build      8. fish
 9. enemy     10. basic  11. peanut    12. ski
13. slide     14. place  15. mechanic  16. fiction
17. crane     18. firm   19. chimney   20. rack
21. artefact  22. buyer  23. action    24. develop
---------------END LND CIPHER SEED-----------------

!!!YOU MUST WRITE DOWN THIS SEED TO BE ABLE TO RESTORE THE WALLET!!!

Around 10 seconds later, lncli terminates with:

[lncli] rpc error: code = Unavailable desc = error reading from server: EOF

At the same time, lnd gets killed only saying:

Killed

At this point I have created a wallet. I can try to run lnd again but I get

error creating wallet config: error unlocking wallet with password from file: missing address manager namespace

To check, I uncomment these lines in lnd.conf so I can enter the password manually:

wallet-unlock-password-file=/asd/password.txt
wallet-unlock-allow-create=true

I start lnd again, this time it runs but wants me to unlock the wallet manually:

2022-01-27 23:18:06.862 [INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.

I do that with lncli and now I get:

x@y:~/.lnd $ lncli unlock
Input wallet password: <I enter the pw here>
[lncli] rpc error: code = Unknown desc = missing address manager namespace
x@y:~/.lnd $

lnd keeps running. Can't unlock the wallet.

I delete everything in the .lnd directory except for my lnd.conf file and start over. Same thing happens.

:(

@Roasbeef
Copy link
Member

Roasbeef commented Jan 27, 2022

Do you have any swap alloacted? I'm guessing the initial scrypt operation to encrypt the keys on disk is running out of memory. Depending on the type of telemetry you have on the machine, you can watch the memory usage.

There're some other settings you can use on the lnd front to reduce memory usage as well.

@HannahMR HannahMR added the P1 MUST be fixed or reviewed label Jan 28, 2022
@Roasbeef
Copy link
Member

Roasbeef commented Feb 7, 2022

Closing due to inactivity. The issue here seems to be lack of swap AFAICT, will re-open if we get any other information.

@Roasbeef Roasbeef closed this as completed Feb 7, 2022
@joostjager
Copy link
Contributor

I think I may have a repro for this scenario. Ran into it as well in a docker environment with insufficient memory. It isn't great, because wallet db seems to get into a state that lnd can't recover from. Restarting doesn't help.

Repro steps:

2022-05-11 14:56:43.410 [ERR] LTND: unable to create wallet controller: missing address manager namespace
2022-05-11 14:56:43.410 [ERR] LTND: Shutting down because error in main method: error loading chain control: unable to create wallet controller: missing address manager namespace```

@joostjager
Copy link
Contributor

The reason seems to be that an empty wallet file is already created, but not yet initialized. This will skip the initialization on the next run.

@joostjager
Copy link
Contributor

@saubyk can this be re-opened? I've added a repro scenario above.

@guggero guggero reopened this Dec 6, 2022
@guggero guggero added resource usage Software resource usage improvements/issues bug Unintended code behaviour and removed P1 MUST be fixed or reviewed troubleshooting raspi ARM labels Dec 6, 2022
@guggero guggero changed the title lnd killed at wallet creation. Can't unlock wallet at second try: missing address manager namespace btcwallet: don't initialize wallet namespace if scrypt derivation fails due to low memory Dec 6, 2022
@saubyk saubyk added this to the v0.16.1 milestone Dec 7, 2022
@saubyk saubyk added the P2 should be fixed if one has time label Aug 8, 2023
@saubyk saubyk removed this from the Medium Priority milestone Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended code behaviour P2 should be fixed if one has time resource usage Software resource usage improvements/issues
Projects
None yet
Development

No branches or pull requests

6 participants