From 82f24d62d41f22787bb8bc728118a20bebd7bc50 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 3 Aug 2020 14:03:04 -0700 Subject: [PATCH] dont divide by zero if blocks have no messages --- cli/chain.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/chain.go b/cli/chain.go index 4eb8a9aa8..f373422f7 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -438,7 +438,12 @@ var chainListCmd = &cli.Command{ 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) }