I want to read a single value from OffchainStorage of a live substrate node. Is it possible? Assume I can not use
localStorageGet rpc request because it is an unsafe rpc.
You can access the data stored in the OffchainStorage using offchain worker threads that have read and write access or through the on-chain logic using offchain indexing.
Read more about Offchain Indexing in the docs.
Offchain indexing allows the runtime to write directly to the offchain storage without using offchain worker threads. You can enable this functionality to persist data by starting a Substrate node with the --enable-offchain-indexing command-line option.
And take a look at this example substrate-offchain-worker-demo.
Before start working with Offchain Workers, I'd recommend read this post in the Polkadot Forum Offchain Workers: Design Assumptions & Vulnerabilities, to understand better possibles vulnerabilities.
I think that's impossible.
offchain-indexing is an option. The node can access the offchain storage only when it enabled this feature. Not every node enables that.
Also, you might notice that there is also a
localStorageSet call, anybody can set the storage if you public this call.
Moreover, the node needs to build the offchain DB from the importing logic from block #0. Every node maintains its own offchain DB. The offchain DB can not sync from other nodes.
So, I think that's why it was marked as unsafe.