I have an Off Chain Worker that validates some data in IPFS and then calls a function on chain to set the status to valid or invalid. That's all working fine.
However, I do not need all nodes to validate all of the data. To avoid wasting node resources I would like to rotate the work of validation between nodes. For example, imagine my network has 5 nodes, on block 1 node 1 runs the validation, on block 2 node 2, on block 3 node 3 etc.
Given that it doesn't matter if there are occasional blocks when 2 nodes run validation or blocks when no node does, my idea has been to use a random number generator in the off chain worker for each node to decide whether to do validation or not. The offchain worker would do something like this:
let peer_count = no. of peers
let random_int = random integer between 0 and peer_count
if random_int == 0 {Carry out the valdiation}
else { quit }
So in my example with 5 nodes, each node will do the validation, on average, once every 5 blocks.
Here's my question - how do I get the no. of peers?