From 94a13605423418b2d5f39f7b7749508e2c3158a1 Mon Sep 17 00:00:00 2001 From: Bitxx <> Date: Wed, 28 Feb 2024 20:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=B1=95=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 14 +++++++------- app/zkf/zkf.go | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/app.go b/app/app.go index 8f3ab6a..5937033 100644 --- a/app/app.go +++ b/app/app.go @@ -42,7 +42,7 @@ func (a *App) ScanAllTransactions() { tx := appModel.Transaction{} err := a.db.Last(&tx).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - log.Errorf("txScan => get latest local block error: %s", err.Error()) + log.Errorf("[txScan] => get latest local block error: %s", err.Error()) continue } // 此时如果err不为空,则说明ErrRecordNotFound,也就是 blockNumStart = 1 @@ -54,13 +54,13 @@ func (a *App) ScanAllTransactions() { //获取块结束 blockNumEnd, err := a.client.LatestBlockNumber() if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - log.Errorf("txScan => get latest chain block error: %s", err.Error()) + log.Errorf("[txScan] => get latest chain block error: %s", err.Error()) continue } //不断追最新块 if blockNumStart < blockNumEnd { - log.Infof("txScan => new scanning, block from %d to %d", blockNumStart, blockNumEnd) + log.Infof("[txScan] => new scanning, block from %d to %d", blockNumStart, blockNumEnd) a.ScanTransactionsByNumber(blockNumStart, blockNumEnd) blockNumStart = blockNumEnd + 1 } @@ -93,7 +93,7 @@ func (a *App) ScanTransactionsByNumber(blockNumStart, blockNumEnd uint64) { for { transactions, err = a.client.TxReceiptByBlockNumber(i) if err != nil { - log.Errorf("txScan => block: %d,transactions error: %s", i, err.Error()) + log.Errorf("[txScan] => block: %d,transactions error: %s", i, err.Error()) time.Sleep(constant.TimeSleep) continue } @@ -146,7 +146,7 @@ func (a *App) saveTransactions(txsCh chan chan []appModel.Transaction, blockNumS //展示扫描情况 for _, tx := range txs { - log.Infof("txScan => scanning ... block number: %d, tx count: %d", tx.BlockNumber, len(txs)) + log.Infof("[txScan] => scanning ... block number: %d, tx count: %d", tx.BlockNumber, len(txs)) break } @@ -156,11 +156,11 @@ func (a *App) saveTransactions(txsCh chan chan []appModel.Transaction, blockNumS for { err := a.db.Create(a.txCache).Error if err != nil { - log.Errorf("txScan => batch insert error, begin block: %d, end block: %d, error info: %s", a.txCache[0].BlockNumber, a.txCache[len(a.txCache)-1].BlockNumber, err) + log.Errorf("[txScan] => batch insert error, begin block: %d, end block: %d, error info: %s", a.txCache[0].BlockNumber, a.txCache[len(a.txCache)-1].BlockNumber, err) time.Sleep(constant.TimeSleep) continue } - log.Infof("txScan => batch insert success, begin block: %d, end block: %d", a.txCache[0].BlockNumber, a.txCache[len(a.txCache)-1].BlockNumber) + log.Infof("[txScan] => batch insert success, begin block: %d, end block: %d", a.txCache[0].BlockNumber, a.txCache[len(a.txCache)-1].BlockNumber) break } a.txCache = []appModel.Transaction{} diff --git a/app/zkf/zkf.go b/app/zkf/zkf.go index 1828af8..42b245b 100644 --- a/app/zkf/zkf.go +++ b/app/zkf/zkf.go @@ -49,13 +49,13 @@ func (z *ZKF) StatGas() { // @receiver z func (z *ZKF) statGasByTableName(tableName string) { if tableName != zkfModel.HourTable && tableName != zkfModel.DailyTable && tableName != zkfModel.WeeklyTable { - log.Error("zkf => table name %s is error", tableName) + log.Errorf("[zkf] => table name %s is error", tableName) return } //UTC启动时间 dateStart, err := dateutil.ParseStrToTime("2024-01-14 00:00:00", "UTC", -1) if err != nil { - log.Error("zkf => get default start date error: ", err) + log.Errorf("[zkf] => get default start date error: %s", err.Error()) return } dateEnd := dateStart @@ -69,7 +69,7 @@ func (z *ZKF) statGasByTableName(tableName string) { zkfStat := zkfModel.ZkfStatGas{} err := z.db.Table(tableName).Last(&zkfStat).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { - log.Errorf("zkf => [%s] get latest gas stat info error: %s", tableName, err.Error()) + log.Errorf("[zkf] => [%s] get latest gas stat info error: %s", tableName, err.Error()) continue } @@ -101,11 +101,11 @@ func (z *ZKF) statGasByTableName(tableName string) { row := z.db.Model(&appModel.Transaction{}).Select("IFNULL(sum(gas_used * effective_gas_price),0),IFNULL(sum(effective_gas_price),0),IFNULL(min(block_number),0),IFNULL(max(block_number),0),IFNULL(max(created_at),now()),IFNULL(count(1),0)").Where("created_at>=? and created_at<=?", dateStart, dateEnd).Row() err = row.Scan(&totalGasFee, &totalGasPrice, &minBlockNumber, &maxBlockNumber, &maxBlockNumberDate, &count) if err != nil { - log.Error("zkf => [%s] stat gas data err: %s", flag, err.Error()) + log.Error("[zkf] => [%s] stat gas data err: %s", flag, err.Error()) continue } if count <= 0 { - log.Warnf("zkf => [%s] tx data is empty", flag) + log.Warnf("[zkf] => [%s] tx data is empty", flag) continue } @@ -113,7 +113,7 @@ func (z *ZKF) statGasByTableName(tableName string) { tx := appModel.Transaction{} err = z.db.Last(&tx).Error if err != nil { - log.Error("zkf => [%s] get latest tx err: %s", flag, err.Error()) + log.Error("[zkf] => [%s] get latest tx err: %s", flag, err.Error()) continue } if tx.CreatedAt.Compare(dateEnd) > 0 { @@ -135,12 +135,12 @@ func (z *ZKF) statGasByTableName(tableName string) { row := z.db.Table(tbName).Select("IFNULL(sum(total_gas_fee),0),IFNULL(sum(total_gas_price),0),IFNULL(min(block_start),0),IFNULL(max(block_end),0),IFNULL(max(date_end),now()),IFNULL(sum(total_tx_count),0)").Where("date_start>=? and date_end<=?", dateStart, dateEnd).Row() err = row.Scan(&totalGasFee, &totalGasPrice, &minBlockNumber, &maxBlockNumber, &maxBlockNumberDate, &count) if err != nil { - log.Error("zkf => [%s] stat gas data err: %s", flag, err.Error()) + log.Error("[zkf] => [%s] stat gas data err: %s", flag, err.Error()) continue } if count <= 0 { - log.Warnf("zkf => [%s] %s data is empty", flag, tbName) + log.Warnf("[zkf] => [%s] %s data is empty", flag, tbName) continue } @@ -148,7 +148,7 @@ func (z *ZKF) statGasByTableName(tableName string) { zkfStatGas := zkfModel.ZkfStatGas{} err = z.db.Table(tbName).Last(&zkfStatGas).Error if err != nil { - log.Errorf("zkf => [%s] get latest tx err: %s", flag, err.Error()) + log.Errorf("[zkf] => [%s] get latest tx err: %s", flag, err.Error()) continue } if zkfStatGas.DateEnd.Compare(dateEnd) > 0 { @@ -186,6 +186,6 @@ func (z *ZKF) statGasByTableName(tableName string) { } z.db.Table(tableName).Save(&result) - log.Infof("zkf => calc over [%s] start block %d, end block %d", flag, minBlockNumber, maxBlockNumber) + log.Infof("[zkf] => [%s] calc over. start block %d, end block %d", flag, minBlockNumber, maxBlockNumber) } }