Commit 60f2ac1e authored by vicotor's avatar vicotor

update

parent ca390b09
......@@ -3,7 +3,7 @@ package server
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"github.com/ethereum/go-ethereum/crypto"
"github.com/odysseus/nodemanager/config"
"github.com/odysseus/nodemanager/nmregistry"
"github.com/odysseus/nodemanager/utils"
......@@ -64,7 +64,7 @@ func NewNode() *Node {
}
func (n *Node) Sign(hash []byte) ([]byte, error) {
return n.privk.Sign(rand.Reader, hash, nil)
return crypto.Sign(hash, n.privk)
}
func (n *Node) Start() error {
......
......@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/golang/protobuf/proto"
lru "github.com/hashicorp/golang-lru"
......@@ -39,6 +40,7 @@ type Worker struct {
uuid int64
publicKey string
addr string
benefitAddr string
status []byte
usageInfo []*omanager.DeviceUsage
deviceInfo []*omanager.DeviceInfo
......@@ -47,6 +49,14 @@ type Worker struct {
stream omanager.NodeManagerService_RegisterWorkerServer
}
func (w *Worker) ProfitAccount() common.Address {
return common.HexToAddress(w.benefitAddr)
}
func (w *Worker) WorkerAccount() common.Address {
return common.HexToAddress(w.addr)
}
type WorkerManager struct {
rdb *redis.Client
heartBeat map[int64]int64
......@@ -329,7 +339,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
paramHash := crypto.Keccak256Hash(task.TaskParam)
resultHash := crypto.Keccak256Hash(result.TaskResult)
dataHash := crypto.Keccak256Hash(utils.CombineBytes([]byte(result.TaskUuid), paramHash[:], resultHash[:],
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()))
signature, err := wm.node.Sign(dataHash[:])
if err != nil {
......@@ -421,6 +431,7 @@ func (wm *WorkerManager) handleWorkerMsg(worker *Worker) {
// receive device info
worker.publicKey = msg.DeviceInfo.MinerPubkey
worker.deviceInfo = msg.DeviceInfo.Devices
worker.benefitAddr = msg.DeviceInfo.BenefitAddress
if pubkey, err := utils.HexToPubkey(worker.publicKey); err != nil {
log.WithFields(log.Fields{
......
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