-
Notifications
You must be signed in to change notification settings - Fork 243
Updated Average Block Time #548
base: master
Are you sure you want to change the base?
Conversation
imports/api/blocks/server/methods.js
Outdated
timeDiff = Math.abs(dateLatest.getTime() - dateLast.getTime()); | ||
// blockTime = (chainStatus.blockTime * (blockData.height - 1) + timeDiff) / blockData.height; | ||
blockTime = (dateLatest.getTime() - genesisTime.getTime()) / blockData.height; | ||
blockTime = (height - blockDiff > 0) ? ((dateLatest.getTime() - pastBlockTime.getTime()) / blockDiff) : (dateLatest.getTime() - pastBlockTime.getTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MonikaCat can you explain the whole logic here?
In the original implementation, averageBlcokTime
= lastBlockTime
- genesisTime
/ blockHeight
. This is always true for the idea of average block time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the genesis time value had been removed from the settings.json file, we cannot calculate the average block time by using averageBlockTime = lastBlockTime - genesisTime / blockHeight
. To handle the calculations, I initially added averageBlockTimeWindow in settings.json file to calculate the average block time of last n blocks...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, I changed the approach and I've just updated the code to calculate average block time starting from the startHeight height set in params in settings.json file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... I have missed the genesisTime
in the default_settings.json
. It should be there as this is how the average block time is being calculated. Querying from chain is not feasible as the genesis could be huge. The size on cosmoshub-4
can't even give a full response if we query from the api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! Alright I will update the code to include genesisTime
calculations again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, how does it do now?
Description
Fixes #542
Checklist
meteor npm run lint
CHANGELOG.md
file.Files changed
in the Github PR explorer.