mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #641 from hermeznetwork/fix/avg-tx-price
Fix average transaction fee calculation
This commit is contained in:
@@ -1146,8 +1146,17 @@ func (hdb *HistoryDB) GetMetricsInternalAPI(lastBatchNum common.BatchNum) (*Metr
|
|||||||
}
|
}
|
||||||
// Set batch frequency
|
// Set batch frequency
|
||||||
metrics.BatchFrequency = seconds / float64(nBatches)
|
metrics.BatchFrequency = seconds / float64(nBatches)
|
||||||
if nTxs > 0 {
|
// Set avg transaction fee (only L2 txs have fee)
|
||||||
metrics.AvgTransactionFee = totalFee / float64(nTxs)
|
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 {
|
} else {
|
||||||
metrics.AvgTransactionFee = 0
|
metrics.AvgTransactionFee = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user