dexbot 1.6.6 → 1.6.8
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 +89 -1
- package/README.md +8 -5
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- 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/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +44 -15
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +20 -9
- package/dist/modules/account_orders.d.ts +44 -4
- package/dist/modules/account_orders.js +104 -7
- package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
- package/dist/modules/bitshares-native/chain_client.js +197 -28
- package/dist/modules/bitshares-native/subscriptions.js +312 -10
- package/dist/modules/bitshares-native/transport.d.ts +1 -0
- package/dist/modules/bitshares-native/transport.js +97 -3
- package/dist/modules/bitshares_client.d.ts +20 -0
- package/dist/modules/bitshares_client.js +29 -0
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/chain_keys.d.ts +37 -22
- package/dist/modules/chain_keys.js +145 -44
- package/dist/modules/cli_start_onboarding.d.ts +10 -0
- package/dist/modules/cli_start_onboarding.js +15 -0
- package/dist/modules/cli_start_output.d.ts +6 -0
- package/dist/modules/cli_start_output.js +8 -0
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +23 -2
- package/dist/modules/constants.js +196 -15
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +53 -96
- package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
- package/dist/modules/dexbot_fill_runtime.js +22 -3
- package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
- package/dist/modules/dexbot_maintenance_runtime.js +103 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +34 -1
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +109 -135
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +13 -2
- package/dist/modules/order/logger.d.ts +12 -2
- package/dist/modules/order/logger.js +29 -7
- package/dist/modules/order/manager.d.ts +53 -0
- package/dist/modules/order/manager.js +86 -25
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +302 -194
- package/dist/modules/order/utils/system.d.ts +97 -0
- package/dist/modules/order/utils/system.js +282 -3
- package/dist/modules/paths.d.ts +8 -1
- package/dist/modules/paths.js +11 -3
- package/dist/modules/utils/text_width.d.ts +19 -0
- package/dist/modules/utils/text_width.js +97 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +104 -18
- package/dist/scripts/update.js +62 -13
- package/dist/unlock.d.ts +14 -2
- package/dist/unlock.js +101 -4
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +11 -2
- package/docs/CREDENTIAL_SECURITY.md +26 -0
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -18
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +204 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/LOGGING.md +17 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +14 -6
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* 1. AccountOrders(options) - Class for per-bot order persistence
|
|
17
17
|
* Constructor options: { botKey, ordersDir?, profilesPath? } (botKey required, throws if missing)
|
|
18
18
|
* Methods:
|
|
19
|
-
* syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls)
|
|
19
|
+
* syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls, lastFillPivot)
|
|
20
20
|
* loadGrid(forceReload), loadRecentFillKeys(forceReload), loadPersistedAssets(forceReload), loadPendingFillCrawls(forceReload)
|
|
21
|
-
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload)
|
|
22
|
-
* clearGrid()
|
|
21
|
+
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload), loadLastFillPivot(forceReload)
|
|
22
|
+
* clearGrid(), clearPersistedBoundary(), clearPersistedLastFillPivot()
|
|
23
23
|
* loadProcessedFills(options), updateProcessedFillsBatch(fills), cleanOldProcessedFills(olderThanMs)
|
|
24
24
|
* getAssetBalances(forceReload)
|
|
25
25
|
*
|
|
@@ -165,7 +165,7 @@ declare class AccountOrders {
|
|
|
165
165
|
* @param {Object|null} recentFillKeys - Optional fill key dedup snapshot for crash recovery
|
|
166
166
|
* @param {Object|null} genesis - Optional frozen genesis (priceLevels etc)
|
|
167
167
|
*/
|
|
168
|
-
storeMasterGrid(orders?: any[], btsFeesOwed?: any, boundaryIdx?: any, assets?: any, debugInputs?: any, recentFillKeys?: any, genesis?: any, gapEvacStreaks?: any, pendingFillCrawls?: any): Promise<void>;
|
|
168
|
+
storeMasterGrid(orders?: any[], btsFeesOwed?: any, boundaryIdx?: any, assets?: any, debugInputs?: any, recentFillKeys?: any, genesis?: any, gapEvacStreaks?: any, pendingFillCrawls?: any, lastFillPivot?: any): Promise<void>;
|
|
169
169
|
/**
|
|
170
170
|
* Erase a poisoned persisted boundary after GRID-LOAD rejects it with no
|
|
171
171
|
* safe re-derivation. storeMasterGrid deliberately never writes a null
|
|
@@ -177,19 +177,59 @@ declare class AccountOrders {
|
|
|
177
177
|
* fills mutate state) but do NOT invoke later in the lifecycle.
|
|
178
178
|
*/
|
|
179
179
|
clearPersistedBoundary(): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Erase a persisted LAST-FILL-GUARD pivot that restoreLastFillPivot
|
|
182
|
+
* rejected (genesis mismatch / TTL expiry / off-ladder). storeMasterGrid
|
|
183
|
+
* deliberately keeps an untouched row for legacy `undefined` callers, so
|
|
184
|
+
* without this explicit erase a rejected value would re-arm the rejection
|
|
185
|
+
* on every restart. Load-time only: this reloads from disk inside the
|
|
186
|
+
* lock, discarding any unsaved in-memory mutations — safe at the
|
|
187
|
+
* loadGrid/restore call site (startup load and recovery reload, both
|
|
188
|
+
* before fills mutate state) but do NOT invoke from an arbitrary runtime
|
|
189
|
+
* path.
|
|
190
|
+
*/
|
|
191
|
+
clearPersistedLastFillPivot(): Promise<void>;
|
|
180
192
|
/**
|
|
181
193
|
* Load the persisted order grid for this bot.
|
|
182
194
|
* @param {boolean} forceReload - If true, reload from disk to ensure fresh data
|
|
183
195
|
* @returns {Array|null} Order grid array or null if not found
|
|
184
196
|
*/
|
|
185
197
|
loadGrid(forceReload?: boolean): any;
|
|
198
|
+
/**
|
|
199
|
+
* Load the persisted price-ladder (genesis) for this bot.
|
|
200
|
+
*
|
|
201
|
+
* SCHEMA GATE (docs/GRID_PRICE_INVARIANT.md, "Schema"): a usable ladder needs a
|
|
202
|
+
* NON-EMPTY `priceLevels` array. A row without one is not a ladder --
|
|
203
|
+
* accepting it would hand `loadGrid` a genesis it cannot validate against
|
|
204
|
+
* (and, for an empty array, silently disable every genesis-derived consumer).
|
|
205
|
+
* Refusing it here means the caller takes the missing-genesis path once, at
|
|
206
|
+
* the source, instead of at every consumer.
|
|
207
|
+
*
|
|
208
|
+
* The hash is deliberately NOT required here: a present-but-tampered hash is
|
|
209
|
+
* still returned, because the hash-mismatch warning belongs to `loadGrid`,
|
|
210
|
+
* which can say what it compared against (`hasGenesisLadder` in
|
|
211
|
+
* modules/order/genesis_policy.ts draws the same distinction).
|
|
212
|
+
* @param {boolean} forceReload - If true, reload from disk
|
|
213
|
+
* @returns {Object|null} The genesis object, or null when absent/invalid
|
|
214
|
+
*/
|
|
186
215
|
loadGenesis(forceReload?: boolean): any;
|
|
216
|
+
/**
|
|
217
|
+
* Record why a persisted genesis row was refused (observability for the
|
|
218
|
+
* schema gate above; loadGrid cannot report a row it never receives).
|
|
219
|
+
*/
|
|
220
|
+
private _noteRejectedGenesis;
|
|
187
221
|
/**
|
|
188
222
|
* Load the persisted gap-evacuation streaks (per-slot in-band cycle counts).
|
|
189
223
|
* @param {boolean} forceReload - If true, reload from disk
|
|
190
224
|
* @returns {Object|null} {slotId: count} map or null when absent
|
|
191
225
|
*/
|
|
192
226
|
loadGapEvacStreaks(forceReload?: boolean): any;
|
|
227
|
+
loadLastFillPivot(forceReload?: boolean): {
|
|
228
|
+
price: number;
|
|
229
|
+
type: string;
|
|
230
|
+
fillsAt: number;
|
|
231
|
+
genesisHash: string;
|
|
232
|
+
} | null;
|
|
193
233
|
/**
|
|
194
234
|
* Load persisted pending fill crawls for this bot.
|
|
195
235
|
* @param {boolean} forceReload - If true, reload from disk
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* 1. AccountOrders(options) - Class for per-bot order persistence
|
|
17
17
|
* Constructor options: { botKey, ordersDir?, profilesPath? } (botKey required, throws if missing)
|
|
18
18
|
* Methods:
|
|
19
|
-
* syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls)
|
|
19
|
+
* syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls, lastFillPivot)
|
|
20
20
|
* loadGrid(forceReload), loadRecentFillKeys(forceReload), loadPersistedAssets(forceReload), loadPendingFillCrawls(forceReload)
|
|
21
|
-
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload)
|
|
22
|
-
* clearGrid()
|
|
21
|
+
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload), loadLastFillPivot(forceReload)
|
|
22
|
+
* clearGrid(), clearPersistedBoundary(), clearPersistedLastFillPivot()
|
|
23
23
|
* loadProcessedFills(options), updateProcessedFillsBatch(fills), cleanOldProcessedFills(olderThanMs)
|
|
24
24
|
* getAssetBalances(forceReload)
|
|
25
25
|
*
|
|
@@ -64,8 +64,9 @@ import { ORDER_TYPES, ORDER_STATES } from './constants.js';
|
|
|
64
64
|
import { PATHS } from './paths.js';
|
|
65
65
|
import AsyncLock from './order/async_lock.js';
|
|
66
66
|
import { isPhantomOrder } from './order/utils/order.js';
|
|
67
|
+
import { hasGenesisLadder } from './order/genesis_policy.js';
|
|
67
68
|
import * as Format from './order/format.js';
|
|
68
|
-
import { ensureDir, nowIso } from './order/utils/system.js';
|
|
69
|
+
import { ensureDir, nowIso, normalizeLastFillPivot } from './order/utils/system.js';
|
|
69
70
|
import Logger from './order/logger.js';
|
|
70
71
|
import { getErrorMessage } from './utils/errors.js';
|
|
71
72
|
import { sanitizeKey } from './utils/sanitize_key.js';
|
|
@@ -317,7 +318,7 @@ class AccountOrders {
|
|
|
317
318
|
* @param {Object|null} recentFillKeys - Optional fill key dedup snapshot for crash recovery
|
|
318
319
|
* @param {Object|null} genesis - Optional frozen genesis (priceLevels etc)
|
|
319
320
|
*/
|
|
320
|
-
async storeMasterGrid(orders = [], btsFeesOwed = null, boundaryIdx = null, assets = null, debugInputs = null, recentFillKeys = null, genesis = null, gapEvacStreaks = undefined, pendingFillCrawls = undefined) {
|
|
321
|
+
async storeMasterGrid(orders = [], btsFeesOwed = null, boundaryIdx = null, assets = null, debugInputs = null, recentFillKeys = null, genesis = null, gapEvacStreaks = undefined, pendingFillCrawls = undefined, lastFillPivot = undefined) {
|
|
321
322
|
// Use AsyncLock to serialize read-modify-write operations
|
|
322
323
|
await this._persistenceLock.acquire(async () => {
|
|
323
324
|
// Reload from disk before writing to prevent race conditions
|
|
@@ -395,6 +396,35 @@ class AccountOrders {
|
|
|
395
396
|
delete this.data.pendingFillCrawls;
|
|
396
397
|
}
|
|
397
398
|
}
|
|
399
|
+
if (lastFillPivot !== undefined) {
|
|
400
|
+
// Only a fill-derived, validated-on-grid pivot survives (provenance
|
|
401
|
+
// gate: a book-derived or unvalidated heuristic is never written as
|
|
402
|
+
// if it were market truth). genesisHash binds it to the snapshot the
|
|
403
|
+
// boundary lives in: a persisted pivot from an old genesis is not
|
|
404
|
+
// valid after a grid regeneration/re-derive, and the restore helper
|
|
405
|
+
// refuses it on mismatch (same lockstep contract as pendingFillCrawls).
|
|
406
|
+
// null clears any previously stored row on every live-grid persist so
|
|
407
|
+
// a consumed pivot never resurrects; undefined (legacy callers) is a
|
|
408
|
+
// no-op; any other malformed shape is treated as an explicit clear
|
|
409
|
+
// (never store, never leave a stale row behind). Row validation is
|
|
410
|
+
// the shared normalizeLastFillPivot gate — the loader enforces the
|
|
411
|
+
// exact same shape, so the two gates cannot drift.
|
|
412
|
+
if (lastFillPivot === undefined) {
|
|
413
|
+
// Legacy no-op (backward-compatible callers), mirror gapEvacStreaks.
|
|
414
|
+
}
|
|
415
|
+
else if (lastFillPivot === null) {
|
|
416
|
+
delete this.data.lastFillPivot;
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
const normalized = normalizeLastFillPivot(lastFillPivot);
|
|
420
|
+
if (normalized) {
|
|
421
|
+
this.data.lastFillPivot = normalized;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
delete this.data.lastFillPivot;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
398
428
|
const timestamp = nowIso();
|
|
399
429
|
this.data.lastUpdated = timestamp;
|
|
400
430
|
if (this.data.meta)
|
|
@@ -419,6 +449,25 @@ class AccountOrders {
|
|
|
419
449
|
this._persist();
|
|
420
450
|
});
|
|
421
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Erase a persisted LAST-FILL-GUARD pivot that restoreLastFillPivot
|
|
454
|
+
* rejected (genesis mismatch / TTL expiry / off-ladder). storeMasterGrid
|
|
455
|
+
* deliberately keeps an untouched row for legacy `undefined` callers, so
|
|
456
|
+
* without this explicit erase a rejected value would re-arm the rejection
|
|
457
|
+
* on every restart. Load-time only: this reloads from disk inside the
|
|
458
|
+
* lock, discarding any unsaved in-memory mutations — safe at the
|
|
459
|
+
* loadGrid/restore call site (startup load and recovery reload, both
|
|
460
|
+
* before fills mutate state) but do NOT invoke from an arbitrary runtime
|
|
461
|
+
* path.
|
|
462
|
+
*/
|
|
463
|
+
async clearPersistedLastFillPivot() {
|
|
464
|
+
await this._persistenceLock.acquire(async () => {
|
|
465
|
+
this.data = this._loadData() || emptyData();
|
|
466
|
+
delete this.data.lastFillPivot;
|
|
467
|
+
this.data.lastUpdated = nowIso();
|
|
468
|
+
this._persist();
|
|
469
|
+
});
|
|
470
|
+
}
|
|
422
471
|
/**
|
|
423
472
|
* Load the persisted order grid for this bot.
|
|
424
473
|
* @param {boolean} forceReload - If true, reload from disk to ensure fresh data
|
|
@@ -430,15 +479,51 @@ class AccountOrders {
|
|
|
430
479
|
}
|
|
431
480
|
return (this.data && Array.isArray(this.data.grid)) ? this.data.grid : null;
|
|
432
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* Load the persisted price-ladder (genesis) for this bot.
|
|
484
|
+
*
|
|
485
|
+
* SCHEMA GATE (docs/GRID_PRICE_INVARIANT.md, "Schema"): a usable ladder needs a
|
|
486
|
+
* NON-EMPTY `priceLevels` array. A row without one is not a ladder --
|
|
487
|
+
* accepting it would hand `loadGrid` a genesis it cannot validate against
|
|
488
|
+
* (and, for an empty array, silently disable every genesis-derived consumer).
|
|
489
|
+
* Refusing it here means the caller takes the missing-genesis path once, at
|
|
490
|
+
* the source, instead of at every consumer.
|
|
491
|
+
*
|
|
492
|
+
* The hash is deliberately NOT required here: a present-but-tampered hash is
|
|
493
|
+
* still returned, because the hash-mismatch warning belongs to `loadGrid`,
|
|
494
|
+
* which can say what it compared against (`hasGenesisLadder` in
|
|
495
|
+
* modules/order/genesis_policy.ts draws the same distinction).
|
|
496
|
+
* @param {boolean} forceReload - If true, reload from disk
|
|
497
|
+
* @returns {Object|null} The genesis object, or null when absent/invalid
|
|
498
|
+
*/
|
|
433
499
|
loadGenesis(forceReload = false) {
|
|
434
500
|
if (forceReload) {
|
|
435
501
|
this.data = this._loadData() || emptyData();
|
|
436
502
|
}
|
|
437
|
-
|
|
438
|
-
|
|
503
|
+
const genesis = this.data?.genesis;
|
|
504
|
+
// Same predicate as loadGrid/genesis_policy: one definition of "usable
|
|
505
|
+
// ladder", so the schema gate cannot diverge from the load-time gate.
|
|
506
|
+
if (hasGenesisLadder(genesis)) {
|
|
507
|
+
return genesis;
|
|
508
|
+
}
|
|
509
|
+
if (genesis) {
|
|
510
|
+
this._noteRejectedGenesis(genesis);
|
|
439
511
|
}
|
|
440
512
|
return null;
|
|
441
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Record why a persisted genesis row was refused (observability for the
|
|
516
|
+
* schema gate above; loadGrid cannot report a row it never receives).
|
|
517
|
+
*/
|
|
518
|
+
_noteRejectedGenesis(genesis) {
|
|
519
|
+
try {
|
|
520
|
+
const reason = !Array.isArray(genesis?.priceLevels)
|
|
521
|
+
? 'priceLevels is not an array'
|
|
522
|
+
: (genesis?.priceLevels?.length === 0 ? 'priceLevels is empty' : 'malformed');
|
|
523
|
+
this._rejectedGenesis = { reason, at: Date.now() };
|
|
524
|
+
}
|
|
525
|
+
catch { /* never fail a load for telemetry */ }
|
|
526
|
+
}
|
|
442
527
|
/**
|
|
443
528
|
* Load the persisted gap-evacuation streaks (per-slot in-band cycle counts).
|
|
444
529
|
* @param {boolean} forceReload - If true, reload from disk
|
|
@@ -453,6 +538,14 @@ class AccountOrders {
|
|
|
453
538
|
}
|
|
454
539
|
return null;
|
|
455
540
|
}
|
|
541
|
+
loadLastFillPivot(forceReload = false) {
|
|
542
|
+
if (forceReload) {
|
|
543
|
+
this.data = this._loadData() || emptyData();
|
|
544
|
+
}
|
|
545
|
+
// Shared row gate (normalizeLastFillPivot): identical validation to the
|
|
546
|
+
// storeMasterGrid sanitizer, one shape contract for the whole ledger.
|
|
547
|
+
return normalizeLastFillPivot(this.data && this.data.lastFillPivot);
|
|
548
|
+
}
|
|
456
549
|
/**
|
|
457
550
|
* Load persisted pending fill crawls for this bot.
|
|
458
551
|
* @param {boolean} forceReload - If true, reload from disk
|
|
@@ -566,6 +659,10 @@ class AccountOrders {
|
|
|
566
659
|
// are relative deltas against the deleted boundary/grid, so a rebuilt
|
|
567
660
|
// generation must not inherit them (the rebuild re-anchors absolutely).
|
|
568
661
|
delete this.data.pendingFillCrawls;
|
|
662
|
+
// The persisted LAST-FILL-GUARD pivot belongs to the deleted snapshot's
|
|
663
|
+
// generation (its slot ids and genesis): a rebuilt grid must re-arm on
|
|
664
|
+
// a fresh fill, not inherit a pivot validated against wiped geometry.
|
|
665
|
+
delete this.data.lastFillPivot;
|
|
569
666
|
this.data.lastUpdated = nowIso();
|
|
570
667
|
this._persist();
|
|
571
668
|
return true;
|
|
@@ -13,6 +13,15 @@ interface ChainClientConfig {
|
|
|
13
13
|
validateChainId?: boolean;
|
|
14
14
|
expectedChainId?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Outcome of a forced-reconnect request.
|
|
18
|
+
* - `issued` a fresh teardown/reconnect was started by this call.
|
|
19
|
+
* - `coalesced` a forced reconnect was already issued within the cooldown (by
|
|
20
|
+
* this or another escalation source); nothing was torn down
|
|
21
|
+
* again, but a recovery attempt is in flight/recent.
|
|
22
|
+
* - `unavailable` no live socket to tear down, so no recovery attempt exists.
|
|
23
|
+
*/
|
|
24
|
+
export type ForcedReconnectOutcome = 'issued' | 'coalesced' | 'unavailable';
|
|
16
25
|
declare function createChainClient(config?: ChainClientConfig): any;
|
|
17
26
|
interface ReadOnlyClientConfig {
|
|
18
27
|
nodes?: string[];
|
|
@@ -24,6 +33,7 @@ interface ReadOnlyClientConfig {
|
|
|
24
33
|
declare function createReadOnlyClient(config?: ReadOnlyClientConfig): {
|
|
25
34
|
connect: (servers?: string[]) => Promise<void>;
|
|
26
35
|
disconnect: () => void;
|
|
36
|
+
forceReconnect: (reason?: string) => ForcedReconnectOutcome;
|
|
27
37
|
db: (method: string, args?: any[]) => Promise<any>;
|
|
28
38
|
history: (method: string, args?: any[]) => Promise<any>;
|
|
29
39
|
setNodes: (servers: string[]) => void;
|
|
@@ -3,7 +3,7 @@ import { createTransport, ConnectionError } from './transport.js';
|
|
|
3
3
|
import { GRAPHENE_CHAIN_ID, GRAPHENE_ADDRESS_PREFIX } from './serial/chain_constants.js';
|
|
4
4
|
import { NATIVE_CLIENT } from '../constants.js';
|
|
5
5
|
import { getErrorMessage } from '../utils/errors.js';
|
|
6
|
-
const { CHAIN } = NATIVE_CLIENT;
|
|
6
|
+
const { CHAIN, TRANSPORT } = NATIVE_CLIENT;
|
|
7
7
|
class ChainConfigError extends Error {
|
|
8
8
|
code;
|
|
9
9
|
constructor(message) {
|
|
@@ -14,13 +14,60 @@ class ChainConfigError extends Error {
|
|
|
14
14
|
function toRpcMethodName(method) {
|
|
15
15
|
return String(method).replace(/([A-Z])/g, (_, ch) => `_${ch.toLowerCase()}`);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* True when an RPC error means the api_id we sent is not registered on the
|
|
19
|
+
* current websocket login session. bitshares-core returns:
|
|
20
|
+
* Execution error: Assert Exception: _local_apis.size() > api_id:
|
|
21
|
+
* A cached api id can outlive its session when a reconnect swaps the socket
|
|
22
|
+
* without a status 'closed' event, or when the node drops the login session
|
|
23
|
+
* server-side; the id then points past the new session's _local_apis map.
|
|
24
|
+
*/
|
|
25
|
+
function isStaleApiIdError(err) {
|
|
26
|
+
const message = err && err.message ? String(err.message) : String(err ?? '');
|
|
27
|
+
if (!message)
|
|
28
|
+
return false;
|
|
29
|
+
return message.includes('_local_apis') || (message.includes('api_id') && message.includes('Assert Exception'));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build the per-client forced-reconnect gate shared by the main and read-only
|
|
33
|
+
* clients, and transitively by the stale-api window and the subscriptions
|
|
34
|
+
* fill-channel watchdog. One cooldown per client stops a wedged session from
|
|
35
|
+
* stacking concurrent reconnects; the outcome lets a caller distinguish a
|
|
36
|
+
* genuinely new teardown from one coalesced onto another source's, so
|
|
37
|
+
* escalation accounting is not starved when the cooldown is already spent.
|
|
38
|
+
*/
|
|
39
|
+
function createForcedReconnectGate(transport) {
|
|
40
|
+
const cooldownMs = Number.isFinite(TRANSPORT.FORCED_RECONNECT_COOLDOWN_MS)
|
|
41
|
+
? Math.max(0, TRANSPORT.FORCED_RECONNECT_COOLDOWN_MS)
|
|
42
|
+
: 30000;
|
|
43
|
+
let lastForcedReconnectAt = 0;
|
|
44
|
+
return function forceReconnect(reason = 'forced') {
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
// Coalesce is checked before connectivity: immediately after a teardown
|
|
47
|
+
// the socket is null while the reconnect is in flight, and that must
|
|
48
|
+
// still read as `coalesced`, not `unavailable`.
|
|
49
|
+
if (now - lastForcedReconnectAt < cooldownMs)
|
|
50
|
+
return 'coalesced';
|
|
51
|
+
// No live socket: there is nothing to tear down, so this is not a
|
|
52
|
+
// recovery attempt. Reporting it as `issued` would let callers count a
|
|
53
|
+
// no-op as a cycle and burn the cooldown.
|
|
54
|
+
if (typeof transport?.isConnected === 'function' && !transport.isConnected())
|
|
55
|
+
return 'unavailable';
|
|
56
|
+
lastForcedReconnectAt = now;
|
|
57
|
+
try {
|
|
58
|
+
transport.forceReconnect(reason);
|
|
59
|
+
}
|
|
60
|
+
catch (_) {
|
|
61
|
+
// Keep the stamp: a throwing recovery must not become a tight loop.
|
|
62
|
+
}
|
|
63
|
+
return 'issued';
|
|
64
|
+
};
|
|
65
|
+
}
|
|
17
66
|
function createChainClient(config = {}) {
|
|
18
67
|
const { nodes = [], onStatusChange = null, onNodeFailure = null, shouldSkipNode = null, rpcTimeoutMs, connectTimeoutMs, autoreconnect = true, validateChainId = true, expectedChainId = GRAPHENE_CHAIN_ID, } = config;
|
|
19
68
|
const wrappedOnStatusChange = (status, nodeUrl) => {
|
|
20
69
|
if (status === 'closed') {
|
|
21
|
-
|
|
22
|
-
_historyApiId = null;
|
|
23
|
-
_broadcastApiId = null;
|
|
70
|
+
resetApiIds();
|
|
24
71
|
_chainConfig = null;
|
|
25
72
|
}
|
|
26
73
|
if (onStatusChange)
|
|
@@ -45,8 +92,30 @@ function createChainClient(config = {}) {
|
|
|
45
92
|
let _historyApiId = null;
|
|
46
93
|
let _broadcastApiId = null;
|
|
47
94
|
let _chainConfig = null;
|
|
95
|
+
function resetApiIds() {
|
|
96
|
+
_dbApiId = null;
|
|
97
|
+
_historyApiId = null;
|
|
98
|
+
_broadcastApiId = null;
|
|
99
|
+
}
|
|
48
100
|
let _loginPromise = null;
|
|
49
101
|
let _apiLimitGetAccountHistory = null;
|
|
102
|
+
// Escalation state for a login session that keeps rejecting cached api ids.
|
|
103
|
+
// A single stale error is handled in place (re-register + retry once); a
|
|
104
|
+
// sustained run means the session is wedged and only a fresh socket (on a
|
|
105
|
+
// different node) clears it.
|
|
106
|
+
let _staleApiErrorCount = 0;
|
|
107
|
+
let _staleApiWindowStartedAt = 0;
|
|
108
|
+
// Shared forced-reconnect debounce. Both escalation sources — the stale
|
|
109
|
+
// api_id window below and the subscriptions fill-channel watchdog — call
|
|
110
|
+
// forceReconnect(), so the cooldown lives here, once per client, instead of
|
|
111
|
+
// being duplicated (and independently tuned) at each call site. A wedged
|
|
112
|
+
// session trips both counters in the same tick; without this they would
|
|
113
|
+
// stack two reconnects on top of each other.
|
|
114
|
+
//
|
|
115
|
+
// Public entry point for higher layers (subscriptions watchdog) to recover
|
|
116
|
+
// a session that is nominally connected but rejecting every call.
|
|
117
|
+
// @returns the {@link ForcedReconnectOutcome} of the request.
|
|
118
|
+
const forceReconnect = createForcedReconnectGate(transport);
|
|
50
119
|
if (Array.isArray(nodes) && nodes.length > 0) {
|
|
51
120
|
transport._setNodes(nodes);
|
|
52
121
|
}
|
|
@@ -54,6 +123,15 @@ function createChainClient(config = {}) {
|
|
|
54
123
|
if (_loginPromise)
|
|
55
124
|
return _loginPromise;
|
|
56
125
|
_loginPromise = (async () => {
|
|
126
|
+
// validateNode() runs login() on every (re)connect. A new websocket
|
|
127
|
+
// session starts with an empty _local_apis map, so api ids cached
|
|
128
|
+
// from the previous session are no longer addressable — the node
|
|
129
|
+
// rejects them with "Assert Exception: _local_apis.size() > api_id".
|
|
130
|
+
// Drop them so every accessor re-registers against this session.
|
|
131
|
+
resetApiIds();
|
|
132
|
+
// A fresh login session is a clean slate for the stale-id escalation.
|
|
133
|
+
_staleApiErrorCount = 0;
|
|
134
|
+
_staleApiWindowStartedAt = 0;
|
|
57
135
|
const result = await transport.call('call', [1, 'login', ['', '']]);
|
|
58
136
|
if (!result) {
|
|
59
137
|
throw new ConnectionError('Login error');
|
|
@@ -118,23 +196,66 @@ function createChainClient(config = {}) {
|
|
|
118
196
|
const apiId = await transport.call('call', [1, apiName, []]);
|
|
119
197
|
return apiId;
|
|
120
198
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Invoke a login_api-registered RPC namespace, transparently recovering
|
|
201
|
+
* from a stale api id. If the node rejects the call because the id is not
|
|
202
|
+
* registered on the current session, drop the cached id, re-register the
|
|
203
|
+
* namespace on this session, and retry once. This is what keeps the fill
|
|
204
|
+
* history channel alive across a node failover without a process restart.
|
|
205
|
+
*/
|
|
206
|
+
async function callWithApiRecovery(apiName, method, args, getApiId, setApiId) {
|
|
207
|
+
let apiId = getApiId();
|
|
208
|
+
if (apiId == null) {
|
|
209
|
+
apiId = await registerApi(apiName);
|
|
210
|
+
setApiId(apiId);
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
return await transport.call('call', [apiId, method, args]);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
if (!isStaleApiIdError(err))
|
|
217
|
+
throw err;
|
|
218
|
+
noteStaleApiError(apiName);
|
|
219
|
+
setApiId(null);
|
|
220
|
+
const freshId = await registerApi(apiName);
|
|
221
|
+
setApiId(freshId);
|
|
222
|
+
return transport.call('call', [freshId, method, args]);
|
|
124
223
|
}
|
|
125
|
-
return transport.call('call', [_dbApiId, toRpcMethodName(method), args || []]);
|
|
126
224
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Record a stale-api error and escalate to a forced reconnect when the
|
|
227
|
+
* session keeps rejecting ids. Counting is windowed: a rare stale id (the
|
|
228
|
+
* normal reconnect-race case) never trips the escalation, while a session
|
|
229
|
+
* that fails every call trips it within a few RPCs. The forced reconnect
|
|
230
|
+
* marks the active node failed, so the transport prefers another node.
|
|
231
|
+
*/
|
|
232
|
+
function noteStaleApiError(apiName) {
|
|
233
|
+
const now = Date.now();
|
|
234
|
+
const windowMs = Number.isFinite(TRANSPORT.STALE_API_WINDOW_MS) ? TRANSPORT.STALE_API_WINDOW_MS : 60000;
|
|
235
|
+
const threshold = Number.isFinite(TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER)
|
|
236
|
+
? TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER
|
|
237
|
+
: 3;
|
|
238
|
+
if (now - _staleApiWindowStartedAt > windowMs) {
|
|
239
|
+
_staleApiWindowStartedAt = now;
|
|
240
|
+
_staleApiErrorCount = 0;
|
|
130
241
|
}
|
|
131
|
-
|
|
242
|
+
_staleApiErrorCount++;
|
|
243
|
+
if (_staleApiErrorCount < threshold)
|
|
244
|
+
return;
|
|
245
|
+
_staleApiErrorCount = 0;
|
|
246
|
+
_staleApiWindowStartedAt = now;
|
|
247
|
+
// Go through the local wrapper so this escalation shares the one
|
|
248
|
+
// per-client cooldown with the subscriptions watchdog.
|
|
249
|
+
forceReconnect(`repeated stale api_id for ${apiName} (${threshold}x)`);
|
|
250
|
+
}
|
|
251
|
+
async function dbCall(method, args) {
|
|
252
|
+
return callWithApiRecovery('database', toRpcMethodName(method), args || [], () => _dbApiId, (id) => { _dbApiId = id; });
|
|
253
|
+
}
|
|
254
|
+
async function historyCall(method, args) {
|
|
255
|
+
return callWithApiRecovery('history', toRpcMethodName(method), args || [], () => _historyApiId, (id) => { _historyApiId = id; });
|
|
132
256
|
}
|
|
133
257
|
async function broadcastCall(method, args) {
|
|
134
|
-
|
|
135
|
-
_broadcastApiId = await registerApi('network_broadcast');
|
|
136
|
-
}
|
|
137
|
-
return transport.call('call', [_broadcastApiId, method, args || []]);
|
|
258
|
+
return callWithApiRecovery('network_broadcast', method, args || [], () => _broadcastApiId, (id) => { _broadcastApiId = id; });
|
|
138
259
|
}
|
|
139
260
|
async function broadcastTx(signedTx) {
|
|
140
261
|
return broadcastCall('broadcast_transaction', [signedTx]);
|
|
@@ -149,9 +270,7 @@ function createChainClient(config = {}) {
|
|
|
149
270
|
await transport.connect(undefined, autoreconnect);
|
|
150
271
|
}
|
|
151
272
|
function disconnect() {
|
|
152
|
-
|
|
153
|
-
_historyApiId = null;
|
|
154
|
-
_broadcastApiId = null;
|
|
273
|
+
resetApiIds();
|
|
155
274
|
_chainConfig = null;
|
|
156
275
|
transport.disconnect();
|
|
157
276
|
}
|
|
@@ -198,6 +317,7 @@ function createChainClient(config = {}) {
|
|
|
198
317
|
transport,
|
|
199
318
|
connect,
|
|
200
319
|
disconnect,
|
|
320
|
+
forceReconnect,
|
|
201
321
|
setNodes,
|
|
202
322
|
getNodes,
|
|
203
323
|
getStatus,
|
|
@@ -217,6 +337,9 @@ function createReadOnlyClient(config = {}) {
|
|
|
217
337
|
let _dbApiId = null;
|
|
218
338
|
let _historyApiId = null;
|
|
219
339
|
let _recoverPromise = null;
|
|
340
|
+
// Windowed escalation for a read channel whose session keeps rejecting ids.
|
|
341
|
+
let _staleApiErrorCount = 0;
|
|
342
|
+
let _staleApiWindowStartedAt = 0;
|
|
220
343
|
function resetApiIds() {
|
|
221
344
|
_dbApiId = null;
|
|
222
345
|
_historyApiId = null;
|
|
@@ -229,6 +352,10 @@ function createReadOnlyClient(config = {}) {
|
|
|
229
352
|
resetApiIds();
|
|
230
353
|
},
|
|
231
354
|
});
|
|
355
|
+
// Shared forced-reconnect debounce for the read channel, mirroring the main
|
|
356
|
+
// client: one cooldown and one outcome for every forced reconnect raised on
|
|
357
|
+
// this client (stale api_id escalation today).
|
|
358
|
+
const forceReconnect = createForcedReconnectGate(transport);
|
|
232
359
|
async function connect(servers) {
|
|
233
360
|
const effectiveNodes = Array.isArray(servers) && servers.length > 0
|
|
234
361
|
? servers
|
|
@@ -285,23 +412,64 @@ function createReadOnlyClient(config = {}) {
|
|
|
285
412
|
resetApiIds();
|
|
286
413
|
transport.disconnect();
|
|
287
414
|
}
|
|
288
|
-
|
|
289
|
-
|
|
415
|
+
/**
|
|
416
|
+
* Invoke a read-only RPC namespace, recovering from a stale api id by
|
|
417
|
+
* re-registering on the current session and retrying once. Mirrors the
|
|
418
|
+
* main client's callWithApiRecovery so a missed 'closed' event cannot
|
|
419
|
+
* permanently wedge the read channel.
|
|
420
|
+
*/
|
|
421
|
+
async function callWithRecovery(method, args, getApiId, setApiId) {
|
|
422
|
+
if (getApiId() == null) {
|
|
290
423
|
await recoverApis();
|
|
291
424
|
const err = await validateChain();
|
|
292
425
|
if (err)
|
|
293
426
|
throw err;
|
|
294
427
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
428
|
+
const apiId = getApiId();
|
|
429
|
+
try {
|
|
430
|
+
return await transport.call('call', [apiId, method, args]);
|
|
431
|
+
}
|
|
432
|
+
catch (err) {
|
|
433
|
+
if (!isStaleApiIdError(err))
|
|
434
|
+
throw err;
|
|
435
|
+
noteStaleApiError();
|
|
436
|
+
setApiId(null);
|
|
299
437
|
await recoverApis();
|
|
300
|
-
const
|
|
301
|
-
if (
|
|
438
|
+
const freshId = getApiId();
|
|
439
|
+
if (freshId == null)
|
|
302
440
|
throw err;
|
|
441
|
+
return transport.call('call', [freshId, method, args]);
|
|
303
442
|
}
|
|
304
|
-
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Windowed stale-id escalation for the read channel. Mirrors the main
|
|
446
|
+
* client: a rare reconnect-race stale id recovers in place, a sustained
|
|
447
|
+
* run forces a fresh connection on another node.
|
|
448
|
+
*/
|
|
449
|
+
function noteStaleApiError() {
|
|
450
|
+
const now = Date.now();
|
|
451
|
+
const windowMs = Number.isFinite(TRANSPORT.STALE_API_WINDOW_MS) ? TRANSPORT.STALE_API_WINDOW_MS : 60000;
|
|
452
|
+
const threshold = Number.isFinite(TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER)
|
|
453
|
+
? TRANSPORT.STALE_API_FORCE_RECONNECT_AFTER
|
|
454
|
+
: 3;
|
|
455
|
+
if (now - _staleApiWindowStartedAt > windowMs) {
|
|
456
|
+
_staleApiWindowStartedAt = now;
|
|
457
|
+
_staleApiErrorCount = 0;
|
|
458
|
+
}
|
|
459
|
+
_staleApiErrorCount++;
|
|
460
|
+
if (_staleApiErrorCount < threshold)
|
|
461
|
+
return;
|
|
462
|
+
_staleApiErrorCount = 0;
|
|
463
|
+
_staleApiWindowStartedAt = now;
|
|
464
|
+
// Route through the shared wrapper so both stale-id escalations on this
|
|
465
|
+
// client obey one cooldown.
|
|
466
|
+
forceReconnect(`repeated stale api_id on read channel (${threshold}x)`);
|
|
467
|
+
}
|
|
468
|
+
async function db(method, args) {
|
|
469
|
+
return callWithRecovery(toRpcMethodName(method), args || [], () => _dbApiId, (id) => { _dbApiId = id; });
|
|
470
|
+
}
|
|
471
|
+
async function history(method, args) {
|
|
472
|
+
return callWithRecovery(toRpcMethodName(method), args || [], () => _historyApiId, (id) => { _historyApiId = id; });
|
|
305
473
|
}
|
|
306
474
|
function setNodes(servers) {
|
|
307
475
|
transport._setNodes(servers);
|
|
@@ -312,6 +480,7 @@ function createReadOnlyClient(config = {}) {
|
|
|
312
480
|
return {
|
|
313
481
|
connect,
|
|
314
482
|
disconnect,
|
|
483
|
+
forceReconnect,
|
|
315
484
|
db,
|
|
316
485
|
history,
|
|
317
486
|
setNodes,
|