Skip to content

Commit

Permalink
[bug-fix] remove json marshall before task args hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewwww committed Oct 18, 2023
1 parent c9ac482 commit 1803c75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 1 addition & 11 deletions models/inference_task.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package models

import (
"encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
"strconv"
)
Expand Down Expand Up @@ -35,15 +33,7 @@ func (t *InferenceTask) GetTaskIdAsString() string {
}

func (t *InferenceTask) GetTaskHash() (*common.Hash, error) {

taskHashBytes, err := json.Marshal(t.TaskArgs)
if err != nil {
return nil, err
}

log.Debugln("task hash string: " + string(taskHashBytes))

hash := crypto.Keccak256Hash(taskHashBytes)
hash := crypto.Keccak256Hash([]byte(t.TaskArgs))
return &hash, nil
}

Expand Down
20 changes: 20 additions & 0 deletions models/inference_task_hash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package models_test

import (
"github.com/stretchr/testify/assert"
"h_relay/models"
"testing"
)

func TestInferenceTaskHash(t *testing.T) {
taskArgs := `{"base_model": "runwayml/stable-diffusion-v1-5", "prompt": "best quality, ultra high res, photorealistic++++, 1girl, off-shoulder sweater, smiling, faded ash gray messy bun hair+, border light, depth of field, looking at viewer, closeup", "negative_prompt": "paintings, sketches, worst quality+++++, low quality+++++, normal quality+++++, lowres, normal quality, monochrome++, grayscale++, skin spots, acnes, skin blemishes, age spot, glans", "task_config": {"num_images": 1, "safety_checker": false}}`
taskArgsHash := `0xe8a09714ac70305cbc7c35202d5c77927b4390c0c26274fd33aadd9061d222ce`

task := &models.InferenceTask{
TaskArgs: taskArgs,
}

generatedHash, err := task.GetTaskHash()
assert.Nil(t, err, "error get task hash")
assert.Equal(t, taskArgsHash, generatedHash.Hex())
}

0 comments on commit 1803c75

Please sign in to comment.