From 672b000360a2f4e62ffcb09369b06b680ad0ae36 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Thu, 15 Sep 2022 21:41:35 +0800 Subject: [PATCH 1/3] replace return err with log for lastDbBlockHeight in parse blocks cmd --- cmd/parse/blocks/blocks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/parse/blocks/blocks.go b/cmd/parse/blocks/blocks.go index 884147ba..15074eb6 100644 --- a/cmd/parse/blocks/blocks.go +++ b/cmd/parse/blocks/blocks.go @@ -47,7 +47,7 @@ will be replaced with the data downloaded from the node. lastDbBlockHeight, err := parseCtx.Database.GetLastBlockHeight() if err != nil { - return err + log.Error().Msgf("error while getting last DB block height: %s", err.Error()) } // Compare start height from config file and last block height in database From fad97d06bee06ca2b49d1a490dc00bf72c857b76 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Thu, 15 Sep 2022 21:47:18 +0800 Subject: [PATCH 2/3] change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2697470..ade71499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Changes - ([\#74](https://github.com/forbole/juno/pull/74)) Added database block count to prometheus to improve alert monitoring - ([\#75](https://github.com/forbole/juno/pull/75)) Allow modules to handle MsgExec inner messages +- ([\#76](https://github.com/forbole/juno/pull/76)) Replace `return err` with `log.Error()` for `GetLastBlockHeight()` method in parse blocks cmd ## v3.4.0 ### Changes From 1cf4105f05830b7f215eccf3519366e8e66cb5fb Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Mon, 19 Sep 2022 15:41:32 +0800 Subject: [PATCH 3/3] Return 0 as height for `GetLastBlockHeight()` method while no block is saved --- CHANGELOG.md | 2 +- cmd/parse/blocks/blocks.go | 2 +- database/postgresql/postgresql.go | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ade71499..b1b407a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Changes - ([\#74](https://github.com/forbole/juno/pull/74)) Added database block count to prometheus to improve alert monitoring - ([\#75](https://github.com/forbole/juno/pull/75)) Allow modules to handle MsgExec inner messages -- ([\#76](https://github.com/forbole/juno/pull/76)) Replace `return err` with `log.Error()` for `GetLastBlockHeight()` method in parse blocks cmd +- ([\#76](https://github.com/forbole/juno/pull/76)) Return 0 as height for `GetLastBlockHeight()` method while no block is saved ## v3.4.0 ### Changes diff --git a/cmd/parse/blocks/blocks.go b/cmd/parse/blocks/blocks.go index 15074eb6..884147ba 100644 --- a/cmd/parse/blocks/blocks.go +++ b/cmd/parse/blocks/blocks.go @@ -47,7 +47,7 @@ will be replaced with the data downloaded from the node. lastDbBlockHeight, err := parseCtx.Database.GetLastBlockHeight() if err != nil { - log.Error().Msgf("error while getting last DB block height: %s", err.Error()) + return err } // Compare start height from config file and last block height in database diff --git a/database/postgresql/postgresql.go b/database/postgresql/postgresql.go index 2dd1113c..47d60acf 100644 --- a/database/postgresql/postgresql.go +++ b/database/postgresql/postgresql.go @@ -101,7 +101,12 @@ func (db *Database) GetLastBlockHeight() (int64, error) { stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1;` var height int64 - if err := db.Sql.QueryRow(stmt).Scan(&height); err != nil { + err := db.Sql.QueryRow(stmt).Scan(&height) + if err != nil { + if strings.Contains(err.Error(), "no rows in result set") { + // If no rows stored in block table, return 0 as height + return 0, nil + } return 0, fmt.Errorf("error while getting last block height, error: %s", err) }