Merge pull request #2790 from filecoin-project/feat/fix-chain-gas-stats

dont divide by zero if blocks have no messages
This commit is contained in:
Łukasz Magiera 2020-08-03 23:06:41 +02:00 committed by GitHub
commit b6cf4964df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -438,7 +438,12 @@ var chainListCmd = &cli.Command{
psum = big.Add(psum, m.Message.GasPrice) psum = big.Add(psum, m.Message.GasPrice)
} }
avgprice := big.Div(psum, big.NewInt(int64(len(msgs.BlsMessages)+len(msgs.SecpkMessages)))) lenmsgs := len(msgs.BlsMessages) + len(msgs.SecpkMessages)
avgprice := big.Zero()
if lenmsgs > 0 {
avgprice = big.Div(psum, big.NewInt(int64(lenmsgs)))
}
fmt.Printf("\t%s: \t%d msgs, gasLimit: %d / %d (%0.2f%%), avgPrice: %s\n", b.Miner, len(msgs.BlsMessages)+len(msgs.SecpkMessages), limitSum, build.BlockGasLimit, 100*float64(limitSum)/float64(build.BlockGasLimit), avgprice) fmt.Printf("\t%s: \t%d msgs, gasLimit: %d / %d (%0.2f%%), avgPrice: %s\n", b.Miner, len(msgs.BlsMessages)+len(msgs.SecpkMessages), limitSum, build.BlockGasLimit, 100*float64(limitSum)/float64(build.BlockGasLimit), avgprice)
} }