ton-provider-system 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -949,15 +949,16 @@ var HealthChecker = class {
949
949
  const existing = this.results.get(key);
950
950
  const result = existing ? {
951
951
  ...existing,
952
- success: false,
953
- // CRITICAL: Always set success: false for degraded providers
952
+ success: true,
953
+ // Degraded providers are still usable, just slower/rate-limited
954
954
  status: "degraded",
955
955
  error: error || "Marked as degraded",
956
956
  lastTested: /* @__PURE__ */ new Date()
957
957
  } : {
958
958
  id: providerId,
959
959
  network,
960
- success: false,
960
+ success: true,
961
+ // Degraded providers are still usable
961
962
  status: "degraded",
962
963
  latencyMs: null,
963
964
  seqno: null,
@@ -1636,13 +1637,25 @@ var ProviderSelector = class {
1636
1637
  );
1637
1638
  this.activeProviderByNetwork.set(network, defaultProvider.id);
1638
1639
  return defaultProvider;
1639
- } else if (health.success === true) {
1640
+ }
1641
+ if (health.success === true) {
1640
1642
  this.logger.warn(
1641
1643
  `No healthy providers for ${network}, using default: ${defaultProvider.id}`
1642
1644
  );
1643
1645
  this.activeProviderByNetwork.set(network, defaultProvider.id);
1644
1646
  return defaultProvider;
1645
1647
  }
1648
+ if (health.success === false && health.lastTested) {
1649
+ const timeSinceFailure = Date.now() - health.lastTested.getTime();
1650
+ const cooldownMs = 3e4;
1651
+ if (timeSinceFailure > cooldownMs) {
1652
+ this.logger.warn(
1653
+ `No healthy providers for ${network}, retrying failed default after cooldown: ${defaultProvider.id}`
1654
+ );
1655
+ this.activeProviderByNetwork.set(network, defaultProvider.id);
1656
+ return defaultProvider;
1657
+ }
1658
+ }
1646
1659
  }
1647
1660
  for (const provider of providers) {
1648
1661
  const health = this.healthChecker.getResult(provider.id, network);
@@ -1653,8 +1666,19 @@ var ProviderSelector = class {
1653
1666
  this.activeProviderByNetwork.set(network, provider.id);
1654
1667
  return provider;
1655
1668
  }
1669
+ if (health.success === false && health.lastTested) {
1670
+ const timeSinceFailure = Date.now() - health.lastTested.getTime();
1671
+ const cooldownMs = 3e4;
1672
+ if (timeSinceFailure > cooldownMs) {
1673
+ this.logger.warn(
1674
+ `No healthy providers for ${network}, retrying failed provider after cooldown: ${provider.id}`
1675
+ );
1676
+ this.activeProviderByNetwork.set(network, provider.id);
1677
+ return provider;
1678
+ }
1679
+ }
1656
1680
  }
1657
- this.logger.error(`No available providers for ${network} (all tested and failed)`);
1681
+ this.logger.error(`No available providers for ${network} (all tested and failed, cooldown active)`);
1658
1682
  return null;
1659
1683
  }
1660
1684
  const best = scored[0].provider;
@@ -1709,6 +1733,13 @@ var ProviderSelector = class {
1709
1733
  return 0.01 * (1 / (provider.priority + 1));
1710
1734
  }
1711
1735
  if (health.success === false) {
1736
+ if (health.lastTested) {
1737
+ const timeSinceFailure = Date.now() - health.lastTested.getTime();
1738
+ const cooldownMs = 3e4;
1739
+ if (timeSinceFailure > cooldownMs) {
1740
+ return 1e-3 * (1 / (provider.priority + 1));
1741
+ }
1742
+ }
1712
1743
  return 0;
1713
1744
  }
1714
1745
  if (health.status === "offline") {