ord icon indicating copy to clipboard operation
ord copied to clipboard

Please can we have a batch blockhash endpoint to provide a source of global/permanent pseudorandom values for onchain games?

Open ZedZeroth opened this issue 6 months ago • 17 comments

Games need random values that are permanently accessible to all players / the whole system so that "everyone" knows what the outcome was.

Examples could be (1) whether one player hits or misses another, (2) what the weather is/was at any given time, (3) whether any kind of random event happens or didn't happen.

Blockhashes are an ideal source of such (psuedo) random data for onchain games. Players cannot easily manipulate blockhashes so their value is unpredictable. Once they have been produced they remain static and provide the same value for all ordinals forever.

I have implemented such randomness in my "chaindrop lottery" that determines whether certain ordinals in the collection receive upgrades or not: https://palindromes.io/flowers/

I am pulling the historic fortnightly difficulty adjustment retarget blockhashes, but these sequential requests are currently the primary bottleneck slowing down the loading of the ordinals:

async harvest(bgn,inc,end){ if(!end)end=parseInt(await this.rec.text('/blockheight'),10); let hsh=[]; for(let i=bgn;i<=end;i+=inc){ const h=await this.rec.text('/blockhash/'+i); hsh.push(h)} return hsh} }

Ideally such an endpoint would include parameters for "start block", "increment" and "end block", and then return a JSON array of all relevant blockhashes. In my case, I start on the first DA blockhash after the halving (840672) then increment by 2016 until the current block height is reached. I think this is sustainable as it only requires an additional 26 blockhashes per year. ~~If performance is a concern, then the parameters of the endpoint could be limited to daily/weekly/fortnightly increments.~~ [Edit: @gmart7t2 says that pagination should fix this]

Unless there is an alternative source of continually generated and permanently stored random values, then I think such an endpoint is essential for the creation of fully functional onchain games.

Thanks

Edit - I think the essential features are:

  1. New values are regularly generated.
  2. The values themselves are unpredictable/random (cannot be manipulated).
  3. The values are stored permanently so that they can always be referred to.

I can't think of any other viable source of such new permanent random data.

ZedZeroth avatar Jul 30 '24 12:07 ZedZeroth