forked from nnlgsakib/Msc-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.go
184 lines (155 loc) · 5.46 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
175
176
177
178
179
180
181
182
183
184
package chain
import (
"errors"
"sort"
"github.com/Mind-chain/mind/forkmanager"
"github.com/Mind-chain/mind/types"
)
var (
// ErrBurnContractAddressMissing is the error when a contract address is not provided
ErrBurnContractAddressMissing = errors.New("burn contract address missing")
)
// Params are all the set of params for the chain
type Params struct {
Forks *Forks `json:"forks"`
ChainID int64 `json:"chainID"`
Engine map[string]interface{} `json:"engine"`
BlockGasTarget uint64 `json:"blockGasTarget"`
// Access control configuration
AccessListsOwner *types.Address `json:"accessListsOwner,omitempty"`
ContractDeployerAllowList *AddressListConfig `json:"contractDeployerAllowList,omitempty"`
ContractDeployerBlockList *AddressListConfig `json:"contractDeployerBlockList,omitempty"`
TransactionsAllowList *AddressListConfig `json:"transactionsAllowList,omitempty"`
TransactionsBlockList *AddressListConfig `json:"transactionsBlockList,omitempty"`
BridgeAllowList *AddressListConfig `json:"bridgeAllowList,omitempty"`
BridgeBlockList *AddressListConfig `json:"bridgeBlockList,omitempty"`
// Governance contract where the token will be sent to and burn in london fork
BurnContract map[uint64]types.Address `json:"burnContract"`
// Destination address to initialize default burn contract with
BurnContractDestinationAddress types.Address `json:"burnContractDestinationAddress,omitempty"`
}
type AddressListConfig struct {
// AdminAddresses is the list of the initial admin addresses
AdminAddresses []types.Address `json:"adminAddresses,omitempty"`
// EnabledAddresses is the list of the initial enabled addresses
EnabledAddresses []types.Address `json:"enabledAddresses,omitempty"`
}
// CalculateBurnContract calculates burn contract address for the given block number
func (p *Params) CalculateBurnContract(block uint64) (types.Address, error) {
blocks := make([]uint64, 0, len(p.BurnContract))
for startBlock := range p.BurnContract {
blocks = append(blocks, startBlock)
}
if len(blocks) == 0 {
return types.ZeroAddress, ErrBurnContractAddressMissing
}
sort.Slice(blocks, func(i, j int) bool {
return blocks[i] < blocks[j]
})
for i := 0; i < len(blocks)-1; i++ {
if block >= blocks[i] && block < blocks[i+1] {
return p.BurnContract[blocks[i]], nil
}
}
return p.BurnContract[blocks[len(blocks)-1]], nil
}
func (p *Params) GetEngine() string {
// We know there is already one
for k := range p.Engine {
return k
}
return ""
}
// predefined forks
const (
Homestead = "homestead"
Byzantium = "byzantium"
Constantinople = "constantinople"
Petersburg = "petersburg"
Istanbul = "istanbul"
London = "london"
EIP150 = "EIP150"
EIP158 = "EIP158"
EIP155 = "EIP155"
EIP2929 = "EIP2929"
Londonv2 = "londonv2"
QuorumCalcAlignment = "quorumcalcalignment"
TxHashWithType = "txHashWithType"
)
// Forks is map which contains all forks and their starting blocks from genesis
type Forks map[string]Fork
// IsActive returns true if fork defined by name exists and defined for the block
func (f *Forks) IsActive(name string, block uint64) bool {
ff, exists := (*f)[name]
return exists && ff.Active(block)
}
// SetFork adds/updates fork defined by name
func (f *Forks) SetFork(name string, value Fork) {
(*f)[name] = value
}
// func (f *Forks) RemoveFork(name string) {
// delete(*f, name)
// }
func (f *Forks) RemoveFork(name string) *Forks {
delete(*f, name)
return f
}
// At returns ForksInTime instance that shows which supported forks are enabled for the block
func (f *Forks) At(block uint64) ForksInTime {
return ForksInTime{
Homestead: f.IsActive(Homestead, block),
Byzantium: f.IsActive(Byzantium, block),
Constantinople: f.IsActive(Constantinople, block),
Petersburg: f.IsActive(Petersburg, block),
Istanbul: f.IsActive(Istanbul, block),
London: f.IsActive(London, block),
EIP150: f.IsActive(EIP150, block),
EIP158: f.IsActive(EIP158, block),
EIP155: f.IsActive(EIP155, block),
QuorumCalcAlignment: f.IsActive(QuorumCalcAlignment, block),
TxHashWithType: f.IsActive(TxHashWithType, block),
Londonv2: f.IsActive(Londonv2, block),
}
}
type Fork struct {
Block uint64 `json:"block"`
Params *forkmanager.ForkParams `json:"params,omitempty"`
}
func NewFork(n uint64) Fork {
return Fork{Block: n}
}
func (f Fork) Active(block uint64) bool {
return block >= f.Block
}
// ForksInTime should contain all supported forks by current edge version
type ForksInTime struct {
Homestead,
Byzantium,
Constantinople,
Petersburg,
Istanbul,
London,
EIP150,
EIP158,
EIP155,
EIP2929,
QuorumCalcAlignment,
TxHashWithType,
Londonv2 bool
}
// AllForksEnabled should contain all supported forks by current edge version
var AllForksEnabled = &Forks{
Homestead: NewFork(0),
EIP150: NewFork(0),
EIP155: NewFork(0),
EIP158: NewFork(0),
EIP2929: NewFork(6334150),
Byzantium: NewFork(0),
Constantinople: NewFork(0),
Petersburg: NewFork(0),
Istanbul: NewFork(0),
London: NewFork(0),
QuorumCalcAlignment: NewFork(0),
TxHashWithType: NewFork(0),
Londonv2: NewFork(6334149),
}