@@ -2,58 +2,46 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
- "context"
6
5
"encoding/json"
7
- "flag"
8
6
"log"
9
7
"log/slog"
10
- "math/big"
11
8
"math/rand"
12
9
"net/http"
13
10
"os"
11
+ "os/exec"
14
12
"os/signal"
15
13
"strconv"
14
+ "strings"
16
15
"sync/atomic"
17
16
"syscall"
18
17
"time"
19
18
20
19
"github.com/cockroachdb/pebble"
21
- "github.com/ethereum/go-ethereum/accounts/abi/bind"
22
20
"github.com/ethereum/go-ethereum/common"
23
- "github.com/ethereum/go-ethereum/core/types"
24
- "github.com/ethereum/go-ethereum/crypto"
25
- "github.com/ethereum/go-ethereum/ethclient"
21
+ "github.com/google/uuid"
26
22
"github.com/pkg/errors"
27
23
28
24
"github.com/machinefi/sprout/apitypes"
29
25
"github.com/machinefi/sprout/persistence/contract"
30
26
"github.com/machinefi/sprout/project"
31
- contractproject "github.com/machinefi/sprout/smartcontracts/go/project"
32
27
"github.com/machinefi/sprout/vm"
33
28
)
34
29
35
30
var (
36
- projectMinterPrivateKey string
37
-
38
31
projectCacheDir = "./project_cache"
39
32
localDBDir = "./local_db"
40
- beginningBlockNumber = uint64 (20000000 )
33
+ beginningBlockNumber = uint64 (26000000 )
41
34
chainEndpoint = "https://babel-api.testnet.iotex.io"
42
- projectContractAddress = common .HexToAddress ("0xCBb7a80983Fd3405972F700101A82DB6304C6547 " )
43
- proverContractAddress = common .HexToAddress ("0x6B544a7603cead52AdfD99AA64B3d798083cc4CC " )
35
+ projectContractAddress = common .HexToAddress ("0x2faBD8F8667158Ff8B0523f7BA8fC0CD0df3d0eA " )
36
+ proverContractAddress = common .HexToAddress ("0x0764e9c021F140d3A8CAb6EDd59904E584378D19 " )
44
37
ipfsEndpoint = "ipfs.mainnet.iotex.io"
45
38
schedulerEpoch = uint64 (20 )
46
39
)
47
40
48
41
var (
49
- halo2ProjectFileURI = "ipfs://ipfs.mainnet.iotex.io/QmX3utHdGsPUmgouwnvCMQrE7RSJydpouEJQhqirbJepsf"
50
- halo2ProjectFileHash = common .HexToHash ("0x5cb6a61aa744f9b3b8350e95ab04dda5f15876ea02b3bcdaf05912e6bfe17c0a" )
51
-
52
- risc0ProjectFileURI = "ipfs://ipfs.mainnet.iotex.io/QmZqwTe8yHSCLA61GkiR7qSzeMcBVSECiPjFEFZVT2R6tN"
53
- risc0ProjectFileHash = common .HexToHash ("0x0a81cbc0463524fdcb48ecd9951b5d34ecd996ad1efbf3019465ada3dc6cc89a" )
54
-
55
- zkwasmProjectFileURI = "ipfs://ipfs.mainnet.iotex.io/QmWhzXMGrNusDY6axpmzV7sEmoUMdmZTa8ZqvKUK9N34af"
56
- zkwasmProjectFileHash = common .HexToHash ("0x1e6779061e0004cb63366596f17e46272afd6ac6556933b1493dae3710c7ce88" )
42
+ halo2ProjectFile = "./project_file/10001"
43
+ risc0ProjectFile = "./project_file/10000"
44
+ zkwasmProjectFile = "./project_file/10001"
57
45
)
58
46
59
47
var (
@@ -62,61 +50,58 @@ var (
62
50
zkwasmMessageData = "{\" private_input\" : [1, 1] , \" public_input\" : [] }"
63
51
)
64
52
65
- func init () {
66
- flag .StringVar (& projectMinterPrivateKey , "projectMinterPrivateKey" , "" , "project minter private key" )
67
- }
53
+ func createProject () {
54
+ cmd := exec .Command ("./ioctl" , "ioid" , "register" , uuid .New ().String ())
55
+ o , err := cmd .CombinedOutput ()
56
+ if err != nil {
57
+ slog .Error ("failed to register project" , "error" , err , "output" , string (o ))
58
+ return
59
+ }
60
+
61
+ pidStr := strings .TrimSpace (strings .TrimPrefix (string (o ), "Registerd ioID project id is" ))
62
+ slog .Info ("currently project id" , "project_id" , pidStr )
68
63
69
- func createProject (client * ethclient.Client , projectInstance * contractproject.Project , opts * bind.TransactOpts ) {
70
- // tx, err := projectInstance.Mint(opts, opts.From) // TODO use new project contract logic
71
- // if err != nil {
72
- // slog.Error("failed to mint project", "error", err)
73
- // return
74
- // }
75
- // slog.Info("new project created", "tx_hash", tx.Hash().Hex())
76
- // for {
77
- // _, isPending, err := client.TransactionByHash(context.Background(), tx.Hash())
78
- // if err != nil {
79
- // slog.Error("failed to query tx hash", "error", err, "tx_hash", tx.Hash().Hex())
80
- // continue
81
- // }
82
- // if !isPending {
83
- // break
84
- // }
85
- // time.Sleep(3 * time.Second)
86
- // }
87
- // projectID, err := projectInstance.Count(nil)
88
- // if err != nil {
89
- // slog.Error("failed to query project id", "error", err)
90
- // return
91
- // }
92
- // slog.Info("new project created", "project_id", projectID.Uint64())
64
+ cmd = exec .Command ("./ioctl" , "ws" , "project" , "register" , "--id" , pidStr )
65
+ o , err = cmd .CombinedOutput ()
66
+ if err != nil {
67
+ slog .Error ("failed to register project" , "error" , err , "output" , string (o ))
68
+ return
69
+ }
93
70
94
- // switch rand.Intn(2) {
95
- // case 0:
96
- // tx, err := projectInstance.UpdateConfig(opts, projectID, halo2ProjectFileURI, halo2ProjectFileHash)
97
- // if err != nil {
98
- // slog.Error("failed to update project config", "error", err)
99
- // return
100
- // }
101
- // slog.Info("project halo2 config updated", "tx_hash", tx.Hash().Hex())
102
- // case 1:
103
- // tx, err := projectInstance.UpdateConfig(opts, projectID, risc0ProjectFileURI, risc0ProjectFileHash)
104
- // if err != nil {
105
- // slog.Error("failed to update project config", "error", err)
106
- // return
107
- // }
108
- // slog.Info("project risc0 config updated", "tx_hash", tx.Hash().Hex())
109
- // case 2: // will not create zkwasm project
110
- // tx, err := projectInstance.UpdateConfig(opts, projectID, zkwasmProjectFileURI, zkwasmProjectFileHash)
111
- // if err != nil {
112
- // slog.Error("failed to update project config", "error", err)
113
- // return
114
- // }
115
- // slog.Info("project zkwasm config updated", "tx_hash", tx.Hash().Hex())
116
- // }
71
+ switch rand .Intn (2 ) {
72
+ case 0 :
73
+ cmd = exec .Command ("./ioctl" , "ws" , "project" , "update" , "--id" , pidStr , "--path" , halo2ProjectFile )
74
+ o , err = cmd .CombinedOutput ()
75
+ if err != nil {
76
+ slog .Error ("failed to update halo2 project" , "project_id" , pidStr , "error" , err , "output" , string (o ))
77
+ return
78
+ }
79
+ slog .Info ("project halo2 config updated" , "project_id" , pidStr )
80
+ case 1 :
81
+ cmd = exec .Command ("./ioctl" , "ws" , "project" , "update" , "--id" , pidStr , "--path" , risc0ProjectFile )
82
+ o , err = cmd .CombinedOutput ()
83
+ if err != nil {
84
+ slog .Error ("failed to update risc0 project" , "project_id" , pidStr , "error" , err , "output" , string (o ))
85
+ return
86
+ }
87
+ slog .Info ("project risc0 config updated" , "project_id" , pidStr )
88
+ // case 2: // will not create zkwasm project
89
+ // tx, err := projectInstance.UpdateConfig(opts, projectID, zkwasmProjectFileURI, zkwasmProjectFileHash)
90
+ // if err != nil {
91
+ // slog.Error("failed to update project config", "error", err)
92
+ // return
93
+ // }
94
+ // slog.Info("project zkwasm config updated", "tx_hash", tx.Hash().Hex())
95
+ }
96
+ cmd = exec .Command ("./ioctl" , "ws" , "project" , "resume" , "--id" , pidStr )
97
+ o , err = cmd .CombinedOutput ()
98
+ if err != nil {
99
+ slog .Error ("failed to resume project" , "error" , err , "output" , string (o ))
100
+ return
101
+ }
117
102
}
118
103
119
- func updateProjectRequiredProver (contractPersistence * contract.Contract , projectInstance * contractproject. Project , opts * bind. TransactOpts ) {
104
+ func updateProjectRequiredProver (contractPersistence * contract.Contract ) {
120
105
projects := contractPersistence .LatestProjects ()
121
106
provers := contractPersistence .LatestProvers ()
122
107
if len (provers ) == 0 {
@@ -128,19 +113,34 @@ func updateProjectRequiredProver(contractPersistence *contract.Contract, project
128
113
project := projects [index ]
129
114
expectProvers := rand .Intn (len (provers )) + 1
130
115
131
- tx , err := projectInstance .SetAttributes (opts , new (big.Int ).SetUint64 (project .ID ), [][32 ]byte {contract .RequiredProverAmount }, [][]byte {[]byte (strconv .Itoa (expectProvers ))})
116
+ pidStr := strconv .FormatUint (project .ID , 10 )
117
+
118
+ cmd := exec .Command ("./ioctl" , "ws" , "project" , "attributes" , "set" , "--id" , pidStr , "--key" , "RequiredProverAmount" , "--val" , strconv .Itoa (expectProvers ))
119
+ var stdin bytes.Buffer
120
+ stdin .Write ([]byte ("\n " ))
121
+ cmd .Stdin = & stdin
122
+ o , err := cmd .CombinedOutput ()
132
123
if err != nil {
133
- slog .Error ("failed to set project attributes" , "error" , err )
124
+ slog .Error ("failed to update project attributes" , "project_id" , pidStr , " error" , err , "output" , string ( o ) )
134
125
return
135
126
}
136
- slog .Info ("project attributes setted" , "project_id" , project .ID , "tx_hash " , tx . Hash (). Hex () )
127
+ slog .Info ("project attributes setted" , "project_id" , project .ID , "prover_amount " , expectProvers )
137
128
}
138
129
139
130
func sendMessage (contractPersistence * contract.Contract , projectManager * project.Manager , taskCount * atomic.Uint64 ) {
140
131
projects := contractPersistence .LatestProjects ()
132
+
133
+ //slog.Info("send message", "project_len", len(projects))
134
+
141
135
for i := 0 ; i < 3 ; i ++ {
142
136
index := rand .Intn (len (projects ))
143
137
project := projects [index ]
138
+ if project .Paused {
139
+ continue
140
+ }
141
+ if project .Uri == "" {
142
+ continue
143
+ }
144
144
projectFile , err := projectManager .Project (project .ID )
145
145
if err != nil {
146
146
slog .Error ("failed to get project data" , "project_id" , project .ID , "error" , err )
@@ -176,7 +176,7 @@ func sendMessage(contractPersistence *contract.Contract, projectManager *project
176
176
continue
177
177
}
178
178
179
- response , err := http .Post ("http ://sprout-staging .w3bstream.com:9000 /message" , "application/json" , bytes .NewReader (j ))
179
+ response , err := http .Post ("https ://sprout-stress .w3bstream.com/message" , "application/json" , bytes .NewReader (j ))
180
180
if err != nil {
181
181
slog .Error ("failed to send message" , "project_id" , project .ID , "error" , err )
182
182
continue
@@ -192,40 +192,12 @@ func sendMessage(contractPersistence *contract.Contract, projectManager *project
192
192
}
193
193
194
194
func main () {
195
- flag .Parse ()
196
195
slog .SetDefault (slog .New (slog .NewTextHandler (os .Stderr , & slog.HandlerOptions {Level : slog .LevelDebug })))
197
196
198
- priKey , err := crypto .HexToECDSA (projectMinterPrivateKey )
199
- if err != nil {
200
- log .Fatal (errors .Wrap (err , "failed parse project minter private key" ))
201
- }
202
- slog .Info ("project minter address" , "address" , crypto .PubkeyToAddress (priKey .PublicKey ).String ())
203
-
204
- client , err := ethclient .Dial (chainEndpoint )
205
- if err != nil {
206
- log .Fatal (errors .Wrap (err , "failed to dial chain endpoint" ))
207
- }
208
- projectInstance , err := contractproject .NewProject (projectContractAddress , client )
209
- if err != nil {
210
- log .Fatal (errors .Wrap (err , "failed to new project contract instance" ))
211
- }
212
-
213
- chainID , err := client .ChainID (context .Background ())
214
- if err != nil {
215
- log .Fatal (errors .Wrap (err , "failed to get chain id" ))
216
- }
217
-
218
- opts := & bind.TransactOpts {
219
- From : crypto .PubkeyToAddress (priKey .PublicKey ),
220
- Signer : func (a common.Address , tx * types.Transaction ) (* types.Transaction , error ) {
221
- return types .SignTx (tx , types .NewLondonSigner (chainID ), priKey )
222
- },
223
- }
224
-
225
- createProjectTicker := time .NewTicker (10 * time .Minute )
197
+ createProjectTicker := time .NewTicker (1 * time .Minute )
226
198
go func () {
227
199
for range createProjectTicker .C {
228
- createProject (client , projectInstance , opts )
200
+ createProject ()
229
201
}
230
202
}()
231
203
@@ -248,7 +220,7 @@ func main() {
248
220
updateProjectRequiredProverTicker := time .NewTicker (1 * time .Hour )
249
221
go func () {
250
222
for range updateProjectRequiredProverTicker .C {
251
- updateProjectRequiredProver (contractPersistence , projectInstance , opts )
223
+ updateProjectRequiredProver (contractPersistence )
252
224
}
253
225
}()
254
226
@@ -265,7 +237,7 @@ func main() {
265
237
}
266
238
}()
267
239
268
- sendMessageTicker := time .NewTicker (5 * time .Minute )
240
+ sendMessageTicker := time .NewTicker (1 * time .Second )
269
241
go func () {
270
242
for range sendMessageTicker .C {
271
243
sendMessage (contractPersistence , projectManager , taskCount )
0 commit comments