dexbot 1.7.0 → 1.7.2
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/CHANGELOG.md +70 -0
- package/README.md +3 -3
- package/analysis/README.md +33 -13
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/account_resolver.js +5 -6
- package/dist/analysis/analyze_liquidity.js +15 -4
- package/dist/analysis/bot_key_utils.d.ts +44 -1
- package/dist/analysis/bot_key_utils.js +76 -7
- package/dist/analysis/fills_cache.js +2 -1
- package/dist/analysis/grid_correction_check.d.ts +1 -19
- package/dist/analysis/grid_correction_check.js +12 -30
- package/dist/analysis/liquidity/liquidity_chart_generator.js +190 -20
- package/dist/analysis/liquidity/liquidity_depth_model.d.ts +41 -16
- package/dist/analysis/liquidity/liquidity_depth_model.js +49 -21
- package/dist/analysis/liquidity/liquidity_view.d.ts +15 -0
- package/dist/analysis/liquidity/liquidity_view.js +11 -0
- package/dist/analysis/resolve_bot_accounts.js +7 -6
- package/dist/analysis/trade_profitability.js +2 -1
- package/dist/credential-daemon.js +13 -2
- package/dist/dexbot.js +4 -4
- package/dist/modules/account_bots.d.ts +12 -1
- package/dist/modules/account_bots.js +7 -5
- package/dist/modules/account_orders.d.ts +12 -0
- package/dist/modules/account_orders.js +30 -0
- package/dist/modules/bitshares-native/transport.js +24 -6
- package/dist/modules/bitshares_client.d.ts +24 -6
- package/dist/modules/bitshares_client.js +44 -7
- package/dist/modules/bot_settings.d.ts +2 -0
- package/dist/modules/constants.d.ts +28 -3
- package/dist/modules/constants.js +79 -10
- package/dist/modules/dexbot_class.d.ts +23 -6
- package/dist/modules/dexbot_class.js +44 -0
- package/dist/modules/dexbot_cow_runtime.d.ts +128 -8
- package/dist/modules/dexbot_cow_runtime.js +688 -188
- package/dist/modules/dexbot_fill_runtime.js +124 -35
- package/dist/modules/dexbot_maintenance_runtime.d.ts +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +259 -79
- package/dist/modules/dexbot_startup_runtime.js +32 -20
- package/dist/modules/dexbot_state_recovery.d.ts +33 -1
- package/dist/modules/dexbot_state_recovery.js +167 -5
- package/dist/modules/node_connect_policy.d.ts +8 -1
- package/dist/modules/node_connect_policy.js +18 -2
- package/dist/modules/node_flap_score.d.ts +87 -0
- package/dist/modules/node_flap_score.js +124 -0
- package/dist/modules/node_health_cache.d.ts +40 -3
- package/dist/modules/node_health_cache.js +66 -20
- package/dist/modules/node_manager.d.ts +101 -19
- package/dist/modules/node_manager.js +255 -65
- package/dist/modules/order/accounting.d.ts +9 -4
- package/dist/modules/order/accounting.js +131 -19
- package/dist/modules/order/async_lock.d.ts +7 -1
- package/dist/modules/order/async_lock.js +7 -1
- package/dist/modules/order/export.js +25 -18
- package/dist/modules/order/fill_ledger.d.ts +99 -0
- package/dist/modules/order/fill_ledger.js +103 -0
- package/dist/modules/order/format.d.ts +24 -10
- package/dist/modules/order/format.js +30 -10
- package/dist/modules/order/grid.d.ts +75 -18
- package/dist/modules/order/grid.js +289 -72
- package/dist/modules/order/grid_reconcile.d.ts +5 -1
- package/dist/modules/order/grid_reconcile.js +333 -210
- package/dist/modules/order/grid_reconcile_internal.d.ts +38 -2
- package/dist/modules/order/grid_reconcile_internal.js +223 -91
- package/dist/modules/order/index.d.ts +18 -5
- package/dist/modules/order/index.js +5 -5
- package/dist/modules/order/lifecycle.d.ts +353 -0
- package/dist/modules/order/lifecycle.js +1109 -0
- package/dist/modules/order/manager.d.ts +277 -20
- package/dist/modules/order/manager.js +680 -64
- package/dist/modules/order/placement_lock.d.ts +102 -0
- package/dist/modules/order/placement_lock.js +222 -0
- package/dist/modules/order/strategy.js +13 -1
- package/dist/modules/order/sync_engine.d.ts +74 -114
- package/dist/modules/order/sync_engine.js +254 -198
- package/dist/modules/order/utils/math.d.ts +29 -4
- package/dist/modules/order/utils/math.js +61 -4
- package/dist/modules/order/utils/order.d.ts +106 -37
- package/dist/modules/order/utils/order.js +256 -81
- package/dist/modules/order/utils/system.d.ts +99 -6
- package/dist/modules/order/utils/system.js +249 -35
- package/dist/modules/order/utils/validate.d.ts +7 -1
- package/dist/modules/order/utils/validate.js +48 -2
- package/dist/modules/outcome.d.ts +54 -0
- package/dist/modules/outcome.js +51 -0
- package/dist/modules/settings_merge.d.ts +4 -0
- package/dist/modules/settings_merge.js +9 -0
- package/dist/modules/timing_policy.d.ts +82 -0
- package/dist/modules/timing_policy.js +244 -0
- package/dist/modules/types.d.ts +149 -22
- package/dist/scripts/analyze-credit.js +54 -17
- package/dist/scripts/analyze-orders.d.ts +4 -2
- package/dist/scripts/analyze-orders.js +113 -34
- package/dist/scripts/chart_targets.js +11 -15
- package/dist/scripts/test-credit-renewal.js +12 -5
- package/docs/COW_INVARIANTS.md +71 -8
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +1 -1
- package/docs/GRID_RECONCILE.md +18 -13
- package/docs/LOGGING.md +25 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +183 -26
- package/docs/README.md +23 -2
- package/docs/WORKFLOW.md +9 -3
- package/docs/architecture.md +68 -13
- package/docs/developer_guide.md +25 -8
- package/modules/README.md +6 -0
- package/package.json +3 -3
- package/scripts/README.md +16 -0
- package/scripts/pdev.sh +14 -1
- package/scripts/pmain.sh +23 -8
- package/scripts/ptest.sh +7 -0
- package/tests/README.md +30 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NODE_MANAGEMENT } from './constants.js';
|
|
2
2
|
import { getNodeHealthCacheFile } from './paths.js';
|
|
3
3
|
import { writeJsonFileAtomic } from './bots_file_lock.js';
|
|
4
|
+
import { dropCounters, flapPenaltyMs, pruneDropTimes, } from './node_flap_score.js';
|
|
4
5
|
import { getStorage } from './storage/index.js';
|
|
5
6
|
const storage = getStorage();
|
|
6
7
|
const { readJSON } = storage;
|
|
@@ -19,24 +20,63 @@ function normalizeNodeList(nodes) {
|
|
|
19
20
|
: [];
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
|
-
* Comparator for healthy/slow nodes: healthy first, then by
|
|
23
|
+
* Comparator for healthy/slow nodes: healthy first, then by *effective*
|
|
24
|
+
* latency (measured ping + decayed connection-churn penalty).
|
|
23
25
|
* Shared by node_health_cache and node_manager.
|
|
24
26
|
*/
|
|
25
|
-
function compareNodeHealth(a, b) {
|
|
27
|
+
function compareNodeHealth(a, b, nowMs = Date.now(), flap) {
|
|
26
28
|
if (a.status !== b.status)
|
|
27
29
|
return a.status === 'healthy' ? -1 : 1;
|
|
28
|
-
|
|
30
|
+
// Compare without subtracting: two unknown latencies are both Infinity,
|
|
31
|
+
// and Infinity - Infinity is NaN (an unstable sort comparator).
|
|
32
|
+
const aRank = nodeRankLatency(a, nowMs, flap);
|
|
33
|
+
const bRank = nodeRankLatency(b, nowMs, flap);
|
|
34
|
+
if (aRank === bRank)
|
|
35
|
+
return 0;
|
|
36
|
+
return aRank < bRank ? -1 : 1;
|
|
29
37
|
}
|
|
30
|
-
|
|
38
|
+
/** Ranking latency: measured ping plus the churn penalty, Infinity when unknown. */
|
|
39
|
+
function nodeRankLatency(node, nowMs, flap) {
|
|
40
|
+
if (typeof node.latencyMs !== 'number' || !Number.isFinite(node.latencyMs))
|
|
41
|
+
return Infinity;
|
|
42
|
+
// Prefer the penalty the writer persisted: recomputing from dropTimes here
|
|
43
|
+
// would silently apply *this* reader's tuning (or the stock defaults) over
|
|
44
|
+
// the one the cache was ordered with.
|
|
45
|
+
if (typeof node.flapPenaltyMs === 'number' && Number.isFinite(node.flapPenaltyMs)) {
|
|
46
|
+
return node.latencyMs + node.flapPenaltyMs;
|
|
47
|
+
}
|
|
48
|
+
const penalty = Array.isArray(node.dropTimes)
|
|
49
|
+
? flapPenaltyMs(node.dropTimes, { nowMs, ...flap })
|
|
50
|
+
: 0;
|
|
51
|
+
return node.latencyMs + penalty;
|
|
52
|
+
}
|
|
53
|
+
function buildHealthCachePayload(stats, now = Date.now(), flap = undefined) {
|
|
54
|
+
const flapOptions = {
|
|
55
|
+
nowMs: now,
|
|
56
|
+
windowMs: flap?.windowMs ?? NODE_MANAGEMENT.FLAP_WINDOW_MS,
|
|
57
|
+
halfLifeMs: flap?.halfLifeMs ?? NODE_MANAGEMENT.FLAP_HALF_LIFE_MS,
|
|
58
|
+
penaltyMsPerDrop: flap?.penaltyMsPerDrop ?? NODE_MANAGEMENT.FLAP_PENALTY_MS_PER_DROP,
|
|
59
|
+
maxPenaltyMs: flap?.maxPenaltyMs ?? NODE_MANAGEMENT.FLAP_PENALTY_MAX_MS,
|
|
60
|
+
};
|
|
31
61
|
const nodes = Array.from(stats || [])
|
|
32
62
|
.filter((stat) => !!stat && (stat.status === 'healthy' || stat.status === 'slow') && typeof stat.url === 'string' && stat.url.trim() !== '')
|
|
33
|
-
.map((stat) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
.map((stat) => {
|
|
64
|
+
const dropTimes = pruneDropTimes(stat.dropTimes, now, flapOptions.windowMs);
|
|
65
|
+
const counters = dropCounters(dropTimes, flapOptions);
|
|
66
|
+
return {
|
|
67
|
+
url: stat.url,
|
|
68
|
+
status: stat.status,
|
|
69
|
+
latencyMs: Number.isFinite(stat.latencyMs) ? (stat.latencyMs ?? null) : null,
|
|
70
|
+
lastCheckTime: stat.lastCheckTime || null,
|
|
71
|
+
dropTimes,
|
|
72
|
+
flapScore: counters.flapScore,
|
|
73
|
+
flapPenaltyMs: counters.penaltyMs,
|
|
74
|
+
dropsLastHour: counters.dropsLastHour,
|
|
75
|
+
drops24h: counters.drops24h,
|
|
76
|
+
dropsPerHour: counters.dropsPerHour,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
nodes.sort((a, b) => compareNodeHealth(a, b, now, flap));
|
|
40
80
|
return {
|
|
41
81
|
version: 1,
|
|
42
82
|
updatedAt: new Date(now).toISOString(),
|
|
@@ -47,7 +87,7 @@ function buildHealthCachePayload(stats, now = Date.now()) {
|
|
|
47
87
|
function writeHealthCache(stats, options = {}) {
|
|
48
88
|
const file = resolveHealthCacheFile(options);
|
|
49
89
|
const now = Number.isFinite(options.now) ? options.now : Date.now();
|
|
50
|
-
const payload = buildHealthCachePayload(stats, now);
|
|
90
|
+
const payload = buildHealthCachePayload(stats, now, options.flap);
|
|
51
91
|
// Atomic write: see writeJsonFileAtomic in bots_file_lock.ts. A torn
|
|
52
92
|
// health cache would either lose all health history or fail to parse.
|
|
53
93
|
writeJsonFileAtomic(file, payload);
|
|
@@ -69,7 +109,11 @@ function readHealthCache(options = {}) {
|
|
|
69
109
|
return null;
|
|
70
110
|
const nodes = payload.nodes
|
|
71
111
|
.filter((node) => !!node && (node.status === 'healthy' || node.status === 'slow') && typeof node.url === 'string' && node.url.trim() !== '')
|
|
72
|
-
.
|
|
112
|
+
.map((node) => ({
|
|
113
|
+
...node,
|
|
114
|
+
dropTimes: pruneDropTimes(node.dropTimes, now, options.flap?.windowMs ?? NODE_MANAGEMENT.FLAP_WINDOW_MS),
|
|
115
|
+
}))
|
|
116
|
+
.sort((a, b) => compareNodeHealth(a, b, now, options.flap));
|
|
73
117
|
return {
|
|
74
118
|
...payload,
|
|
75
119
|
nodes,
|
|
@@ -95,12 +139,14 @@ function removeNodesFromHealthCache(urls, options = {}) {
|
|
|
95
139
|
return null;
|
|
96
140
|
const remaining = cache.nodes
|
|
97
141
|
.filter((n) => !n || !n.url || !toRemove.has(n.url))
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
142
|
+
// Spread, not a field whitelist: dropping a node must not erase the
|
|
143
|
+
// churn history (dropTimes) of the nodes that stay.
|
|
144
|
+
.map((n) => ({ ...n, latencyMs: n.latencyMs ?? undefined, lastCheckTime: n.lastCheckTime }));
|
|
145
|
+
// The rewrite re-derives the drops/h counters from `dropTimes` using the
|
|
146
|
+
// caller's tuning (stock defaults when the caller has no bot config, e.g.
|
|
147
|
+
// the credential daemon). A bot that tuned NODES.healthCheck.flap* restores
|
|
148
|
+
// its own numbers on its next health sweep; until then the ordering can be
|
|
149
|
+
// computed with defaults, which is the best a tuning-less process can do.
|
|
104
150
|
return writeHealthCache(remaining, { ...options, now: Date.now() });
|
|
105
151
|
}
|
|
106
152
|
function orderNodesFromHealthCache(configuredNodes, options = {}) {
|
|
@@ -145,5 +191,5 @@ function orderNodesForSettings(settings, options = {}) {
|
|
|
145
191
|
: resolveHealthCacheMaxAgeMs(settings),
|
|
146
192
|
});
|
|
147
193
|
}
|
|
148
|
-
export { compareNodeHealth, orderNodesFromHealthCache, orderNodesForSettings, readHealthCache, removeNodesFromHealthCache, resolveConfiguredNodes, resolveHealthCacheFile, writeHealthCache };
|
|
194
|
+
export { compareNodeHealth, nodeRankLatency, orderNodesFromHealthCache, orderNodesForSettings, readHealthCache, removeNodesFromHealthCache, resolveConfiguredNodes, resolveHealthCacheFile, writeHealthCache };
|
|
149
195
|
//# sourceMappingURL=node_health_cache.js.map
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
* - Automatic blacklisting of failed nodes
|
|
16
16
|
*
|
|
17
17
|
* 2. Intelligent Node Selection
|
|
18
|
-
* -
|
|
18
|
+
* - Ranks nodes by measured latency plus a time-decayed connection-churn
|
|
19
|
+
* penalty (see modules/node_flap_score.ts), so a fast node that keeps
|
|
20
|
+
* dropping its socket loses to a stable slightly-slower one
|
|
19
21
|
* - Falls back to slow nodes if no healthy ones available
|
|
20
22
|
* - Respects user-preferred node if healthy
|
|
21
23
|
*
|
|
@@ -50,7 +52,14 @@ interface NodeManagerConfig {
|
|
|
50
52
|
timeoutMs?: number;
|
|
51
53
|
maxPingMs?: number;
|
|
52
54
|
blacklistThreshold?: number;
|
|
53
|
-
|
|
55
|
+
/** Strikes live this long without a new failure before being forgiven. */
|
|
56
|
+
strikeDecayMs?: number;
|
|
57
|
+
/** Time for a connection drop's selection penalty to halve. */
|
|
58
|
+
flapHalfLifeMs?: number;
|
|
59
|
+
/** Effective-latency cost of one fresh (undecayed) drop. */
|
|
60
|
+
flapPenaltyMsPerDrop?: number;
|
|
61
|
+
/** Ceiling for the decayed penalty, so a degraded node stays usable. */
|
|
62
|
+
flapPenaltyMaxMs?: number;
|
|
54
63
|
enabled?: boolean;
|
|
55
64
|
};
|
|
56
65
|
selection?: {
|
|
@@ -70,8 +79,14 @@ interface NodeStat {
|
|
|
70
79
|
lastErrorMessage: string | null;
|
|
71
80
|
chainId: string | null;
|
|
72
81
|
blacklistedAt: number | null;
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
/** When the most recent strike was recorded (drives strike decay). */
|
|
83
|
+
lastFailureAtMs: number | null;
|
|
84
|
+
/**
|
|
85
|
+
* Timestamps of live-transport drops inside the flap window. This is the
|
|
86
|
+
* stability signal node selection ranks on (see modules/node_flap_score.ts)
|
|
87
|
+
* and the value persisted into the shared health cache as drops/h.
|
|
88
|
+
*/
|
|
89
|
+
dropTimes: number[];
|
|
75
90
|
}
|
|
76
91
|
interface ResolvedNodeManagerConfig {
|
|
77
92
|
list: string[];
|
|
@@ -80,7 +95,10 @@ interface ResolvedNodeManagerConfig {
|
|
|
80
95
|
timeoutMs: number;
|
|
81
96
|
maxPingMs: number;
|
|
82
97
|
blacklistThreshold: number;
|
|
83
|
-
|
|
98
|
+
strikeDecayMs: number;
|
|
99
|
+
flapHalfLifeMs: number;
|
|
100
|
+
flapPenaltyMsPerDrop: number;
|
|
101
|
+
flapPenaltyMaxMs: number;
|
|
84
102
|
enabled: boolean;
|
|
85
103
|
};
|
|
86
104
|
selection: {
|
|
@@ -91,6 +109,10 @@ interface ResolvedNodeManagerConfig {
|
|
|
91
109
|
/**
|
|
92
110
|
* NodeManager - Manages health checking and selection of BitShares nodes
|
|
93
111
|
*
|
|
112
|
+
* Selection ranks healthy nodes on `latency + decayed churn penalty`, keeps a
|
|
113
|
+
* time-decaying strike count for blacklisting, and exposes per-node churn
|
|
114
|
+
* counters (drops/h) for logging and the shared health cache.
|
|
115
|
+
*
|
|
94
116
|
* @class
|
|
95
117
|
* @param {Object} config - Configuration object
|
|
96
118
|
* @param {string[]} config.list - List of node URLs to monitor (e.g., wss://dex.iobanker.com/ws)
|
|
@@ -99,8 +121,12 @@ interface ResolvedNodeManagerConfig {
|
|
|
99
121
|
* @param {number} [config.healthCheck.timeoutMs=5000] - Timeout for each health check
|
|
100
122
|
* @param {number} [config.healthCheck.maxPingMs=3000] - Max acceptable latency
|
|
101
123
|
* @param {number} [config.healthCheck.blacklistThreshold=3] - Failures before blacklist
|
|
124
|
+
* @param {number} [config.healthCheck.strikeDecayMs] - Lifetime of a strike without a new failure
|
|
125
|
+
* @param {number} [config.healthCheck.flapHalfLifeMs] - Half-life of a connection-drop penalty
|
|
126
|
+
* @param {number} [config.healthCheck.flapPenaltyMsPerDrop] - Effective-latency cost per fresh drop
|
|
127
|
+
* @param {number} [config.healthCheck.flapPenaltyMaxMs] - Cap on the decayed churn penalty
|
|
102
128
|
* @param {Object} [config.selection] - Node selection settings
|
|
103
|
-
* @param {string} [config.selection.strategy="latency"] - Selection strategy
|
|
129
|
+
* @param {string} [config.selection.strategy="latency"] - Selection strategy (latency + churn penalty)
|
|
104
130
|
* @param {string} [config.selection.preferredNode] - Optional preferred node (if healthy)
|
|
105
131
|
*/
|
|
106
132
|
declare class NodeManager {
|
|
@@ -133,6 +159,17 @@ declare class NodeManager {
|
|
|
133
159
|
* @private
|
|
134
160
|
*/
|
|
135
161
|
private saveBlacklistState;
|
|
162
|
+
/**
|
|
163
|
+
* Seed the in-memory drop history from the shared health cache.
|
|
164
|
+
*
|
|
165
|
+
* Churn has to survive process restarts: a bot that is restarted every few
|
|
166
|
+
* hours would otherwise start every node at zero drops and re-select the
|
|
167
|
+
* flapping endpoint immediately. The cache is written by whichever process
|
|
168
|
+
* last ran a health sweep, so treat it as advisory (any parse/age problem
|
|
169
|
+
* just means "no history yet").
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
private loadChurnHistory;
|
|
136
173
|
/**
|
|
137
174
|
* Persist the latest healthy/slow node ordering for lightweight consumers
|
|
138
175
|
* such as the credential daemon.
|
|
@@ -170,17 +207,30 @@ declare class NodeManager {
|
|
|
170
207
|
error: string | null;
|
|
171
208
|
}>;
|
|
172
209
|
/**
|
|
173
|
-
*
|
|
174
|
-
* whether to clear the failure ledger.
|
|
210
|
+
* Remaining (decayed) strikes for a node at `nowMs`.
|
|
175
211
|
*
|
|
176
|
-
* A
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
212
|
+
* A strike is worth 1.0 when recorded and falls linearly to 0 across
|
|
213
|
+
* `strikeDecayMs`. Linear decay (not exponential) keeps the threshold
|
|
214
|
+
* meaningful: three strikes on the same day still blacklist, while a node
|
|
215
|
+
* that failed once three days ago starts from 0 again. The remainder is
|
|
216
|
+
* rounded *up*, so a fresh single strike is not silently discounted to 0
|
|
217
|
+
* within minutes by the rounding step.
|
|
218
|
+
*/
|
|
219
|
+
_decayedStrikeCount(stats: NodeStat, nowMs?: number): number;
|
|
220
|
+
/**
|
|
221
|
+
* Record a successful health-probe result: set status/latency and let the
|
|
222
|
+
* strike count decay.
|
|
182
223
|
*
|
|
183
|
-
*
|
|
224
|
+
* This deliberately no longer *resets* strikes: the old
|
|
225
|
+
* liveFailureSuccessStreak rule cleared a live-transport strike after two
|
|
226
|
+
* successful probes, and with a 4h probe interval that forgave a
|
|
227
|
+
* once-a-day flapper twice a day — every failure logged "attempt 1/3" and
|
|
228
|
+
* the node was never blacklisted. Strikes now age out on their own
|
|
229
|
+
* (`strikeDecayMs`), so probe success can re-admit a node's *status*
|
|
230
|
+
* without erasing the evidence that it drops connections.
|
|
231
|
+
*
|
|
232
|
+
* @returns {{ recovered: boolean, failureCount: number }} whether every
|
|
233
|
+
* strike has aged out, and the remaining count.
|
|
184
234
|
*/
|
|
185
235
|
_recordHealthCheckSuccess(nodeUrl: string, status: string, latencyMs: number | null, chainId: string | null): {
|
|
186
236
|
recovered: boolean;
|
|
@@ -215,12 +265,37 @@ declare class NodeManager {
|
|
|
215
265
|
*/
|
|
216
266
|
rpcCall(ws: WebSocketLike, method: string, params: unknown[], timeoutMs: number): Promise<unknown>;
|
|
217
267
|
/**
|
|
218
|
-
*
|
|
268
|
+
* Flap-scoring options built from this manager's configuration.
|
|
269
|
+
* Single place that maps config -> the pure ranking maths, so the ranking,
|
|
270
|
+
* the logged counters and the persisted health cache always agree.
|
|
271
|
+
* @private
|
|
272
|
+
*/
|
|
273
|
+
private _flapOptions;
|
|
274
|
+
/**
|
|
275
|
+
* Get list of healthy nodes, best first.
|
|
276
|
+
*
|
|
277
|
+
* Ranking is `measured latency + decayed connection-churn penalty`, so a
|
|
278
|
+
* 50ms node that drops its socket daily loses to a stable 350ms node. See
|
|
279
|
+
* modules/node_flap_score.ts for the penalty maths.
|
|
219
280
|
* @returns {string[]} Array of node URLs
|
|
220
281
|
*/
|
|
221
282
|
getHealthyNodes(): string[];
|
|
222
283
|
/**
|
|
223
|
-
*
|
|
284
|
+
* Connection-churn counters for one node (drops/h, decayed score, penalty).
|
|
285
|
+
* Used for logging and for the shared health cache.
|
|
286
|
+
* @param {string} nodeUrl - Node URL
|
|
287
|
+
* @returns {Object|null} Churn counters or null for an unknown node
|
|
288
|
+
*/
|
|
289
|
+
getNodeChurn(nodeUrl: string, nowMs?: number): {
|
|
290
|
+
dropTimes: number[];
|
|
291
|
+
flapScore: number;
|
|
292
|
+
penaltyMs: number;
|
|
293
|
+
dropsLastHour: number;
|
|
294
|
+
drops24h: number;
|
|
295
|
+
dropsPerHour: number;
|
|
296
|
+
} | null;
|
|
297
|
+
/**
|
|
298
|
+
* Get the single best-ranked healthy node (latency + churn penalty)
|
|
224
299
|
* @returns {string|null} Best node URL or null if none available
|
|
225
300
|
*/
|
|
226
301
|
getBestNode(): string | null;
|
|
@@ -246,9 +321,12 @@ declare class NodeManager {
|
|
|
246
321
|
* failure ledger — the same rules the credential daemon applies.
|
|
247
322
|
* @param {string} nodeUrl - Node URL that failed
|
|
248
323
|
* @param {string} [errorMessage] - Optional error description
|
|
249
|
-
* @param {string} [source] - Failure source ('health-check'
|
|
324
|
+
* @param {string} [source] - Failure source ('health-check', 'broadcast',
|
|
325
|
+
* 'connection', 'keep-alive'); controls log level and churn accounting
|
|
326
|
+
* @param {number} [nowMs] - Timestamp for the strike/drop (defaults to now;
|
|
327
|
+
* injectable so tests do not need to sleep past the report cooldown)
|
|
250
328
|
*/
|
|
251
|
-
reportNodeFailure(nodeUrl: string, errorMessage?: string, source?: string): void;
|
|
329
|
+
reportNodeFailure(nodeUrl: string, errorMessage?: string, source?: string, nowMs?: number): void;
|
|
252
330
|
/**
|
|
253
331
|
* Manually blacklist a node (e.g., when it causes a connection failure)
|
|
254
332
|
* @param {string} nodeUrl - Node URL to blacklist
|
|
@@ -274,6 +352,9 @@ declare class NodeManager {
|
|
|
274
352
|
failureCount: number;
|
|
275
353
|
lastCheckTime: string | null;
|
|
276
354
|
lastErrorMessage: string | null;
|
|
355
|
+
drops24h: number;
|
|
356
|
+
dropsPerHour: number;
|
|
357
|
+
flapPenaltyMs: number;
|
|
277
358
|
}>;
|
|
278
359
|
/**
|
|
279
360
|
* Get summary statistics
|
|
@@ -284,6 +365,7 @@ declare class NodeManager {
|
|
|
284
365
|
counts: Record<string, number>;
|
|
285
366
|
bestNode: string | null;
|
|
286
367
|
avgLatency: number | null;
|
|
368
|
+
totalDrops24h: number;
|
|
287
369
|
};
|
|
288
370
|
}
|
|
289
371
|
export default NodeManager;
|