From 97cfb525f2010d744352331dd1342ba0857f13d7 Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Thu, 11 Jul 2019 22:15:34 +0200 Subject: [PATCH] Feat: txspammer issues bundles + bundleprocessor triggers events --- .../value_transaction/value_transaction.go | 2 +- .../transactionspammer/transactionspammer.go | 22 +++++++++---------- .../bundleprocessor/bundleprocessor_test.go | 3 +++ plugins/webapi-spammer/plugin.go | 2 +- plugins/webapi/plugin.go | 1 + 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/model/value_transaction/value_transaction.go b/packages/model/value_transaction/value_transaction.go index 25e98607..f0470a40 100644 --- a/packages/model/value_transaction/value_transaction.go +++ b/packages/model/value_transaction/value_transaction.go @@ -182,7 +182,7 @@ func (this *ValueTransaction) SetTimestamp(timestamp uint) bool { this.timestamp = ×tamp this.BlockHasher() - copy(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END], trinary.IntToTrits(int64(timestamp))[:TIMESTAMP_SIZE]) + copy(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END], trinary.PadTrits(trinary.IntToTrits(int64(timestamp)), TIMESTAMP_SIZE)[:TIMESTAMP_SIZE]) this.UnblockHasher() this.SetModified(true) diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index 777671a2..9b9fe4a3 100644 --- a/packages/transactionspammer/transactionspammer.go +++ b/packages/transactionspammer/transactionspammer.go @@ -18,6 +18,8 @@ var shutdownSignal chan int var sentCounter = uint(0) +var totalSentCounter = uint(0) + func Start(tps uint) { startMutex.Lock() @@ -28,7 +30,6 @@ func Start(tps uint) { daemon.BackgroundWorker("Transaction Spammer", func() { for { start := time.Now() - totalSentCounter := int64(0) for { select { @@ -39,15 +40,9 @@ func Start(tps uint) { return default: - sentCounter++ - totalSentCounter++ - - tx := value_transaction.New() - tx.SetValue(totalSentCounter) - tx.SetBranchTransactionHash(tipselection.GetRandomTip()) - tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) - - gossip.Events.ReceiveTransaction.Trigger(tx.MetaTransaction) + for _, bundleTransaction := range GenerateBundle(3) { + gossip.Events.ReceiveTransaction.Trigger(bundleTransaction.MetaTransaction) + } if sentCounter >= tps { duration := time.Since(start) @@ -90,10 +85,13 @@ func GenerateBundle(bundleLength int) (result []*value_transaction.ValueTransact trunk := tipselection.GetRandomTip() for i := 0; i < bundleLength; i++ { + sentCounter++ + totalSentCounter++ + tx := value_transaction.New() tx.SetTail(i == 0) - tx.SetHead(i == bundleLength - 1) - tx.SetTimestamp(sentCounter) + tx.SetHead(i == bundleLength-1) + tx.SetTimestamp(totalSentCounter) tx.SetBranchTransactionHash(branch) tx.SetTrunkTransactionHash(trunk) diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index a4853715..989c67d5 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -15,6 +15,9 @@ import ( ) func TestProcessSolidBundleHead(t *testing.T) { + // show all error messages for tests + *node.LOG_LEVEL.Value = node.LOG_LEVEL_DEBUG + // start a test node node.Start(tangle.PLUGIN, PLUGIN) diff --git a/plugins/webapi-spammer/plugin.go b/plugins/webapi-spammer/plugin.go index b216aca5..4823ac75 100644 --- a/plugins/webapi-spammer/plugin.go +++ b/plugins/webapi-spammer/plugin.go @@ -69,5 +69,5 @@ type webResponse struct { type webRequest struct { Cmd string `json:"cmd"` - Tps int64 `json:"tps"` + Tps uint `json:"tps"` } diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index 4d80bdad..f19c9e47 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -16,6 +16,7 @@ var Server = echo.New() func configure(plugin *node.Plugin) { Server.HideBanner = true + Server.HidePort = true Server.GET("/", IndexRequest) daemon.Events.Shutdown.Attach(events.NewClosure(func() { -- GitLab