-
Notifications
You must be signed in to change notification settings - Fork 33
/
static.go
191 lines (161 loc) · 5.25 KB
/
static.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
185
186
187
188
189
190
191
package netconf
import (
"fmt"
"strconv"
"strings"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/evmchain"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
_ "embed"
)
const consensusIDPrefix = "omni-"
const consensusIDOffset = 1_000_000
const maxValidators = 10
// Static defines static config and data for a network.
type Static struct {
Version string
OmniExecutionChainID uint64
AVSContractAddress common.Address
Portals []Deployment
MaxValidators uint32
ConsensusGenesisJSON []byte
ConsensusSeedTXT []byte
ExecutionGenesisJSON []byte
ExecutionSeedTXT []byte
}
type Deployment struct {
ChainID uint64
Address common.Address
DeployHeight uint64
}
// OmniConsensusChainIDStr returns the chain ID string for the Omni consensus chain.
// It is calculated as "omni-<OmniConsensusChainIDUint64>".
func (s Static) OmniConsensusChainIDStr() string {
return fmt.Sprintf("%s%d", consensusIDPrefix, s.OmniConsensusChainIDUint64())
}
// OmniConsensusChainIDUint64 returns the chain ID uint64 for the Omni consensus chain.
// It is calculated as 1_000_000 + OmniExecutionChainID.
func (s Static) OmniConsensusChainIDUint64() uint64 {
return consensusIDOffset + s.OmniExecutionChainID
}
// PortalDeployment returns the portal deployment for the given chainID.
// If there is none, it returns an empty deployment.
func (s Static) PortalDeployment(chainID uint64) (Deployment, bool) {
for _, d := range s.Portals {
if d.ChainID == chainID {
return d, true
}
}
return Deployment{}, false
}
func (s Static) ConsensusSeeds() []string {
var resp []string
for _, seed := range strings.Split(string(s.ConsensusSeedTXT), "\n") {
if seed = strings.TrimSpace(seed); seed != "" {
resp = append(resp, seed)
}
}
return resp
}
func (s Static) ExecutionSeeds() []string {
var resp []string
for _, seed := range strings.Split(string(s.ExecutionSeedTXT), "\n") {
if seed = strings.TrimSpace(seed); seed != "" {
resp = append(resp, seed)
}
}
return resp
}
// Use random runid for staging version.
//
//nolint:gochecknoglobals // Static ID
var runid = uuid.New().String()
//nolint:gochecknoglobals // Static addresses
var (
// Address matches lib/contracts.TestnetPortal() and lib/contracts.TestnetAVS().
// We do not import to avoid cylic dependencies.
testnetPortal = common.HexToAddress("0xFf22F3532C19a6f890c52c4CfcDB94007aA471Dc")
testnetAVS = common.HexToAddress("0xa7b2e7830C51728832D33421670DbBE30299fD92")
// This address DOES NOT match lib/contracts.MainnetAVS().
// This mainnet AVS was deployed outside of the e2e deployment flow, without Create3.
mainnetAVS = common.HexToAddress("0xed2f4d90b073128ae6769a9A8D51547B1Df766C8")
//go:embed testnet/consensus-genesis.json
testnetConsensusGenesisJSON []byte
//go:embed testnet/consensus-seeds.txt
testnetConsensusSeedsTXT []byte
//go:embed testnet/execution-genesis.json
testnetExecutionGenesisJSON []byte
//go:embed testnet/execution-seeds.txt
testnetExecutionSeedsTXT []byte
)
//nolint:gochecknoglobals // Static mappings.
var statics = map[ID]Static{
Simnet: {
Version: "simnet",
OmniExecutionChainID: evmchain.IDOmniEphemeral,
MaxValidators: maxValidators,
},
Devnet: {
Version: "devnet",
OmniExecutionChainID: evmchain.IDOmniEphemeral,
MaxValidators: maxValidators,
},
Staging: {
Version: runid,
OmniExecutionChainID: evmchain.IDOmniEphemeral,
MaxValidators: maxValidators,
},
Testnet: {
Version: "v0.0.2",
AVSContractAddress: testnetAVS,
OmniExecutionChainID: evmchain.IDOmniTestnet,
MaxValidators: maxValidators,
Portals: []Deployment{
{
ChainID: evmchain.IDHolesky,
Address: testnetPortal,
DeployHeight: 1357819,
},
{
ChainID: evmchain.IDOpSepolia,
Address: testnetPortal,
DeployHeight: 10731455,
},
{
ChainID: evmchain.IDArbSepolia,
Address: testnetPortal,
DeployHeight: 34237972,
},
},
ConsensusGenesisJSON: testnetConsensusGenesisJSON,
ConsensusSeedTXT: testnetConsensusSeedsTXT,
ExecutionGenesisJSON: testnetExecutionGenesisJSON,
ExecutionSeedTXT: testnetExecutionSeedsTXT,
},
Mainnet: {
Version: "v0.0.1",
AVSContractAddress: mainnetAVS,
MaxValidators: maxValidators,
},
}
// ConsensusChainIDStr2Uint64 parses the uint suffix from the provided a consensus chain ID string.
func ConsensusChainIDStr2Uint64(id string) (uint64, error) {
if !strings.HasPrefix(id, consensusIDPrefix) {
return 0, errors.New("invalid consensus chain ID", "id", id)
}
suffix := strings.TrimPrefix(id, consensusIDPrefix)
resp, err := strconv.ParseUint(suffix, 10, 64)
if err != nil {
return 0, errors.Wrap(err, "parse consensus chain ID", "id", id)
}
return resp, nil
}
// IsOmniConsensus returns true if provided chainID is the omni consensus chain for the network.
func IsOmniConsensus(network ID, chainID uint64) bool {
return network.Static().OmniConsensusChainIDUint64() == chainID
}
// IsOmniExecution returns true if provided chainID is the omni execution chain for the network.
func IsOmniExecution(network ID, chainID uint64) bool {
return network.Static().OmniExecutionChainID == chainID
}