8 votes

How can a OCW determine if a node is fully synced?

OCW don't determine if a node is fully synced. It got notified by txpool when new block is imported https://github.com/paritytech/substrate/blob/97ee3d1de19e3f7442b6c0aa4ad360a49d5ea663/client/...
Bryan Chen's user avatar
7 votes

When does an off-chain worker get executed?

OCW's run asynchronously at the end of every block import. You could use a combination of off-chain storage and off-chain indexing. Off-chain Storage to orchestrate when to run the OCW (it does not ...
Bruno's user avatar
  • 8,335
7 votes
Accepted

How can a OCW determine if a node is fully synced?

Adding to what Bryan said, you can just call the RPC system.health. The response isSyncing will be false if the node is in sync. No need for an OCW.
joepetrowski's user avatar
  • 2,945
6 votes
Accepted

How to avoid multiple OCWs duplicating work?

It sounds to me that you are using offchain workers incorrectly. They should not be thought of as trusted applications which can modify your runtime's state or behave in expected ways. In fact, you ...
Shawn Tabrizi's user avatar
  • 16k
5 votes

How to ensure call was made by Offchain Worker

If you're comfortable introducing a layer of permissioning into your design, you could perhaps use the SignedExtension trait. You'd have to keep an on-chain list of OCW identities that are "...
Bernardo Rodrigues's user avatar
5 votes
Accepted

Can I call external APIs inside my pallet?

To add to Sam's post: It should be noted that Offchain Workers are very often misunderstood. It is not trivial just to write some random http request as part of pallet development and expect it to ...
Shawn Tabrizi's user avatar
  • 16k
5 votes

Can I call external APIs inside my pallet?

The Off-chain worker was introduced directly to solve this problem. You can see a full guide on how to do GET/POST requests here Some sample code // We want to keep the offchain worker execution time ...
Sam Elamin's user avatar
  • 1,223
5 votes
Accepted

How to create a transaction that calls an offchain worker?

If you take a look at this diagram: The dotted red lines indicate that the Off-Chain Worker (OCW), although existing in the Substrate Node in tandem with the Substrate Runtime, actually lives in its ...
Bruno's user avatar
  • 8,335
5 votes

How can I create OCW that won't activates every block, but will activates only when I call function that it represents?

There are 3 levels of answer to this question. As OCW being a commonly misunderstood topic, it is a very good question. Simple Answer First, a crude and objectively inefficient answer. You can use the ...
kianenigma's user avatar
  • 2,789
4 votes
Accepted

Process ethereum transactions in an offchain worker

You can use some of the tools from: https://github.com/rust-ethereum/. Namely, if you're looking to create Ethereum transactions in an offchain worker then this should work: https://github.com/rust-...
Drew Stone's user avatar
  • 1,194
4 votes

When does an off-chain worker get executed?

Except your question about ocw, for your target "So before this storage changes I want to use offchain_worker() to dump storage to some http server", I think it's not a great scenario to use ...
ironman_ch_parami's user avatar
4 votes
Accepted

Offchain Worker Not Initializing - Cumulus Parachain Template

You are most likely missing the offchain worker initialisation in the service.rs file, like this https://github.com/substrate-developer-hub/substrate-node-template/blob/...
0xsierra's user avatar
  • 106
3 votes

How to comprehend the hooks of Substrate? Such as `on_initialize`, `on_finialize` and `offchain_worker`

The order is the following: A node imports/start building a block: on_initialize is called for all Pallets in the runtime. All extrinsics are executed/applied. on_finalize is called for all Pallets ...
bkchr's user avatar
  • 11.1k
3 votes
Accepted

Implementing an Identity Management pallet, would be more efficient in a Relay or Parachain?

There is not an easy answers for your questions. First of all I recommend you to take a look to an existing FRAME pallet: Identity pallet that is being used in the relay chains Polkadot and Kusama. ...
Alex Bean's user avatar
  • 5,702
2 votes
Accepted

Is it possible to query an OCW's Off-chain storage via RPC from an external service?

