|
|
@ -797,32 +797,43 @@ func FetchBalance(address common.Address) []*AccountState { |
|
|
|
|
|
|
|
|
|
|
|
result[uint32(shardID)] = &AccountState{balance, 0} |
|
|
|
result[uint32(shardID)] = &AccountState{balance, 0} |
|
|
|
|
|
|
|
|
|
|
|
LOOP: |
|
|
|
var wgShard sync.WaitGroup |
|
|
|
for j := 0; j < len(walletProfile.RPCServer[shardID]); j++ { |
|
|
|
wgShard.Add(len(walletProfile.RPCServer[shardID])) |
|
|
|
for retry := 0; retry < rpcRetry; retry++ { |
|
|
|
|
|
|
|
server := walletProfile.RPCServer[shardID][j] |
|
|
|
var mutexAccountState = &sync.Mutex{} |
|
|
|
client, err := clientService.NewClient(server.IP, server.Port) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
for rpcServerID := 0; rpcServerID < len(walletProfile.RPCServer[shardID]); rpcServerID++ { |
|
|
|
continue |
|
|
|
go func(rpcServerID int) { |
|
|
|
|
|
|
|
defer wgShard.Done() |
|
|
|
|
|
|
|
log.Debug("Launched goroutiune"); |
|
|
|
|
|
|
|
for retry := 0; retry < rpcRetry; retry++ { |
|
|
|
|
|
|
|
server := walletProfile.RPCServer[shardID][rpcServerID] |
|
|
|
|
|
|
|
client, err := clientService.NewClient(server.IP, server.Port) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Debug("FetchBalance", "server", server) |
|
|
|
|
|
|
|
response, err := client.GetBalance(address) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Info("failed to get balance, retrying ...") |
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond) |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mutexAccountState.Unlock() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}(rpcServerID) |
|
|
|
log.Debug("FetchBalance", "server", server) |
|
|
|
|
|
|
|
response, err := client.GetBalance(address) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Info("failed to get balance, retrying ...") |
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond) |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Debug("FetchBalance", "response", response) |
|
|
|
|
|
|
|
respBalance := big.NewInt(0) |
|
|
|
|
|
|
|
respBalance.SetBytes(response.Balance) |
|
|
|
|
|
|
|
if balance.Cmp(respBalance) < 0 { |
|
|
|
|
|
|
|
balance.SetBytes(response.Balance) |
|
|
|
|
|
|
|
nonce = response.Nonce |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break LOOP |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
wgShard.Wait() |
|
|
|
|
|
|
|
|
|
|
|
result[shardID] = &AccountState{balance, nonce} |
|
|
|
result[shardID] = &AccountState{balance, nonce} |
|
|
|
}(shardID) |
|
|
|
}(shardID) |
|
|
|
} |
|
|
|
} |
|
|
|