Skip to content

Commit

Permalink
Better implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Satchitananda committed Nov 12, 2024
1 parent 7556356 commit 20333ba
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions kvasir/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 20333ba

Please sign in to comment.