From 9e202bc9f912a26bed73d6438d00ed74e2a4bfe4 Mon Sep 17 00:00:00 2001 From: jdutchak Date: Fri, 19 Jul 2024 11:27:36 -0400 Subject: [PATCH] base64 blocks input data --- pkg/api/handlers_data.go | 6 +++--- pkg/chain/pos.go | 2 +- pkg/oracle_node.go | 7 ++++--- pkg/workers/workers.go | 22 ++++++---------------- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pkg/api/handlers_data.go b/pkg/api/handlers_data.go index bb3680b4..248d0c93 100644 --- a/pkg/api/handlers_data.go +++ b/pkg/api/handlers_data.go @@ -867,11 +867,11 @@ func (api *API) GetBlocks() gin.HandlerFunc { InputData interface{} `json:"input_data"` TransactionHash string `json:"transaction_hash"` PreviousHash string `json:"previous_hash"` - TransactionNonce int `json:"transaction_nonce"` + TransactionNonce int `json:"nonce"` } type Blocks struct { - BlockData []BlockData `json:"block_data"` + BlockData []BlockData `json:"blocks"` } var existingBlocks Blocks blocks := chain.GetBlockchain(api.Node.Blockchain) @@ -884,7 +884,7 @@ func (api *API) GetBlocks() gin.HandlerFunc { } blockData := BlockData{ - InputData: inputData, + InputData: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v", inputData))), TransactionHash: fmt.Sprintf("%x", block.Hash), PreviousHash: fmt.Sprintf("%x", block.Link), TransactionNonce: int(block.Nonce), diff --git a/pkg/chain/pos.go b/pkg/chain/pos.go index cd25b541..6964b15c 100644 --- a/pkg/chain/pos.go +++ b/pkg/chain/pos.go @@ -46,7 +46,7 @@ func (pos *ProofOfStake) Run() (int64, []byte) { var hashInt big.Int currentTime := time.Now().Unix() - logrus.WithFields(logrus.Fields{"block_content": string(pos.Block.Data)}).Info("Running Proof of Stake...") + logrus.WithFields(logrus.Fields{"timestamp": currentTime}).Info("Running Proof of Stake...") spinner := []string{"|", "/", "-", "\\"} i := 0 for { diff --git a/pkg/oracle_node.go b/pkg/oracle_node.go index a9a8285a..564450d2 100644 --- a/pkg/oracle_node.go +++ b/pkg/oracle_node.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/ecdsa" + "encoding/base64" "encoding/json" "fmt" "io" @@ -370,11 +371,11 @@ type BlockData struct { InputData interface{} `json:"input_data"` TransactionHash string `json:"transaction_hash"` PreviousHash string `json:"previous_hash"` - TransactionNonce int `json:"transaction_nonce"` + TransactionNonce int `json:"nonce"` } type Blocks struct { - BlockData []BlockData `json:"block_data"` + BlockData []BlockData `json:"blocks"` } type BlockEvents struct{} @@ -412,7 +413,7 @@ func updateBlocks(ctx context.Context, node *OracleNode) { } blockData := BlockData{ - InputData: inputData, + InputData: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v", inputData))), TransactionHash: fmt.Sprintf("%x", block.Hash), PreviousHash: fmt.Sprintf("%x", block.Link), TransactionNonce: int(block.Nonce), diff --git a/pkg/workers/workers.go b/pkg/workers/workers.go index 8731d2e7..3f3d7026 100644 --- a/pkg/workers/workers.go +++ b/pkg/workers/workers.go @@ -313,12 +313,10 @@ func SendWork(node *masa.OracleNode, m *pubsub2.Message) { msg := &pubsub2.Message{} err = json.Unmarshal([]byte(response.Value), msg) if err != nil { - _, err = getResponseMessage(result.(*messages.Response)) + msg, err = getResponseMessage(result.(*messages.Response)) if err != nil { logrus.Debugf("Error getting response message: %v", err) - return - } else { - // don't send back failed messages here + workerDoneCh <- &pubsub2.Message{ValidatorData: err.Error()} return } } @@ -394,22 +392,14 @@ func SubscribeToWorkers(node *masa.OracleNode) { // marshals the data to JSON, and writes it to the database using the WriteData function. // The monitoring continues until the context is done. func MonitorWorkers(ctx context.Context, node *masa.OracleNode) { - if node == nil { - logrus.Error("MonitorWorkers: node is nil") - return - } - if node.ActorRemote == nil { - logrus.Error("MonitorWorkers: node.ActorRemote is nil") - return - } + // Register self as a remote node for the network + node.ActorRemote.Register("peer", actor.PropsFromProducer(NewWorker(node))) + if node.WorkerTracker == nil || node.WorkerTracker.WorkerStatusCh == nil { logrus.Debug("MonitorWorkers: WorkerTracker or WorkerStatusCh is nil") return } - // Register self as a remote node for the network - node.ActorRemote.Register("peer", actor.PropsFromProducer(NewWorker(node))) - ticker := time.NewTicker(time.Second * 10) defer ticker.Stop() rcm := pubsub.GetResponseChannelMap() @@ -510,7 +500,7 @@ func processWork(data *pubsub2.Message, work string, startTime *time.Time, node Duration: duration.Seconds(), Timestamp: time.Now().Unix(), } - logrus.Infof("[+] Work event: %v", workEvent) + logrus.Infof("[+] Work event for : %s", workEvent.PeerId) _ = node.PubSubManager.Publish(config.TopicWithVersion(config.BlockTopic), workEvent.Payload)