for example the blockchain is upgraded at 1000 height(including systems code updates event), and I need to decode the storage data by metadata at 1000 height, which metadata do I need to use, is it the latest one? or the old metadata of 999 height?
If you do the upgrade at block 1000, aka setting the
:code storage item, the new runtime will be used for building block 1001.
There is actually an open issue about this topic, as the block that sets the storage item isn't running potential migrations directly. So, you currently get the "wrong" metadata when querying block 1000. Substrate will already return you the metadata of the new runtime while it should return the metadata of the old runtime.
So to your question, to decode items at height 1000, you should use the metadata of height 999.