From 20333ba4afcc995718b49e377b1dc5af6a3769a9 Mon Sep 17 00:00:00 2001 From: Vladimir Sinitcin Date: Tue, 12 Nov 2024 18:35:55 +0700 Subject: [PATCH] Better implementation --- kvasir/execute.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/kvasir/execute.go b/kvasir/execute.go index 9dd11f42..b7dc706f 100644 --- a/kvasir/execute.go +++ b/kvasir/execute.go @@ -105,6 +105,16 @@ func queryAccount(clientCtx client.Context, key *keyring.Record) (client.Account return acc, nil } +func reProcessRequest(c *Context, l *Logger, contractAddress string, request Request) { + // Resending request for reprocessing + c.pendingRequests[RequestKey{ + ContractAddress: contractAddress, + RequestID: request.RequestID, + }] = true + + go handleRequest(c, l, contractAddress, request) +} + // SubmitReport TODO: rework func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWithKey) { // Return key and update pending metric when done with SubmitReport whether successfully or not. @@ -115,13 +125,20 @@ func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWith // Summarize execute version versionMap := make(map[string]bool) - msgs := make([]sdk.Msg, len(reports)) - ids := make([]uint64, len(reports)) + msgs := make([]sdk.Msg, 0) + ids := make([]uint64, 0) + + for _, report := range reports { + // On empty result we don't even try to upload to IPFS + if report.result == nil { + reProcessRequest(c, l, report.contractAddress, report.request) + continue + } - for i, report := range reports { hash, err := uploadToIPFS(c, l, report.result, report) if err != nil { - fmt.Println(err) + l.Error(":warning: error when processing file %s", c, err.Error()) + reProcessRequest(c, l, report.contractAddress, report.request) continue } fmt.Println(hash) @@ -144,12 +161,13 @@ func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWith l.Error(":exploding_head: Failed to validate basic with error: %s", c, err.Error()) return } - msgs[i] = sdk.Msg(&msg) - ids[i] = report.request.RequestID + + msgs = append(msgs, sdk.Msg(&msg)) + ids = append(ids, report.request.RequestID) versionMap[report.execVersion] = true } - if len(reports) == 0 { + if len(msgs) == 0 { l.Info(":warning: No reports to submit") return }