mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add API metric for time to forge L1 tx
This commit is contained in:
@@ -1008,6 +1008,18 @@ func (hdb *HistoryDB) GetMetricsAPI(lastBatchNum common.BatchNum) (*Metrics, err
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
err = meddler.QueryRow(
|
||||
hdb.dbRead, metrics,
|
||||
`SELECT COALESCE (AVG(EXTRACT(EPOCH FROM (forged.timestamp - added.timestamp))), 0) AS estimatedTimeToForgeL1 FROM tx
|
||||
INNER JOIN block AS added ON tx.eth_block_num = added.eth_block_num
|
||||
INNER JOIN batch AS forged_batch ON tx.batch_num = forged_batch.batch_num
|
||||
INNER JOIN block AS forged ON forged_batch.eth_block_num = forged.eth_block_num
|
||||
WHERE tx.batch_num between $1 and $2 AND tx.is_l1 AND tx.user_origin;`,
|
||||
metricsTotals.FirstBatchNum, lastBatchNum,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
return metrics, nil
|
||||
}
|
||||
|
||||
@@ -304,12 +304,13 @@ type BatchAPI struct {
|
||||
|
||||
// Metrics define metrics of the network
|
||||
type Metrics struct {
|
||||
TransactionsPerBatch float64 `json:"transactionsPerBatch"`
|
||||
BatchFrequency float64 `json:"batchFrequency"`
|
||||
TransactionsPerSecond float64 `json:"transactionsPerSecond"`
|
||||
TotalAccounts int64 `json:"totalAccounts" meddler:"total_accounts"`
|
||||
TotalBJJs int64 `json:"totalBJJs" meddler:"total_bjjs"`
|
||||
AvgTransactionFee float64 `json:"avgTransactionFee"`
|
||||
TransactionsPerBatch float64 `json:"transactionsPerBatch"`
|
||||
BatchFrequency float64 `json:"batchFrequency"`
|
||||
TransactionsPerSecond float64 `json:"transactionsPerSecond"`
|
||||
TotalAccounts int64 `json:"totalAccounts" meddler:"total_accounts"`
|
||||
TotalBJJs int64 `json:"totalBJJs" meddler:"total_bjjs"`
|
||||
AvgTransactionFee float64 `json:"avgTransactionFee"`
|
||||
EstimatedTimeToForgeL1 float64 `json:"estimatedTimeToForgeL1" meddler:"estimatedTimeToForgeL1"`
|
||||
}
|
||||
|
||||
// MetricsTotals is used to get temporal information from HistoryDB
|
||||
|
||||
Reference in New Issue
Block a user