Add heuristic fee engine and related services#533
Open
markettes wants to merge 9 commits into
Open
Conversation
…e and LightningService
…ting states; add corresponding interfaces and tests
…fee management and automated rebalancing
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces the Phase 1 “foundation + signal” components for a heuristic routing engine, adding persisted routing/fee state models, a scheduled job to compute per-channel signals from forwarding history + live channel data, and UI/config surfaces to stage nodes for future Phase 2/3 actuation.
Changes:
- Add
ChannelRoutingState/ChannelFeeStateentities + repositories and EF migration to persist routing-engine state. - Add
TargetRatioReevaluationJobplusPeerCategorizationService(hysteresis categorization + EWMA smoothing) to compute targets and peer flow categories. - Extend services/UI/config:
GetInfo/block height retrieval, routing-engine constants, and node settings UI for dynamic fees/rebalancing.
Reviewed changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/NodeGuard.Tests/Services/PeerCategorizationServiceTests.cs | Unit tests for categorization hysteresis + target/EMA smoothing math. |
| test/NodeGuard.Tests/Helpers/ChannelOwnershipHelperTests.cs | Tests ownership dedup logic for managed↔managed channels. |
| test/NodeGuard.Tests/Helpers/BlockHeightHelperTests.cs | Tests SCID funding-height/age parsing and alias/zero handling. |
| test/NodeGuard.Tests/Data/Repositories/RebalanceRepositoryRoutingEngineTests.cs | Tests new rebalance in-flight count and budget-consumption calculations. |
| test/NodeGuard.Tests/Data/Repositories/ChannelRoutingStateRepositoryTests.cs | Tests routing-state upsert semantics and filtering by node pubkey. |
| test/NodeGuard.Tests/Data/Repositories/ChannelFlowAnalyticsRepositoryTests.cs | Tests settled-only, windowed per-channel forwarding aggregations. |
| src/Services/PeerCategorizationService.cs | Adds categorization decision record + core categorization/target smoothing logic. |
| src/Services/LightningService.cs | Adds GetBlockHeight to expose chain tip via LND GetInfo. |
| src/Services/LightningClientService.cs | Adds GetInfo RPC wrapper with error handling/logging. |
| src/Program.cs | Registers new repositories/service and schedules the new Quartz job/trigger. |
| src/Pages/Nodes.razor | Adds routing-engine configuration fields (dynamic fees/rebalance budgets/dry-run) to node UI. |
| src/Migrations/ApplicationDbContextModelSnapshot.cs | Updates EF snapshot with routing-engine entities and new columns/defaults. |
| src/Migrations/20260707155251_AddRoutingEngineFoundation.Designer.cs | Migration designer for routing-engine foundation schema changes. |
| src/Migrations/20260707155251_AddRoutingEngineFoundation.cs | Adds new node/channel columns and creates ChannelRoutingStates / ChannelFeeStates tables. |
| src/Jobs/TargetRatioReevaluationJob.cs | Implements Phase 1 job to compute/store routing signals and target ratios per channel. |
| src/Helpers/Constants.cs | Adds routing-engine constants and env var parsing. |
| src/Helpers/ChannelOwnershipHelper.cs | Adds helper to decide managed-node channel “ownership” for dedup. |
| src/Helpers/BlockHeightHelper.cs | Adds helper to parse funding height and channel age from SCID. |
| src/Data/Repositories/RebalanceRepository.cs | Adds in-flight count and consumed-fees calculations for routing-engine budgeting. |
| src/Data/Repositories/Interfaces/IRebalanceRepository.cs | Declares new rebalance query methods for Phase 3 budgeting/caps. |
| src/Data/Repositories/Interfaces/IChannelRoutingStateRepository.cs | New repository interface for routing-state persistence/upsert. |
| src/Data/Repositories/Interfaces/IChannelFlowAnalyticsRepository.cs | New interface for settled-only forwarding flow aggregations. |
| src/Data/Repositories/Interfaces/IChannelFeeStateRepository.cs | New interface for fee-state persistence/upsert (Phase 2). |
| src/Data/Repositories/ChannelRoutingStateRepository.cs | Implements routing-state get/upsert logic keyed by ChannelId. |
| src/Data/Repositories/ChannelFlowAnalyticsRepository.cs | Implements settled-only forwarding aggregations over ForwardingHtlcEvents. |
| src/Data/Repositories/ChannelFeeStateRepository.cs | Implements fee-state get/upsert logic keyed by ChannelId. |
| src/Data/Models/Rebalance.cs | Adds ReservedFeeSats for in-flight budget accounting. |
| src/Data/Models/Node.cs | Adds routing-engine node-level feature flags and budget/cap settings. |
| src/Data/Models/ChannelRoutingState.cs | Adds routing-state entity + PeerFlowCategory enum. |
| src/Data/Models/ChannelFeeState.cs | Adds fee-state entity for future fee engine (baseline/last-applied/circuit breaker). |
| src/Data/Models/Channel.cs | Adds per-channel opt-out flag IsDynamicFeeEnabled (default true). |
| src/Data/ApplicationDbContext.cs | Wires up new DbSets, 1:1 mappings, and default values for new flags. |
Files not reviewed (1)
- src/Migrations/20260707155251_AddRoutingEngineFoundation.Designer.cs: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce foundational components for a heuristic routing engine, including new methods for LightningClientService, migrations for routing engine tables, and repositories for channel fee and routing states. Implement helper classes for block height and channel ownership, along with tests to ensure functionality. This update enhances dynamic fee management and automated rebalancing capabilities.