forked from Finschia/finschia-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
96 lines (77 loc) · 2.71 KB
/
params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package baseapp
import (
"errors"
"fmt"
abci "github.com/line/ostracon/abci/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
octypes "github.com/line/ostracon/types"
sdk "github.com/line/lbm-sdk/types"
)
// Paramspace defines the parameter subspace to be used for the paramstore.
const Paramspace = "baseapp"
// Parameter store keys for all the consensus parameter types.
var (
ParamStoreKeyBlockParams = []byte("BlockParams")
ParamStoreKeyEvidenceParams = []byte("EvidenceParams")
ParamStoreKeyValidatorParams = []byte("ValidatorParams")
)
// ParamStore defines the interface the parameter store used by the BaseApp must
// fulfill.
type ParamStore interface {
Get(ctx sdk.Context, key []byte, ptr interface{})
Has(ctx sdk.Context, key []byte) bool
Set(ctx sdk.Context, key []byte, param interface{})
}
// ValidateBlockParams defines a stateless validation on BlockParams. This function
// is called whenever the parameters are updated or stored.
func ValidateBlockParams(i interface{}) error {
v, ok := i.(abci.BlockParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.MaxBytes <= 0 {
return fmt.Errorf("block maximum bytes must be positive: %d", v.MaxBytes)
}
if v.MaxGas < -1 {
return fmt.Errorf("block maximum gas must be greater than or equal to -1: %d", v.MaxGas)
}
return nil
}
// ValidateEvidenceParams defines a stateless validation on EvidenceParams. This
// function is called whenever the parameters are updated or stored.
func ValidateEvidenceParams(i interface{}) error {
v, ok := i.(ocproto.EvidenceParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.MaxAgeNumBlocks <= 0 {
return fmt.Errorf("evidence maximum age in blocks must be positive: %d", v.MaxAgeNumBlocks)
}
if v.MaxAgeDuration <= 0 {
return fmt.Errorf("evidence maximum age time duration must be positive: %v", v.MaxAgeDuration)
}
if v.MaxBytes < 0 {
return fmt.Errorf("maximum evidence bytes must be non-negative: %v", v.MaxBytes)
}
return nil
}
// ValidateValidatorParams defines a stateless validation on ValidatorParams. This
// function is called whenever the parameters are updated or stored.
func ValidateValidatorParams(i interface{}) error {
v, ok := i.(ocproto.ValidatorParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if len(v.PubKeyTypes) == 0 {
return errors.New("validator allowed pubkey types must not be empty")
}
for _, pubKeyType := range v.PubKeyTypes {
switch pubKeyType {
case octypes.ABCIPubKeyTypeBls12WithEd25519, octypes.ABCIPubKeyTypeEd25519, octypes.ABCIPubKeyTypeSecp256k1, octypes.ABCIPubKeyTypeBls12:
continue
default:
return fmt.Errorf("not-allowed pubkey type: %s", pubKeyType)
}
}
return nil
}