arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #641 from hermeznetwork/fix/avg-tx-price

Fix average transaction fee calculation
Eduard S eduard@iden3.io
Thu, 18 Mar 2021 10:24:25 +0100
commit

e78fd613c619836162530a547f1a45069a830224

parent

9edbd135ef9c2a7fe64f5002dae01cb42bc29ada

1 files changed, 11 insertions(+), 2 deletions(-)

jump to
M db/historydb/apiqueries.go → db/historydb/apiqueries.go

@@ -1146,8 +1146,17 @@ return nil, tracerr.Wrap(err)

} // 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 }