Make fetching balances multi-thread

pull/1144/head
Rongjian Lan 6 years ago
parent 348977d746
commit fdbe27c4fc
  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