Skip to content

Commit a0ecd38

Browse files
committed
fix race condition
1 parent d46e138 commit a0ecd38

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cmd/loadtest/account.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// Structure used by the account pool to control the
2626
// current state of an account
2727
type Account struct {
28-
ready bool
28+
ready atomic.Bool
2929
address common.Address
3030
privateKey *ecdsa.PrivateKey
3131
startNonce uint64
@@ -42,7 +42,7 @@ func newAccount(ctx context.Context, client *ethclient.Client, clientRateLimiter
4242
address := crypto.PubkeyToAddress(*publicKeyECDSA)
4343

4444
acc := &Account{
45-
ready: false,
45+
ready: atomic.Bool{},
4646
privateKey: privateKey,
4747
address: address,
4848
funded: false,
@@ -52,7 +52,7 @@ func newAccount(ctx context.Context, client *ethclient.Client, clientRateLimiter
5252
if startNonce != nil {
5353
acc.nonce = *startNonce
5454
acc.startNonce = *startNonce
55-
acc.ready = true
55+
acc.ready.Store(true)
5656
} else {
5757
go func(a *Account) {
5858
out:
@@ -72,7 +72,7 @@ func newAccount(ctx context.Context, client *ethclient.Client, clientRateLimiter
7272
continue
7373
}
7474
acc.startNonce = acc.nonce
75-
acc.ready = true
75+
acc.ready.Store(true)
7676
break out
7777
}
7878
}(acc)
@@ -215,7 +215,7 @@ func (ap *AccountPool) AllAccountsReady() (bool, int, int) {
215215
defer ap.mu.Unlock()
216216
rdyCount := 0
217217
for i := range ap.accounts {
218-
if ap.accounts[i].ready {
218+
if ap.accounts[i].ready.Load() {
219219
rdyCount++
220220
}
221221
}

0 commit comments

Comments
 (0)