Bitcoin Forum
April 27, 2024, 01:59:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What happens when you unlock the wallet?  (Read 116 times)
calchuchesta (OP)
Member
**
Offline Offline

Activity: 124
Merit: 11


View Profile
September 24, 2021, 02:21:53 AM
Merited by ABCbits (1)
 #1

Specifically, what goes on when you get prompted by the GUI to enter your password in order to make a transaction?

Does the code run the default walletpassphrase <your password> <timeout (seconds)> command line with the default 60 seconds or something else happens?

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
nc50lc
Legendary
*
Offline Offline

Activity: 2394
Merit: 5538


Self-proclaimed Genius


View Profile
September 24, 2021, 05:07:44 AM
Last edit: September 25, 2021, 07:40:47 AM by nc50lc
 #2

This has everything you need to know about wallet encryption: github.com/bitcoin/bitcoin/blob/6b8a5ab622e5c9386c872036646bf94da983b190/doc/README

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
If you need to do that, you can set a timeout of '1' second so your passphrase master key wont stay in your RAM for too long.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
calchuchesta (OP)
Member
**
Offline Offline

Activity: 124
Merit: 11


View Profile
September 26, 2021, 03:36:22 PM
 #3

This has everything you need to know about wallet encryption: github.com/bitcoin/bitcoin/blob/6b8a5ab622e5c9386c872036646bf94da983b190/doc/README

Unfortunately it doesn't answer about what GUI do when you unlock the wallet.

I use the walletpassphrase to see if I still can remember my password and I don't want to transact, so im curious about what goes on when the GUI unlocks it when making a transaction.
If you need to do that, you can set a timeout of '1' second so your passphrase wont stay in your RAM for too long.

You also could use command walletlock if you accidentally use default unlock duration and being extremely careful.

It should be somewhere on the code. Im trying to find things related to transactions on the qt folder source where it it's related to the passphrase being used:

https://github.com/bitcoin/bitcoin/blob/master/src/qt/askpassphrasedialog.h
https://github.com/bitcoin/bitcoin/blob/master/src/qt/askpassphrasedialog.cpp

I think this only relates to the actual window but not what happens with the passphrase. There's also this:

https://github.com/bitcoin/bitcoin/blob/master/src/interfaces/wallet.h

Code:
    //! Encrypt wallet.
    virtual bool encryptWallet(const SecureString& wallet_passphrase) = 0;

    //! Return whether wallet is encrypted.
    virtual bool isCrypted() = 0;

    //! Lock wallet.
    virtual bool lock() = 0;

    //! Unlock wallet.
    virtual bool unlock(const SecureString& wallet_passphrase) = 0;

    //! Return whether wallet is locked.
    virtual bool isLocked() = 0;

    //! Change wallet passphrase.
    virtual bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
        const SecureString& new_wallet_passphrase) = 0;

I can't find what the "default timeout" would be.

achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
September 26, 2021, 11:56:47 PM
Merited by Welsh (6), EFS (4), ABCbits (3)
 #4

When you unlock the wallet, the password is used to decrypt the key actually used to encrypt the private keys. That decryption key is stored in the wallet as vMasterKey. It will remain there in memory (and thus the wallet is unlocked) until CWallet::Lock is called to remove it from memory and thus lock the wallet.

When you use the walletpassphrase RPC, a timer thread will be scheduled to run after the given timeout. That thread will just call CWallet::Lock and lock the wallet.

The GUI doesn't need a timer like the RPC does because it can ask for the passphrase when needed, and lock the wallet when it is done with what it is doing. So it does not have a timeout in the same way the RPC does. Rather each action that needs the wallet to be unlocked for it to succeed will create a WalletModel::UnlockContext object, which in doing so, will spawn the AskPassphraseDialog to get your passphrase. That sets CWallet::vMasterKey thereby unlocking your wallet. The UnlockContext object has a destructor which calls CWallet::Lock so when it is destroyed, the wallet is locked. The object is destroyed when it goes out of scope, i.e. when the action being performed that needed the wallet to be unlocked is completed.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!