1

While experimenting with importing addresses and keys via json rpc I noticed that importing an address twice triggers two rescans. This strikes me as very odd. My question is:

  • Is this intended behaviour and if so, what is the reasoning behind it?
  • OR: Is this a bug? If so, is it a known bug?
1

Calling importaddress will rescan the whole blockchain in default according to bitcoin.org

Set rescan parameter to false to not rescan the block database (rescanning can be performed at any time by restarting Bitcoin Core with the -rescan command-line argument). Rescanning may take several minutes.


help importaddress

importaddress "address" ( "label" rescan p2sh )

Adds a script (in hex) or address that can be watched as if it were in your wallet but cannot be used to spend. Requires a new wallet backup.

Arguments:
1. "script" (string, required) The hex-encoded script (or address)
2. "label" (string, optional, default="") An optional label
3. rescan (boolean, optional, default=true) Rescan the wallet for transactions
4. p2sh (boolean, optional, default=false) Add the P2SH version of the script as well

Note: This call can take minutes to complete if rescan is true, during that time, other rpc calls may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.
If you have the full public key, you should call importpubkey instead of this.

Note: If you import a non-standard raw script in hex form, outputs sending to it will be treated as change, and not show up in many RPCs.

Examples:

Import a script with rescan
bitcoin-cli importaddress "myscript"

Import using a label without rescan
bitcoin-cli importaddress "myscript" "testing" false


UPDATE Since Bitcoin core v0.14 you can use importmulti to import addresses.

bitcoin-cli importmulti '
  [
    {
      "scriptPubKey" : { "address": "1NL9w5fP9kX2D9ToNZPxaiwFJCngNYEYJo" },
      "timestamp" : "0",
      "label" : "Personal",
      "watchonly": true
    },
    {
      "scriptPubKey" : "76a9149e857da0a5b397559c78c98c9d3f7f655d19c68688ac",
      "timestamp" : 1493912405,
      "label" : "TestFailure"
    }
  ]' '{ "rescan": true }'

Response:

 [
{
  "success": true
}, 
{
  "success": false,
  "error": {
  "code": -8,
  "message": "Internal must be set for hex scriptPubKey"
  }
}
]

Note:

  • Bech32 addresses are not supported using this method until the moment. (You're free to edit this answer when it's available.)
  • importmulti will not speed up importing progress since this method locks your wallet and block any further RPC calls.
  • But if an address has already been imported earlier why would it trigger the rescan again? That seems very odd. The node could simply do nothing in that case and all would be fine, and a lot of CPU time saved. – blues Nov 28 '17 at 8:55
  • Bitcoin core commands is like for advanced users and it's not an interface you can just use bitcoin-qt instead. in your case if you would like to use bitcoin-cli you can check if address not exist you can call importaddress – Adam Nov 28 '17 at 8:59
  • So what you are telling me is that it is a bug, but a workaround exists by checking first? A rescan of an address that is already in the wallet and was rescanned for before can never result in any new information. – blues Nov 28 '17 at 9:12
  • I have taken the liberty of adding further info about importaddress to your answer. – Willtech Apr 4 '18 at 4:03
  • Now it's even better! @Willtech – Adam Apr 5 '18 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.