importprivkey found bitcoins even with rescan set to false #10666

issue FrozenPrincess opened this issue on June 24, 2017
  1. FrozenPrincess commented at 5:30 AM on June 24, 2017: none

    I imported a private key to a funded address with importprivkey {privateKey} "" false expecting that the wallet would only know about future transactions to this address. However it immediately found the funds (which had 4 confirmations), despite rescan set to false. My expectation was that it would only find funds for future transactions. Looking at the source code I can't see how this would happen and how many blocks it actually does scan back.

    I'm not sure if the current behavior is intended or not, but it could be made a lot more clear

  2. laanwj commented at 9:48 AM on June 24, 2017: member

    Did it do a rescan? (hard to miss, your node would hang for some time and it prints to debug.log)

  3. laanwj added the label Wallet on Jun 24, 2017
  4. FrozenPrincess commented at 6:13 PM on June 24, 2017: none

    Yeah, there was no rescan. I am able to reproduce by:

    Create an address on bitaddress.org Send some bitcoin to that address Wait until the bitcoin have got a couple of confirmations Check the balance Import private key with false set for rescan Check the balance, and see that it found the money

  5. FrozenPrincess commented at 6:15 PM on June 24, 2017: none

    I'm also totally sure I didn't run with rescan, because if I try:

    Rescan is disabled in pruned mode (code -4)

  6. laanwj added the label RPC/REST/ZMQ on Jun 28, 2017
  7. achow101 commented at 4:03 PM on October 5, 2017: member

    we were able to see the coins associated with the imported privkeys instantly.

    What made you think that would happen? The wallet only knows about your coins if it rescans the blockchain. If you don't have it rescan, then it won't know about any of your coins.

    The call returned w/o an error but the coins did not show up

    As is expected.

    repeating the same importprivkey with rescan=true had no effect.

    What exactly is the command you are running?

  8. jonasschnelli commented at 3:44 AM on October 7, 2017: contributor

    random though: do you import an HD derived private key that uses the same seed and derivation-path than core does (maybe exported your xpriv via dumpwallet)?

    Or: do you have "rescan=1" in your bitcoin.conf?

  9. FrozenPrincess commented at 3:49 AM on October 7, 2017: none

    random though: do you import an HD derived private key that uses the same seed and derivation-path than core does (maybe exported your xpriv via dumpwallet)?

    No. The issue is easily reproducible with arbitrary addresses

    Or: do you have "rescan=1" in your bitcoin.conf?

    Nope

  10. MarcoFalke commented at 7:50 AM on October 7, 2017: member

    Transforming your description into a python test, I could not reproduce on current master:

            # clean chain. set up nodes[1] with "-prune=550". Mine 101 blocks on nodes[0]
    
            address_new = self.nodes[0].getnewaddress()
            self.nodes[0].sendtoaddress(address_new, 0.1)
            self.nodes[0].generate(4)
            self.nodes[1].importprivkey(privkey=self.nodes[0].dumpprivkey(address_new), rescan=False)
            assert self.nodes[1].getbalance() == 0
    
  11. meshcollider commented at 4:10 AM on October 10, 2017: contributor

    Did you send the coins to the new address from the wallet you are importing into? If so I'd imagine the transaction would already be 'yours' as a sent transaction in the wallet, might be the cause.

    Edit: indeed, a test along these lines reproduces the behaviour:

    # clean chain. set up nodes[1] with "-prune=550"
    
    address_new = self.nodes[0].getnewaddress()
    self.nodes[1].generate(101)
    self.nodes[1].sendtoaddress(address_new, 49)
    self.nodes[1].generate(1)
    balance_before = self.nodes[1].getbalance()
    self.nodes[1].importprivkey(privkey=self.nodes[0].dumpprivkey(address_new), rescan=False)
    assert self.nodes[1].getbalance() == balance_before
    

    Test fails with nearly all 100 mature BTC left, just minus the fee for the transaction. Issue probably should be closed then

  12. MarcoFalke closed this on Oct 10, 2017

  13. 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-13 15:15 UTC

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