Browse Source

fixes from rebase

pull/592/head
Ethan Buchman 7 years ago
parent
commit
6a4fd46479
16 changed files with 51 additions and 57 deletions
  1. +2
    -3
      consensus/replay_test.go
  2. +2
    -1
      consensus/wal_generator.go
  3. +3
    -4
      evidence/pool.go
  4. +3
    -4
      evidence/pool_test.go
  5. +1
    -4
      evidence/reactor.go
  6. +4
    -4
      evidence/reactor_test.go
  7. +6
    -6
      evidence/store.go
  8. +6
    -6
      evidence/store_test.go
  9. +2
    -3
      node/node.go
  10. +1
    -1
      state/execution.go
  11. +3
    -3
      state/state.go
  12. +13
    -2
      types/block_test.go
  13. +2
    -2
      types/evidence.go
  14. +1
    -12
      types/evidence_test.go
  15. +1
    -1
      types/params.go
  16. +1
    -1
      types/services.go

+ 2
- 3
consensus/replay_test.go View File

@ -261,9 +261,8 @@ const (
)
var (
NUM_BLOCKS = 6 // number of blocks in the test_data/many_blocks.cswal
mempool = types.MockMempool{}
evpool = types.MockEvidencePool{}
mempool = types.MockMempool{}
evpool = types.MockEvidencePool{}
)
//---------------------------------------


+ 2
- 1
consensus/wal_generator.go View File

