Commit 60f2ac1e authored by vicotor's avatar vicotor

update

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