Commit c7d888d1 authored by vicotor's avatar vicotor

update protocol

parent 54b1e141
......@@ -144,7 +144,7 @@ func main() {
TaskUuid: b.PushTaskMessage.TaskUuid,
ContainerSignature: make([]byte, 65),
MinerSignature: make([]byte, 65),
TaskResult: []byte(demoResult),
TaskResultBody: []byte(demoResult),
},
},
}
......
......@@ -68,6 +68,7 @@ func NewNode() *Node {
}
node.wm = NewWorkerManager(rdb, node)
log.WithField("nm pubkey", utils.PubkeyToHex(&privk.PublicKey)).Info("node manager started")
return node
}
......
......@@ -300,12 +300,13 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
if result.IsSuccessed == false {
taskResponse := &odysseus.TaskResponse{
TaskUuid: task.TaskUuid,
TaskResult: result.TaskResult,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
TaskIsSucceed: false,
TaskError: "worker failed",
TaskUuid: task.TaskUuid,
TaskResultHeader: result.TaskResultHeader,
TaskResultBody: result.TaskResultBody,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
TaskIsSucceed: false,
TaskError: "worker failed",
}
receipt := wm.makeReceipt(worker, task, result, errors.New("worker failed"))
wm.node.PostResult(receipt)
......@@ -329,7 +330,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
// verify miner_signature
// miner_signature = sign(hash((task_id+hash(task_param)+hash(task_result)))
paramHash := crypto.Keccak256Hash(task.TaskParam)
resultHash := crypto.Keccak256Hash(result.TaskResult)
resultHash := crypto.Keccak256Hash(result.TaskResultBody)
dataHash := crypto.Keccak256Hash(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:]))
minerPubkey, _ := utils.HexToPubkey(worker.publicKey) // todo: get miner pubkey
verified := ecdsa.VerifyASN1(minerPubkey, dataHash[:], result.MinerSignature)
......@@ -344,7 +345,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
//manager_signature = sign(hash((task_id+hash(task_param)+hash(task_result)+container_signature+miner_signature+workload))
paramHash := crypto.Keccak256Hash(task.TaskParam)
resultHash := crypto.Keccak256Hash(result.TaskResult)
resultHash := crypto.Keccak256Hash(result.TaskResultBody)
dataHash := crypto.Keccak256Hash(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:],
worker.ProfitAccount().Bytes(), worker.WorkerAccount().Bytes(), result.ContainerSignature, result.MinerSignature, big.NewInt(int64(task.TaskWorkload)).Bytes()))
......@@ -361,6 +362,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
Workload: uint64(task.TaskWorkload),
ContainerPubkey: utils.CombineBytes(task.ContainerPubkey),
}
msg.Message = proof
callback = func(err error) bool {
if err == nil {
......@@ -368,12 +370,13 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
worker.recentTask.Remove(result.TaskUuid)
}
taskResponse := &odysseus.TaskResponse{
TaskUuid: task.TaskUuid,
TaskResult: result.TaskResult,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
TaskIsSucceed: true,
TaskError: "",
TaskUuid: task.TaskUuid,
TaskResultHeader: result.TaskResultHeader,
TaskResultBody: result.TaskResultBody,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
TaskIsSucceed: true,
TaskError: "",
}
go wm.doCallback(task.TaskCallback, taskResponse)
......@@ -511,7 +514,7 @@ func (wm *WorkerManager) makeReceipt(worker *Worker, task *odysseus.TaskContent,
TaskWorkload: task.TaskWorkload,
TaskDuration: int64(now-task.TaskTimestamp) / 1000,
TaskFee: 0,
TaskOutLen: int64(len(result.TaskResult)),
TaskOutLen: int64(len(result.TaskResultBody)),
TaskProfitAccount: worker.ProfitAccount().Hex(),
TaskWorkerAccount: worker.WorkerAccount().Hex(),
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment