@@ -2,58 +2,46 @@ package main
22
33import (
44 "bytes"
5- "context"
65 "encoding/json"
7- "flag"
86 "log"
97 "log/slog"
10- "math/big"
118 "math/rand"
129 "net/http"
1310 "os"
11+ "os/exec"
1412 "os/signal"
1513 "strconv"
14+ "strings"
1615 "sync/atomic"
1716 "syscall"
1817 "time"
1918
2019 "github.com/cockroachdb/pebble"
21- "github.com/ethereum/go-ethereum/accounts/abi/bind"
2220 "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"
2622 "github.com/pkg/errors"
2723
2824 "github.com/machinefi/sprout/apitypes"
2925 "github.com/machinefi/sprout/persistence/contract"
3026 "github.com/machinefi/sprout/project"
31- contractproject "github.com/machinefi/sprout/smartcontracts/go/project"
3227 "github.com/machinefi/sprout/vm"
3328)
3429
3530var (
36- projectMinterPrivateKey string
37-
3831 projectCacheDir = "./project_cache"
3932 localDBDir = "./local_db"
40- beginningBlockNumber = uint64 (20000000 )
33+ beginningBlockNumber = uint64 (26000000 )
4134 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 " )
4437 ipfsEndpoint = "ipfs.mainnet.iotex.io"
4538 schedulerEpoch = uint64 (20 )
4639)
4740
4841var (
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"
5745)
5846
5947var (
@@ -62,61 +50,58 @@ var (
6250 zkwasmMessageData = "{\" private_input\" : [1, 1] , \" public_input\" : [] }"
6351)
6452
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 )
6863
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+ }
9370
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+ }
117102}
118103
119- func updateProjectRequiredProver (contractPersistence * contract.Contract , projectInstance * contractproject. Project , opts * bind. TransactOpts ) {
104+ func updateProjectRequiredProver (contractPersistence * contract.Contract ) {
120105 projects := contractPersistence .LatestProjects ()
121106 provers := contractPersistence .LatestProvers ()
122107 if len (provers ) == 0 {
@@ -128,19 +113,34 @@ func updateProjectRequiredProver(contractPersistence *contract.Contract, project
128113 project := projects [index ]
129114 expectProvers := rand .Intn (len (provers )) + 1
130115
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 ()
132123 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 ) )
134125 return
135126 }
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 )
137128}
138129
139130func sendMessage (contractPersistence * contract.Contract , projectManager * project.Manager , taskCount * atomic.Uint64 ) {
140131 projects := contractPersistence .LatestProjects ()
132+
133+ //slog.Info("send message", "project_len", len(projects))
134+
141135 for i := 0 ; i < 3 ; i ++ {
142136 index := rand .Intn (len (projects ))
143137 project := projects [index ]
138+ if project .Paused {
139+ continue
140+ }
141+ if project .Uri == "" {
142+ continue
143+ }
144144 projectFile , err := projectManager .Project (project .ID )
145145 if err != nil {
146146 slog .Error ("failed to get project data" , "project_id" , project .ID , "error" , err )
@@ -176,7 +176,7 @@ func sendMessage(contractPersistence *contract.Contract, projectManager *project
176176 continue
177177 }
178178
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 ))
180180 if err != nil {
181181 slog .Error ("failed to send message" , "project_id" , project .ID , "error" , err )
182182 continue
@@ -192,40 +192,12 @@ func sendMessage(contractPersistence *contract.Contract, projectManager *project
192192}
193193
194194func main () {
195- flag .Parse ()
196195 slog .SetDefault (slog .New (slog .NewTextHandler (os .Stderr , & slog.HandlerOptions {Level : slog .LevelDebug })))
197196
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 )
226198 go func () {
227199 for range createProjectTicker .C {
228- createProject (client , projectInstance , opts )
200+ createProject ()
229201 }
230202 }()
231203
@@ -248,7 +220,7 @@ func main() {
248220 updateProjectRequiredProverTicker := time .NewTicker (1 * time .Hour )
249221 go func () {
250222 for range updateProjectRequiredProverTicker .C {
251- updateProjectRequiredProver (contractPersistence , projectInstance , opts )
223+ updateProjectRequiredProver (contractPersistence )
252224 }
253225 }()
254226
@@ -265,7 +237,7 @@ func main() {
265237 }
266238 }()
267239
268- sendMessageTicker := time .NewTicker (5 * time .Minute )
240+ sendMessageTicker := time .NewTicker (1 * time .Second )
269241 go func () {
270242 for range sendMessageTicker .C {
271243 sendMessage (contractPersistence , projectManager , taskCount )
0 commit comments