As far as i know that key pool gets refilled automatically with each address taken out of it. Why should i use keypoolrefill then ? What's the benefit of this command ?
Most people don't need to use
Bitcoin Core tries to fill the keypool to its configured maximum size whenever you take an address from the keypool. (It does not wait until the keypool is empty before regenerating it.) However, it isn't possible to add keys to the keypool unless the wallet is unlocked with
walletpassphrase. So if you call
getnewaddress 100 times (by default), your keypool will be empty and you will be prompted to unlock your wallet and run
keypoolrefill. The same effect could be achieved by unlocking your wallet and then generating another address, which will also cause the keypool to be topped up.
Another use is if you want to temporarily increase the size of your keypool. For example, a really safe way of doing payment processing is to generate an encrypted wallet with a strong passphrase, generate thousands of keys using
keypoolrefill 10000 or whatever, put this wallet on the live payment processing server, but only use the commands that don't require unlocking the wallet. Then even if the live server is compromised, the attacker can't steal the money because he can't unlock the wallet. This is similar to the idea of a watch-only wallet. You could do the same thing with the
keypool setting, but I guess that restarting Bitcoin Core might be inconvenient in some cases.
Running Bitcoin with
-keypool=0 and then only manually adjusting the keypool with
keypoolresize might also be useful for some backup strategies, or if you have multiple servers using the same wallet (which is not recommended, but maybe possible if you're really careful).
If you believe that your databases files have been compromised at one time (which contain the key sets) it is a good idea to refill your keypool, so that attackers can't abuse any of the corrupted keys yet to be used by your Bitcoin client. You must do this of course before "transferring" any Bitcoins to newly requested addresses.
Tim S. already alluded to this but it has to do with the performance penalty of a keypoolrefill. If you have a really large pool because you run a high volume site and don't want to frequently backup your wallet as an example you may want to run keypoolrefill at off-peak so as not to impact the performance of Bitcoind.
Otherwise keypoolrefill will run once the pool is exhausted which may happen at an inopportune time.