@ -66,7 +66,8 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) {
}
defer eventBus.Stop()
mempool := types.MockMempool{}
consensusState := NewConsensusState(config.Consensus, state.Copy(), proxyApp.Consensus(), blockStore, mempool)
evpool := types.MockEvidencePool{}
consensusState := NewConsensusState(config.Consensus, state.Copy(), proxyApp.Consensus(), blockStore, mempool, evpool)
consensusState.SetLogger(logger)
consensusState.SetEventBus(eventBus)
if privValidator != nil {


+ 3
- 4
evidence/pool.go View File

@ -3,14 +3,13 @@ package evidence
import (
"github.com/tendermint/tmlibs/log"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
)
// EvidencePool maintains a pool of valid evidence
// in an EvidenceStore.
type EvidencePool struct {
config *cfg.EvidenceConfig
params types.EvidenceParams
logger log.Logger
state types.State
@ -19,9 +18,9 @@ type EvidencePool struct {
evidenceChan chan types.Evidence
}
func NewEvidencePool(config *cfg.EvidenceConfig, evidenceStore *EvidenceStore, state types.State) *EvidencePool {
func NewEvidencePool(params types.EvidenceParams, evidenceStore *EvidenceStore, state types.State) *EvidencePool {
evpool := &EvidencePool{
config: config,
params: params,
logger: log.NewNopLogger(),
evidenceStore: evidenceStore,
state: state,


+ 3
- 4
evidence/pool_test.go View File

@ -6,14 +6,13 @@ import (
"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) {
func (m mockState) VerifyEvidence(ev types.Evidence) (int64, error) {
err := ev.Verify("")
return 10, err
}
@ -21,10 +20,10 @@ func (m mockState) VerifyEvidence(ev types.Evidence) (int, error) {
func TestEvidencePool(t *testing.T) {
assert := assert.New(t)
config := &cfg.EvidenceConfig{}
params := types.EvidenceParams{}
store := NewEvidenceStore(dbm.NewMemDB())
state := mockState{}
pool := NewEvidencePool(config, store, state)
pool := NewEvidencePool(params, store, state)
goodEvidence := newMockGoodEvidence(5, 1, []byte("val1"))
badEvidence := MockBadEvidence{goodEvidence}


+ 1
- 4
evidence/reactor.go View File

@ -9,7 +9,6 @@ import (
wire "github.com/tendermint/go-wire"
"github.com/tendermint/tmlibs/log"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)
@ -24,15 +23,13 @@ const (
// EvidenceReactor handles evpool evidence broadcasting amongst peers.
type EvidenceReactor struct {
p2p.BaseReactor
config *cfg.EvidenceConfig
evpool *EvidencePool
eventBus *types.EventBus
}
// NewEvidenceReactor returns a new EvidenceReactor with the given config and evpool.
func NewEvidenceReactor(config *cfg.EvidenceConfig, evpool *EvidencePool) *EvidenceReactor {
func NewEvidenceReactor(evpool *EvidencePool) *EvidenceReactor {
evR := &EvidenceReactor{
config: config,
evpool: evpool,
}
evR.BaseReactor = *p2p.NewBaseReactor("EvidenceReactor", evR)


+ 4
- 4
evidence/reactor_test.go View File

@ -37,11 +37,11 @@ func makeAndConnectEvidenceReactors(config *cfg.Config, N int) []*EvidenceReacto
logger := evidenceLogger()
for i := 0; i < N; i++ {
config := &cfg.EvidenceConfig{}
params := types.EvidenceParams{}
store := NewEvidenceStore(dbm.NewMemDB())
state := mockState{}
pool := NewEvidencePool(config, store, state)
reactors[i] = NewEvidenceReactor(config, pool)
pool := NewEvidencePool(params, store, state)
reactors[i] = NewEvidenceReactor(pool)
reactors[i].SetLogger(logger.With("validator", i))
}
@ -102,7 +102,7 @@ func _waitForEvidence(t *testing.T, wg *sync.WaitGroup, evs types.EvidenceList,
func sendEvidence(t *testing.T, evpool *EvidencePool, n int) types.EvidenceList {
evList := make([]types.Evidence, n)
for i := 0; i < n; i++ {
ev := newMockGoodEvidence(i, 2, []byte("val"))
ev := newMockGoodEvidence(int64(i), 2, []byte("val"))
err := evpool.AddEvidence(ev)
assert.Nil(t, err)
evList[i] = ev


+ 6
- 6
evidence/store.go View File

@ -32,7 +32,7 @@ Schema for indexing evidence (note you need both height and hash to find a piece
type EvidenceInfo struct {
Committed bool
Priority int
Priority int64
Evidence types.Evidence
}
@ -47,15 +47,15 @@ func keyLookup(evidence types.Evidence) []byte {
}
// big endian padded hex
func be(h int) string {
func be(h int64) string {
return fmt.Sprintf("%0.16X", h)
}
func keyLookupFromHeightAndHash(height int, hash []byte) []byte {
func keyLookupFromHeightAndHash(height int64, hash []byte) []byte {
return _key("%s/%s/%X", baseKeyLookup, be(height), hash)
}
func keyOutqueue(evidence types.Evidence, priority int) []byte {
func keyOutqueue(evidence types.Evidence, priority int64) []byte {
return _key("%s/%s/%s/%X", baseKeyOutqueue, be(priority), be(evidence.Height()), evidence.Hash())
}
@ -111,7 +111,7 @@ func (store *EvidenceStore) ListEvidence(prefixKey string) (evidence []types.Evi
}
// GetEvidence fetches the evidence with the given height and hash.
func (store *EvidenceStore) GetEvidence(height int, hash []byte) *EvidenceInfo {
func (store *EvidenceStore) GetEvidence(height int64, hash []byte) *EvidenceInfo {
key := keyLookupFromHeightAndHash(height, hash)
val := store.db.Get(key)
@ -125,7 +125,7 @@ func (store *EvidenceStore) GetEvidence(height int, hash []byte) *EvidenceInfo {
// AddNewEvidence adds the given evidence to the database.
// It returns false if the evidence is already stored.
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int) bool {
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int64) bool {
// check if we already have seen it
ei_ := store.GetEvidence(evidence.Height(), evidence.Hash())
if ei_ != nil && ei_.Evidence != nil {


+ 6
- 6
evidence/store_test.go View File

@ -19,7 +19,7 @@ func TestStoreAddDuplicate(t *testing.T) {
db := dbm.NewMemDB()
store := NewEvidenceStore(db)
priority := 10
priority := int64(10)
ev := newMockGoodEvidence(2, 1, []byte("val1"))
added := store.AddNewEvidence(ev, priority)
@ -42,7 +42,7 @@ func TestStoreMark(t *testing.T) {
assert.Equal(0, len(priorityEv))
assert.Equal(0, len(pendingEv))
priority := 10
priority := int64(10)
ev := newMockGoodEvidence(2, 1, []byte("val1"))
added := store.AddNewEvidence(ev, priority)
@ -90,7 +90,7 @@ func TestStorePriority(t *testing.T) {
// sorted by priority and then height
cases := []struct {
ev MockGoodEvidence
priority int
priority int64
}{
{newMockGoodEvidence(2, 1, []byte("val1")), 17},
{newMockGoodEvidence(5, 2, []byte("val2")), 15},
@ -122,16 +122,16 @@ var _ = wire.RegisterInterface(
)
type MockGoodEvidence struct {
Height_ int
Height_ int64
Address_ []byte
Index_ int
}
func newMockGoodEvidence(height, index int, address []byte) MockGoodEvidence {
func newMockGoodEvidence(height int64, index int, address []byte) MockGoodEvidence {
return MockGoodEvidence{height, address, index}
}
func (e MockGoodEvidence) Height() int { return e.Height_ }
func (e MockGoodEvidence) Height() int64 { return e.Height_ }
func (e MockGoodEvidence) Address() []byte { return e.Address_ }
func (e MockGoodEvidence) Index() int { return e.Index_ }
func (e MockGoodEvidence) Hash() []byte {


+ 2
- 3
node/node.go View File

@ -210,16 +210,15 @@ func NewNode(config *cfg.Config,
}
// Make Evidence Reactor
evidenceConfig := &cfg.EvidenceConfig{} // TODO
evidenceDB, err := dbProvider(&DBContext{"evidence", config})
if err != nil {
return nil, err
}
evidenceLogger := logger.With("module", "evidence")
evidenceStore := evidence.NewEvidenceStore(evidenceDB)
evidencePool := evidence.NewEvidencePool(evidenceConfig, evidenceStore, state)
evidencePool := evidence.NewEvidencePool(state.ConsensusParams.EvidenceParams, evidenceStore, state)
evidencePool.SetLogger(evidenceLogger)
evidenceReactor := evidence.NewEvidenceReactor(evidenceConfig, evidencePool)
evidenceReactor := evidence.NewEvidenceReactor(evidencePool)
evidenceReactor.SetLogger(evidenceLogger)
// Make ConsensusReactor


+ 1
- 1
state/execution.go View File

@ -309,7 +309,7 @@ func (s *State) validateBlock(b *types.Block) error {
}
}
for _, ev := range block.Evidence.Evidence {
for _, ev := range b.Evidence.Evidence {
if _, err := s.VerifyEvidence(ev); err != nil {
return types.NewEvidenceInvalidErr(ev, err)
}


+ 3
- 3
state/state.go View File

@ -388,9 +388,9 @@ func (s *State) GetValidators() (last *types.ValidatorSet, current *types.Valida
// It returns the priority of this evidence, or an error.
// NOTE: return error may be ErrNoValSetForHeight, in which case the validator set
// for the evidence height could not be loaded.
func (s *State) VerifyEvidence(evidence types.Evidence) (priority int, err error) {
func (s *State) VerifyEvidence(evidence types.Evidence) (priority int64, err error) {
evidenceAge := s.LastBlockHeight - evidence.Height()
maxAge := s.Params.EvidenceParams.MaxAge
maxAge := s.ConsensusParams.EvidenceParams.MaxAge
if evidenceAge > maxAge {
return priority, fmt.Errorf("Evidence from height %d is too old. Min height is %d",
evidence.Height(), s.LastBlockHeight-maxAge)
@ -416,7 +416,7 @@ func (s *State) VerifyEvidence(evidence types.Evidence) (priority int, err error
return priority, fmt.Errorf("Address %X was validator %d at height %d, not %d", addr, valIdx, height, idx)
}
priority = int(val.VotingPower)
priority = val.VotingPower
return priority, nil
}


+ 13
- 2
types/block_test.go View File

@ -10,7 +10,7 @@ import (
func TestValidateBlock(t *testing.T) {
txs := []Tx{Tx("foo"), Tx("bar")}
lastID := makeBlockID()
lastID := makeBlockIDRandom()
h := int64(3)
voteSet, _, vals := randVoteSet(h-1, 1, VoteTypePrecommit,
@ -58,7 +58,18 @@ func TestValidateBlock(t *testing.T) {
require.Error(t, err)
}
func makeBlockID() BlockID {
func makeBlockIDRandom() BlockID {
blockHash, blockPartsHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}
return BlockID{blockHash, blockPartsHeader}
}
func makeBlockID(hash string, partSetSize int, partSetHash string) BlockID {
return BlockID{
Hash: []byte(hash),
PartsHeader: PartSetHeader{
Total: partSetSize,
Hash: []byte(partSetHash),
},
}
}

+ 2
- 2
types/evidence.go View File

@ -28,7 +28,7 @@ func (err *ErrEvidenceInvalid) Error() string {
// Evidence represents any provable malicious activity by a validator
type Evidence interface {
Height() int // height of the equivocation
Height() int64 // height of the equivocation
Address() []byte // address of the equivocating validator
Index() int // index of the validator in the validator set
Hash() []byte // hash of the evidence
@ -104,7 +104,7 @@ func (dve *DuplicateVoteEvidence) String() string {
}
// Height returns the height this evidence refers to.
func (dve *DuplicateVoteEvidence) Height() int {
func (dve *DuplicateVoteEvidence) Height() int64 {
return dve.VoteA.Height
}


+ 1
- 12
types/evidence_test.go View File

@ -13,7 +13,7 @@ type voteData struct {
valid bool
}
func makeVote(val *PrivValidatorFS, chainID string, valIndex, height, round, step int, blockID BlockID) *Vote {
func makeVote(val *PrivValidatorFS, chainID string, valIndex int, height int64, round, step int, blockID BlockID) *Vote {
v := &Vote{
ValidatorAddress: val.PubKey.Address(),
ValidatorIndex: valIndex,
@ -28,17 +28,6 @@ func makeVote(val *PrivValidatorFS, chainID string, valIndex, height, round, ste
}
func makeBlockID(hash string, partSetSize int, partSetHash string) BlockID {
return BlockID{
Hash: []byte(hash),
PartsHeader: PartSetHeader{
Total: partSetSize,
Hash: []byte(partSetHash),
},
}
}
func TestEvidence(t *testing.T) {
_, tmpFilePath := cmn.Tempfile("priv_validator_")
val := GenPrivValidatorFS(tmpFilePath)


+ 1
- 1
types/params.go View File

@ -40,7 +40,7 @@ type BlockGossip struct {
// EvidenceParams determine how we handle evidence of malfeasance
type EvidenceParams struct {
MaxAge int `json:"max_age"` // only accept new evidence more recent than this
MaxAge int64 `json:"max_age"` // only accept new evidence more recent than this
}
// DefaultConsensusParams returns a default ConsensusParams.


+ 1
- 1
types/services.go View File

@ -76,7 +76,7 @@ type BlockStore interface {
// State defines the stateful interface used to verify evidence.
// UNSTABLE
type State interface {
VerifyEvidence(Evidence) (priority int, err error)
VerifyEvidence(Evidence) (priority int64, err error)
}
//------------------------------------------------------


Loading…
Cancel
Save