Browse Source

evidence: pool test

pull/592/head
Ethan Buchman 7 years ago
parent
commit
666ae244b3
6 changed files with 68 additions and 20 deletions
  1. +3
    -5
      evidence/pool.go
  2. +54
    -0
      evidence/pool_test.go
  3. +1
    -1
      evidence/reactor.go
  4. +4
    -4
      evidence/store.go
  5. +5
    -9
      evidence/store_test.go
  6. +1
    -1
      node/node.go

+ 3
- 5
evidence/pool.go View File

@ -1,4 +1,4 @@
package evpool
package evidence
import (
"github.com/tendermint/tmlibs/log"
@ -60,10 +60,8 @@ func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
return err
}
added, err := evpool.evidenceStore.AddNewEvidence(evidence, priority)
if err != nil {
return err
} else if !added {
added := evpool.evidenceStore.AddNewEvidence(evidence, priority)
if !added {
// evidence already known, just ignore
return
}


+ 54
- 0
evidence/pool_test.go View File

@ -0,0 +1,54 @@
package evidence
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tmlibs/db"
)
type mockState struct{}
func (m mockState) VerifyEvidence(ev types.Evidence) (int, error) {
err := ev.Verify("")
return 10, err
}
func TestEvidencePool(t *testing.T) {
assert := assert.New(t)
config := &cfg.EvidenceConfig{}
store := NewEvidenceStore(dbm.NewMemDB())
state := mockState{}
pool := NewEvidencePool(config, store, state)
goodEvidence := newMockGoodEvidence(5, 1, []byte("val1"))
badEvidence := MockBadEvidence{goodEvidence}
err := pool.AddEvidence(badEvidence)
assert.NotNil(err)
var wg sync.WaitGroup
wg.Add(1)
go func() {
<-pool.EvidenceChan()
wg.Done()
}()
err = pool.AddEvidence(goodEvidence)
assert.Nil(err)
wg.Wait()
// if we send it again it wont fire on the chan
err = pool.AddEvidence(goodEvidence)
assert.Nil(err)
select {
case <-pool.EvidenceChan():
t.Fatal("unexpected read on EvidenceChan")
default:
}
}

+ 1
- 1
evidence/reactor.go View File

@ -1,4 +1,4 @@
package evpool
package evidence
import (
"bytes"


+ 4
- 4
evidence/store.go View File

@ -1,4 +1,4 @@
package evpool
package evidence
import (
"fmt"
@ -124,11 +124,11 @@ func (store *EvidenceStore) GetEvidence(height int, hash []byte) *EvidenceInfo {
}
// AddNewEvidence adds the given evidence to the database.
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int) (bool, error) {
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int) bool {
// check if we already have seen it
ei_ := store.GetEvidence(evidence.Height(), evidence.Hash())
if ei_ != nil && ei_.Evidence != nil {
return false, nil
return false
}
ei := EvidenceInfo{
@ -148,7 +148,7 @@ func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int
key = keyLookup(evidence)
store.db.SetSync(key, eiBytes)
return true, nil
return true
}
// MarkEvidenceAsBroadcasted removes evidence from Outqueue.


+ 5
- 9
evidence/store_test.go View File

@ -1,4 +1,4 @@
package evpool
package evidence
import (
"bytes"
@ -22,13 +22,11 @@ func TestStoreAddDuplicate(t *testing.T) {
priority := 10
ev := newMockGoodEvidence(2, 1, []byte("val1"))
added, err := store.AddNewEvidence(ev, priority)
assert.Nil(err)
added := store.AddNewEvidence(ev, priority)
assert.True(added)
// cant add twice
added, err = store.AddNewEvidence(ev, priority)
assert.Nil(err)
added = store.AddNewEvidence(ev, priority)
assert.False(added)
}
@ -47,8 +45,7 @@ func TestStoreMark(t *testing.T) {
priority := 10
ev := newMockGoodEvidence(2, 1, []byte("val1"))
added, err := store.AddNewEvidence(ev, priority)
assert.Nil(err)
added := store.AddNewEvidence(ev, priority)
assert.True(added)
// get the evidence. verify. should be uncommitted
@ -104,9 +101,8 @@ func TestStorePriority(t *testing.T) {
}
for _, c := range cases {
added, err := store.AddNewEvidence(c.ev, c.priority)
added := store.AddNewEvidence(c.ev, c.priority)
assert.True(added)
assert.Nil(err)
}
evList := store.PriorityEvidence()


+ 1
- 1
node/node.go View File

@ -19,7 +19,7 @@ import (
bc "github.com/tendermint/tendermint/blockchain"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/consensus"
evidence "github.com/tendermint/tendermint/evidence"
"github.com/tendermint/tendermint/evidence"
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/trust"


Loading…
Cancel
Save