fix cycling through price providers

This commit is contained in:
woodser 2023-12-10 07:46:18 -05:00
parent 6cb120e4b9
commit c7277187c5

View file

@ -47,7 +47,7 @@ public class ProvidersRepository {
@Getter @Getter
@Nullable @Nullable
private List<String> bannedNodes; private List<String> bannedNodes;
private int index = 0; private int index = -1;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -80,16 +80,21 @@ public class ProvidersRepository {
} }
// returns true if provider selection loops to beginning // returns true if provider selection loops to beginning
public boolean selectNextProviderBaseUrl() { public synchronized boolean selectNextProviderBaseUrl() {
boolean looped = false; boolean looped = false;
if (!providerList.isEmpty()) { if (!providerList.isEmpty()) {
// increment index
index++;
// loop to beginning
if (index >= providerList.size()) { if (index >= providerList.size()) {
index = 0; index = 0;
looped = true; looped = true;
} }
// update base url
baseUrl = providerList.get(index); baseUrl = providerList.get(index);
index++;
if (providerList.size() == 1 && config.baseCurrencyNetwork.isMainnet()) if (providerList.size() == 1 && config.baseCurrencyNetwork.isMainnet())
log.warn("We only have one provider"); log.warn("We only have one provider");