Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 4b91b55

Browse files
authored
feat: enable execute only networks (#44)
1 parent 7b6e21b commit 4b91b55

File tree

6 files changed

+47
-38
lines changed

6 files changed

+47
-38
lines changed

.github/workflows/deploy_mainnet.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# The Licensed Work is (c) 2023 Sygma
2+
# SPDX-License-Identifier: LGPL-3.0-only
3+
14
name: Deploy Spectre on mainnet
25

36
on:

chains/evm/config/config.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
type EVMConfig struct {
1414
config.BaseNetworkConfig
15-
BeaconEndpoint string `required:"true" split_words:"true"`
16-
Router string `required:"true"`
17-
Spectre string `required:"true"`
15+
BeaconEndpoint string `split_words:"true"`
16+
Router string
17+
Spectre string
1818
Spec string `default:"mainnet"`
1919
MaxGasPrice int64 `default:"500000000000" split_words:"true"`
2020
GasMultiplier float64 `default:"1" split_words:"true"`
@@ -25,6 +25,7 @@ type EVMConfig struct {
2525
ForcePeriod bool `default:"false" split_words:"true"`
2626
FinalityThreshold uint64 `default:"342" split_words:"true"`
2727
SlotsPerEpoch uint64 `default:"32" split_words:"true"`
28+
TargetDomains []int16 `split_words:"true"`
2829
}
2930

3031
// LoadEVMConfig loads EVM config from the environment and validates the fields

chains/evm/config/config_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() {
8787
os.Setenv("SPECTRE_DOMAINS_1_FORCE_PERIOD", "true")
8888
os.Setenv("SPECTRE_DOMAINS_1_FINALITY_THRESHOLD", "382")
8989
os.Setenv("SPECTRE_DOMAINS_1_SLOTS_PER_EPOCH", "16")
90+
os.Setenv("SPECTRE_DOMAINS_1_TARGET_DOMAINS", "1,2")
9091

9192
c, err := config.LoadEVMConfig(1)
9293

@@ -109,5 +110,6 @@ func (s *EVMConfigTestSuite) Test_LoadEVMConfig_SuccessfulLoad() {
109110
ForcePeriod: true,
110111
FinalityThreshold: 382,
111112
SlotsPerEpoch: 16,
113+
TargetDomains: []int16{1, 2},
112114
})
113115
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/kelseyhightower/envconfig v1.4.0
1010
github.com/rs/zerolog v1.31.0
1111
github.com/stretchr/testify v1.8.4
12-
github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d
12+
github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51
1313
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a
1414
github.com/umbracle/go-eth-consensus v0.1.3-0.20230605085523-929b6624372a
1515
github.com/ybbus/jsonrpc/v3 v3.1.5

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbe
330330
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
331331
github.com/sygmaprotocol/go-eth-consensus v0.0.0-20240209115220-99232c637bc3 h1:SQsyRz3yyUxPlrfTR0s9YCdicTuJ3gE0ZiVm4xfz71c=
332332
github.com/sygmaprotocol/go-eth-consensus v0.0.0-20240209115220-99232c637bc3/go.mod h1:qaMaUGUsL5Twx/6TfG6BkJU3t6e8Pp9QUqFn7LvUOf8=
333-
github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d h1:S2129X3uNculIdDae6J88ekiPWfzpcYhnVAeEuNRLQg=
334-
github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc=
333+
github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51 h1:6JyEFnvR5MCyVV3aB2Qtpr/mEm4p2N32PmytBJE5z9M=
334+
github.com/sygmaprotocol/sygma-core v0.0.0-20240916115618-aa7e4ebefb51/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc=
335335
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
336336
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
337337
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=

main.go

+35-32
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ func main() {
6969
}
7070
periodStore := store.NewPeriodStore(db)
7171

72-
domains := make([]uint8, 0)
73-
for domain := range cfg.Domains {
74-
domains = append(domains, domain)
75-
}
76-
7772
proverClient := jsonrpc.NewClient(cfg.Prover.URL)
7873

7974
msgChan := make(chan []*message.Message)
@@ -106,33 +101,41 @@ func main() {
106101
t := monitored.NewMonitoredTransactor(transaction.NewTransaction, gasPricer, client, big.NewInt(config.MaxGasPrice), big.NewInt(config.GasIncreasePercentage))
107102
go t.Monitor(ctx, time.Minute*3, time.Minute*10, time.Minute)
108103

109-
beaconClient, err := http.New(ctx,
110-
http.WithAddress(config.BeaconEndpoint),
111-
http.WithLogLevel(logLevel),
112-
http.WithTimeout(time.Second*30),
113-
)
114-
if err != nil {
115-
panic(err)
116-
}
117-
beaconProvider := beaconClient.(*http.Service)
118-
119-
storedPeriod, err := periodStore.Period(id)
120-
if err != nil {
121-
panic(err)
104+
var evmListener *listener.EVMListener
105+
if len(config.TargetDomains) > 0 {
106+
beaconClient, err := http.New(ctx,
107+
http.WithAddress(config.BeaconEndpoint),
108+
http.WithLogLevel(logLevel),
109+
http.WithTimeout(time.Second*30),
110+
)
111+
if err != nil {
112+
panic(err)
113+
}
114+
beaconProvider := beaconClient.(*http.Service)
115+
116+
storedPeriod, err := periodStore.Period(id)
117+
if err != nil {
118+
panic(err)
119+
}
120+
var latestPeriod *big.Int
121+
if (storedPeriod.Uint64() >= config.StartingPeriod) && !config.ForcePeriod {
122+
latestPeriod = storedPeriod
123+
} else {
124+
latestPeriod = big.NewInt(int64(config.StartingPeriod))
125+
}
126+
127+
targetDomains := make([]uint8, len(config.TargetDomains))
128+
for i, d := range config.TargetDomains {
129+
targetDomains[i] = uint8(d)
130+
}
131+
132+
lightClient := lightclient.NewLightClient(config.BeaconEndpoint)
133+
p := prover.NewProver(proverClient, beaconProvider, lightClient, prover.Spec(config.Spec), config.FinalityThreshold, config.SlotsPerEpoch)
134+
routerAddress := common.HexToAddress(config.Router)
135+
stepHandler := handlers.NewStepEventHandler(msgChan, client, beaconProvider, p, routerAddress, id, targetDomains)
136+
rotateHandler := handlers.NewRotateHandler(msgChan, periodStore, p, id, targetDomains, config.CommitteePeriodLength, latestPeriod)
137+
evmListener = listener.NewEVMListener(beaconProvider, []listener.EventHandler{rotateHandler, stepHandler}, id, time.Duration(config.RetryInterval)*time.Second)
122138
}
123-
var latestPeriod *big.Int
124-
if (storedPeriod.Uint64() >= config.StartingPeriod) && !config.ForcePeriod {
125-
latestPeriod = storedPeriod
126-
} else {
127-
latestPeriod = big.NewInt(int64(config.StartingPeriod))
128-
}
129-
130-
lightClient := lightclient.NewLightClient(config.BeaconEndpoint)
131-
p := prover.NewProver(proverClient, beaconProvider, lightClient, prover.Spec(config.Spec), config.FinalityThreshold, config.SlotsPerEpoch)
132-
routerAddress := common.HexToAddress(config.Router)
133-
stepHandler := handlers.NewStepEventHandler(msgChan, client, beaconProvider, p, routerAddress, id, domains)
134-
rotateHandler := handlers.NewRotateHandler(msgChan, periodStore, p, id, domains, config.CommitteePeriodLength, latestPeriod)
135-
listener := listener.NewEVMListener(beaconProvider, []listener.EventHandler{rotateHandler, stepHandler}, id, time.Duration(config.RetryInterval)*time.Second)
136139

137140
messageHandler := message.NewMessageHandler()
138141
rotateMessageHandler := evmMessage.EvmRotateHandler{}
@@ -143,7 +146,7 @@ func main() {
143146
spectre := contracts.NewSpectreContract(common.HexToAddress(config.Spectre), t)
144147
executor := executor.NewEVMExecutor(id, spectre)
145148

146-
chain := evm.NewEVMChain(listener, messageHandler, executor, id, nil)
149+
chain := evm.NewEVMChain(evmListener, messageHandler, executor, id, nil)
147150
chains[id] = chain
148151
}
149152
default:

0 commit comments

Comments
 (0)