Open sudipghimire533 opened 2 years ago
Because accessing the local storage could easily introduce non determinism. Aka you could accidentally store this value in the state and it could be different per node leading to a different storage root.
We could probably add some api to append data.
Thanks for explaining it. Yeah we should definitely add an api to append data. Also we may try returning an error than just having panic along the way?
No, the panic is "valid" there. You are doing some "illegal" operation, so panicking there is correct.
That also sounds legit though. About having an api to append, is there any blocker? or possible limitation? Maybe I could look on that or someone from parity will
You will want to use the offchain index API https://github.com/paritytech/substrate/pull/5200
We could probably add some api to append data.
Renamed issue accordingly.
For those who happen to land here, here is a quick fix: ( please consider side-effect )
My original intent was ( I was just getting started with substrate & all ) that I need to keep adding incoming parameters in offchain storage block wise. For this purpose, temporary fix was something like:
_TemporaryUse
on_finalize
hook: read all the data from _TemporaryUse
and put it to offchain storage at once under key current_block_numer
and then ::kill
the _TemporaryUse
This however bring unwanted effect depending on how much size and how intensive calculation is required. I however adapted to different approach, might be useful for someone who is still learning.
Also don't know if having an api to append to offchain storage would be worth as not all storage types will be appendable
. So might not be worth to handle such narrow case. Feel free to close this @bkchr if you think so
Sample code:
Given that above function is a extrinsic. This call will fail with panic
Panic message
Expected
As far as I can say, this error arise because we cannot have read access to offchain storage ( and for mutate function we still need read access to reference to previous value on which later we would write ).
It would be wise for us to return a error type rather than doing a panic?
A novice question.
I actually do not understand why reading from offchain storage is not allowed outside offchain worker context. Is it because of possible time consumption if reading large chunk from storage?
Actual context
I am trying to keep a vector of some data in offchain storage, Source of data to this vector is extrinsic call. So it is required that we keep push a data for every call. Is there any idiomatic way to do so?