importprivkey is very slow #1085

Closed
dooglus opened this Issue Apr 12, 2012 · 11 comments

Comments

Projects
None yet
9 participants
@dooglus
Contributor

dooglus commented Apr 12, 2012

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.

@laanwj

This comment has been minimized.

Show comment Hide comment
@laanwj

laanwj Apr 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
Member

laanwj commented Apr 13, 2012

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
@ciyam

This comment has been minimized.

Show comment Hide comment
@ciyam

ciyam Dec 6, 2012

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).

ciyam commented Dec 6, 2012

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).

@jonls

This comment has been minimized.

Show comment Hide comment
@jonls

jonls Mar 22, 2013

Contributor

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

Contributor

jonls commented Mar 22, 2013

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

@rebroad

This comment has been minimized.

Show comment Hide comment
@rebroad

rebroad Apr 1, 2013

Contributor

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

Contributor

rebroad commented Apr 1, 2013

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

@gmaxwell

This comment has been minimized.

Show comment Hide comment
@gmaxwell

gmaxwell Apr 1, 2013

Member

@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)

Member

gmaxwell commented Apr 1, 2013

@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)

@extr0p

This comment has been minimized.

Show comment Hide comment
@extr0p

extr0p Apr 6, 2013

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

extr0p commented Apr 6, 2013

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

@gmaxwell

This comment has been minimized.

Show comment Hide comment
@gmaxwell

gmaxwell Apr 6, 2013

Member

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

Member

gmaxwell commented Apr 6, 2013

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

@sipa

This comment has been minimized.

Show comment Hide comment
@sipa

sipa Apr 23, 2013

Member

I think this is fixed, closing.

Member

sipa commented Apr 23, 2013

I think this is fixed, closing.

@sipa sipa closed this Apr 23, 2013

@rebroad

This comment has been minimized.

Show comment Hide comment
@rebroad

rebroad Jul 18, 2014

Contributor

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

Contributor

rebroad commented Jul 18, 2014

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

@rkfg

This comment has been minimized.

Show comment Hide comment
@rkfg

rkfg Sep 10, 2014

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.

rkfg commented Sep 10, 2014

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.

@rebroad

This comment has been minimized.

Show comment Hide comment
@rebroad

rebroad Sep 15, 2014

Contributor

#4922 raised to address this, @rkfg

Contributor

rebroad commented Sep 15, 2014

#4922 raised to address this, @rkfg

@bearsylla bearsylla referenced this issue in JohnDolittle/blackcoin-old Mar 9, 2015

Closed

importprivkey broken on both Mac OS X and Windows #42

sanch0panza pushed a commit to sanch0panza/bitcoin that referenced this issue May 17, 2018

Merge pull request #1085 from ptschip/dev_comment
 Update comment to reflect pcoinsTip is protected by cs_utxo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment