Skip to content

Commit 5fe0cd6

Browse files
committed
fix(api&database): addressed the bugs for the validator queries
1 parent f53f386 commit 5fe0cd6

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

api/huma-types/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type AllValidatorSigningsGetOutput struct {
3838

3939
type ValidatorLastNSigningGetInput struct {
4040
ValidatorAddress string `path:"validator_address" doc:"Validator consensus address" required:"true" minLength:"40" maxLength:"40"`
41-
Amount uint64 `query:"amount" doc:"Number of last blocks to check" required:"true" example:"10" max:"100"`
41+
Amount uint64 `query:"amount" doc:"Number of last blocks to check" required:"true" example:"10" max:"100" min:"1"`
4242
SortOrder database.SortOrder `query:"sort_order" doc:"Sort order for results" enum:"asc,desc" default:"desc"`
4343
}
4444

pkgs/database/timescaledb/queries_validator.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (t *TimescaleDb) GetValidatorLastNSigning(
7272

7373
query2 := `
7474
SELECT
75-
max(block_height)
75+
COALESCE(max(block_height), 0)
7676
FROM
7777
validator_block_signing
7878
WHERE
@@ -84,8 +84,16 @@ func (t *TimescaleDb) GetValidatorLastNSigning(
8484
if err != nil {
8585
return nil, err
8686
}
87+
if maxBlockHeight == 0 {
88+
return nil, fmt.Errorf("error max block height is zero for chain %s, check if the database is populated", chainName)
89+
}
8790

88-
startHeight := maxBlockHeight - uint64(limit-1) // minus one because SQL BETWEEN is inclusive
91+
var startHeight uint64
92+
if limit > maxBlockHeight {
93+
startHeight = 0
94+
} else {
95+
startHeight = maxBlockHeight - uint64(limit-1) // minus one because SQL BETWEEN is inclusive
96+
}
8997
order := orderBy.SQL()
9098

9199
query3 := fmt.Sprintf(`

pkgs/database/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ type AllValidatorSignings map[string]ValidatorSigning
281281

282282
type ValInfoPerBlock struct {
283283
Height uint64 `json:"height" doc:"Block height"`
284-
Proposed bool `json:"proposer" doc:"Proposer address"`
285-
Signed bool `json:"signed" doc:"Blocks signed"`
284+
Proposed bool `json:"proposer" doc:"Confirmation that the validator proposed the block."`
285+
Signed bool `json:"signed" doc:"Confirmation that the validator signed the block."`
286286
}
287287

288288
type ValidatorSigningsForLastNBlocks []ValInfoPerBlock

0 commit comments

Comments
 (0)