Commit c7d888d1 authored by vicotor's avatar vicotor

update protocol

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