Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importprivkey found bitcoins even with rescan set to false #10666

Closed
FrozenPrincess opened this issue Jun 24, 2017 · 8 comments

Comments

Projects
None yet
6 participants
@FrozenPrincess
Copy link

commented Jun 24, 2017

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

@laanwj

This comment has been minimized.

Copy link
Member

commented Jun 24, 2017

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

@laanwj laanwj added the Wallet label Jun 24, 2017

@FrozenPrincess

This comment has been minimized.

Copy link
Author

commented Jun 24, 2017

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

@FrozenPrincess

This comment has been minimized.

Copy link
Author

commented Jun 24, 2017

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

Rescan is disabled in pruned mode (code -4)

@laanwj laanwj added the RPC/REST/ZMQ label Jun 28, 2017

@achow101

This comment has been minimized.

Copy link
Member

commented Oct 5, 2017

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?

@jonasschnelli

This comment has been minimized.

Copy link
Member

commented Oct 7, 2017

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?

@FrozenPrincess

This comment has been minimized.

Copy link
Author

commented Oct 7, 2017

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

@MarcoFalke

This comment has been minimized.

Copy link
Member

commented Oct 7, 2017

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

This comment has been minimized.

Copy link
Member

commented Oct 10, 2017

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

@MarcoFalke MarcoFalke closed this Oct 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.