Skip to content
Snippets Groups Projects
Commit 7e81eac9 authored by capossele's avatar capossele
Browse files

:construction: WIP

parent a8c0a045
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/gossip"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto" pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/goshimmer/plugins/tipselection"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
) )
...@@ -53,7 +54,7 @@ func Start(tps uint) { ...@@ -53,7 +54,7 @@ func Start(tps uint) {
mtx := &pb.Transaction{Body: tx.MetaTransaction.GetBytes()} mtx := &pb.Transaction{Body: tx.MetaTransaction.GetBytes()}
b, _ := proto.Marshal(mtx) b, _ := proto.Marshal(mtx)
gossip.Events.NewTransaction.Trigger(b) gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b, Peer: &local.INSTANCE.Peer})
if sentCounter >= tps { if sentCounter >= tps {
duration := time.Since(start) duration := time.Since(start)
......
package bundleprocessor package bundleprocessor
import ( import (
"github.com/iotaledger/hive.go/parameter"
"os" "os"
"sync" "sync"
"testing" "testing"
"github.com/iotaledger/goshimmer/packages/client"
"github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/bundle"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "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/plugins/tipselection"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/goshimmer/packages/client"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/iota.go/consts" "github.com/iotaledger/iota.go/consts"
"github.com/magiconair/properties/assert" "github.com/magiconair/properties/assert"
) )
...@@ -49,7 +45,7 @@ func BenchmarkValidateSignatures(b *testing.B) { ...@@ -49,7 +45,7 @@ func BenchmarkValidateSignatures(b *testing.B) {
} }
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
parameter.FetchConfig() parameter.FetchConfig(false)
os.Exit(m.Run()) os.Exit(m.Run())
} }
......
...@@ -2,6 +2,7 @@ package gossip ...@@ -2,6 +2,7 @@ package gossip
import ( import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
zL "github.com/iotaledger/autopeering-sim/logger"
"github.com/iotaledger/autopeering-sim/peer/service" "github.com/iotaledger/autopeering-sim/peer/service"
"github.com/iotaledger/autopeering-sim/selection" "github.com/iotaledger/autopeering-sim/selection"
gp "github.com/iotaledger/goshimmer/packages/gossip" gp "github.com/iotaledger/goshimmer/packages/gossip"
...@@ -14,7 +15,29 @@ import ( ...@@ -14,7 +15,29 @@ import (
"go.uber.org/zap" "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 ( var (
debugLevel = "debug"
zLogger *zap.SugaredLogger zLogger *zap.SugaredLogger
mgr *gp.Manager mgr *gp.Manager
SendTransaction = mgr.SendTransaction SendTransaction = mgr.SendTransaction
...@@ -24,14 +47,6 @@ var ( ...@@ -24,14 +47,6 @@ var (
DropNeighbor = mgr.DropNeighbor 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) { func getTransaction(h []byte) ([]byte, error) {
tx := &pb.TransactionRequest{ tx := &pb.TransactionRequest{
Hash: []byte("testTx"), Hash: []byte("testTx"),
...@@ -41,7 +56,7 @@ func getTransaction(h []byte) ([]byte, error) { ...@@ -41,7 +56,7 @@ func getTransaction(h []byte) ([]byte, error) {
} }
func configureGossip() { func configureGossip() {
defer func() { _ = zLogger.Sync() }() // ignore the returned error zLogger = zL.NewLogger(defaultZLC, debugLevel)
trans, err := transport.Listen(local.INSTANCE, zLogger) trans, err := transport.Listen(local.INSTANCE, zLogger)
if err != nil { if err != nil {
...@@ -56,7 +71,7 @@ func configureEvents() { ...@@ -56,7 +71,7 @@ func configureEvents() {
selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) { selection.Events.Dropped.Attach(events.NewClosure(func(ev *selection.DroppedEvent) {
log.Info("neighbor removed: " + ev.DroppedID.String()) 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) { selection.Events.IncomingPeering.Attach(events.NewClosure(func(ev *selection.PeeringEvent) {
...@@ -78,6 +93,7 @@ func configureEvents() { ...@@ -78,6 +93,7 @@ func configureEvents() {
})) }))
tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) { tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) {
log.Info("Tx solidified")
t := &pb.Transaction{ t := &pb.Transaction{
Body: tx.GetBytes(), Body: tx.GetBytes(),
} }
......
...@@ -11,8 +11,7 @@ var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run) ...@@ -11,8 +11,7 @@ var PLUGIN = node.NewPlugin("Gossip", node.Enabled, configure, run)
var log = logger.NewLogger("Gossip") var log = logger.NewLogger("Gossip")
var ( var (
debugLevel = "debug" close = make(chan struct{}, 1)
close = make(chan struct{}, 1)
) )
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
......
package tangle package tangle
import ( import (
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
) )
...@@ -16,5 +16,5 @@ type pluginEvents struct { ...@@ -16,5 +16,5 @@ type pluginEvents struct {
} }
func transactionCaller(handler interface{}, params ...interface{}) { 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))
} }
...@@ -3,8 +3,10 @@ package tangle ...@@ -3,8 +3,10 @@ package tangle
import ( import (
"runtime" "runtime"
"github.com/golang/protobuf/proto"
"github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/errors"
"github.com/iotaledger/goshimmer/packages/gossip" "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/approvers"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/meta_transaction"
"github.com/iotaledger/goshimmer/packages/model/transactionmetadata" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata"
...@@ -28,8 +30,10 @@ func configureSolidifier(plugin *node.Plugin) { ...@@ -28,8 +30,10 @@ func configureSolidifier(plugin *node.Plugin) {
}, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000)) }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000))
gossip.Events.NewTransaction.Attach(events.NewClosure(func(ev *gossip.NewTransactionEvent) { gossip.Events.NewTransaction.Attach(events.NewClosure(func(ev *gossip.NewTransactionEvent) {
tx := ev.Body //log.Info("New Transaction", ev.Body)
metaTx := meta_transaction.FromBytes(tx) pTx := &pb.Transaction{}
proto.Unmarshal(ev.Body, pTx)
metaTx := meta_transaction.FromBytes(pTx.GetBody())
workerPool.Submit(metaTx) workerPool.Submit(metaTx)
})) }))
......
...@@ -6,13 +6,12 @@ import ( ...@@ -6,13 +6,12 @@ import (
"testing" "testing"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/gossip"
pb "github.com/iotaledger/goshimmer/packages/gossip/proto" pb "github.com/iotaledger/goshimmer/packages/gossip/proto"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/parameter"
"github.com/iotaledger/iota.go/trinary" "github.com/iotaledger/iota.go/trinary"
) )
...@@ -48,19 +47,19 @@ func TestSolidifier(t *testing.T) { ...@@ -48,19 +47,19 @@ func TestSolidifier(t *testing.T) {
wg.Add(4) wg.Add(4)
tx := &pb.Transaction{Body: transaction1.MetaTransaction.GetBytes()} tx := &pb.Transaction{Body: transaction1.MetaTransaction.GetBytes()}
b, _ := proto.Marshal(tx) b, _ := proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b) gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
tx = &pb.Transaction{Body: transaction2.MetaTransaction.GetBytes()} tx = &pb.Transaction{Body: transaction2.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx) b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b) gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
tx = &pb.Transaction{Body: transaction3.MetaTransaction.GetBytes()} tx = &pb.Transaction{Body: transaction3.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx) b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b) gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
tx = &pb.Transaction{Body: transaction4.MetaTransaction.GetBytes()} tx = &pb.Transaction{Body: transaction4.MetaTransaction.GetBytes()}
b, _ = proto.Marshal(tx) b, _ = proto.Marshal(tx)
gossip.Event.NewTransaction.Trigger(b) gossip.Events.NewTransaction.Trigger(&gossip.NewTransactionEvent{Body: b})
// wait until all are solid // wait until all are solid
wg.Wait() wg.Wait()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment