From 7e81eac92872dae76b8acc1b0f296612b54b5ea8 Mon Sep 17 00:00:00 2001
From: capossele <angelocapossele@gmail.com>
Date: Sun, 8 Dec 2019 11:21:06 +0000
Subject: [PATCH] :construction: WIP

---
 .../transactionspammer/transactionspammer.go  |  3 +-
 .../bundleprocessor/bundleprocessor_test.go   | 14 +++-----
 plugins/gossip/gossip.go                      | 36 +++++++++++++------
 plugins/gossip/plugin.go                      |  3 +-
 plugins/tangle/events.go                      |  4 +--
 plugins/tangle/solidifier.go                  |  8 +++--
 plugins/tangle/solidifier_test.go             | 11 +++---
 7 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go
index e9fd616c..00866b8a 100644
--- a/packages/transactionspammer/transactionspammer.go
+++ b/packages/transactionspammer/transactionspammer.go
@@ -8,6 +8,7 @@ import (
 	"github.com/iotaledger/goshimmer/packages/gossip"
 	pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
 	"github.com/iotaledger/goshimmer/packages/model/value_transaction"
+	"github.com/iotaledger/goshimmer/plugins/autopeering/local"
 	"github.com/iotaledger/goshimmer/plugins/tipselection"
 	"github.com/iotaledger/hive.go/daemon"
 )
