Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
19f276af
Commit
19f276af
authored
5 years ago
by
capossele
Browse files
Options
Downloads
Patches
Plain Diff
fix data races on spammer
parent
963f23ec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/transactionspammer/transactionspammer.go
+56
-61
56 additions, 61 deletions
packages/transactionspammer/transactionspammer.go
with
56 additions
and
61 deletions
packages/transactionspammer/transactionspammer.go
+
56
−
61
View file @
19f276af
...
@@ -14,79 +14,74 @@ import (
...
@@ -14,79 +14,74 @@ import (
)
)
var
spamming
=
false
var
spamming
=
false
var
spammingMutex
sync
.
Mutex
var
startMutex
sync
.
Mutex
var
shutdownSignal
chan
struct
{}
var
done
chan
struct
{}
var
shutdownSignal
chan
int
var
sentCounter
=
uint
(
0
)
var
sentCounter
=
uint
(
0
)
func
Start
(
tps
uint
)
{
func
init
()
{
startMutex
.
Lock
()
shutdownSignal
=
make
(
chan
struct
{})
done
=
make
(
chan
struct
{})
if
!
spamming
{
}
shutdownSignal
=
make
(
chan
int
,
1
)
func
(
shutdownSignal
chan
int
)
{
daemon
.
BackgroundWorker
(
"Transaction Spammer"
,
func
()
{
for
{
start
:=
time
.
Now
()
totalSentCounter
:=
int64
(
0
)
for
{
select
{
case
<-
daemon
.
ShutdownSignal
:
return
case
<-
shutdownSignal
:
return
default
:
sentCounter
++
totalSentCounter
++
tx
:=
value_transaction
.
New
()
tx
.
SetHead
(
true
)
tx
.
SetTail
(
true
)
tx
.
SetValue
(
totalSentCounter
)
tx
.
SetBranchTransactionHash
(
tipselection
.
GetRandomTip
())
tx
.
SetTrunkTransactionHash
(
tipselection
.
GetRandomTip
())
mtx
:=
&
pb
.
Transaction
{
Body
:
tx
.
MetaTransaction
.
GetBytes
()}
b
,
_
:=
proto
.
Marshal
(
mtx
)
gossip
.
Events
.
TransactionReceived
.
Trigger
(
&
gossip
.
TransactionReceivedEvent
{
Body
:
b
,
Peer
:
&
local
.
INSTANCE
.
Peer
})
if
sentCounter
>=
tps
{
duration
:=
time
.
Since
(
start
)
if
duration
<
time
.
Second
{
time
.
Sleep
(
time
.
Second
-
duration
)
}
start
=
time
.
Now
()
sentCounter
=
0
func
Start
(
tps
uint
)
{
}
spammingMutex
.
Lock
()
}
spamming
=
true
spammingMutex
.
Unlock
()
daemon
.
BackgroundWorker
(
"Transaction Spammer"
,
func
()
{
start
:=
time
.
Now
()
totalSentCounter
:=
int64
(
0
)
for
{
select
{
case
<-
daemon
.
ShutdownSignal
:
return
case
<-
shutdownSignal
:
done
<-
struct
{}{}
return
default
:
sentCounter
++
totalSentCounter
++
tx
:=
value_transaction
.
New
()
tx
.
SetHead
(
true
)
tx
.
SetTail
(
true
)
tx
.
SetValue
(
totalSentCounter
)
tx
.
SetBranchTransactionHash
(
tipselection
.
GetRandomTip
())
tx
.
SetTrunkTransactionHash
(
tipselection
.
GetRandomTip
())
mtx
:=
&
pb
.
Transaction
{
Body
:
tx
.
MetaTransaction
.
GetBytes
()}
b
,
_
:=
proto
.
Marshal
(
mtx
)
gossip
.
Events
.
TransactionReceived
.
Trigger
(
&
gossip
.
TransactionReceivedEvent
{
Body
:
b
,
Peer
:
&
local
.
INSTANCE
.
Peer
})
if
sentCounter
>=
tps
{
duration
:=
time
.
Since
(
start
)
if
duration
<
time
.
Second
{
time
.
Sleep
(
time
.
Second
-
duration
)
}
}
}
})
}(
shutdownSignal
)
spamming
=
true
start
=
time
.
Now
()
}
startMutex
.
Unlock
()
sentCounter
=
0
}
}
}
})
}
}
func
Stop
()
{
func
Stop
()
{
startMutex
.
Lock
()
spammingMutex
.
Lock
()
if
spamming
{
if
spamming
{
close
(
shutdownSignal
)
shutdownSignal
<-
struct
{}{}
// wait for spammer to be done
<-
done
spamming
=
false
spamming
=
false
}
}
spammingMutex
.
Unlock
()
startMutex
.
Unlock
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment