btcsuite / btcwallet

A secure bitcoin wallet daemon written in Go (golang)
ISC License
1.15k stars 590 forks source link

Restore non-default accounts #957

Open louisinger opened 2 months ago

louisinger commented 2 months ago

While restoring from seed, default account (index = 0) addresses are restored perfectly. However, all other custom accounts are not checked by the recovery process.

After some debugging, it seems to me that externalKeyPath and internalKeyPath are hardcoding the account member in derivation path to waddrmgr.DefaultAccountNum.

Is it expected ? Is there a way to recover an account with account index greater than 0 ?

https://github.com/btcsuite/btcwallet/blob/ffb143c77cc57602c812bf7498ef1d407ba41581/wallet/wallet.go#L1010

Roasbeef commented 2 months ago

Is there a way to recover an account with account index greater than 0 ?

Sure, make a PR that expands the ressurection logic beyond the first account index. Usage in lnd uses the BIP 44 scopes as our account construction essentially.

louisinger commented 2 months ago

Sure, make a PR that expands the ressurection logic beyond the first account index. Usage in lnd uses the BIP 44 scopes as our account construction essentially.

Not as easy as it sounds because most getters does not support well the non-default accounts. For instance, UnspentOutputs seems unable to filter by key scope (filter account = 0 returns utxos whatever the keyscope type). It makes the custom account really hard and confuse to use and probably also need a rework beside recovery functions.

At least, I'd put a comment or enrich the documentation to explain how custom accounts are managed by the wallet.

Roasbeef commented 2 months ago

That sounds like a good list of intermediate steps to address for whoever to take on this issue in the future. Those that have this requirement would be the most suited to implement this feature with those requirements in mind.