Merge pull request #1144 from rlan35/wallet_multi_thread_balance

Wallet multi thread balance
pull/1146/head
Rongjian Lan 6 years ago committed by GitHub
commit 57750d1ffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      cmd/client/wallet/main.go

@ -10,6 +10,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"path" "path"
"sync"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -785,7 +786,12 @@ func FetchBalance(address common.Address) []*AccountState {
result = append(result, nil) result = append(result, nil)
} }
var wg sync.WaitGroup
wg.Add(walletProfile.Shards)
for shardID := 0; shardID < walletProfile.Shards; shardID++ { for shardID := 0; shardID < walletProfile.Shards; shardID++ {
go func(shardID int) {
defer wg.Done()
balance := big.NewInt(0) balance := big.NewInt(0)
var nonce uint64 var nonce uint64
@ -818,7 +824,9 @@ func FetchBalance(address common.Address) []*AccountState {
} }
} }
result[shardID] = &AccountState{balance, nonce} result[shardID] = &AccountState{balance, nonce}
}(shardID)
} }
wg.Wait()
return result return result
} }

Loading…
Cancel
Save