Skip to content

Commit d5b0b26

Browse files
authored
Merge pull request #1222 from oasisprotocol/ptrus/feature/validator-ids
Support validators by node-id/entity-id
2 parents c2885d0 + 0a3a6a3 commit d5b0b26

27 files changed

+996
-772
lines changed

.changelog/1222.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support searching validators by node-id/entity-id

api/spec/v1.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,13 @@ paths:
561561
description: |
562562
A filter on the validator name. Every returned validator will have
563563
a name that is a superstring of the input param.
564+
- in: query
565+
name: id
566+
schema:
567+
type: string
568+
description: |
569+
A filter on the entity or node ID (base64-encoded ed25519 public key).
570+
Returns the validator whose entity_id matches the provided value, or whose node's node_id matches the provided value.
564571
responses:
565572
'200':
566573
description: |
@@ -2490,8 +2497,7 @@ components:
24902497
required: [total_voting_power, total_delegators, total_staked_balance]
24912498
properties:
24922499
total_voting_power:
2493-
type: integer
2494-
format: int64
2500+
allOf: [$ref: '#/components/schemas/TextBigInt']
24952501
description: The total voting power across all validators.
24962502
total_delegators:
24972503
type: integer
@@ -2564,12 +2570,10 @@ components:
25642570
allOf: [$ref: '#/components/schemas/Escrow']
25652571
description: The escrow account data for this validator.
25662572
voting_power:
2567-
type: integer
2568-
format: int64
2573+
allOf: [$ref: '#/components/schemas/TextBigInt']
25692574
description: The voting power of this validator.
25702575
voting_power_cumulative:
2571-
type: integer
2572-
format: int64
2576+
allOf: [$ref: '#/components/schemas/TextBigInt']
25732577
description: The cumulative voting power of this validator and all other validators ranked higher than itself.
25742578
active:
25752579
type: boolean

storage/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ func (c *StorageClient) Validators(ctx context.Context, p apiTypes.GetConsensusV
13661366
queries.ValidatorsData,
13671367
address,
13681368
p.Name,
1369+
p.Id,
13691370
p.Limit,
13701371
p.Offset,
13711372
)

