Browse Source

evidence: fix usage of time field in abci evidence (#5201)

* fix usage of time in abci evidence

* update changelong and upgrading

* add test cases
pull/5204/head
Callum Waters 4 years ago
committed by GitHub
parent
commit
68468fb024
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 13 deletions
  1. +5
    -1
      CHANGELOG_PENDING.md
  2. +3
    -0
      proto/tendermint/abci/types.proto
  3. +1
    -1
      state/execution.go
  4. +3
    -3
      state/execution_test.go
  5. +4
    -5
      types/protobuf.go
  6. +4
    -3
      types/protobuf_test.go

+ 5
- 1
CHANGELOG_PENDING.md View File

@ -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)
- [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)

+ 3
- 0
proto/tendermint/abci/types.proto View File

@ -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


+ 1
- 1
state/execution.go View File

@ -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{


+ 3
- 3
state/execution_test.go View File

@ -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 (


+ 4
- 5
types/protobuf.go View File

@ -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(),
}
}


+ 4
- 3
types/protobuf_test.go View File

@ -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{}


Loading…
Cancel
Save