From 578edc80bc088d0808e034a2e240a430576db6ca Mon Sep 17 00:00:00 2001 From: arnaubennassar Date: Tue, 16 Mar 2021 11:50:43 +0100 Subject: [PATCH] Fix average transaction fee calculation --- db/historydb/apiqueries.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/db/historydb/apiqueries.go b/db/historydb/apiqueries.go index 6e1bc04..62ee1c6 100644 --- a/db/historydb/apiqueries.go +++ b/db/historydb/apiqueries.go @@ -1138,8 +1138,17 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr } // Set batch frequency metrics.BatchFrequency = seconds / float64(nBatches) - if nTxs > 0 { - metrics.AvgTransactionFee = totalFee / float64(nTxs) + // Set avg transaction fee (only L2 txs have fee) + row = hdb.dbRead.QueryRow( + `SELECT COUNT(*) as total_txs FROM tx WHERE tx.batch_num between $1 AND $2 AND NOT is_l1;`, + p.FromBatchNum, p.ToBatchNum, + ) + var nL2Txs int + if err := row.Scan(&nL2Txs); err != nil { + return nil, tracerr.Wrap(err) + } + if nL2Txs > 0 { + metrics.AvgTransactionFee = totalFee / float64(nL2Txs) } else { metrics.AvgTransactionFee = 0 }