diff --git a/packages/curl/batch_hasher.go b/packages/curl/batch_hasher.go index ba174808d0e73d417c29d190991ac994f8d6164e..51d63f20e7856c82726f0a7e061e750ffb62c419 100644 --- a/packages/curl/batch_hasher.go +++ b/packages/curl/batch_hasher.go @@ -20,7 +20,7 @@ func NewBatchHasher(hashLength int, rounds int) (result *BatchHasher) { rounds: rounds, } - result.workerPool = batchworkerpool.New(result.processHashes, batchworkerpool.BatchSize(strconv.IntSize)) + result.workerPool = batchworkerpool.New(result.processHashes, batchworkerpool.BatchSize(strconv.IntSize), batchworkerpool.WorkerCount(100), batchworkerpool.QueueSize(500000)) result.workerPool.Start() return diff --git a/packages/curl/batch_hasher_test.go b/packages/curl/batch_hasher_test.go index 009cc6bf9bf26c3b27f696e140a4d97a55fbee1d..c76727330117a1c0655dd974a6c8bb810295ef21 100644 --- a/packages/curl/batch_hasher_test.go +++ b/packages/curl/batch_hasher_test.go @@ -5,11 +5,62 @@ import ( "testing" "github.com/iotaledger/iota.go/trinary" + "golang.org/x/crypto/blake2b" + "golang.org/x/crypto/ed25519" ) +type zeroReader struct{} + +func (zeroReader) Read(buf []byte) (int, error) { + for i := range buf { + buf[i] = 0 + } + return len(buf), nil +} + +func BenchmarkEd25519(b *testing.B) { + var zero zeroReader + public, private, _ := ed25519.GenerateKey(zero) + + message := make([]byte, 75) + sig := ed25519.Sign(private, message) + + b.ResetTimer() + + var wg sync.WaitGroup + for i := 0; i < b.N; i++ { + wg.Add(1) + + go func() { + if !ed25519.Verify(public, message, sig) { + panic("valid signature rejected") + } + + wg.Done() + }() + } + wg.Wait() +} + +func BenchmarkBlake2b(b *testing.B) { + data := make([]byte, 750) + + var wg sync.WaitGroup + for i := 0; i < b.N; i++ { + wg.Add(1) + + go func() { + blake2b.Sum256(data) + + wg.Done() + }() + } + wg.Wait() +} + func BenchmarkBatchHasher_Hash(b *testing.B) { batchHasher := NewBatchHasher(243, 81) - tritsToHash := trinary.MustTrytesToTrits(trinary.Trytes("A999999FF")) + tritsToHash := make(trinary.Trits, 7500) b.ResetTimer() diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index 9b9fe4a37ff2b40c3c39e1ee3c2c410a0f0d63de..8038727265a8c1e3d5514a5d3e5f9dbf533e7127 100644 --- a/packages/transactionspammer/transactionspammer.go +++ b/packages/transactionspammer/transactionspammer.go @@ -4,9 +4,10 @@ import ( "sync" "time" + "github.com/iotaledger/goshimmer/plugins/gossip" + "github.com/iotaledger/goshimmer/packages/daemon" "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/tipselection" ) @@ -18,8 +19,6 @@ var shutdownSignal chan int var sentCounter = uint(0) -var totalSentCounter = uint(0) - func Start(tps uint) { startMutex.Lock() @@ -30,6 +29,7 @@ func Start(tps uint) { daemon.BackgroundWorker("Transaction Spammer", func() { for { start := time.Now() + totalSentCounter := int64(0) for { select { @@ -40,18 +40,25 @@ func Start(tps uint) { return default: - for _, bundleTransaction := range GenerateBundle(3) { - gossip.Events.ReceiveTransaction.Trigger(bundleTransaction.MetaTransaction) - } + sentCounter++ + totalSentCounter++ + + tx := value_transaction.New() + tx.SetValue(totalSentCounter) + tx.SetBranchTransactionHash(tipselection.GetRandomTip()) + tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) + + gossip.Events.ReceiveTransaction.Trigger(tx.MetaTransaction) if sentCounter >= tps { duration := time.Since(start) + if duration < time.Second { time.Sleep(time.Second - duration) - - start = time.Now() } + start = time.Now() + sentCounter = 0 } } @@ -77,28 +84,3 @@ func Stop() { startMutex.Unlock() } - -func GenerateBundle(bundleLength int) (result []*value_transaction.ValueTransaction) { - result = make([]*value_transaction.ValueTransaction, bundleLength) - - branch := tipselection.GetRandomTip() - 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(totalSentCounter) - tx.SetBranchTransactionHash(branch) - tx.SetTrunkTransactionHash(trunk) - - result[i] = tx - - trunk = tx.GetHash() - } - - return result -} diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index c7ed648bf1177f40df63ef4f0b089f7a92474ac2..71494b86230c43d53748df28ab33e483016955ab 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -21,7 +21,9 @@ var workerPool *workerpool.WorkerPool func configureSolidifier(plugin *node.Plugin) { workerPool = workerpool.New(func(task workerpool.Task) { processMetaTransaction(plugin, task.Param(0).(*meta_transaction.MetaTransaction)) - }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(2*WORKER_COUNT)) + + task.Return(nil) + }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000)) gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(rawTransaction *meta_transaction.MetaTransaction) { workerPool.Submit(rawTransaction) @@ -186,4 +188,4 @@ func processTransaction(plugin *node.Plugin, transaction *value_transaction.Valu } } -const WORKER_COUNT = 400 +const WORKER_COUNT = 5000