-
Notifications
You must be signed in to change notification settings - Fork 4
/
params.go
148 lines (135 loc) · 4.53 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package types
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"gopkg.in/yaml.v2"
)
// nolint
const (
// Each value below is the default value for each parameter when generating the default
// genesis file. See comments in types.proto for explanation for each parameter.
DefaultMaxRawRequestCount = uint64(16)
DefaultMaxAskCount = uint64(16)
DefaultMaxCalldataSize = uint64(256) // 256B
DefaultMaxReportDataSize = uint64(512) // 512B
DefaultExpirationBlockCount = uint64(100)
DefaultBaseRequestGas = uint64(50000)
DefaultPerValidatorRequestGas = uint64(0)
DefaultSamplingTryCount = uint64(3)
DefaultOracleRewardPercentage = uint64(70)
DefaultInactivePenaltyDuration = uint64(10 * time.Minute)
DefaultIBCRequestEnabled = true
DefaultDataProviderRewardDenom = "minigeo"
DefaultRewardThresholdBlocks = uint64(28820)
)
var (
DefaultRewardThresholdAmount = sdk.NewCoins(sdk.NewInt64Coin(DefaultDataProviderRewardDenom, 200000000000), sdk.NewInt64Coin("loki", 200000000000)) // 200000 * 10^6
)
// NewParams creates a new parameter configuration for the oracle module
func NewParams(
maxRawRequestCount, maxAskCount, maxCalldataSize, maxReportDataSize, expirationBlockCount, baseRequestGas, perValidatorRequestGas,
samplingTryCount, oracleRewardPercentage, inactivePenaltyDuration uint64,
ibcRequestEnabled bool, dataProviderRewardThreshold RewardThreshold,
) Params {
return Params{
MaxRawRequestCount: maxRawRequestCount,
MaxAskCount: maxAskCount,
MaxCalldataSize: maxCalldataSize,
MaxReportDataSize: maxReportDataSize,
ExpirationBlockCount: expirationBlockCount,
BaseOwasmGas: baseRequestGas,
PerValidatorRequestGas: perValidatorRequestGas,
SamplingTryCount: samplingTryCount,
OracleRewardPercentage: oracleRewardPercentage,
InactivePenaltyDuration: inactivePenaltyDuration,
IBCRequestEnabled: ibcRequestEnabled,
DataProviderRewardThreshold: dataProviderRewardThreshold,
}
}
// DefaultParams defines the default parameters.
func DefaultParams() Params {
return NewParams(
DefaultMaxRawRequestCount,
DefaultMaxAskCount,
DefaultMaxCalldataSize,
DefaultMaxReportDataSize,
DefaultExpirationBlockCount,
DefaultBaseRequestGas,
DefaultPerValidatorRequestGas,
DefaultSamplingTryCount,
DefaultOracleRewardPercentage,
DefaultInactivePenaltyDuration,
DefaultIBCRequestEnabled,
DefaultRewardThreshold(),
)
}
func DefaultRewardThreshold() RewardThreshold {
return RewardThreshold{
Amount: DefaultRewardThresholdAmount,
Blocks: DefaultRewardThresholdBlocks,
}
}
// Validate does the sanity check on the params.
func (p Params) Validate() error {
if err := validateUint64("max raw request count", true)(p.MaxRawRequestCount); err != nil {
return err
}
if err := validateUint64("max ask count", true)(p.MaxAskCount); err != nil {
return err
}
if err := validateUint64("max calldata size", true)(p.MaxCalldataSize); err != nil {
return err
}
if err := validateUint64("max report data size", true)(p.MaxReportDataSize); err != nil {
return err
}
if err := validateUint64("expiration block count", true)(p.ExpirationBlockCount); err != nil {
return err
}
if err := validateUint64("base request gas", false)(p.BaseOwasmGas); err != nil {
return err
}
if err := validateUint64("per validator request gas", false)(p.PerValidatorRequestGas); err != nil {
return err
}
if err := validateUint64("sampling try count", true)(p.SamplingTryCount); err != nil {
return err
}
if err := validateUint64("oracle reward percentage", false)(p.OracleRewardPercentage); err != nil {
return err
}
if err := validateUint64("inactive penalty duration", false)(p.InactivePenaltyDuration); err != nil {
return err
}
if err := validateBool()(p.IBCRequestEnabled); err != nil {
return err
}
return nil
}
// String returns a human readable string representation of the parameters.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
func validateUint64(name string, positiveOnly bool) func(interface{}) error {
return func(i interface{}) error {
v, ok := i.(uint64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v <= 0 && positiveOnly {
return fmt.Errorf("%s must be positive: %d", name, v)
}
return nil
}
}
func validateBool() func(interface{}) error {
return func(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
}