Browse Source

revert "make `/status` RPC endpoint resistant to consensus halt"

Refs #1772

Reasons:
- this was a bad patch for something not well understood

Lessons learned:
- nobody should be modifying code without understanding the problem
first. it will only result in more technical debt and code rot.
- we never hide information when we suspect a bug or we'not sure what's
going on.
pull/2097/head
Anton Kaliaev 6 years ago
parent
commit
7634073718
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 2 additions and 82 deletions
  1. +2
    -43
      rpc/core/status.go
  2. +0
    -39
      rpc/core/status_test.go

+ 2
- 43
rpc/core/status.go View File

@ -104,20 +104,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()
lastBlockHeight, vals := consensusState.GetValidators()
// if we're still at height h, search in the current validator set
if lastBlockHeight == h {
for _, val := range vals {
@ -140,35 +131,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):
if logger != nil {
logger.Error("Timed out querying validators from consensus", "timeout", t)
}
return -1, []*types.Validator{}
}
}

+ 0
- 39
rpc/core/status_test.go View File

@ -1,39 +0,0 @@
package core
import (
"testing"
"time"
"github.com/tendermint/tendermint/types"
)
func TestGetValidatorsWithTimeout(t *testing.T) {
height, vs := getValidatorsWithTimeout(
testValidatorReceiver{},
time.Millisecond,
)
if height != -1 {
t.Errorf("expected negative height")
}
if len(vs) != 0 {
t.Errorf("expected no validators")
}
}
type testValidatorReceiver struct{}
func (tr testValidatorReceiver) GetValidators() (int64, []*types.Validator) {
vs := []*types.Validator{}
for i := 0; i < 3; i++ {
v, _ := types.RandValidator(true, 10)
vs = append(vs, v)
}
time.Sleep(time.Millisecond)
return 10, vs
}

Loading…
Cancel
Save