diff --git a/packages/gossip/manager.go b/packages/gossip/manager.go index 6c889e36fd6771f4d40c6b6e0d8d5c905da6de02..681f6b07c89cc888fe27f66c1d467179607514e8 100644 --- a/packages/gossip/manager.go +++ b/packages/gossip/manager.go @@ -3,11 +3,11 @@ package gossip import ( "net" - "github.com/capossele/gossip/neighbor" - pb "github.com/capossele/gossip/proto" - "github.com/capossele/gossip/transport" "github.com/golang/protobuf/proto" "github.com/iotaledger/autopeering-sim/peer" + "github.com/iotaledger/goshimmer/packages/gossip/neighbor" + pb "github.com/iotaledger/goshimmer/packages/gossip/proto" + "github.com/iotaledger/goshimmer/packages/gossip/transport" "github.com/iotaledger/hive.go/events" "github.com/pkg/errors" "go.uber.org/zap" diff --git a/packages/gossip/manager_test.go b/packages/gossip/manager_test.go index e037c22d9fd1abf1d370f4de081d6e41db5d69ec..51df26e9ebeca0d85336c2354ba188d39b732ab6 100644 --- a/packages/gossip/manager_test.go +++ b/packages/gossip/manager_test.go @@ -6,11 +6,11 @@ import ( "testing" "time" - pb "github.com/capossele/gossip/proto" - "github.com/capossele/gossip/transport" "github.com/golang/protobuf/proto" "github.com/iotaledger/autopeering-sim/peer" "github.com/iotaledger/autopeering-sim/peer/service" + pb "github.com/iotaledger/goshimmer/packages/gossip/proto" + "github.com/iotaledger/goshimmer/packages/gossip/transport" "github.com/iotaledger/hive.go/events" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/packages/gossip/neighbor/neighbor.go b/packages/gossip/neighbor/neighbor.go index 41d2d25fbc3241a926299699761cda5f045b84f2..e3ec6bda8799fddd95aa67b74447ee13d44e994d 100644 --- a/packages/gossip/neighbor/neighbor.go +++ b/packages/gossip/neighbor/neighbor.go @@ -3,8 +3,8 @@ package neighbor import ( "sync" - "github.com/capossele/gossip/transport" "github.com/iotaledger/autopeering-sim/peer" + "github.com/iotaledger/goshimmer/packages/gossip/transport" ) // Neighbor defines a neighbor diff --git a/packages/gossip/proto/message.proto b/packages/gossip/proto/message.proto index b01b93680ce540aea64f26535cb269bd1435df90..6be94fdf5119fde1b682eb4307d15d85f745b472 100644 --- a/packages/gossip/proto/message.proto +++ b/packages/gossip/proto/message.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/capossele/gossip/proto"; +option go_package = "github.com/iotaledger/goshimmer/packages/gossip/proto"; package proto; diff --git a/packages/gossip/transport/handshake.go b/packages/gossip/transport/handshake.go index c6e253ffda9b0a4a39f1637d854d6214c240a526..ef3e8608e518d668678034971c5180e8f8a7e9da 100644 --- a/packages/gossip/transport/handshake.go +++ b/packages/gossip/transport/handshake.go @@ -4,9 +4,9 @@ import ( "bytes" "time" - pb "github.com/capossele/gossip/transport/proto" "github.com/golang/protobuf/proto" "github.com/iotaledger/autopeering-sim/server" + pb "github.com/iotaledger/goshimmer/packages/gossip/transport/proto" ) const ( diff --git a/packages/gossip/transport/proto/handshake.proto b/packages/gossip/transport/proto/handshake.proto index 2f9c628169cb57daa324e5ff16fa9510d6990950..68537177d979d46a6fc9215ff6fb8b2f404e23b2 100644 --- a/packages/gossip/transport/proto/handshake.proto +++ b/packages/gossip/transport/proto/handshake.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "github.com/capossele/gossip/transport/proto"; +option go_package = "github.com/iotaledger/goshimmer/packages/gossip/transport/proto"; package proto; diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index ac1834f6c403a7a3cd7f0aaa5649a637b38c4ab3..f37a2fc3bfbaf9eb476a74e75f6be58947157a2d 100644 --- a/packages/transactionspammer/transactionspammer.go +++ b/packages/transactionspammer/transactionspammer.go @@ -4,8 +4,9 @@ import ( "sync" "time" - "github.com/iotaledger/goshimmer/plugins/gossip" - + "github.com/golang/protobuf/proto" + "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/tipselection" "github.com/iotaledger/hive.go/daemon" @@ -50,7 +51,9 @@ func Start(tps uint) { tx.SetBranchTransactionHash(tipselection.GetRandomTip()) tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) - gossip.Events.ReceiveTransaction.Trigger(tx.MetaTransaction) + mtx := &pb.Transaction{Body: tx.MetaTransaction.GetBytes()} + b, _ := proto.Marshal(mtx) + gossip.Event.NewTransaction.Trigger(b) if sentCounter >= tps { duration := time.Since(start) diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 47fe0934df7356d09699b6de908e35f7d59e7ab4..eefa8de3dec4fab5a49198b15903a99ac5a3b6bc 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -1,12 +1,9 @@ package autopeering import ( - "net" - "github.com/iotaledger/autopeering-sim/discover" - "github.com/iotaledger/autopeering-sim/peer/service" - "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/packages/gossip" + "github.com/iotaledger/goshimmer/packages/gossip/neighbor" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" @@ -29,37 +26,12 @@ func run(plugin *node.Plugin) { } func configureLogging(plugin *node.Plugin) { - gossip.Event.DropNeighbor.Attach(events.NewClosure(func(peer *gossip.Neighbor) { + gossip.Event.DropNeighbor.Attach(events.NewClosure(func(peer *neighbor.Neighbor) { if Selection != nil { Selection.DropPeer(peer.Peer) } })) - selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) { - log.Info("neighbor removed: " + ev.DroppedID.String()) - gossip.RemoveNeighbor(ev.DroppedID.String()) - })) - - selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Info("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - log.Info("services: " + ev.Peer.Services().CreateRecord().String()) - gossipService := ev.Peer.Services().Get(service.GossipKey) - if gossipService != nil { - address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) - gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) - } - })) - - selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Info("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - log.Info("services: " + ev.Peer.Services().CreateRecord().String()) - gossipService := ev.Peer.Services().Get(service.GossipKey) - if gossipService != nil { - address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) - gossip.AddNeighbor(gossip.NewNeighbor(ev.Peer, address, port)) - } - })) - discover.Events.PeerDiscovered.Attach(events.NewClosure(func(ev *discover.DiscoveredEvent) { log.Info("new peer discovered: " + ev.Peer.Address() + " / " + ev.Peer.ID().String()) })) diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 0ca491a83656bce9d8084bcdb5226d6c53a13a66..89683109d7bcfb8c960be6764ee9559a6b6b7e23 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -1,11 +1,13 @@ package gossip import ( + "github.com/iotaledger/goshimmer/packages/gossip/transport" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" gp "github.com/iotaledger/goshimmer/packages/gossip" pb "github.com/iotaledger/goshimmer/packages/gossip/proto" "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/goshimmer/plugins/tangle" "go.uber.org/zap" @@ -58,13 +60,21 @@ func configureEvents() { })) selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Debug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - AddInbound(ev.Peer) + gossipService := ev.Peer.Services().Get(service.GossipKey) + if gossipService != nil { + log.Debug("accepted neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + //address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) + AddInbound(ev.Peer) + } })) selection.Events.OutgoingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) { - log.Debug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) - AddOutbound(ev.Peer) + gossipService := ev.Peer.Services().Get(service.GossipKey) + if gossipService != nil { + log.Debug("chosen neighbor added: " + ev.Peer.Address() + " / " + ev.Peer.String()) + //address, port, _ := net.SplitHostPort(ev.Peer.Services().Get(service.GossipKey).String()) + AddOutbound(ev.Peer) + } })) // mgr.Events.NewTransaction.Attach(events.NewClosure(func(ev *gp.NewTransactionEvent) { diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index c483a42a9af5ae100bc2b835f376f6e72ecc9af3..b379f012f359f706a3050cd29c5fc7517e08abee 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -3,9 +3,8 @@ package metrics import ( "time" - "github.com/iotaledger/goshimmer/packages/model/meta_transaction" + "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/timeutil" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" @@ -15,7 +14,7 @@ var PLUGIN = node.NewPlugin("Metrics", node.Enabled, configure, run) func configure(plugin *node.Plugin) { // increase received TPS counter whenever we receive a new transaction - gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { increaseReceivedTPSCounter() })) + gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) { increaseReceivedTPSCounter() })) } func run(plugin *node.Plugin) { diff --git a/plugins/statusscreen-tps/plugin.go b/plugins/statusscreen-tps/plugin.go index 15f4d1babc87751048cbe66b1c17696c74db8139..c05fedb2baf6bb9e34a32c5db7337d06c281361d 100644 --- a/plugins/statusscreen-tps/plugin.go +++ b/plugins/statusscreen-tps/plugin.go @@ -5,9 +5,8 @@ import ( "sync/atomic" "time" - "github.com/iotaledger/goshimmer/packages/model/meta_transaction" + "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/statusscreen" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/hive.go/daemon" @@ -24,7 +23,7 @@ var receivedTps uint64 var solidTps uint64 var PLUGIN = node.NewPlugin("Statusscreen TPS", node.Enabled, func(plugin *node.Plugin) { - gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { + gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) { atomic.AddUint64(&receivedTpsCounter, 1) })) diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index 53a0fe61a4dc703da903594ce3e5f1a8e4c7abab..899764fcfa8958a1e620cfccdc519f9a750d37d0 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -4,12 +4,12 @@ import ( "runtime" "github.com/iotaledger/goshimmer/packages/errors" + "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/model/approvers" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/workerpool" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" @@ -27,8 +27,10 @@ func configureSolidifier(plugin *node.Plugin) { task.Return(nil) }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000)) - gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(rawTransaction *meta_transaction.MetaTransaction) { - workerPool.Submit(rawTransaction) + gossip.Event.NewTransaction.Attach(events.NewClosure(func(ev *gossip.NewTransactionEvent) { + tx := ev.Body + metaTx := meta_transaction.FromBytes(tx) + workerPool.Submit(metaTx) })) daemon.Events.Shutdown.Attach(events.NewClosure(func() { diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index f13daf1bf445f673254994c7e4107c3141a67ea1..9062eda476bf5b79ad16bec8d3cc7ddfd6fc217b 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -1,20 +1,23 @@ package tangle import ( - "github.com/iotaledger/hive.go/parameter" "os" "sync" "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/goshimmer/plugins/gossip" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/trinary" ) func TestMain(m *testing.M) { - parameter.FetchConfig() + parameter.FetchConfig(false) os.Exit(m.Run()) } @@ -43,10 +46,21 @@ func TestSolidifier(t *testing.T) { // issue transactions wg.Add(4) - gossip.Events.ReceiveTransaction.Trigger(transaction1.MetaTransaction) - gossip.Events.ReceiveTransaction.Trigger(transaction2.MetaTransaction) - gossip.Events.ReceiveTransaction.Trigger(transaction3.MetaTransaction) - gossip.Events.ReceiveTransaction.Trigger(transaction4.MetaTransaction) + tx := &pb.Transaction{Body: transaction1.MetaTransaction.GetBytes()} + b, _ := proto.Marshal(tx) + gossip.Event.NewTransaction.Trigger(b) + + tx = &pb.Transaction{Body: transaction2.MetaTransaction.GetBytes()} + b, _ = proto.Marshal(tx) + gossip.Event.NewTransaction.Trigger(b) + + tx = &pb.Transaction{Body: transaction3.MetaTransaction.GetBytes()} + b, _ = proto.Marshal(tx) + gossip.Event.NewTransaction.Trigger(b) + + tx = &pb.Transaction{Body: transaction4.MetaTransaction.GetBytes()} + b, _ = proto.Marshal(tx) + gossip.Event.NewTransaction.Trigger(b) // wait until all are solid wg.Wait() diff --git a/plugins/ui/ui.go b/plugins/ui/ui.go index 2bc5d3654fa65a67072d2fbbaba98b97efd0c780..66ef3099417a8d4ecf659b74f06d9ca0a1600958 100644 --- a/plugins/ui/ui.go +++ b/plugins/ui/ui.go @@ -6,9 +6,8 @@ import ( "sync/atomic" "time" - "github.com/iotaledger/goshimmer/packages/model/meta_transaction" + "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/hive.go/daemon" @@ -35,7 +34,7 @@ func configure(plugin *node.Plugin) { return c.JSON(http.StatusOK, tpsQueue) }) - gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { + gossip.Event.NewTransaction.Attach(events.NewClosure(func(_ *gossip.NewTransactionEvent) { atomic.AddUint64(&receivedTpsCounter, 1) })) tangle.Events.TransactionSolid.Attach(events.NewClosure(func(_ *value_transaction.ValueTransaction) {