mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-13 11:34:17 +00:00
@@ -3,8 +3,10 @@ package types
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
@@ -54,6 +56,7 @@ func (err *ErrEvidenceOverflow) Error() string {
|
||||
// Evidence represents any provable malicious activity by a validator
|
||||
type Evidence interface {
|
||||
Height() int64 // height of the equivocation
|
||||
Time() time.Time // when the evidence was created
|
||||
Address() []byte // address of the equivocating validator
|
||||
Bytes() []byte // bytes which compromise the evidence
|
||||
Hash() []byte // hash of the evidence
|
||||
@@ -102,6 +105,11 @@ func (dve *DuplicateVoteEvidence) Height() int64 {
|
||||
return dve.VoteA.Height
|
||||
}
|
||||
|
||||
// Time returns the time when the evidence was created.
|
||||
func (dve *DuplicateVoteEvidence) Time() time.Time {
|
||||
return dve.VoteA.Timestamp
|
||||
}
|
||||
|
||||
// Address returns the address of the validator.
|
||||
func (dve *DuplicateVoteEvidence) Address() []byte {
|
||||
return dve.PubKey.Address()
|
||||
@@ -188,6 +196,7 @@ func NewMockGoodEvidence(height int64, idx int, address []byte) MockGoodEvidence
|
||||
}
|
||||
|
||||
func (e MockGoodEvidence) Height() int64 { return e.Height_ }
|
||||
func (e MockGoodEvidence) Time() time.Time { return tmtime.Now() }
|
||||
func (e MockGoodEvidence) Address() []byte { return e.Address_ }
|
||||
func (e MockGoodEvidence) Hash() []byte {
|
||||
return []byte(fmt.Sprintf("%d-%x", e.Height_, e.Address_))
|
||||
|
||||
+7
-3
@@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
@@ -29,7 +31,7 @@ type BlockSize struct {
|
||||
|
||||
// EvidenceParams determine how we handle evidence of malfeasance
|
||||
type EvidenceParams struct {
|
||||
MaxAge int64 `json:"max_age"` // only accept new evidence more recent than this
|
||||
MaxAge time.Duration `json:"max_age"` // only accept new evidence more recent than this
|
||||
}
|
||||
|
||||
// DefaultConsensusParams returns a default ConsensusParams.
|
||||
@@ -51,7 +53,7 @@ func DefaultBlockSize() BlockSize {
|
||||
// DefaultEvidenceParams Params returns a default EvidenceParams.
|
||||
func DefaultEvidenceParams() EvidenceParams {
|
||||
return EvidenceParams{
|
||||
MaxAge: 100000, // 27.8 hrs at 1block/s
|
||||
MaxAge: 48 * time.Hour,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +111,9 @@ func (params ConsensusParams) Update(params2 *abci.ConsensusParams) ConsensusPar
|
||||
res.BlockSize.MaxGas = params2.BlockSize.MaxGas
|
||||
}
|
||||
if params2.EvidenceParams != nil {
|
||||
res.EvidenceParams.MaxAge = params2.EvidenceParams.MaxAge
|
||||
if params2.EvidenceParams.MaxAge != nil {
|
||||
res.EvidenceParams.MaxAge = *params2.EvidenceParams.MaxAge
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
+20
-23
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@@ -15,17 +16,17 @@ func TestConsensusParamsValidation(t *testing.T) {
|
||||
valid bool
|
||||
}{
|
||||
// test block size
|
||||
0: {makeParams(1, 0, 1), true},
|
||||
1: {makeParams(0, 0, 1), false},
|
||||
2: {makeParams(47*1024*1024, 0, 1), true},
|
||||
3: {makeParams(10, 0, 1), true},
|
||||
4: {makeParams(100*1024*1024, 0, 1), true},
|
||||
5: {makeParams(101*1024*1024, 0, 1), false},
|
||||
6: {makeParams(1024*1024*1024, 0, 1), false},
|
||||
7: {makeParams(1024*1024*1024, 0, -1), false},
|
||||
0: {makeParams(1, 0, 10*time.Second), true},
|
||||
1: {makeParams(0, 0, 10*time.Second), false},
|
||||
2: {makeParams(47*1024*1024, 0, 10*time.Second), true},
|
||||
3: {makeParams(10, 0, 10*time.Second), true},
|
||||
4: {makeParams(100*1024*1024, 0, 10*time.Second), true},
|
||||
5: {makeParams(101*1024*1024, 0, 10*time.Second), false},
|
||||
6: {makeParams(1024*1024*1024, 0, 10*time.Second), false},
|
||||
7: {makeParams(1024*1024*1024, 0, -10*time.Second), false},
|
||||
// test evidence age
|
||||
8: {makeParams(1, 0, 0), false},
|
||||
9: {makeParams(1, 0, -1), false},
|
||||
9: {makeParams(1, 0, -1*time.Millisecond), false},
|
||||
}
|
||||
for i, tc := range testCases {
|
||||
if tc.valid {
|
||||
@@ -36,7 +37,7 @@ func TestConsensusParamsValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeParams(blockBytes, blockGas, evidenceAge int64) ConsensusParams {
|
||||
func makeParams(blockBytes, blockGas int64, evidenceAge time.Duration) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
BlockSize: BlockSize{
|
||||
MaxBytes: blockBytes,
|
||||
@@ -50,14 +51,9 @@ func makeParams(blockBytes, blockGas, evidenceAge int64) ConsensusParams {
|
||||
|
||||
func TestConsensusParamsHash(t *testing.T) {
|
||||
params := []ConsensusParams{
|
||||
makeParams(4, 2, 3),
|
||||
makeParams(1, 4, 3),
|
||||
makeParams(1, 2, 4),
|
||||
makeParams(2, 5, 7),
|
||||
makeParams(1, 7, 6),
|
||||
makeParams(9, 5, 4),
|
||||
makeParams(7, 8, 9),
|
||||
makeParams(4, 6, 5),
|
||||
makeParams(4, 2, 3*time.Second),
|
||||
makeParams(1, 4, 3*time.Second),
|
||||
makeParams(1, 2, 4*time.Second),
|
||||
}
|
||||
|
||||
hashes := make([][]byte, len(params))
|
||||
@@ -76,6 +72,7 @@ func TestConsensusParamsHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConsensusParamsUpdate(t *testing.T) {
|
||||
newMaxAge := 300 * time.Second
|
||||
testCases := []struct {
|
||||
params ConsensusParams
|
||||
updates *abci.ConsensusParams
|
||||
@@ -83,23 +80,23 @@ func TestConsensusParamsUpdate(t *testing.T) {
|
||||
}{
|
||||
// empty updates
|
||||
{
|
||||
makeParams(1, 2, 3),
|
||||
makeParams(1, 2, 3*time.Second),
|
||||
&abci.ConsensusParams{},
|
||||
makeParams(1, 2, 3),
|
||||
makeParams(1, 2, 3*time.Second),
|
||||
},
|
||||
// fine updates
|
||||
{
|
||||
makeParams(1, 2, 3),
|
||||
makeParams(1, 2, 3*time.Second),
|
||||
&abci.ConsensusParams{
|
||||
BlockSize: &abci.BlockSize{
|
||||
MaxBytes: 100,
|
||||
MaxGas: 200,
|
||||
},
|
||||
EvidenceParams: &abci.EvidenceParams{
|
||||
MaxAge: 300,
|
||||
MaxAge: &newMaxAge,
|
||||
},
|
||||
},
|
||||
makeParams(100, 200, 300),
|
||||
makeParams(100, 200, 300*time.Second),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
|
||||
+6
-5
@@ -119,7 +119,7 @@ func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
|
||||
MaxGas: params.BlockSize.MaxGas,
|
||||
},
|
||||
EvidenceParams: &abci.EvidenceParams{
|
||||
MaxAge: params.EvidenceParams.MaxAge,
|
||||
MaxAge: ¶ms.EvidenceParams.MaxAge,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -209,13 +209,14 @@ func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error)
|
||||
}
|
||||
|
||||
func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams {
|
||||
return ConsensusParams{
|
||||
params := ConsensusParams{
|
||||
BlockSize: BlockSize{
|
||||
MaxBytes: csp.BlockSize.MaxBytes,
|
||||
MaxGas: csp.BlockSize.MaxGas,
|
||||
},
|
||||
EvidenceParams: EvidenceParams{
|
||||
MaxAge: csp.EvidenceParams.MaxAge,
|
||||
},
|
||||
}
|
||||
if csp.EvidenceParams.MaxAge != nil {
|
||||
params.EvidenceParams.MaxAge = *csp.EvidenceParams.MaxAge
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user