Y-Foundry-Dao / yfd-dapp-core

Governance dApp
GNU Affero General Public License v3.0
2 stars 1 forks source link

[REQUEST] Use block timing based on on chain block average rather than variable estimate #133

Open rayraspberry opened 1 year ago

rayraspberry commented 1 year ago

Is there an existing feature request for this?

Is your feature request related to a problem? Please describe.

Block-time guestimates based on long-term average can change in the relative time depending on validators and network activity. For multi-chain deployment and general use it would be more convenient to use the actual average of block time based on the reported data from the chain itself.

Describe the solution you'd like

something that incorporates this to generate an actual rolling average blocktime. It would only need to be run once when the site is loaded currently utilities/variables/chrono.ts variable CHAIN_SECONDS_PER_BLOCK is used to determine the conversion from blocks to seconds

const resLast = await fetch(`${NETWORKS[network].LCD}/blocks/latest`)

  const latestBlock = await resLast.json()

  const height = parseInt(latestBlock.block.header.height)

  const resOld = await fetch(
    `${NETWORKS[network].LCD}/blocks/${height - 10_000}`,
  )

  const oldBlock = await resOld.json()

  const blockTime =
    (new Date(latestBlock.block.header.time).getTime() -
      new Date(oldBlock.block.header.time).getTime()) /
    10_000

Describe alternatives you've considered

continuing to use CHAIN_SECONDS_PER_BLOCK in the variables/crono.ts file

Anything else?

No response