make ConsensusParams.EvidenceParams.MaxAge time

Refs #2565
This commit is contained in:
Anton Kaliaev
2018-10-16 10:26:59 +04:00
parent 80562669bf
commit 7e7e4c74ca
15 changed files with 520 additions and 269 deletions
+7 -5
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -386,7 +387,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
}
}
func makeParams(blockBytes, blockGas, evidenceAge int64) types.ConsensusParams {
func makeParams(blockBytes, blockGas int64, evidenceAge time.Duration) types.ConsensusParams {
return types.ConsensusParams{
BlockSize: types.BlockSize{
MaxBytes: blockBytes,
@@ -403,7 +404,8 @@ func pk() []byte {
}
func TestApplyUpdates(t *testing.T) {
initParams := makeParams(1, 2, 3)
initParams := makeParams(1, 2, 3*time.Second)
newMaxAge := 66 * time.Second
cases := [...]struct {
init types.ConsensusParams
@@ -419,14 +421,14 @@ func TestApplyUpdates(t *testing.T) {
MaxGas: 55,
},
},
makeParams(44, 55, 3)},
makeParams(44, 55, 3*time.Second)},
3: {initParams,
abci.ConsensusParams{
EvidenceParams: &abci.EvidenceParams{
MaxAge: 66,
MaxAge: &newMaxAge,
},
},
makeParams(1, 2, 66)},
makeParams(1, 2, 66*time.Second)},
}
for i, tc := range cases {
+3 -5
View File
@@ -168,13 +168,11 @@ func validateBlock(stateDB dbm.DB, state State, block *types.Block) error {
// - it is internally consistent
// - it was properly signed by the alleged equivocator
func VerifyEvidence(stateDB dbm.DB, state State, evidence types.Evidence) error {
height := state.LastBlockHeight
evidenceAge := height - evidence.Height()
evidenceAge := state.LastBlockTime.Sub(evidence.Time())
maxAge := state.ConsensusParams.EvidenceParams.MaxAge
if evidenceAge > maxAge {
return fmt.Errorf("Evidence from height %d is too old. Min height is %d",
evidence.Height(), height-maxAge)
return fmt.Errorf("Evidence from %v is too old. Expecting evidence no older than %v",
evidence.Time(), state.LastBlockTime.Add(-maxAge))
}
valset, err := LoadValidators(stateDB, evidence.Height())