You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
offchain: double index to overcome overrides (#2360)
# Goal
The goal of this PR is to fix the bug in offchain worker
Closes#2293
There are 2 kinds of errors:
- Some MsaIds have multiple indexed keys which only one of them is valid
(ex: 1394377)
- Some MsaIds have no indexed keys (ex: 1414115)
The main issue is that forks cause overwrites on offchain indexed events
so we had to find a way to fix these overwrites.
# Attempted solution
We are now double indexing any event so that if one of them gets
overwritten the other one would most likely get consumed. To do this we
are getting a pseudo random index from 1 to 1000 and store that event
inside a bucket associated with that block and index. The only tradeoff
is that we have to look at all the buckets for each block inside
offchain worker to fetch these stored events since there is no
`iter_prefix` from inside offchain worker.
# Discussion
- To fix the existing wrong indices I tried to add a runtime but any
code not called from offchain worker context can not access to any
offchain worker related features such as locks and timestamps and ...
- Since adding an extrinsic was the easiest way to handle it added a new
extrinsic (similar to `remark`) which only adds an event to reindexing a
certain msa id. This is not the best solution since we have to spend
some token to reindex but it was the fastest and easiest to do.
Currently it's not free but if desired we can make it free or capacity
supported but will need to ensure it's not going to be abused
- The other way to fix this is to add a new rpc and refactor the code
such that it can be called from this rpc but it was a heavier lift
# Further attempts that didn't work
- Using the Remark event to inject the reindex data doesn't work since
the event only stores the hash of the remark not the data
- Using the Remark Extrinsic to inject the reindex data also doesn't
work since it is only stored temporarily and if the offchain worker does
not run in the the exact time-window that it's available it would be
lost.
# Checklist
- [x] Unit Tests added?
- [x] Benchmarks added?
- [x] Spec version incremented?
0 commit comments