From 2b5c7352996dcd94d8d66aa2f6dd564e7485af87 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 26 Aug 2024 11:32:23 +0800 Subject: [PATCH] core: avoid zero division --- core/blockchain.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 7a80d5001e..8ba5b670ee 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1957,9 +1957,12 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s accountRead := statedb.SnapshotAccountReads + statedb.AccountReads // The time spent on account read storageRead := statedb.SnapshotStorageReads + statedb.StorageReads // The time spent on storage read - accountReadSingleTimer.Update(accountRead / time.Duration(statedb.AccountLoaded)) - storageReadSingleTimer.Update(storageRead / time.Duration(statedb.StorageLoaded)) - + if statedb.AccountLoaded != 0 { + accountReadSingleTimer.Update(accountRead / time.Duration(statedb.AccountLoaded)) + } + if statedb.StorageLoaded != 0 { + storageReadSingleTimer.Update(storageRead / time.Duration(statedb.StorageLoaded)) + } accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation) storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation) accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation)