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.cjs +36 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -952,15 +952,16 @@ var HealthChecker = class {
|
|
|
952
952
|
const existing = this.results.get(key);
|
|
953
953
|
const result = existing ? {
|
|
954
954
|
...existing,
|
|
955
|
-
success:
|
|
956
|
-
//
|
|
955
|
+
success: true,
|
|
956
|
+
// Degraded providers are still usable, just slower/rate-limited
|
|
957
957
|
status: "degraded",
|
|
958
958
|
error: error || "Marked as degraded",
|
|
959
959
|
lastTested: /* @__PURE__ */ new Date()
|
|
960
960
|
} : {
|
|
961
961
|
id: providerId,
|
|
962
962
|
network,
|
|
963
|
-
success:
|
|
963
|
+
success: true,
|
|
964
|
+
// Degraded providers are still usable
|
|
964
965
|
status: "degraded",
|
|
965
966
|
latencyMs: null,
|
|
966
967
|
seqno: null,
|
|
@@ -1639,13 +1640,25 @@ var ProviderSelector = class {
|
|
|
1639
1640
|
);
|
|
1640
1641
|
this.activeProviderByNetwork.set(network, defaultProvider.id);
|
|
1641
1642
|
return defaultProvider;
|
|
1642
|
-
}
|
|
1643
|
+
}
|
|
1644
|
+
if (health.success === true) {
|
|
1643
1645
|
this.logger.warn(
|
|
1644
1646
|
`No healthy providers for ${network}, using default: ${defaultProvider.id}`
|
|
1645
1647
|
);
|
|
1646
1648
|
this.activeProviderByNetwork.set(network, defaultProvider.id);
|
|
1647
1649
|
return defaultProvider;
|
|
1648
1650
|
}
|
|
1651
|
+
if (health.success === false && health.lastTested) {
|
|
1652
|
+
const timeSinceFailure = Date.now() - health.lastTested.getTime();
|
|
1653
|
+
const cooldownMs = 3e4;
|
|
1654
|
+
if (timeSinceFailure > cooldownMs) {
|
|
1655
|
+
this.logger.warn(
|
|
1656
|
+
`No healthy providers for ${network}, retrying failed default after cooldown: ${defaultProvider.id}`
|
|
1657
|
+
);
|
|
1658
|
+
this.activeProviderByNetwork.set(network, defaultProvider.id);
|
|
1659
|
+
return defaultProvider;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1649
1662
|
}
|
|
1650
1663
|
for (const provider of providers) {
|
|
1651
1664
|
const health = this.healthChecker.getResult(provider.id, network);
|
|
@@ -1656,8 +1669,19 @@ var ProviderSelector = class {
|
|
|
1656
1669
|
this.activeProviderByNetwork.set(network, provider.id);
|
|
1657
1670
|
return provider;
|
|
1658
1671
|
}
|
|
1672
|
+
if (health.success === false && health.lastTested) {
|
|
1673
|
+
const timeSinceFailure = Date.now() - health.lastTested.getTime();
|
|
1674
|
+
const cooldownMs = 3e4;
|
|
1675
|
+
if (timeSinceFailure > cooldownMs) {
|
|
1676
|
+
this.logger.warn(
|
|
1677
|
+
`No healthy providers for ${network}, retrying failed provider after cooldown: ${provider.id}`
|
|
1678
|
+
);
|
|
1679
|
+
this.activeProviderByNetwork.set(network, provider.id);
|
|
1680
|
+
return provider;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1659
1683
|
}
|
|
1660
|
-
this.logger.error(`No available providers for ${network} (all tested and failed)`);
|
|
1684
|
+
this.logger.error(`No available providers for ${network} (all tested and failed, cooldown active)`);
|
|
1661
1685
|
return null;
|
|
1662
1686
|
}
|
|
1663
1687
|
const best = scored[0].provider;
|
|
@@ -1712,6 +1736,13 @@ var ProviderSelector = class {
|
|
|
1712
1736
|
return 0.01 * (1 / (provider.priority + 1));
|
|
1713
1737
|
}
|
|
1714
1738
|
if (health.success === false) {
|
|
1739
|
+
if (health.lastTested) {
|
|
1740
|
+
const timeSinceFailure = Date.now() - health.lastTested.getTime();
|
|
1741
|
+
const cooldownMs = 3e4;
|
|
1742
|
+
if (timeSinceFailure > cooldownMs) {
|
|
1743
|
+
return 1e-3 * (1 / (provider.priority + 1));
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1715
1746
|
return 0;
|
|
1716
1747
|
}
|
|
1717
1748
|
if (health.status === "offline") {
|