mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-13 11:34:17 +00:00
Use proposer timestamp instead of genesis time for height 1 block time (#7541)
This commit is contained in:
+12
-15
@@ -15,15 +15,11 @@ import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// For some reason the empty node used in tests has a time of
|
||||
// 2018-10-10 08:20:13.695936996 +0000 UTC
|
||||
// this is because the test genesis time is set here
|
||||
// so in order to validate evidence we need evidence to be the same time
|
||||
var defaultTestTime = time.Date(2018, 10, 10, 8, 20, 13, 695936996, time.UTC)
|
||||
|
||||
func newEvidence(t *testing.T, val *privval.FilePV,
|
||||
vote *types.Vote, vote2 *types.Vote,
|
||||
chainID string) *types.DuplicateVoteEvidence {
|
||||
chainID string,
|
||||
timestamp time.Time,
|
||||
) *types.DuplicateVoteEvidence {
|
||||
t.Helper()
|
||||
var err error
|
||||
|
||||
@@ -39,7 +35,7 @@ func newEvidence(t *testing.T, val *privval.FilePV,
|
||||
validator := types.NewValidator(val.Key.PubKey, 10)
|
||||
valSet := types.NewValidatorSet([]*types.Validator{validator})
|
||||
|
||||
ev, err := types.NewDuplicateVoteEvidence(vote, vote2, defaultTestTime, valSet)
|
||||
ev, err := types.NewDuplicateVoteEvidence(vote, vote2, timestamp, valSet)
|
||||
require.NoError(t, err)
|
||||
return ev
|
||||
}
|
||||
@@ -48,6 +44,7 @@ func makeEvidences(
|
||||
t *testing.T,
|
||||
val *privval.FilePV,
|
||||
chainID string,
|
||||
timestamp time.Time,
|
||||
) (correct *types.DuplicateVoteEvidence, fakes []*types.DuplicateVoteEvidence) {
|
||||
vote := types.Vote{
|
||||
ValidatorAddress: val.Key.Address,
|
||||
@@ -55,7 +52,7 @@ func makeEvidences(
|
||||
Height: 1,
|
||||
Round: 0,
|
||||
Type: tmproto.PrevoteType,
|
||||
Timestamp: defaultTestTime,
|
||||
Timestamp: timestamp,
|
||||
BlockID: types.BlockID{
|
||||
Hash: tmhash.Sum(tmrand.Bytes(tmhash.Size)),
|
||||
PartSetHeader: types.PartSetHeader{
|
||||
@@ -67,7 +64,7 @@ func makeEvidences(
|
||||
|
||||
vote2 := vote
|
||||
vote2.BlockID.Hash = tmhash.Sum([]byte("blockhash2"))
|
||||
correct = newEvidence(t, val, &vote, &vote2, chainID)
|
||||
correct = newEvidence(t, val, &vote, &vote2, chainID, timestamp)
|
||||
|
||||
fakes = make([]*types.DuplicateVoteEvidence, 0)
|
||||
|
||||
@@ -75,34 +72,34 @@ func makeEvidences(
|
||||
{
|
||||
v := vote2
|
||||
v.ValidatorAddress = []byte("some_address")
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID, timestamp))
|
||||
}
|
||||
|
||||
// different height
|
||||
{
|
||||
v := vote2
|
||||
v.Height = vote.Height + 1
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID, timestamp))
|
||||
}
|
||||
|
||||
// different round
|
||||
{
|
||||
v := vote2
|
||||
v.Round = vote.Round + 1
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID, timestamp))
|
||||
}
|
||||
|
||||
// different type
|
||||
{
|
||||
v := vote2
|
||||
v.Type = tmproto.PrecommitType
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID, timestamp))
|
||||
}
|
||||
|
||||
// exactly same vote
|
||||
{
|
||||
v := vote
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID, timestamp))
|
||||
}
|
||||
|
||||
return correct, fakes
|
||||
|
||||
@@ -544,10 +544,12 @@ func TestClientMethodCalls(t *testing.T) {
|
||||
|
||||
chainID := conf.ChainID()
|
||||
|
||||
correct, fakes := makeEvidences(t, pv, chainID)
|
||||
|
||||
// make sure that the node has produced enough blocks
|
||||
waitForBlock(ctx, t, c, 2)
|
||||
evidenceHeight := int64(1)
|
||||
block, _ := c.Block(ctx, &evidenceHeight)
|
||||
ts := block.Block.Time
|
||||
correct, fakes := makeEvidences(t, pv, chainID, ts)
|
||||
|
||||
result, err := c.BroadcastEvidence(ctx, correct)
|
||||
require.NoError(t, err, "BroadcastEvidence(%s) failed", correct)
|
||||
|
||||
Reference in New Issue
Block a user