arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #581 from hermeznetwork/feature/api-L1-forge-time

Add API metric for time to forge L1 tx
Eduard S eduard@iden3.io
Thu, 25 Feb 2021 16:37:05 +0100
commit

83c256deda84cdae8e20f0870ce60510d5e1f53b

parent

d50ae717101483f68fd9b7789c6a45984c8f260b

5 files changed, 26 insertions(+), 18 deletions(-)

jump to
M api/swagger.yml → api/swagger.yml

@@ -1329,13 +1329,6 @@ timestamp:

type: string description: Moment in which the transaction was added to the pool. format: date-time - batchNum: - type: integer - description: Identifier of a batch. Every new forged batch increases by one the batchNum, starting at 0. - minimum: 0 - maximum: 4294967295 - nullable: true - example: null requestFromAccountIndex: type: string description: >-

@@ -1390,7 +1383,6 @@ token:

$ref: '#/components/schemas/Token' example: amount: '100000000000000' - batchNum: fee: 0 fromAccountIndex: hez:SCC:256 fromBJJ: hez:r_trOasVEk0zNaalOoS9aLedu6mO7jI5XTIPu_zGXoyn

@@ -1438,7 +1430,6 @@ - state

- info - signature - timestamp - - batchNum - requestFromAccountIndex - requestToAccountIndex - requestToHezEthereumAddress

@@ -2812,6 +2803,10 @@ avgTransactionFee:

type: number description: Average fee percentage paid for L2 transactions in the last 24 hours. example: 1.54 + estimatedTimeToForgeL1: + type: number + description: Estimated time needed to forge a L1 transaction, from the time it's added on the smart contract, until it's actualy forged. In seconds. + example: 193.4 additionalProperties: false required: - transactionsPerBatch

@@ -2820,6 +2815,7 @@ - transactionsPerSecond

- totalAccounts - totalBJJs - avgTransactionFee + - estimatedTimeToForgeL1 PendingItems: type: integer description: Amount of items that will be returned in subsequent calls to the endpoint, as long as they are done with same filters. When the value is 0 it means that all items have been sent.
M common/pooll2tx.go → common/pooll2tx.go

@@ -73,7 +73,7 @@ }

// If original Type doesn't match the correct one, return error if txTypeOld != "" && txTypeOld != tx.Type { return nil, tracerr.Wrap(fmt.Errorf("L2Tx.Type: %s, should be: %s", - tx.Type, txTypeOld)) + txTypeOld, tx.Type)) } txIDOld := tx.TxID

@@ -83,7 +83,7 @@ }

// If original TxID doesn't match the correct one, return error if txIDOld != (TxID{}) && txIDOld != tx.TxID { return tx, tracerr.Wrap(fmt.Errorf("PoolL2Tx.TxID: %s, should be: %s", - tx.TxID.String(), txIDOld.String())) + txIDOld.String(), tx.TxID.String())) } return tx, nil
M db/historydb/apiqueries.go → db/historydb/apiqueries.go

@@ -1008,6 +1008,18 @@ `SELECT COUNT(*) AS total_bjjs, COUNT(DISTINCT(bjj)) AS total_accounts FROM account;`)

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 }
M db/historydb/views.go → db/historydb/views.go

@@ -304,12 +304,13 @@ }

// 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
M db/l2db/views.go → db/l2db/views.go

@@ -95,7 +95,6 @@ "state": tx.State,

"info": tx.Info, "signature": tx.Signature, "timestamp": tx.Timestamp, - "batchNum": tx.BatchNum, "requestFromAccountIndex": tx.RqFromIdx, "requestToAccountIndex": tx.RqToIdx, "requestToHezEthereumAddress": tx.RqToEthAddr,