Concurrent rpc balances queries

pull/1211/head
flicker-harmony 5 years ago
parent c63dc3251b
commit d12c5434f7
  1. 19
      cmd/client/wallet/main.go

@ -797,10 +797,17 @@ func FetchBalance(address common.Address) []*AccountState {
result[uint32(shardID)] = &AccountState{balance, 0}
LOOP:
for j := 0; j < len(walletProfile.RPCServer[shardID]); j++ {
var wgShard sync.WaitGroup
wgShard.Add(len(walletProfile.RPCServer[shardID]))
var mutexAccountState = &sync.Mutex{}
for rpcServerID := 0; rpcServerID < len(walletProfile.RPCServer[shardID]); rpcServerID++ {
go func(rpcServerID int) {
defer wgShard.Done()
log.Debug("Launched goroutiune");
for retry := 0; retry < rpcRetry; retry++ {
server := walletProfile.RPCServer[shardID][j]
server := walletProfile.RPCServer[shardID][rpcServerID]
client, err := clientService.NewClient(server.IP, server.Port)
if err != nil {
continue
@ -816,13 +823,17 @@ func FetchBalance(address common.Address) []*AccountState {
log.Debug("FetchBalance", "response", response)
respBalance := big.NewInt(0)
respBalance.SetBytes(response.Balance)
mutexAccountState.Lock()
if balance.Cmp(respBalance) < 0 {
balance.SetBytes(response.Balance)
nonce = response.Nonce
}
break LOOP
mutexAccountState.Unlock()
}
}(rpcServerID)
}
wgShard.Wait()
result[shardID] = &AccountState{balance, nonce}
}(shardID)
}

Loading…
Cancel
Save