importprivkey is very slow #1085

issue dooglus opened this issue on April 12, 2012
  1. dooglus commented at 11:50 PM on April 12, 2012: contributor

    I recently needed to import some private keys into my wallet.

    I knew the addresses had never been used, and so didn't need to rescan the blockchain, but there's no way to import a private key without the client automatically rescanning the whole blockchain.

    There's also no way to import multiple private keys at once, so to import 5 private keys I had to wait while the client scanned the whole blockchain 5 times over for transactions I knew it wouldn't find anyway.

    I'd like to be able to either:

    • import multiple keys with a single importprivkey RPC call, or
    • optionally suppress the blockchain rescan

    Or both.

    I ended up commenting these two lines in rpcdump.cpp to get the job done:

        // pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
        // pwalletMain->ReacceptWalletTransactions();
    

    but would prefer a better solution.

  2. laanwj commented at 6:10 AM on April 13, 2012: member

    Both sound good with me, as they can be useful in different scenarios.

    1. Make it possible to pass a JSON array of keys to import as well as a single key
      • to import multiple keys faster, but still safely
    2. And add a flag to suppress rescan
      • if you can guarantee or don't care whether the private key is used before
  3. ciyam commented at 3:23 AM on December 6, 2012: none

    I think it had also been mentioned that it might be useful to be able to specify how far back to rescan (either from a block or a date I guess).

  4. jonls commented at 2:04 PM on March 22, 2013: contributor

    The second part seems to have been fixed by 44051af1a87a5fb8f4e88442c0eb64a1b4ecf2e6.

  5. rebroad commented at 1:11 AM on April 1, 2013: contributor

    Why not simply remove the automatic rescan since a manual rescan can be performed any time someone wishes to run one?

  6. gmaxwell commented at 1:36 AM on April 1, 2013: contributor

    @rebroad because that would leave the wallet in an undertested 'inconsistent' state. (e.g. you may find out transactions from the network spending prior transactions of yours which you don't know about)

  7. extr0p commented at 7:20 PM on April 6, 2013: none

    this is an issue, would love to see the suggested features import multiple keys with a single importprivkey RPC call, or optionally suppress the blockchain rescan

  8. gmaxwell commented at 7:35 PM on April 6, 2013: contributor

    This was fixed by 44051af1a87a5fb8f4e88442c0eb64a1b4ecf2e6 which allows you to suppress the rescan.

  9. sipa commented at 11:28 PM on April 23, 2013: member

    I think this is fixed, closing.

  10. sipa closed this on Apr 23, 2013

  11. rebroad commented at 4:43 PM on July 18, 2014: contributor

    it's really not clear from the current help output how to suppress the rescan...

  12. rkfg commented at 9:44 AM on September 10, 2014: none

    Yes, this should be clarified. Moreover, there's no way to stop the rescan once it has started. You can't even close bitcoin (AFAIK), only kill it with -9. Actually, the format for the command is importprivkey 5HzBeH... "account name" false if you don't want to rescan. And the default is true which is confusing — the help line looks like importprivkey "bitcoinprivkey" ( "label" rescan ) so it makes me think that if I don't add rescan it won't be rescanned.

  13. rebroad commented at 11:34 AM on September 15, 2014: contributor

    #4922 raised to address this, @rkfg

  14. sanch0panza referenced this in commit 0d1b5177d3 on May 17, 2018
  15. lateminer referenced this in commit a4d141fd1c on Dec 25, 2019
  16. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 00:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me