@ -104,20 +104,11 @@ func Status() (*ctypes.ResultStatus, error) {
return result , nil
return result , nil
}
}
const consensusTimeout = time . Second
func validatorAtHeight ( h int64 ) * types . Validator {
func validatorAtHeight ( h int64 ) * types . Validator {
lastBlockHeight , vals := getValidatorsWithTimeout (
consensusState ,
consensusTimeout ,
)
if lastBlockHeight == - 1 {
return nil
}
privValAddress := pubKey . Address ( )
privValAddress := pubKey . Address ( )
lastBlockHeight , vals := consensusState . GetValidators ( )
// if we're still at height h, search in the current validator set
// if we're still at height h, search in the current validator set
if lastBlockHeight == h {
if lastBlockHeight == h {
for _ , val := range vals {
for _ , val := range vals {
@ -140,35 +131,3 @@ func validatorAtHeight(h int64) *types.Validator {
return nil
return nil
}
}
type validatorRetriever interface {
GetValidators ( ) ( int64 , [ ] * types . Validator )
}
// NOTE: Consensus might halt, but we still need to process RPC requests (at
// least for endpoints whole output does not depend on consensus state).
func getValidatorsWithTimeout (
vr validatorRetriever ,
t time . Duration ,
) ( int64 , [ ] * types . Validator ) {
resultCh := make ( chan struct {
lastBlockHeight int64
vals [ ] * types . Validator
} )
go func ( ) {
h , v := vr . GetValidators ( )
resultCh <- struct {
lastBlockHeight int64
vals [ ] * types . Validator
} { h , v }
} ( )
select {
case res := <- resultCh :
return res . lastBlockHeight , res . vals
case <- time . After ( t ) :
if logger != nil {
logger . Error ( "Timed out querying validators from consensus" , "timeout" , t )
}
return - 1 , [ ] * types . Validator { }
}
}