Yes, Custom RPC work for the off-chain runtime. Custom Rpc Doc For example, you can define custom rpc in the following way: #[rpc] public trait SomeOcsApi { #[rpc(name="some_method")] ...
ironman_ch_parami's user avatar
2 votes

Persistent Offchain Worker Storage

I think StorageKind is used to distinguish between different behavior when block revert or fork happens. And, if storage use memory or disk is depends on the DatabaseSettings.source configuration, ...
ironman_ch_parami's user avatar
2 votes

How to avoid multiple OCWs duplicating work?

So the idea of OCW's is that it will do some off-chain "work" and ultimately submit a transaction that will call a public function in the runtime to get the result of that work on-chain. OCW'...
Bruno's user avatar
  • 8,335
2 votes
Accepted

Only one node should make http call from OCW

"And have a question is it possible to configure OCW so that if one node starts an HTTP call in OCW other nodes will skip it", you can add a judgement to make sure only the author of the ...
ironman_ch_parami's user avatar
2 votes

Can we enable off-chain workers http client to support web-sockets request?

Phala Network has a design for Fat Contracts called the SideVM (requires deploying local testnet to use for now). You can check out some examples here Fat Contract Examples. We also enable HTTPS ...
Joshua's user avatar
  • 101
2 votes
Accepted

How to write unit tests for offchain workers?

You need something like this to register the offchain ext. It's a really good example. Check the whole tests.rs.
AurevoirXavier's user avatar
2 votes
Accepted

Can an off-chain worker read/write the state of an EVM contract?

I don't know much about EVM and Frontier, but in general offchain workers cannot write to the state directly, so if they call into a function directly that has some side effect, it will be ignored. ...
kianenigma's user avatar
  • 2,789
2 votes
Accepted

How to enable off-chain workers for parachain via command line?

Are you using the parachain node template from Cumulus? According to the help text, it's only enabled for nodes that are authoring new blocks: ./target/release/parachain-template-node --help --...
Bruno's user avatar
  • 8,335
2 votes

Read a value from offchain storage of a node

You can access the data stored in the OffchainStorage using offchain worker threads that have read and write access or through the on-chain logic using offchain indexing. Read more about Offchain ...
Alex Bean's user avatar
  • 5,702
2 votes
Accepted

Is it possible to write-access Local Storage from the Node?

Yes, there is an RPC method. offchain_localStorageSet you need to enable --offchian-indexing for your node you need to enable --rpc-methods unsafe for your node you'd better don't expose your RPC ...
AurevoirXavier's user avatar
2 votes

AccountId in offchain worker

Bear in mind that a particular node isn't inherently associated with a particular on chain validator. Node X is only validator X because to happens to have the current session keys for that validator. ...
JelliedOwl - Paul's user avatar
2 votes
Accepted

offchain-workers vs asynchronous task

To my understanding, tasks are some client-only properties. OCW has the ability to access the runtime directly. It's much easier to query the storage and submit some off-chain extrinsics. Examples: If ...
AurevoirXavier's user avatar
2 votes

How to fetch data through api?

In the Substrate docs you have this example Make offchain HTTP requests that shows you an example on how to retrieve the price of Bitcoin from the cryptocompare API and how to submit data using an ...
Alex Bean's user avatar
  • 5,702
2 votes

How to establish web socket connection in offchain_worker

Find a relevant package that works in no-std context, for example, embedded-websocket. I managed to establish ws connection to a Substrate chain with the following code: fn offchain_worker(_now: ...
dastansam's user avatar
  • 511
2 votes
Accepted

Substrate Offchain Worker - failed to fetch sample price

You need to allow http requests. https://github.com/paritytech/polkadot-sdk/blob/283d3cc5676417a29783786a41a01680d123f7bb/substrate/client/offchain/src/lib.rs#L112
muharem's user avatar
  • 409
1 vote

How to use "A secure, local entropy source for random number generation" in offchain worker?

For offchain workers there is the random_seed function. This will return you a random seed that you can use to initialize a random number generator.
bkchr's user avatar
  • 11.1k

Only top scored, non community-wiki answers of a minimum length are eligible