diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 495fc42cc..f1a060ec1 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -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{} ) //--------------------------------------- diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index b46ef93d1..b4efb5a91 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -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 { diff --git a/evidence/pool.go b/evidence/pool.go index 097b74a8a..821fdf3c2 100644 --- a/evidence/pool.go +++ b/evidence/pool.go @@ -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, diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 2908bb425..0997505ca 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -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} diff --git a/evidence/reactor.go b/evidence/reactor.go index 54bc37a1d..ff502ed0c 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -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) diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index d6e8653bc..fb83667ce 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -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 diff --git a/evidence/store.go b/evidence/store.go index e4246cfa4..5b677c347 100644 --- a/evidence/store.go +++ b/evidence/store.go @@ -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 { diff --git a/evidence/store_test.go b/evidence/store_test.go index ca55a98dc..7828d37b9 100644 --- a/evidence/store_test.go +++ b/evidence/store_test.go @@ -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 { diff --git a/node/node.go b/node/node.go index 8134074ab..1f51354a8 100644 --- a/node/node.go +++ b/node/node.go @@ -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 diff --git a/state/execution.go b/state/execution.go index a55bc5f8b..c96861524 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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) } diff --git a/state/state.go b/state/state.go index 54ad0b104..773b46fcc 100644 --- a/state/state.go +++ b/state/state.go @@ -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 } diff --git a/types/block_test.go b/types/block_test.go index bde474403..1fcfa469b 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -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), + }, + } + +} diff --git a/types/evidence.go b/types/evidence.go index 48c2d1897..d6b408119 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -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 } diff --git a/types/evidence_test.go b/types/evidence_test.go index a69040d49..876b68ad1 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -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) diff --git a/types/params.go b/types/params.go index 216f13907..90ab5f659 100644 --- a/types/params.go +++ b/types/params.go @@ -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. diff --git a/types/services.go b/types/services.go index b23ccff44..787b1b99e 100644 --- a/types/services.go +++ b/types/services.go @@ -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) } //------------------------------------------------------