paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

Adding data to offchain-storage from running asynchronous task. #14320

Closed Haider-Ali-DS closed 1 year ago

Haider-Ali-DS commented 1 year ago

Is there an existing issue?

Experiencing problems? Have you tried our Stack Exchange first?

Discussed in https://github.com/paritytech/substrate/discussions/14319

Originally posted by **Haider-Ali-DS** June 7, 2023 Hey i want to add data to offchain-storage from asynchronous task running in `task_manager`. i tried to use runtime_api to get access to pallet calls and then tried adding data to offchain_storage but its not working as expected and giving error. ``` Thread 'tokio-runtime-worker' panicked at 'Accessing a forbidden API: local_storage_set. No: OFFCHAIN_DB_WRITE capability.', /Users/abc/.cargo/git/checkouts/substrate-7e08433d4c370a21/7c195bf/primitives/core/src/offchain/mod.rs:520 ``` my main concern is to add data `onchain db` (submit extrinsic) from asynchronous task and for that, I am trying to use offchain_worker for submitting transactions. By using ```task_manager_service -> runtime_api -> pallet_call(add offchain_data) -> offchain_worker(getdata) -> submit extrinsic``` Any guide how can i achieve my end goal or any working approach for this problem?
Haider-Ali-DS commented 1 year ago

we can pass backend client which exposes a interface to offchain worker for our tasks and we can use them instead.