Merge remote-tracking branch 'origin/develop' into jae/literefactor4

This commit is contained in:
Ethan Buchman
2018-08-02 19:12:22 -04:00
111 changed files with 5359 additions and 3140 deletions

View File

@ -109,21 +109,11 @@ func Status() (*ctypes.ResultStatus, error) {
return result, nil
}
const consensusTimeout = time.Second
func validatorAtHeight(h int64) *types.Validator {
lastBlockHeight, vals := getValidatorsWithTimeout(
consensusState,
consensusTimeout,
)
if lastBlockHeight == -1 {
return nil
}
privValAddress := pubKey.Address()
// If we're still at height h, search in the current validator set.
lastBlockHeight, vals := consensusState.GetValidators()
if lastBlockHeight == h {
for _, val := range vals {
if bytes.Equal(val.Address, privValAddress) {
@ -144,32 +134,3 @@ func validatorAtHeight(h int64) *types.Validator {
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):
return -1, []*types.Validator{}
}
}