2

As given in the title, I would like to get access to an instance of the backend from a host function.

When I say 'backend instance' here, I'm referring to this. I hope to call its offchain_storage(), and later use that offchain storage instance. My use case here is to call some host function from the runtime to retrieve some expected value stored in the node.

1 Answer 1

2

Offchain storage isn't part of consensus and therefore making the runtime access such storage would lead to non-determinism (since different nodes could have different data there).

If you want to access offchain storage from within an offchain worker then that is already possible without adding new host functions: https://docs.substrate.io/reference/how-to-guides/offchain-workers/offchain-local-storage/.

If you really want to bring in data from offchain storage into the chain then it must be done by submitting an extrinsic with the given data.

3
  • 1
    That answer confirms my thinking. Thanks. Jun 24, 2022 at 18:58
  • Would this advice still apply if the extrinsic data that we want submitted is specific to each node? Jun 28, 2022 at 23:38
  • It's a bit hard to give specific advice as it really depends on your use case, but I think the main point you need to consider is: do you need consensus on this data? I.e. even if the data is specific to each node, do other nodes care about it and need access to it? If yes, then it should be posted on-chain through extrinsics (assuming it's not too much data), if not then it should just be stored locally on each node (maybe using an offchain worker?).
    – André
    Jun 29, 2022 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.