Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/consensus/validators: Expose validator signed blocks info #760

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/760.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api/consensus/valudators: Expose validator signed blocks info
20 changes: 20 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2080,9 +2080,29 @@ components:
description: Commission rate.
current_commission_bound:
allOf: [$ref: '#/components/schemas/ValidatorCommissionBound']
signed_blocks:
type: array
description: An array containing details of the last 100 consensus blocks, indicating whether each block was signed by the validator. Only available when querying a single validator.
items:
allOf: [$ref: '#/components/schemas/ValidatorSignedBlock']
description: |
An validator registered at the consensus layer.

ValidatorSignedBlock:
type: object
required: [height, signed]
properties:
height:
type: integer
format: int64
description: The block height.
example: *block_height_1
signed:
type: boolean
description: Whether the validator signed the block.
description: |
Information whether a block was signed by the validator.

Escrow:
type: object
properties:
Expand Down
25 changes: 24 additions & 1 deletion storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ func (c *StorageClient) Validators(ctx context.Context, p apiTypes.GetConsensusV
}
var schedule staking.CommissionSchedule
var logoUrl *string
if err := res.rows.Scan(
if err = res.rows.Scan(
ptrus marked this conversation as resolved.
Show resolved Hide resolved
&v.EntityID,
&v.EntityAddress,
&v.NodeID,
Expand Down Expand Up @@ -1303,6 +1303,29 @@ func (c *StorageClient) Validators(ctx context.Context, p apiTypes.GetConsensusV
vs.Validators = append(vs.Validators, v)
}

// When querying for a single validator, include the detailed block sign data for last 100 blocks.
ptrus marked this conversation as resolved.
Show resolved Hide resolved
if address != nil && len(vs.Validators) == 1 {
rows, err := c.db.Query(ctx, queries.ValidatorLast100BlocksSigned, vs.Validators[0].EntityID)
if err != nil {
return nil, wrapError(err)
}
defer rows.Close()

signedBlocks := []ValidatorSignedBlock{}
for rows.Next() {
var height int64
var signed bool
if err = rows.Scan(
&height,
&signed,
); err != nil {
return nil, wrapError(err)
}
signedBlocks = append(signedBlocks, ValidatorSignedBlock{Height: height, Signed: signed})
}
vs.Validators[0].SignedBlocks = &signedBlocks
}

return &vs, nil
}

Expand Down
6 changes: 6 additions & 0 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ const (
JOIN chain.accounts AS accts ON entities.address = accts.address)
, 0) AS total_staked_balance`

ValidatorLast100BlocksSigned = `
SELECT height, COALESCE($1 = ANY(signer_entity_ids), FALSE)
FROM chain.blocks
ORDER BY height DESC
LIMIT 100`

ValidatorsData = `
WITH
-- Find all self-delegations for all accounts with active delegations.
Expand Down
3 changes: 3 additions & 0 deletions storage/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ type ValidatorMedia = api.ValidatorMedia
// ValidatorCommissionBound is the commission bound for a validator.
type ValidatorCommissionBound = api.ValidatorCommissionBound

// ValidatorSignedBlock is the information weather a validator has signed a specific block.
type ValidatorSignedBlock = api.ValidatorSignedBlock

// ValidatorHistory is the storage response for GetValidatorHistory.
type ValidatorHistory = api.ValidatorHistory

Expand Down
Loading
Loading