From 68468fb024ebb63a2b693d6ed03b4f5d108fb68a Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 4 Aug 2020 12:58:48 +0200 Subject: [PATCH] evidence: fix usage of time field in abci evidence (#5201) * fix usage of time in abci evidence * update changelong and upgrading * add test cases --- CHANGELOG_PENDING.md | 6 +++++- proto/tendermint/abci/types.proto | 3 +++ state/execution.go | 2 +- state/execution_test.go | 6 +++--- types/protobuf.go | 9 ++++----- types/protobuf_test.go | 7 ++++--- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 70895dbec..0488e8b94 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -12,4 +12,8 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi ### FEATURES: -- [abci] [\#5174](https://github.com/tendermint/tendermint/pull/5174) Add amnesia evidence and remove mock and potential amnesia evidence from abci (@cmwaters) \ No newline at end of file +- [abci] [\#5174](https://github.com/tendermint/tendermint/pull/5174) Add amnesia evidence and remove mock and potential amnesia evidence from abci (@cmwaters) + +### BUG FIXES: + +- [evidence] [\#5170](https://github.com/tendermint/tendermint/pull/5170) change abci evidence time to the time the infraction happened not the time the evidence was committed on the block (@cmwaters) diff --git a/proto/tendermint/abci/types.proto b/proto/tendermint/abci/types.proto index 59309f070..a966cc21b 100644 --- a/proto/tendermint/abci/types.proto +++ b/proto/tendermint/abci/types.proto @@ -351,8 +351,11 @@ message VoteInfo { message Evidence { string type = 1; + // The offending validator Validator validator = 2 [(gogoproto.nullable) = false]; + // The height when the offense occurred int64 height = 3; + // The corresponding time where the offense occurred google.protobuf.Timestamp time = 4 [ (gogoproto.nullable) = false, (gogoproto.stdtime) = true diff --git a/state/execution.go b/state/execution.go index c7760f004..df979cb7f 100644 --- a/state/execution.go +++ b/state/execution.go @@ -360,7 +360,7 @@ func getBeginBlockValidatorInfo(block *types.Block, stateDB dbm.DB) (abci.LastCo if err != nil { panic(err) } - byzVals[i] = types.TM2PB.Evidence(ev, valset, block.Time) + byzVals[i] = types.TM2PB.Evidence(ev, valset) } return abci.LastCommitInfo{ diff --git a/state/execution_test.go b/state/execution_test.go index 0cb5310aa..86a7c8bb9 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -140,10 +140,10 @@ func TestBeginBlockByzantineValidators(t *testing.T) { expectedByzantineValidators []abci.Evidence }{ {"none byzantine", []types.Evidence{}, []abci.Evidence{}}, - {"one byzantine", []types.Evidence{ev1}, []abci.Evidence{types.TM2PB.Evidence(ev1, valSet, now)}}, + {"one byzantine", []types.Evidence{ev1}, []abci.Evidence{types.TM2PB.Evidence(ev1, valSet)}}, {"multiple byzantine", []types.Evidence{ev1, ev2}, []abci.Evidence{ - types.TM2PB.Evidence(ev1, valSet, now), - types.TM2PB.Evidence(ev2, valSet, now)}}, + types.TM2PB.Evidence(ev1, valSet), + types.TM2PB.Evidence(ev2, valSet)}}, } var ( diff --git a/types/protobuf.go b/types/protobuf.go index 9dbe9d430..6197e0888 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -3,7 +3,6 @@ package types import ( "fmt" "reflect" - "time" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" @@ -118,12 +117,12 @@ func (tm2pb) ConsensusParams(params *tmproto.ConsensusParams) *abci.ConsensusPar // ABCI Evidence includes information from the past that's not included in the evidence itself // so Evidence types stays compact. // XXX: panics on nil or unknown pubkey type -func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci.Evidence { +func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet) abci.Evidence { addr := ev.Address() _, val := valSet.GetByAddress(addr) if val == nil { // should already have checked this - panic(val) + panic(fmt.Sprintf("validator in evidence is not in val set, val addr: %v", addr)) } // set type @@ -136,14 +135,14 @@ func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci. case *AmnesiaEvidence: evType = ABCIEvidenceTypeAmnesia default: - panic(fmt.Sprintf("Unknown evidence type: %v %v", ev, reflect.TypeOf(ev))) + panic(fmt.Sprintf("unknown evidence type: %v %v", ev, reflect.TypeOf(ev))) } return abci.Evidence{ Type: evType, Validator: TM2PB.Validator(val), Height: ev.Height(), - Time: evTime, + Time: ev.Time(), TotalVotingPower: valSet.TotalVotingPower(), } } diff --git a/types/protobuf_test.go b/types/protobuf_test.go index b0e73ac29..f845e99b4 100644 --- a/types/protobuf_test.go +++ b/types/protobuf_test.go @@ -2,7 +2,6 @@ package types import ( "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -75,10 +74,12 @@ func TestABCIEvidence(t *testing.T) { abciEv := TM2PB.Evidence( ev, NewValidatorSet([]*Validator{NewValidator(pubKey, 10)}), - time.Now(), ) - assert.Equal(t, "duplicate/vote", abciEv.Type) + assert.Equal(t, ABCIEvidenceTypeDuplicateVote, abciEv.Type) + assert.Equal(t, ev.Time(), abciEv.GetTime()) + assert.Equal(t, ev.Address(), abciEv.Validator.GetAddress()) + assert.Equal(t, ev.Height(), abciEv.GetHeight()) } type pubKeyEddie struct{}