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.
This commit is contained in:
Oliver Gugger 2020-10-24 16:34:53 +02:00
parent 37817f192e
commit a7c81eb595
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

28
lnd.go
View File

@ -1188,6 +1188,12 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr,
return nil, err
}
// For new wallets, the ResetWalletTransactions flag is a no-op.
if cfg.ResetWalletTransactions {
ltndLog.Warnf("Ignoring reset-wallet-transactions " +
"flag for new wallet as it has no effect")
}
return &WalletUnlockParams{
Password: password,
Birthday: birthday,
@ -1200,6 +1206,28 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr,
// The wallet has already been created in the past, and is simply being
// unlocked. So we'll just return these passphrases.
case unlockMsg := <-pwService.UnlockMsgs:
// Resetting the transactions is something the user likely only
// wants to do once so we add a prominent warning to the log to
// remind the user to turn off the setting again after
// successful completion.
if cfg.ResetWalletTransactions {
ltndLog.Warnf("Dropping all transaction history from " +
"on-chain wallet. Remember to disable " +
"reset-wallet-transactions flag for next " +
"start of lnd")
err := wallet.DropTransactionHistory(
unlockMsg.Wallet.Database(), true,
)
if err != nil {
if err := unlockMsg.UnloadWallet(); err != nil {
ltndLog.Errorf("Could not unload "+
"wallet: %v", err)
}
return nil, err
}
}
return &WalletUnlockParams{
Password: unlockMsg.Passphrase,
RecoveryWindow: unlockMsg.RecoveryWindow,