-
Notifications
You must be signed in to change notification settings - Fork 105
/
params.go
162 lines (147 loc) · 6.35 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package types
import (
time "time"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"
)
const (
// about 2 hr at 7.6 seconds per blocks
DefaultBlocksPerDistributionTransmission = 1000
// Default transfer timeout period is 1 hour, less than the default blocks
// per dist transmission * average block time.
// Since IBC token transfers do not have to be in order, it could be easier
// to reason about the distribution protocol if the previous reward times out
// before sending the next one. Note that on timeout, the transferred funds are
// added back to the pool, so the next transfer will include them as well.
DefaultTransferTimeoutPeriod = time.Hour
// The default fraction of tokens allocated to the consumer redistribution address
// during distribution events. The fraction is a string representing a
// decimal number. For example "0.75" would represent 75%.
DefaultConsumerRedistributeFrac = "0.75"
// Default number of historical info entries to persist in store.
// We use the same default as the staking module, but use a signed integer
// so that negative values can be caught during parameter validation in a readable way,
// (and for consistency with other protobuf schemas defined for ccv).
DefaultHistoricalEntries = int64(stakingtypes.DefaultHistoricalEntries)
// In general, the default unbonding period on the consumer is one day less
// than the default unbonding period on the provider, where the provider uses
// the staking module default.
DefaultConsumerUnbondingPeriod = stakingtypes.DefaultUnbondingTime - 24*time.Hour
)
// Reflection based keys for params subspace
var (
KeyEnabled = []byte("Enabled")
KeyBlocksPerDistributionTransmission = []byte("BlocksPerDistributionTransmission")
KeyDistributionTransmissionChannel = []byte("DistributionTransmissionChannel")
KeyProviderFeePoolAddrStr = []byte("ProviderFeePoolAddrStr")
KeyTransferTimeoutPeriod = []byte("TransferTimeoutPeriod")
KeyConsumerRedistributionFrac = []byte("ConsumerRedistributionFraction")
KeyHistoricalEntries = []byte("HistoricalEntries")
KeyConsumerUnbondingPeriod = []byte("UnbondingPeriod")
)
// ParamKeyTable type declaration for parameters
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
// NewParams creates new consumer parameters with provided arguments
func NewParams(enabled bool, blocksPerDistributionTransmission int64,
distributionTransmissionChannel, providerFeePoolAddrStr string,
ccvTimeoutPeriod time.Duration, transferTimeoutPeriod time.Duration,
consumerRedistributionFraction string, historicalEntries int64,
consumerUnbondingPeriod time.Duration) Params {
return Params{
Enabled: enabled,
BlocksPerDistributionTransmission: blocksPerDistributionTransmission,
DistributionTransmissionChannel: distributionTransmissionChannel,
ProviderFeePoolAddrStr: providerFeePoolAddrStr,
CcvTimeoutPeriod: ccvTimeoutPeriod,
TransferTimeoutPeriod: transferTimeoutPeriod,
ConsumerRedistributionFraction: consumerRedistributionFraction,
HistoricalEntries: historicalEntries,
UnbondingPeriod: consumerUnbondingPeriod,
}
}
// DefaultParams is the default params for the consumer module
func DefaultParams() Params {
return NewParams(
false,
DefaultBlocksPerDistributionTransmission,
"",
"",
ccvtypes.DefaultCCVTimeoutPeriod,
DefaultTransferTimeoutPeriod,
DefaultConsumerRedistributeFrac,
DefaultHistoricalEntries,
DefaultConsumerUnbondingPeriod,
)
}
// Validate all ccv-consumer module parameters
func (p Params) Validate() error {
if err := ccvtypes.ValidateBool(p.Enabled); err != nil {
return err
}
if err := ccvtypes.ValidatePositiveInt64(p.BlocksPerDistributionTransmission); err != nil {
return err
}
if err := validateDistributionTransmissionChannel(p.DistributionTransmissionChannel); err != nil {
return err
}
if err := validateProviderFeePoolAddrStr(p.ProviderFeePoolAddrStr); err != nil {
return err
}
if err := ccvtypes.ValidateDuration(p.CcvTimeoutPeriod); err != nil {
return err
}
if err := ccvtypes.ValidateDuration(p.TransferTimeoutPeriod); err != nil {
return err
}
if err := ccvtypes.ValidateStringFraction(p.ConsumerRedistributionFraction); err != nil {
return err
}
if err := ccvtypes.ValidatePositiveInt64(p.HistoricalEntries); err != nil {
return err
}
if err := ccvtypes.ValidateDuration(p.UnbondingPeriod); err != nil {
return err
}
return nil
}
// ParamSetPairs implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyEnabled, p.Enabled, ccvtypes.ValidateBool),
paramtypes.NewParamSetPair(KeyBlocksPerDistributionTransmission,
p.BlocksPerDistributionTransmission, ccvtypes.ValidatePositiveInt64),
paramtypes.NewParamSetPair(KeyDistributionTransmissionChannel,
p.DistributionTransmissionChannel, validateDistributionTransmissionChannel),
paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr,
p.ProviderFeePoolAddrStr, validateProviderFeePoolAddrStr),
paramtypes.NewParamSetPair(ccvtypes.KeyCCVTimeoutPeriod,
p.CcvTimeoutPeriod, ccvtypes.ValidateDuration),
paramtypes.NewParamSetPair(KeyTransferTimeoutPeriod,
p.TransferTimeoutPeriod, ccvtypes.ValidateDuration),
paramtypes.NewParamSetPair(KeyConsumerRedistributionFrac,
p.ConsumerRedistributionFraction, ccvtypes.ValidateStringFraction),
paramtypes.NewParamSetPair(KeyHistoricalEntries,
p.HistoricalEntries, ccvtypes.ValidatePositiveInt64),
paramtypes.NewParamSetPair(KeyConsumerUnbondingPeriod,
p.UnbondingPeriod, ccvtypes.ValidateDuration),
}
}
func validateDistributionTransmissionChannel(i interface{}) error {
// Accept empty string as valid, since this will be the default value on genesis
if i == "" {
return nil
}
// Otherwise validate as usual for a channelID
return ccvtypes.ValidateChannelIdentifier(i)
}
func validateProviderFeePoolAddrStr(i interface{}) error {
// Accept empty string as valid, since this will be the default value on genesis
if i == "" {
return nil
}
// Otherwise validate as usual for a bech32 address
return ccvtypes.ValidateBech32(i)
}