Expected behavior:
importaddress
orimportpubkey
a watching-only address or pubkey with a label- Receive a transaction to that address; observe that the label has been applied to that transaction
importprivkey
the private key for that address without specifying any change to the label- Have the previous label still applied to the transaction after the import.
Observed behavior on 0.15 and current master:
Steps 1-3 the same. 4. Previous label is replaced with the default empty label ("")
Problem seems to have occurred on 0.15 and affects the latest master (see subsequent details). I’d suspect all versions are affected, i.e. it’s not a regression.
Steps to reproduce
0## For testing
1ADDRESS=2N6Y2wdhd91mQnZ8qCeH6hT5aZZygXFnNjP
2PRIVKEY=cQriWp98xU9ghRvDKbzkRcgcecQLezjYwtPUjLNN5kzT8GbdnxQt
3
4## Starting a fresh regtest (i.e. ~/.bitcoin/regtest/ previously deleted)
5$ bitcoind -daemon -regtest
6Bitcoin server starting
7
8## Import the address with a label and no rescan
9$ bitcoin-cli -regtest importaddress $ADDRESS "Watch-only test" false
10
11## Mine a generation tx to the address (regular spending works too)
12$ bitcoin-cli -regtest generatetoaddress 1 $ADDRESS > /dev/null
13
14## Bury the generation tx so it shows up in the wallet
15$ bitcoin-cli -regtest generate 100 > /dev/null
16
17## See that the address label was applied to the tx
18$ bitcoin-cli -regtest listunspent | jq .[].label
19"Watch-only test"
20
21## Import the private key. Note the 'label' parameter is not explicitly passed
22$ bitcoin-cli -regtest importprivkey $PRIVKEY
23
24## See that the address label has been set to empty :-(
25$ bitcoin-cli -regtest listunspent | jq .[].label
Same thing happens if importpubkey
is substituted for importaddress
. I haven’t tested importmulti
for either address/pubkey or privkey import, nor have I tested using named parameters.
Use case
I was watching-only addresses from my cold wallet, then moved my coins to new addresses and (after some confirmations) imported the old private keys so that I could sell fork coins. I didn’t realize until now when I was trying to do some bookkeeping that all my old cold wallet labels were reset (happily, I have backups, so nothing is lost but time).
Possibly related issues
- #12698 looks related but the poster there says that it works on mainnet. I discovered my problem from actual use on mainnet and reproduced on regtest.