Skip to content

Commit be2abd5

Browse files
authored
[scheduler] support restart & retry (#422)
1 parent 67e84d4 commit be2abd5

File tree

25 files changed

+2354
-4744
lines changed

25 files changed

+2354
-4744
lines changed

cmd/coordinator/config/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
DatabaseDSN: "postgres://test_user:test_passwd@postgres:5432/test?sslmode=disable",
3434
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
3535
IoTeXChainID: 2,
36-
ProjectContractAddress: "0x2339644f65c371Ca36b335A7eC3EB8AD8CBd5F51",
36+
ProjectContractAddress: "0x57872cF4b6D02053D5486F6882062c41a0F5C26a",
3737
IPFSEndpoint: "ipfs.mainnet.iotex.io",
3838
DIDAuthServerEndpoint: "didkit:9999",
3939
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
@@ -46,9 +46,8 @@ var (
4646
DatabaseDSN: "postgres://test_user:test_passwd@localhost:5432/test?sslmode=disable",
4747
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
4848
IoTeXChainID: 2,
49-
ProjectContractAddress: "0x2339644f65c371Ca36b335A7eC3EB8AD8CBd5F51",
49+
ProjectContractAddress: "0x57872cF4b6D02053D5486F6882062c41a0F5C26a",
5050
IPFSEndpoint: "ipfs.mainnet.iotex.io",
51-
ProjectFileDirectory: "../../test/project",
5251
DIDAuthServerEndpoint: "localhost:9999",
5352
ProjectCacheDirectory: "./project_cache",
5453
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",

cmd/coordinator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
projectManager, err := project.NewManager(conf.ChainEndpoint, conf.ProjectContractAddress,
3434
conf.ProjectCacheDirectory, conf.IPFSEndpoint, conf.ProjectFileDirectory)
3535
if err != nil {
36-
log.Fatal(errors.Wrap(err, "failed to new project config manager"))
36+
log.Fatal(errors.Wrap(err, "failed to new project manager"))
3737
}
3838

3939
if err := task.RunDispatcher(persistence, datasource.NewPostgres, projectManager.GetCachedProjectIDs, projectManager.Get, conf.BootNodeMultiAddr, conf.OperatorPrivateKey, conf.OperatorPrivateKeyED25519, conf.ChainEndpoint, conf.ProjectContractAddress, conf.ProjectFileDirectory, conf.IoTeXChainID); err != nil {

cmd/prover/config/config.go

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,81 @@ import (
88
)
99

1010
type Config struct {
11-
Risc0ServerEndpoint string `env:"RISC0_SERVER_ENDPOINT"`
12-
Halo2ServerEndpoint string `env:"HALO2_SERVER_ENDPOINT"`
13-
ZKWasmServerEndpoint string `env:"ZKWASM_SERVER_ENDPOINT"`
14-
WasmServerEndpoint string `env:"WASM_SERVER_ENDPOINT"`
15-
ChainEndpoint string `env:"CHAIN_ENDPOINT"`
16-
ProjectContractAddress string `env:"PROJECT_CONTRACT_ADDRESS,optional"`
17-
DatabaseDSN string `env:"DATABASE_DSN"`
18-
BootNodeMultiAddr string `env:"BOOTNODE_MULTIADDR"`
19-
ProverContractAddress string `env:"PROVER_CONTRACT_ADDRESS,optional"`
20-
ProverPrivateKey string `env:"PROVER_PRIVATE_KEY,optional"`
21-
IoTeXChainID int `env:"IOTEX_CHAINID"`
22-
SchedulerEpoch uint64 `env:"SCHEDULER_EPOCH"`
23-
IPFSEndpoint string `env:"IPFS_ENDPOINT"`
24-
ProjectFileDirectory string `env:"PROJECT_FILE_DIRECTORY,optional"`
25-
ProjectCacheDirectory string `env:"PROJECT_CACHE_DIRECTORY,optional"`
26-
LogLevel int `env:"LOG_LEVEL,optional"`
27-
SequencerPubKey string `env:"SEQUENCER_PUBKEY,optional"`
28-
env string `env:"-"`
11+
Risc0ServerEndpoint string `env:"RISC0_SERVER_ENDPOINT"`
12+
Halo2ServerEndpoint string `env:"HALO2_SERVER_ENDPOINT"`
13+
ZKWasmServerEndpoint string `env:"ZKWASM_SERVER_ENDPOINT"`
14+
WasmServerEndpoint string `env:"WASM_SERVER_ENDPOINT"`
15+
ChainEndpoint string `env:"CHAIN_ENDPOINT"`
16+
ProjectContractAddress string `env:"PROJECT_CONTRACT_ADDRESS,optional"`
17+
DatabaseDSN string `env:"DATABASE_DSN"`
18+
BootNodeMultiAddr string `env:"BOOTNODE_MULTIADDR"`
19+
ProverContractAddress string `env:"PROVER_CONTRACT_ADDRESS,optional"`
20+
ProverOperatorPrivateKey string `env:"PROVER_OPERATOR_PRIVATE_KEY,optional"`
21+
IoTeXChainID int `env:"IOTEX_CHAINID"`
22+
SchedulerEpoch uint64 `env:"SCHEDULER_EPOCH"`
23+
IPFSEndpoint string `env:"IPFS_ENDPOINT"`
24+
ProjectFileDirectory string `env:"PROJECT_FILE_DIRECTORY,optional"`
25+
ProjectCacheDirectory string `env:"PROJECT_CACHE_DIRECTORY,optional"`
26+
LogLevel int `env:"LOG_LEVEL,optional"`
27+
SequencerPubKey string `env:"SEQUENCER_PUBKEY,optional"`
28+
env string `env:"-"`
2929
}
3030

3131
var (
3232
defaultConfig = &Config{
33-
Risc0ServerEndpoint: "risc0:4001",
34-
Halo2ServerEndpoint: "halo2:4001",
35-
ZKWasmServerEndpoint: "zkwasm:4001",
36-
WasmServerEndpoint: "wasm:4001",
37-
ChainEndpoint: "https://babel-api.testnet.iotex.io",
38-
ProjectContractAddress: "0x2339644f65c371Ca36b335A7eC3EB8AD8CBd5F51",
39-
DatabaseDSN: "postgres://test_user:test_passwd@postgres:5432/test?sslmode=disable",
40-
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
41-
ProverContractAddress: "0x2B9BC8eC74E7F2526045eb13fFa37b10e0d40464",
42-
ProverPrivateKey: "did:key:z6MkmF1AgufHf8ASaxDcCR8iSZjEsEbJMp7LkqyEHw6123",
43-
IoTeXChainID: 2,
44-
SchedulerEpoch: 20,
45-
IPFSEndpoint: "ipfs.mainnet.iotex.io",
46-
LogLevel: int(slog.LevelDebug),
47-
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
33+
Risc0ServerEndpoint: "risc0:4001",
34+
Halo2ServerEndpoint: "halo2:4001",
35+
ZKWasmServerEndpoint: "zkwasm:4001",
36+
WasmServerEndpoint: "wasm:4001",
37+
ChainEndpoint: "https://babel-api.testnet.iotex.io",
38+
ProjectContractAddress: "0x57872cF4b6D02053D5486F6882062c41a0F5C26a",
39+
DatabaseDSN: "postgres://test_user:test_passwd@postgres:5432/test?sslmode=disable",
40+
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
41+
ProverContractAddress: "0x5B1AE92ed4a819C0B0e957a67F8dc39c0aC17Dfc",
42+
ProverOperatorPrivateKey: "did:key:z6MkmF1AgufHf8ASaxDcCR8iSZjEsEbJMp7LkqyEHw6123",
43+
IoTeXChainID: 2,
44+
SchedulerEpoch: 20,
45+
IPFSEndpoint: "ipfs.mainnet.iotex.io",
46+
LogLevel: int(slog.LevelDebug),
47+
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
4848
}
4949

5050
defaultDebugConfig = &Config{
51-
Risc0ServerEndpoint: "localhost:4001",
52-
Halo2ServerEndpoint: "localhost:4002",
53-
ZKWasmServerEndpoint: "localhost:4003",
54-
WasmServerEndpoint: "localhost:4004",
55-
ChainEndpoint: "https://babel-api.testnet.iotex.io",
56-
ProjectContractAddress: "0x2339644f65c371Ca36b335A7eC3EB8AD8CBd5F51",
57-
DatabaseDSN: "postgres://test_user:test_passwd@localhost:5432/test?sslmode=disable",
58-
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
59-
ProverContractAddress: "0x2B9BC8eC74E7F2526045eb13fFa37b10e0d40464",
60-
ProverPrivateKey: "dbfe03b0406549232b8dccc04be8224fcc0afa300a33d4f335dcfdfead861c85",
61-
IoTeXChainID: 2,
62-
SchedulerEpoch: 20,
63-
IPFSEndpoint: "ipfs.mainnet.iotex.io",
64-
ProjectFileDirectory: "../../test/project",
65-
ProjectCacheDirectory: "./project_cache",
66-
LogLevel: int(slog.LevelDebug),
67-
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
51+
Risc0ServerEndpoint: "localhost:4001",
52+
Halo2ServerEndpoint: "localhost:4002",
53+
ZKWasmServerEndpoint: "localhost:4003",
54+
WasmServerEndpoint: "localhost:4004",
55+
ChainEndpoint: "https://babel-api.testnet.iotex.io",
56+
ProjectContractAddress: "0x57872cF4b6D02053D5486F6882062c41a0F5C26a",
57+
DatabaseDSN: "postgres://test_user:test_passwd@localhost:5432/test?sslmode=disable",
58+
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
59+
ProverContractAddress: "0x5B1AE92ed4a819C0B0e957a67F8dc39c0aC17Dfc",
60+
ProverOperatorPrivateKey: "dbfe03b0406549232b8dccc04be8224fcc0afa300a33d4f335dcfdfead861c85",
61+
IoTeXChainID: 2,
62+
SchedulerEpoch: 20,
63+
IPFSEndpoint: "ipfs.mainnet.iotex.io",
64+
ProjectCacheDirectory: "./project_cache",
65+
LogLevel: int(slog.LevelDebug),
66+
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
6867
}
6968

7069
defaultTestConfig = &Config{
71-
Risc0ServerEndpoint: "localhost:14001",
72-
Halo2ServerEndpoint: "localhost:14002",
73-
ZKWasmServerEndpoint: "localhost:14003",
74-
WasmServerEndpoint: "localhost:14004",
75-
ChainEndpoint: "https://babel-api.testnet.iotex.io",
76-
ProjectContractAddress: "",
77-
DatabaseDSN: "postgres://test_user:test_passwd@localhost:15432/test?sslmode=disable",
78-
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
79-
ProverContractAddress: "",
80-
ProverPrivateKey: "",
81-
IoTeXChainID: 2,
82-
SchedulerEpoch: 20,
83-
IPFSEndpoint: "ipfs.mainnet.iotex.io",
84-
ProjectFileDirectory: "./testdata",
85-
LogLevel: int(slog.LevelDebug),
86-
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
70+
Risc0ServerEndpoint: "localhost:14001",
71+
Halo2ServerEndpoint: "localhost:14002",
72+
ZKWasmServerEndpoint: "localhost:14003",
73+
WasmServerEndpoint: "localhost:14004",
74+
ChainEndpoint: "https://babel-api.testnet.iotex.io",
75+
ProjectContractAddress: "",
76+
DatabaseDSN: "postgres://test_user:test_passwd@localhost:15432/test?sslmode=disable",
77+
BootNodeMultiAddr: "/dns4/bootnode-0.testnet.iotex.one/tcp/4689/ipfs/12D3KooWFnaTYuLo8Mkbm3wzaWHtUuaxBRe24Uiopu15Wr5EhD3o",
78+
ProverContractAddress: "",
79+
ProverOperatorPrivateKey: "",
80+
IoTeXChainID: 2,
81+
SchedulerEpoch: 20,
82+
IPFSEndpoint: "ipfs.mainnet.iotex.io",
83+
ProjectFileDirectory: "./testdata",
84+
LogLevel: int(slog.LevelDebug),
85+
SequencerPubKey: "0x04df6acbc5b355aabfb2145b36b20b7942c831c245c423a20b189fab4cf3a3dba3d564080841f2eb4890c118ca5e0b80b25f81269621c5e28273a962996c109afa",
8786
}
8887
)
8988

cmd/prover/config/config_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ func TestConfig_Init(t *testing.T) {
1616
t.Run("UseEnvConfig", func(t *testing.T) {
1717
os.Clearenv()
1818
expected := config.Config{
19-
Risc0ServerEndpoint: "risc0:1111",
20-
Halo2ServerEndpoint: "halo2:2222",
21-
ZKWasmServerEndpoint: "zkwasm:3333",
22-
WasmServerEndpoint: "wasm:4444",
23-
ChainEndpoint: "http://abc.def.com",
24-
ProjectContractAddress: "0x123",
25-
DatabaseDSN: "postgres://root@localhost/abc?ext=666",
26-
BootNodeMultiAddr: "/dsn4/abc/123",
27-
ProverContractAddress: "0x456",
28-
IoTeXChainID: 5,
29-
SchedulerEpoch: 720,
30-
IPFSEndpoint: "abc.ipfs.net",
31-
ProverPrivateKey: "private key",
32-
ProjectFileDirectory: "/path/to/project/configs",
19+
Risc0ServerEndpoint: "risc0:1111",
20+
Halo2ServerEndpoint: "halo2:2222",
21+
ZKWasmServerEndpoint: "zkwasm:3333",
22+
WasmServerEndpoint: "wasm:4444",
23+
ChainEndpoint: "http://abc.def.com",
24+
ProjectContractAddress: "0x123",
25+
DatabaseDSN: "postgres://root@localhost/abc?ext=666",
26+
BootNodeMultiAddr: "/dsn4/abc/123",
27+
ProverContractAddress: "0x456",
28+
IoTeXChainID: 5,
29+
SchedulerEpoch: 720,
30+
IPFSEndpoint: "abc.ipfs.net",
31+
ProverOperatorPrivateKey: "private key",
32+
ProjectFileDirectory: "/path/to/project/configs",
3333
}
3434

3535
_ = os.Setenv("RISC0_SERVER_ENDPOINT", expected.Risc0ServerEndpoint)
@@ -44,7 +44,7 @@ func TestConfig_Init(t *testing.T) {
4444
_ = os.Setenv("SCHEDULER_EPOCH", strconv.FormatUint(expected.SchedulerEpoch, 10))
4545
_ = os.Setenv("PROJECT_CONTRACT_ADDRESS", expected.ProjectContractAddress)
4646
_ = os.Setenv("IPFS_ENDPOINT", expected.IPFSEndpoint)
47-
_ = os.Setenv("PROVER_PRIVATE_KEY", expected.ProverPrivateKey)
47+
_ = os.Setenv("PROVER_OPERATOR_PRIVATE_KEY", expected.ProverOperatorPrivateKey)
4848
_ = os.Setenv("PROJECT_FILE_DIRECTORY", expected.ProjectFileDirectory)
4949

5050
c := &config.Config{}

cmd/prover/main.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import (
77
"os/signal"
88
"syscall"
99

10+
"github.com/ethereum/go-ethereum/common"
1011
"github.com/ethereum/go-ethereum/common/hexutil"
1112
"github.com/ethereum/go-ethereum/crypto"
13+
"github.com/ethereum/go-ethereum/ethclient"
1214
"github.com/pkg/errors"
1315

1416
"github.com/machinefi/sprout/cmd/prover/config"
1517
"github.com/machinefi/sprout/p2p"
1618
"github.com/machinefi/sprout/project"
1719
"github.com/machinefi/sprout/scheduler"
20+
"github.com/machinefi/sprout/smartcontracts/go/prover"
1821
"github.com/machinefi/sprout/task"
1922
"github.com/machinefi/sprout/vm"
2023
)
@@ -46,28 +49,42 @@ func main() {
4649
log.Fatal(err)
4750
}
4851

49-
sk, err := crypto.HexToECDSA(conf.ProverPrivateKey)
52+
sk, err := crypto.HexToECDSA(conf.ProverOperatorPrivateKey)
5053
if err != nil {
5154
log.Fatal(errors.Wrap(err, "failed to parse prover private key"))
5255
}
53-
proverID := crypto.PubkeyToAddress(sk.PublicKey).String()
54-
55-
slog.Info("my prover id", "prover_id", proverID)
56+
proverOperatorAddress := crypto.PubkeyToAddress(sk.PublicKey)
5657

5758
sequencerPubKey, err := hexutil.Decode(conf.SequencerPubKey)
5859
if err != nil {
5960
log.Fatal(errors.Wrap(err, "failed to decode sequencer pubkey"))
6061
}
6162

62-
taskProcessor := task.NewProcessor(vmHandler, projectManager.Get, sk, sequencerPubKey, proverID)
63+
// TODO move to utils contract
64+
client, err := ethclient.Dial(conf.ChainEndpoint)
65+
if err != nil {
66+
log.Fatal(err, "failed to dial chain endpoint")
67+
}
68+
instance, err := prover.NewProver(common.HexToAddress(conf.ProverContractAddress), client)
69+
if err != nil {
70+
log.Fatal(errors.Wrap(err, "failed to new prover contract instance"))
71+
}
72+
proverID, _, err := instance.OwnerOfOperator(nil, proverOperatorAddress)
73+
if err != nil {
74+
log.Fatal(errors.Wrap(err, "failed to query operator's prover id"))
75+
}
76+
77+
slog.Info("my prover id", "prover_id", proverID.Uint64())
78+
79+
taskProcessor := task.NewProcessor(vmHandler, projectManager.Get, sk, sequencerPubKey, proverID.Uint64())
6380

6481
pubSubs, err := p2p.NewPubSubs(taskProcessor.HandleP2PData, conf.BootNodeMultiAddr, conf.IoTeXChainID)
6582
if err != nil {
6683
log.Fatal(err)
6784
}
6885

6986
if err := scheduler.Run(conf.SchedulerEpoch, conf.ChainEndpoint, conf.ProverContractAddress,
70-
conf.ProjectContractAddress, conf.ProjectFileDirectory, proverID, pubSubs, taskProcessor.HandleProjectProvers,
87+
conf.ProjectContractAddress, conf.ProjectFileDirectory, proverID.Uint64(), pubSubs, taskProcessor.HandleProjectProvers,
7188
projectManager.GetCachedProjectIDs); err != nil {
7289
log.Fatal(err)
7390
}

cmd/tests/init.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,25 @@ func runProver(conf *proverconfig.Config) {
120120
log.Fatal(err)
121121
}
122122

123-
sk, err := crypto.HexToECDSA(conf.ProverPrivateKey)
123+
sk, err := crypto.HexToECDSA(conf.ProverOperatorPrivateKey)
124124
if err != nil {
125125
log.Fatal(errors.Wrap(err, "failed parse prover private key"))
126126
}
127-
proverID := crypto.PubkeyToAddress(sk.PublicKey).String()
128127

129128
sequencerPubKey, err := hexutil.Decode(conf.SequencerPubKey)
130129
if err != nil {
131130
log.Fatal(errors.Wrap(err, "failed to decode sequencer pubkey"))
132131
}
133132

134-
taskProcessor := task.NewProcessor(vmHandler, projectManager.Get, sk, sequencerPubKey, proverID)
133+
taskProcessor := task.NewProcessor(vmHandler, projectManager.Get, sk, sequencerPubKey, 1)
135134

136135
pubSubs, err := p2p.NewPubSubs(taskProcessor.HandleP2PData, conf.BootNodeMultiAddr, conf.IoTeXChainID)
137136
if err != nil {
138137
log.Fatal(err)
139138
}
140139

141140
if err := scheduler.Run(conf.SchedulerEpoch, conf.ChainEndpoint, conf.ProverContractAddress, conf.ProjectContractAddress,
142-
conf.ProjectFileDirectory, proverID, pubSubs, taskProcessor.HandleProjectProvers, projectManager.GetCachedProjectIDs); err != nil {
141+
conf.ProjectFileDirectory, 1, pubSubs, taskProcessor.HandleProjectProvers, projectManager.GetCachedProjectIDs); err != nil {
143142
log.Fatal(err)
144143
}
145144

0 commit comments

Comments
 (0)