-
Notifications
You must be signed in to change notification settings - Fork 73
/
params.go
174 lines (143 loc) · 5.17 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
163
164
165
166
167
168
169
170
171
172
173
174
package support
import (
"fmt"
"math/big"
paramsmodule "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/artela-network/artela/ethereum/utils"
"github.com/artela-network/artela-evm/vm"
"github.com/ethereum/go-ethereum/params"
cosmos "github.com/cosmos/cosmos-sdk/types"
)
var (
// DefaultEVMDenom defines the default EVM denomination on Artela
DefaultEVMDenom = utils.BaseDenom
// DefaultAllowUnprotectedTxs rejects all unprotected txs (i.e false)
DefaultAllowUnprotectedTxs = false
// DefaultEnableCreate enables contract creation (i.e true)
DefaultEnableCreate = true
// DefaultEnableCall enables contract calls (i.e true)
DefaultEnableCall = true
)
// AvailableExtraEIPs define the list of all EIPs that can be enabled by the
// EVM interpreter. These EIPs are applied in order and can override the
// instruction sets from the latest hard fork enabled by the ChainConfig. For
// more info check:
// https://github.com/ethereum/go-ethereum/blob/master/core/vm/interpreter.go#L97
var AvailableExtraEIPs = []int64{1344, 1884, 2200, 2929, 3198, 3529}
// Parameter keys
var (
ParamStoreKeyEVMDenom = []byte("EVMDenom")
ParamStoreKeyEnableCreate = []byte("EnableCreate")
ParamStoreKeyEnableCall = []byte("EnableCall")
ParamStoreKeyExtraEIPs = []byte("EnableExtraEIPs")
ParamStoreKeyChainConfig = []byte("ChainConfig")
ParamStoreKeyAllowUnprotectedTxs = []byte("AllowUnprotectedTxs")
)
// NewParams creates a new Params instance
func NewParams(evmDenom string, allowUnprotectedTxs, enableCreate, enableCall bool, config ChainConfig, extraEIPs []int64) Params {
return Params{
EvmDenom: evmDenom,
AllowUnprotectedTxs: allowUnprotectedTxs,
EnableCreate: enableCreate,
EnableCall: enableCall,
ExtraEIPs: extraEIPs,
ChainConfig: config,
}
}
// DefaultParams returns default evm parameters
// ExtraEIPs is empty to prevent overriding the latest hard fork instruction set
func DefaultParams() Params {
return Params{
EvmDenom: DefaultEVMDenom,
EnableCreate: DefaultEnableCreate,
EnableCall: DefaultEnableCall,
ChainConfig: DefaultChainConfig(),
ExtraEIPs: nil,
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
}
}
// Validate performs basic validation on evm parameters.
func (p Params) Validate() error {
if err := validateEVMDenom(p.EvmDenom); err != nil {
return err
}
if err := validateEIPs(p.ExtraEIPs); err != nil {
return err
}
if err := validateBool(p.EnableCall); err != nil {
return err
}
if err := validateBool(p.EnableCreate); err != nil {
return err
}
if err := validateBool(p.AllowUnprotectedTxs); err != nil {
return err
}
return validateChainConfig(p.ChainConfig)
}
// EIPs returns the ExtraEIPS as a int slice
func (p Params) EIPs() []int {
eips := make([]int, len(p.ExtraEIPs))
for i, eip := range p.ExtraEIPs {
eips[i] = int(eip)
}
return eips
}
// Deprecated: ParamKeyTable returns the parameter key table.
// Usage of x/params to manage parameters is deprecated in favor of x/gov
// controlled execution of MsgUpdateParams messages. These types remain solely
// for migration purposes and will be removed in a future release.
func ParamKeyTable() paramsmodule.KeyTable {
return paramsmodule.NewKeyTable().RegisterParamSet(&Params{})
}
// Deprecated: ParamSetPairs returns the parameter set pairs.
// Usage of x/params to manage parameters is deprecated in favor of x/gov
// controlled execution of MsgUpdateParams messages. These types remain solely
// for migration purposes and will be removed in a future release.
func (p *Params) ParamSetPairs() paramsmodule.ParamSetPairs {
return paramsmodule.ParamSetPairs{
paramsmodule.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
paramsmodule.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
paramsmodule.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
paramsmodule.NewParamSetPair(ParamStoreKeyExtraEIPs, &p.ExtraEIPs, validateEIPs),
paramsmodule.NewParamSetPair(ParamStoreKeyChainConfig, &p.ChainConfig, validateChainConfig),
paramsmodule.NewParamSetPair(ParamStoreKeyAllowUnprotectedTxs, &p.AllowUnprotectedTxs, validateBool),
}
}
func validateEVMDenom(i interface{}) error {
denom, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter EVM denom type: %T", i)
}
return cosmos.ValidateDenom(denom)
}
func validateBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateEIPs(i interface{}) error {
eips, ok := i.([]int64)
if !ok {
return fmt.Errorf("invalid EIP slice type: %T", i)
}
for _, eip := range eips {
if !vm.ValidEip(int(eip)) {
return fmt.Errorf("EIP %d is not activateable, valid EIPS are: %s", eip, vm.ActivateableEips())
}
}
return nil
}
func validateChainConfig(i interface{}) error {
cfg, ok := i.(ChainConfig)
if !ok {
return fmt.Errorf("invalid chain config type: %T", i)
}
return cfg.Validate()
}
// IsLondon returns if london hardfork is enabled.
func IsLondon(ethConfig *params.ChainConfig, height int64) bool {
return ethConfig.IsLondon(big.NewInt(height))
}