(This is based on #9682 to avoid merge conflicts in importmulti.py. Only the two commits “Dedup nTimeFirstKey update logic” and “Use importmulti timestamp when importing watch only keys” pertain to this PR. The other three commits belong to #9682).
This fixes issue #9034.
When importing a watch-only address over importmulti with a specific timestamp, the wallet’s nTimeFirstKey is currently set to 1. After this change, the provided timestamp will be used and stored as metadata associated with watch-only key. This can improve wallet performance because it can avoid the need to scan the entire blockchain for watch only addresses when timestamps are provided.