diff --git a/CHANGELOG.md b/CHANGELOG.md index e2697470..b1b407a0 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)) Return 0 as height for `GetLastBlockHeight()` method while no block is saved ## v3.4.0 ### Changes 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) }