mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
evidence: fix usage of time field in abci evidence (#5201)
* fix usage of time in abci evidence * update changelong and upgrading * add test cases
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user