2

I don't think this is possible but is it?

I have data that comes from an API that ultimately needs to be stored onchain which I don't want to risk having done through a Pays::No fn in case the call takes longer than the block.

This seems like one of the only solutions I can find to do this; by creating logic that only specified stored accounts through a Pays::No fn can call on a per interim basis.

But this solution can possibly take longer than the block time since it uses an API call.

There are basically two ways I think I want to do this, either have a user who the blockchain knows who it is to make the http call (possible using Pays:No), or through initialize (same issue in case http takes too long), or have the offchain worker call it but this requires public functions.

Is there any way to have a offchain worker store data without exposing the Call to the public?

Or...Such as, storing the offchain API call in local storage, then allowing anyone to submit that data using an unsigned tx after a certain amount of time? But how safe is storing the data to local storage?

How would you solve this

1 Answer 1

1

Transactions from offchain workers are treated no differently from transactions originating elsewhere.

I suggest adjusting the assumptions you're making about your runtime architecture, so it's completely independent from offchain workers.

If you want to get data fetched by an offchain worker onto your chain, a couple solutions could be

  • a permissioned system where some offchain worker origin/s are trusted and the only ones allowed to set that storage or

  • allow anyone to 'stake' value when propose new data, and a mechanism to slash dishonest actors

4
  • What about not using an offchain worker with an API call? Wouldn't this be a huge risk if the API call + computation doesn't complete by the end of the block?
    – bobby dy
    Commented Feb 1 at 16:49
  • I see, so basically you're saying instead of calling through http, just require users to send the data in? because it technically works this way. instead of calling, we could allow a gasless tx with slashing if not honest
    – bobby dy
    Commented Feb 1 at 18:49
  • Pallet method that accepts data, offchain worker makes api call and calls the pallet with the data it fetched. From the POV of the pallet it doesn't know it's an offchain worker that'll usually be calling it. The offchain worker just automates what would otherwise be a laborious manual task of periodically calling the pallet.
    – liamaharon
    Commented Feb 2 at 5:36
  • 1
    I ended up going with the route of not using an offchain worker and instead requiring multiple users to send the data in using Pays::No tx so its gasless with rate limiters. this allows to blockchain to know whos calling it and whos allowed and how often. using offchain + unsigned leaves all the functions public
    – bobby dy
    Commented Feb 5 at 15:06

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.