@@ -14,16 +14,18 @@ import (
14
14
)
15
15
16
16
type TendermintGRPC struct {
17
- NodeConfig NodeConfig
18
- Limit uint64
19
- Client * grpc.ClientConn
20
- Logger zerolog.Logger
21
- Registry codectypes.InterfaceRegistry
17
+ NodeConfig NodeConfig
18
+ Limit uint64
19
+ Client * grpc.ClientConn
20
+ Logger zerolog.Logger
21
+ Registry codectypes.InterfaceRegistry
22
+ QueryEachSigningInfo bool
22
23
}
23
24
24
25
func NewTendermintGRPC (
25
26
nodeConfig NodeConfig ,
26
27
registry codectypes.InterfaceRegistry ,
28
+ queryEachSigningInfo bool ,
27
29
logger * zerolog.Logger ,
28
30
) * TendermintGRPC {
29
31
grpcConn , err := grpc .Dial (
@@ -35,11 +37,12 @@ func NewTendermintGRPC(
35
37
}
36
38
37
39
return & TendermintGRPC {
38
- NodeConfig : nodeConfig ,
39
- Limit : 1000 ,
40
- Logger : logger .With ().Str ("component" , "grpc" ).Logger (),
41
- Client : grpcConn ,
42
- Registry : registry ,
40
+ NodeConfig : nodeConfig ,
41
+ Limit : 1000 ,
42
+ Logger : logger .With ().Str ("component" , "grpc" ).Logger (),
43
+ Client : grpcConn ,
44
+ Registry : registry ,
45
+ QueryEachSigningInfo : queryEachSigningInfo ,
43
46
}
44
47
}
45
48
@@ -75,6 +78,10 @@ func (grpc *TendermintGRPC) GetSlashingParams() SlashingParams {
75
78
}
76
79
77
80
func (grpc * TendermintGRPC ) GetValidatorsState () (ValidatorsState , error ) {
81
+ if grpc .QueryEachSigningInfo {
82
+ return grpc .GetValidatorsStateWithEachSigningInfo ()
83
+ }
84
+
78
85
slashingClient := slashingtypes .NewQueryClient (grpc .Client )
79
86
signingInfos , err := slashingClient .SigningInfos (
80
87
context .Background (),
@@ -135,6 +142,53 @@ func (grpc *TendermintGRPC) GetValidatorsState() (ValidatorsState, error) {
135
142
return newState , nil
136
143
}
137
144
145
+ func (grpc * TendermintGRPC ) GetValidatorsStateWithEachSigningInfo () (ValidatorsState , error ) {
146
+ slashingClient := slashingtypes .NewQueryClient (grpc .Client )
147
+ stakingClient := stakingtypes .NewQueryClient (grpc .Client )
148
+ validatorsResult , err := stakingClient .Validators (
149
+ context .Background (),
150
+ & stakingtypes.QueryValidatorsRequest {
151
+ Pagination : & querytypes.PageRequest {
152
+ Limit : grpc .Limit ,
153
+ },
154
+ },
155
+ )
156
+ if err != nil {
157
+ grpc .Logger .Error ().Err (err ).Msg ("Could not query for validators" )
158
+ return nil , err
159
+ }
160
+
161
+ newState := make (ValidatorsState , len (validatorsResult .Validators ))
162
+ for _ , validator := range validatorsResult .Validators {
163
+ err := validator .UnpackInterfaces (grpc .Registry )
164
+ if err != nil {
165
+ grpc .Logger .Error ().Err (err ).Msg ("Could not unpack interface" )
166
+ return nil , err
167
+ }
168
+
169
+ pubKey , err := validator .GetConsAddr ()
170
+ if err != nil {
171
+ grpc .Logger .Error ().Err (err ).Msg ("Could not get cons addr" )
172
+ return nil , err
173
+ }
174
+
175
+ info , err := slashingClient .SigningInfo (
176
+ context .Background (),
177
+ & slashingtypes.QuerySigningInfoRequest {
178
+ ConsAddress : pubKey .String (),
179
+ },
180
+ )
181
+ if err != nil {
182
+ grpc .Logger .Error ().Err (err ).Msg ("Could not query for signing info" )
183
+ continue
184
+ }
185
+
186
+ newState [pubKey .String ()] = NewValidatorState (validator , info .ValSigningInfo )
187
+ }
188
+
189
+ return newState , nil
190
+ }
191
+
138
192
func (grpc * TendermintGRPC ) GetValidator (address string ) (stakingtypes.Validator , error ) {
139
193
stakingClient := stakingtypes .NewQueryClient (grpc .Client )
140
194
0 commit comments