Browse Source

fix evidence

pull/1015/head
Ethan Buchman 7 years ago
parent
commit
397251b0f4
5 changed files with 32 additions and 25 deletions
  1. +23
    -12
      evidence/pool.go
  2. +3
    -8
      evidence/pool_test.go
  3. +1
    -2
      evidence/reactor_test.go
  4. +4
    -2
      evidence/store_test.go
  5. +1
    -1
      node/node.go

+ 23
- 12
evidence/pool.go View File

@ -3,6 +3,7 @@ package evidence
import (
"github.com/tendermint/tmlibs/log"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)
@ -13,16 +14,16 @@ type EvidencePool struct {
evidenceStore *EvidenceStore
chainID string
lastBlockHeight int64
params types.EvidenceParams
state sm.State
params types.EvidenceParams
// never close
evidenceChan chan types.Evidence
}
func NewEvidencePool(params types.EvidenceParams, evidenceStore *EvidenceStore) *EvidencePool {
func NewEvidencePool(params types.EvidenceParams, evidenceStore *EvidenceStore, state sm.State) *EvidencePool {
evpool := &EvidencePool{
state: state,
params: params,
logger: log.NewNopLogger(),
evidenceStore: evidenceStore,
@ -58,15 +59,25 @@ func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
// TODO: check if we already have evidence for this
// validator at this height so we dont get spammed
// TODO
if err := sm.VerifyEvidence(evpool.state, evidence); err != nil {
return err
}
var priority int64
/*
priority, err := sm.VerifyEvidence(evpool.state, evidence)
if err != nil {
// TODO: if err is just that we cant find it cuz we pruned, ignore.
// TODO: if its actually bad evidence, punish peer
return err
}*/
/* // Needs a db ...
// TODO: if err is just that we cant find it cuz we pruned, ignore.
// TODO: if its actually bad evidence, punish peer
valset, err := LoadValidators(s.db, ev.Height())
if err != nil {
// XXX/TODO: what do we do if we can't load the valset?
// eg. if we have pruned the state or height is too high?
return err
}
if err := VerifyEvidenceValidator(valSet, ev); err != nil {
return types.NewEvidenceInvalidErr(ev, err)
}
*/
added := evpool.evidenceStore.AddNewEvidence(evidence, priority)
if !added {


+ 3
- 8
evidence/pool_test.go View File

@ -6,24 +6,19 @@ import (
"github.com/stretchr/testify/assert"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tmlibs/db"
)
type mockState struct{}
func (m mockState) VerifyEvidence(ev types.Evidence) (int64, error) {
err := ev.Verify("")
return 10, err
}
var mockState = sm.State{}
func TestEvidencePool(t *testing.T) {
assert := assert.New(t)
params := types.EvidenceParams{}
store := NewEvidenceStore(dbm.NewMemDB())
state := mockState{}
pool := NewEvidencePool(params, store, state)
pool := NewEvidencePool(params, store, mockState)
goodEvidence := newMockGoodEvidence(5, 1, []byte("val1"))
badEvidence := MockBadEvidence{goodEvidence}


+ 1
- 2
evidence/reactor_test.go View File

@ -39,8 +39,7 @@ func makeAndConnectEvidenceReactors(config *cfg.Config, N int) []*EvidenceReacto
params := types.EvidenceParams{}
store := NewEvidenceStore(dbm.NewMemDB())
state := mockState{}
pool := NewEvidencePool(params, store, state)
pool := NewEvidencePool(params, store, mockState)
reactors[i] = NewEvidenceReactor(pool)
reactors[i].SetLogger(logger.With("validator", i))
}


+ 4
- 2
evidence/store_test.go View File

@ -113,12 +113,14 @@ func TestStorePriority(t *testing.T) {
//-------------------------------------------
const (
evidenceTypeMock = byte(0x01)
evidenceTypeMockGood = byte(0x01)
evidenceTypeMockBad = byte(0x02)
)
var _ = wire.RegisterInterface(
struct{ types.Evidence }{},
wire.ConcreteType{MockGoodEvidence{}, evidenceTypeMock},
wire.ConcreteType{MockGoodEvidence{}, evidenceTypeMockGood},
wire.ConcreteType{MockBadEvidence{}, evidenceTypeMockBad},
)
type MockGoodEvidence struct {


+ 1
- 1
node/node.go View File

@ -211,7 +211,7 @@ func NewNode(config *cfg.Config,
}
evidenceLogger := logger.With("module", "evidence")
evidenceStore := evidence.NewEvidenceStore(evidenceDB)
evidencePool := evidence.NewEvidencePool(state.ConsensusParams.EvidenceParams, evidenceStore) // , state.Copy())
evidencePool := evidence.NewEvidencePool(state.ConsensusParams.EvidenceParams, evidenceStore, state.Copy())
evidencePool.SetLogger(evidenceLogger)
evidenceReactor := evidence.NewEvidenceReactor(evidencePool)
evidenceReactor.SetLogger(evidenceLogger)


Loading…
Cancel
Save