Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Updated Average Block Time #548

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [UNRELEASED]
* [#523] Implemented readable messages for IBC messages

* [#542] Removed `defaultBlockTime` from default_settings.json and updated average block time calculations.
## [v0.41.x-14.2]
* Fixes Ledger WebUSB + Chrome 91.x issue (https://github.com/LedgerHQ/ledgerjs/issues/607)

Expand Down
2 changes: 1 addition & 1 deletion default_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"chainName": "Cosmos",
"chainId": "{Chain ID}",
"gtm": "{Add your Google Tag Manager ID here}",
"genesisTime": "",
"slashingWindow": 10000,
"uptimeWindow": 250,
"initialPageSize": 30,
Expand Down Expand Up @@ -53,7 +54,6 @@
},
"params":{
"startHeight": 0,
"defaultBlockTime": 5000,
"validatorUpdateWindow": 300,
"blockInterval": 15000,
"transactionsInterval": 18000,
Expand Down
5 changes: 2 additions & 3 deletions imports/api/blocks/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,19 @@ Meteor.methods({
let chainStatus = Chain.findOne({chainId:block.block.header.chain_id});
let lastSyncedTime = chainStatus?chainStatus.lastSyncedTime:0;
let timeDiff;
let blockTime = Meteor.settings.params.defaultBlockTime;
let blockTime = 0;
if (lastSyncedTime){
let dateLatest = new Date(blockData.time);
let dateLast = new Date(lastSyncedTime);
let genesisTime = new Date(Meteor.settings.public.genesisTime);
timeDiff = Math.abs(dateLatest.getTime() - dateLast.getTime());
// blockTime = (chainStatus.blockTime * (blockData.height - 1) + timeDiff) / blockData.height;
blockTime = (dateLatest.getTime() - genesisTime.getTime()) / blockData.height;
}

let endGetValidatorsTime = new Date();
console.log("Get height validators time: "+((endGetValidatorsTime-startGetValidatorsTime)/1000)+"seconds.");

Chain.update({chainId:block.block.header.chainId}, {$set:{lastSyncedTime:blockData.time, blockTime:blockTime}});
Chain.update({chainId:block.block.header.chain_id}, {$set:{lastSyncedTime:blockData.time, blockTime:blockTime}});

analyticsData.averageBlockTime = blockTime;
analyticsData.timeDiff = timeDiff;
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/home/ChainStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ChainStatus extends React.Component {
switch (this.state.avgBlockTimeType){
case "":
this.setState({
averageBlockTime: numbro(this.props.status.blockTime/1000).format('0,0.00')
averageBlockTime: numbro(this.props.status.blockTime > 0 ? this.props.status.blockTime / 1000 : 0).format('0,0.00')
})
break;
case "m":
Expand Down