storage/client/queries/queries.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ const (
426426
ValidatorsAggStats = `
427427
SELECT
428428
COALESCE (
429-
(SELECT SUM(voting_power)
429+
(SELECT SUM(voting_power)::NUMERIC
430430
FROM chain.nodes)
431431
, 0) AS total_voting_power,
432432
COALESCE (
@@ -504,9 +504,9 @@ const (
504504
delegators_count.count
505505
, 0) AS num_delegators,
506506
COALESCE (
507-
validator_nodes.voting_power
507+
validator_nodes.voting_power::NUMERIC
508508
, 0) AS voting_power,
509-
SUM(validator_nodes.voting_power)
509+
SUM(validator_nodes.voting_power::NUMERIC)
510510
OVER (ORDER BY validator_rank.rank) AS voting_power_cumulative,
511511
COALESCE(chain.commissions.schedule, '{}'::JSONB) AS commissions_schedule,
512512
chain.blocks.time AS start_date,
@@ -537,10 +537,11 @@ const (
537537
AND chain.nodes.roles LIKE '%validator%'
538538
AND chain.nodes.voting_power = validator_nodes.voting_power
539539
WHERE ($1::text IS NULL OR chain.entities.address = $1::text) AND
540-
($2::text IS NULL OR chain.entities.meta->>'name' LIKE '%' || $2::text || '%')
540+
($2::text IS NULL OR chain.entities.meta->>'name' LIKE '%' || $2::text || '%') AND
541+
($3::text IS NULL OR chain.entities.id = $3::text OR chain.nodes.id = $3::text)
541542
ORDER BY rank
542-
LIMIT $3::bigint
543-
OFFSET $4::bigint`
543+
LIMIT $4::bigint
544+
OFFSET $5::bigint`
544545

545546
ValidatorHistory = `
546547
WITH entity AS (

tests/e2e_regression/damask/expected/validator.body

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"stats": {
44
"total_delegators": 35414,
55
"total_staked_balance": "5708092745980859133",
6-
"total_voting_power": 307554773957760060
6+
"total_voting_power": "307554773957760057"
77
},
88
"total_count": 1,
99
"validators": [
@@ -460,8 +460,8 @@
460460
"window_length": 14400,
461461
"window_uptime": 884
462462
},
463-
"voting_power": 34834350461211,
464-
"voting_power_cumulative": 34834350461211
463+
"voting_power": "34834350461211",
464+
"voting_power_cumulative": "34834350461211"
465465
}
466466
]
467467
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"is_total_count_clipped": false,
3+
"stats": {
4+
"total_delegators": 35414,
5+
"total_staked_balance": "5708092745980859133",
6+
"total_voting_power": "307554773957760057"
7+
},
8+
"total_count": 1,
9+
"validators": [
10+
{
11+
"active": true,
12+
"current_commission_bound": {
13+
"epoch_end": 0,
14+
"epoch_start": 2310,
15+
"lower": 0,
16+
"upper": 25000
17+
},
18+
"current_rate": 20000,
19+
"entity_address": "oasis1qr3w66akc8ud9a4zsgyjw2muvcfjgfszn5ycgc0a",
20+
"entity_id": "HPeLbzc88IoYEP0TC4nqSxfxdPCPjduLeJqFvmxFye8=",
21+
"escrow": {
22+
"active_balance": "557356819483297",
23+
"active_shares": "506789203787843",
24+
"debonding_balance": "0",
25+
"debonding_shares": "0",
26+
"num_delegators": 13,
27+
"self_delegation_balance": "9263128275881",
28+
"self_delegation_shares": "8422707392134"
29+
},
30+
"in_validator_set": true,
31+
"media": {
32+
"email": "[email protected]",
33+
"keybase": "mikefairbairn",
34+
"logoUrl": "http:://e2e-tests-mock-static-logo-url",
35+
"name": "RMIT Blockchain Innovation Hub",
36+
"twitter": "BlockchainRMIT",
37+
"url": "https://rmitblockchain.io"
38+
},
39+
"node_id": "wqd9Yy3n7TWKfYRn2bI9Hd6/623CfC7NCUoRbQ5UkR8=",
40+
"rank": 92,
41+
"start_date": "2022-04-11T09:30:00Z",
42+
"uptime": {
43+
"segment_length": 1200,
44+
"segment_uptimes": [
45+
884,
46+
0,
47+
0,
48+
0,
49+
0,
50+
0,
51+
0,
52+
0,
53+
0,
54+
0,
55+
0,
56+
0
57+
],
58+
"window_length": 14400,
59+
"window_uptime": 884
60+
},
61+
"voting_power": "34834350461211",
62+
"voting_power_cumulative": "34834350461211"
63+
}
64+
]
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"is_total_count_clipped": false,
3+
"stats": {
4+
"total_delegators": 35414,
5+
"total_staked_balance": "5708092745980859133",
6+
"total_voting_power": "307554773957760057"
7+
},
8+
"total_count": 1,
9+
"validators": [
10+
{
11+
"active": true,
12+
"current_commission_bound": {
13+
"epoch_end": 0,
14+
"epoch_start": 2310,
15+
"lower": 0,
16+
"upper": 25000
17+
},
18+
"current_rate": 20000,
19+
"entity_address": "oasis1qr3w66akc8ud9a4zsgyjw2muvcfjgfszn5ycgc0a",
20+
"entity_id": "HPeLbzc88IoYEP0TC4nqSxfxdPCPjduLeJqFvmxFye8=",
21+
"escrow": {
22+
"active_balance": "557356819483297",
23+
"active_shares": "506789203787843",
24+
"debonding_balance": "0",
25+
"debonding_shares": "0",
26+
"num_delegators": 13,
27+
"self_delegation_balance": "9263128275881",
28+
"self_delegation_shares": "8422707392134"
29+
},
30+
"in_validator_set": true,
31+
"media": {
32+
"email": "[email protected]",
33+
"keybase": "mikefairbairn",
34+
"logoUrl": "http:://e2e-tests-mock-static-logo-url",
35+
"name": "RMIT Blockchain Innovation Hub",
36+
"twitter": "BlockchainRMIT",
37+
"url": "https://rmitblockchain.io"
38+
},
39+
"node_id": "wqd9Yy3n7TWKfYRn2bI9Hd6/623CfC7NCUoRbQ5UkR8=",
40+
"rank": 92,
41+
"start_date": "2022-04-11T09:30:00Z",
42+
"uptime": {
43+
"segment_length": 1200,
44+
"segment_uptimes": [
45+
884,
46+
0,
47+
0,
48+
0,
49+
0,
50+
0,
51+
0,
52+
0,
53+
0,
54+
0,
55+
0,
56+
0
57+
],
58+
"window_length": 14400,
59+
"window_uptime": 884
60+
},
61+
"voting_power": "34834350461211",
62+
"voting_power_cumulative": "34834350461211"
63+
}
64+
]
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+

0 commit comments

Comments
 (0)