@@ -53,7 +54,7 @@ func Start(tps uint) {
 
 							mtx := &pb.Transaction{Body: tx.MetaTransaction.GetBytes()}
 							b, _ := proto.Marshal(mtx)
-							gossip.Events.NewTransaction.Trigger(b)
+							gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b, Peer: &local.INSTANCE.Peer})
 
 							if sentCounter >= tps {
 								duration := time.Since(start)
diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go
index 6fda9085..93ea4dcd 100644
--- a/plugins/bundleprocessor/bundleprocessor_test.go
+++ b/plugins/bundleprocessor/bundleprocessor_test.go
@@ -1,22 +1,18 @@
 package bundleprocessor
 
 import (
-	"github.com/iotaledger/hive.go/parameter"
 	"os"
 	"sync"
 	"testing"
 
+	"github.com/iotaledger/goshimmer/packages/client"
 	"github.com/iotaledger/goshimmer/packages/model/bundle"
 	"github.com/iotaledger/goshimmer/packages/model/value_transaction"
-	"github.com/iotaledger/hive.go/events"
-
+	"github.com/iotaledger/goshimmer/plugins/tangle"
 	"github.com/iotaledger/goshimmer/plugins/tipselection"
-
-	"github.com/iotaledger/goshimmer/packages/client"
-
+	"github.com/iotaledger/hive.go/events"
 	"github.com/iotaledger/hive.go/node"
-
-	"github.com/iotaledger/goshimmer/plugins/tangle"
+	"github.com/iotaledger/hive.go/parameter"
 	"github.com/iotaledger/iota.go/consts"
 	"github.com/magiconair/properties/assert"
 )
@@ -49,7 +45,7 @@ func BenchmarkValidateSignatures(b *testing.B) {
 }
 
 func TestMain(m *testing.M) {
-	parameter.FetchConfig()
+	parameter.FetchConfig(false)
 	os.Exit(m.Run())
 }
 
diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go
index 00598e5f..1f58e107 100644
--- a/plugins/gossip/gossip.go
+++ b/plugins/gossip/gossip.go
@@ -2,6 +2,7 @@ package gossip
 
 import (
 	"github.com/golang/protobuf/proto"
+	zL "github.com/iotaledger/autopeering-sim/logger"
 	"github.com/iotaledger/autopeering-sim/peer/service"
 	"github.com/iotaledger/autopeering-sim/selection"
 	gp "github.com/iotaledger/goshimmer/packages/gossip"
@@ -14,7 +15,29 @@ import (
 	"go.uber.org/zap"
 )
 
+const defaultZLC = `{
+	"level": "info",
+	"development": false,
+	"outputPaths": ["stdout"],
+	"errorOutputPaths": ["stderr"],
+	"encoding": "console",
+	"encoderConfig": {
+	  "timeKey": "ts",
+	  "levelKey": "level",
+	  "nameKey": "logger",
+	  "callerKey": "caller",
+	  "messageKey": "msg",
+	  "stacktraceKey": "stacktrace",
+	  "lineEnding": "",
+	  "levelEncoder": "",
+	  "timeEncoder": "iso8601",
+	  "durationEncoder": "",
+	  "callerEncoder": ""
+	}
+  }`
+
 var (
+	debugLevel         = "debug"
 	zLogger            *zap.SugaredLogger
 	mgr                *gp.Manager
 	SendTransaction    = mgr.SendTransaction
@@ -24,14 +47,6 @@ var (
 	DropNeighbor       = mgr.DropNeighbor
 )
 
-func init() {
-	l, err := zap.NewDevelopment()
-	if err != nil {
-		log.Fatalf("cannot initialize logger: %v", err)
-	}
-	zLogger = l.Sugar()
-}
-
 func getTransaction(h []byte) ([]byte, error) {
 	tx := &pb.TransactionRequest{
 		Hash: []byte("testTx"),
@@ -41,7 +56,7 @@ func getTransaction(h []byte) ([]byte, error) {
 }
 
 func configureGossip() {
-	defer func() { _ = zLogger.Sync() }() // ignore the returned error
+	zLogger = zL.NewLogger(defaultZLC, debugLevel)
 
 	trans, err := transport.Listen(local.INSTANCE, zLogger)
 	if err != nil {
@@ -56,7 +71,7 @@ func configureEvents() {
 
 	selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) {
 		log.Info("neighbor removed: " + ev.DroppedID.String())
-		mgr.DropNeighbor(ev.DroppedID)
+		go mgr.DropNeighbor(ev.DroppedID)
 	}))
 
 	selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
@@ -78,6 +93,7 @@ func configureEvents() {
 	}))
 
 	tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) {
+		log.Info("Tx solidified")
 		t := &pb.Transaction{
 			Body: tx.GetBytes(),
 		}
diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go
index 3cfadd24..5bf6cfca 100644
--- a/plugins/gossip/plugin.go
+++ b/plugins/gossip/plugin.go
@@ -11,8 +11,7 @@ var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run)
 var log = logger.NewLogger("Gossip")
 
 var (
-	debugLevel = "debug"
-	close      = make(chan struct{}, 1)
+	close = make(chan struct{}, 1)
 )
 
 func configure(plugin *node.Plugin) {
diff --git a/plugins/tangle/events.go b/plugins/tangle/events.go
index b9c0acf5..3cc90ba4 100644
--- a/plugins/tangle/events.go
+++ b/plugins/tangle/events.go
@@ -1,7 +1,7 @@
 package tangle
 
 import (
-	"github.com/iotaledger/goshimmer/packages/model/meta_transaction"
+	"github.com/iotaledger/goshimmer/packages/model/value_transaction"
 	"github.com/iotaledger/hive.go/events"
 )
 
@@ -16,5 +16,5 @@ type pluginEvents struct {
 }
 
 func transactionCaller(handler interface{}, params ...interface{}) {
-	handler.(func(*meta_transaction.MetaTransaction))(params[0].(*meta_transaction.MetaTransaction))
+	handler.(func(*value_transaction.ValueTransaction))(params[0].(*value_transaction.ValueTransaction))
 }
diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go
index 6e7b1991..addd5ee1 100644
--- a/plugins/tangle/solidifier.go
+++ b/plugins/tangle/solidifier.go
@@ -3,8 +3,10 @@ package tangle
 import (
 	"runtime"
 
+	"github.com/golang/protobuf/proto"
 	"github.com/iotaledger/goshimmer/packages/errors"
 	"github.com/iotaledger/goshimmer/packages/gossip"
+	pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
 	"github.com/iotaledger/goshimmer/packages/model/approvers"
 	"github.com/iotaledger/goshimmer/packages/model/meta_transaction"
 	"github.com/iotaledger/goshimmer/packages/model/transactionmetadata"
@@ -28,8 +30,10 @@ func configureSolidifier(plugin *node.Plugin) {
 	}, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000))
 
 	gossip.Events.NewTransaction.Attach(events.NewClosure(func(ev *gossip.NewTransactionEvent) {
-		tx := ev.Body
-		metaTx := meta_transaction.FromBytes(tx)
+		//log.Info("New Transaction", ev.Body)
+		pTx := &pb.Transaction{}
+		proto.Unmarshal(ev.Body, pTx)
+		metaTx := meta_transaction.FromBytes(pTx.GetBody())
 		workerPool.Submit(metaTx)
 	}))
 
diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go
index 9062eda4..692e5ccd 100644
--- a/plugins/tangle/solidifier_test.go
+++ b/plugins/tangle/solidifier_test.go
@@ -6,13 +6,12 @@ import (
 	"testing"
 
 	"github.com/golang/protobuf/proto"
-	"github.com/iotaledger/hive.go/parameter"
-
 	"github.com/iotaledger/goshimmer/packages/gossip"
 	pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
 	"github.com/iotaledger/goshimmer/packages/model/value_transaction"
 	"github.com/iotaledger/hive.go/events"
 	"github.com/iotaledger/hive.go/node"
+	"github.com/iotaledger/hive.go/parameter"
 	"github.com/iotaledger/iota.go/trinary"
 )
 
@@ -48,19 +47,19 @@ func TestSolidifier(t *testing.T) {
 	wg.Add(4)
 	tx := &pb.Transaction{Body: transaction1.MetaTransaction.GetBytes()}
 	b, _ := proto.Marshal(tx)
-	gossip.Event.NewTransaction.Trigger(b)
+	gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
 
 	tx = &pb.Transaction{Body: transaction2.MetaTransaction.GetBytes()}
 	b, _ = proto.Marshal(tx)
-	gossip.Event.NewTransaction.Trigger(b)
+	gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
 
 	tx = &pb.Transaction{Body: transaction3.MetaTransaction.GetBytes()}
 	b, _ = proto.Marshal(tx)
-	gossip.Event.NewTransaction.Trigger(b)
+	gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
 
 	tx = &pb.Transaction{Body: transaction4.MetaTransaction.GetBytes()}
 	b, _ = proto.Marshal(tx)
-	gossip.Event.NewTransaction.Trigger(b)
+	gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
 
 	// wait until all are solid
 	wg.Wait()
-- 
GitLab