-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
179 lines (152 loc) · 4.84 KB
/
config.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
package operator
import (
"context"
"crypto/ecdsa"
"encoding/json"
"os"
"strings"
"github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/automata-network/multi-prover-avs/contracts/bindings"
"github.com/automata-network/multi-prover-avs/contracts/bindings/RegistryCoordinator"
"github.com/automata-network/multi-prover-avs/utils"
"github.com/chzyer/logex"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)
type ConfigContext struct {
Config *Config
BlsKey *bls.KeyPair
AttestationEcdsaKey *ecdsa.PrivateKey
Client *ethclient.Client
AttestationClient *ethclient.Client
EigenClients *clients.Clients
AvsName string
}
func (c *ConfigContext) QueryOperatorAddress() (common.Address, error) {
registry, err := RegistryCoordinator.NewRegistryCoordinatorCaller(c.Config.RegistryCoordinatorAddress, c.Client)
if err != nil {
return utils.ZeroAddress, logex.Trace(err)
}
operatorAddress, err := bindings.GetOperatorAddrFromBlsKey(c.BlsKey, c.Client, registry)
if err != nil {
return utils.ZeroAddress, logex.Trace(err)
}
return operatorAddress, nil
}
func ParseConfigContext(cfgPath string, ecdsaKey *ecdsa.PrivateKey) (*ConfigContext, error) {
if ecdsaKey == nil {
var err error
ecdsaKey, err = crypto.GenerateKey()
if err != nil {
return nil, logex.Trace(err, "generate test ecdsa key", cfgPath)
}
}
var cfg Config
cfgData, err := os.ReadFile(cfgPath)
if err != nil {
return nil, logex.Trace(err)
}
if err := json.Unmarshal(cfgData, &cfg); err != nil {
return nil, logex.Trace(err, cfgPath)
}
cfg.InitFromEnv()
kp, err := utils.ReadBlsKey(cfg.BlsKeyFile, cfg.BlsKeyPassword)
if err != nil {
return nil, logex.Trace(err, "BlsKeyFile", cfg.BlsKeyFile, cfgPath)
}
logger := logex.NewLoggerEx(os.Stderr)
elog := utils.NewLogger(logger)
logex.Debugf("connecting to EthRpcUrl %v...", cfg.EthRpcUrl)
client, err := ethclient.Dial(cfg.EthRpcUrl)
if err != nil {
return nil, logex.Trace(err, cfg.EthRpcUrl)
}
logex.Debugf("connecting to AttestationLayerRpcURL %v...", cfg.AttestationLayerRpcURL)
attestationClient, err := ethclient.Dial(cfg.AttestationLayerRpcURL)
if err != nil {
return nil, logex.Trace(err, "AttestationLayerRpcURL", cfg.AttestationLayerRpcURL)
}
avsChainID, err := client.ChainID(context.Background())
if err != nil {
return nil, logex.Trace(err, "check chain ID")
}
avsName := utils.GetAvsName(avsChainID)
chainioConfig := clients.BuildAllConfig{
EthHttpUrl: cfg.EthRpcUrl,
EthWsUrl: cfg.EthRpcUrl,
RegistryCoordinatorAddr: cfg.RegistryCoordinatorAddress.String(),
OperatorStateRetrieverAddr: cfg.OperatorStateRetrieverAddress.String(),
AvsName: avsName,
PromMetricsIpPortAddress: cfg.EigenMetricsIpPortAddress,
}
logex.Debugf("build clients %#v", chainioConfig)
eigenClients, err := clients.BuildAll(chainioConfig, ecdsaKey, elog)
if err != nil {
return nil, logex.Trace(err)
}
if cfg.Identifier == 0 {
cfg.Identifier = 1
}
attestationEcdsaKey, err := crypto.HexToECDSA(cfg.AttestationLayerEcdsaKey)
if err != nil {
return nil, logex.Trace(err, "AttestationLayerEcdsaKey")
}
return &ConfigContext{
Config: &cfg,
BlsKey: kp,
Client: client,
EigenClients: eigenClients,
AttestationEcdsaKey: attestationEcdsaKey,
AttestationClient: attestationClient,
AvsName: avsName,
}, nil
}
type Config struct {
ProverURL string
AggregatorURL string
Identifier int64
BlsKeyFile string
BlsKeyPassword string
EthRpcUrl string
AttestationLayerProfile string
AttestationLayerEcdsaKey string
AttestationLayerRpcURL string
RegistryCoordinatorAddress common.Address
OperatorStateRetrieverAddress common.Address
TEELivenessVerifierAddress common.Address
EigenMetricsIpPortAddress string
NodeApiIpPortAddress string
}
func (c *Config) InitFromEnv() {
if c.NodeApiIpPortAddress == "" {
c.NodeApiIpPortAddress = ":15692"
}
preset := utils.PresetConfigByRegistryCoordinatorAddress(c.RegistryCoordinatorAddress)
if preset != nil {
if c.OperatorStateRetrieverAddress == utils.ZeroAddress {
c.OperatorStateRetrieverAddress = preset.OperatorStateRetrieverAddress
}
cfg := preset.GetAttestationLayer(c.AttestationLayerProfile)
c.TEELivenessVerifierAddress = cfg.Address
if cfg.URL != "" {
c.AttestationLayerRpcURL = cfg.URL
}
}
}
func (c *Config) check(env *string) {
if strings.HasPrefix(*env, "$") {
envVal := os.Getenv((*env)[1:])
if envVal != "" {
*env = envVal
}
}
}
type TaskFetcher struct {
Endpoint string
Topics [][]common.Hash
Addresses []common.Address
OffsetFile string
ScanIntervalSecs int64
}