Repository navigation
Channel open recommendations: data model and per-node settings - #659
Conversation
d9a5091 to
ded13c5
Compare
ded13c5 to
2e30003
Compare
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds the ChannelOpenRecommendation entity, per-node auto-channel-open settings, one EF Core migration, and repository methods (recommendation upsert/expire/fail, per-channel forwarding aggregates, budget-committed sums) with defaults in Constants. Nothing consumes the new methods yet — no job, endpoint, RPC handler, or DI registration exists in this change, which the description confirms. On the triage-flagged SQL surface: every new query is parameterized EF Core LINQ (no FromSqlRaw/ExecuteSql anywhere in src), the migration is standard generated DDL, and the upsert is backed by a unique index on (NodeId, PeerPubKey). No secrets, no raw SQL, no new trust-boundary entry points — I found no exploitable defect.
Reviewed 17 files at 2e30003. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
There was a problem hiding this comment.
🟡 Changes recommended
Unprotected lifecycle writes can let stale dismissals erase live promotion links and enable premature recycling, while rejection cooldowns incorrectly use promotion time rather than rejection time.
2 open issues
1 file not reviewed
src/Migrations/20261029165151_AddAutoChannelOpen.Designer.cs: Generated file
What changed in this PR
Adds the data foundation for NodeGuard’s simplified channel-opening recommendations: fixed-size opens to peers with earned fees and recent outbound shortages. This first PR in the replacement stack adds persistence and settings; the planning job follows separately.
Changes:
- Adds recommendation evidence, lifecycle states, per-node settings, and one database migration.
- Adds repository operations for recommendations, routing evidence, eligible nodes, and committed opening budgets.
- Adds defaults and tests for lifecycle rules, aggregates, budget accounting, and node updates.
| File | Description |
|---|---|
| test/NodeGuard.Tests/Data/Repositories/NodeRepositoryTests.cs | Tests eligibility, wallet loading, and safe node updates. |
| test/NodeGuard.Tests/Data/Repositories/ForwardingHtlcEventRepositoryTests.cs | Tests per-channel routing evidence aggregates. |
| test/NodeGuard.Tests/Data/Repositories/ChannelOperationRequestRepositoryTests.cs | Tests committed opening-budget totals. |
| test/NodeGuard.Tests/Data/Repositories/ChannelOpenRecommendationRepositoryTests.cs | Tests recommendation lifecycle and cooldown queries. |
| test/NodeGuard.Tests/Data/Models/ChannelOperationRequestTests.cs | Tests finalized request statuses. |
| src/Migrations/ApplicationDbContextModelSnapshot.cs | Records the updated persistence model. |
| src/Migrations/20261029165151_AddAutoChannelOpen.Designer.cs | Defines migration target-model metadata. |
| src/Migrations/20261029165151_AddAutoChannelOpen.cs | Adds recommendation storage and node settings. |
| src/Helpers/Constants.cs | Adds defaults and environment overrides. |
| src/Data/Repositories/NodeRepository.cs | Retrieves eligible nodes with funding wallets. |
| src/Data/Repositories/Interfaces/INodeRepository.cs | Declares the eligible-node query. |
| src/Data/Repositories/Interfaces/IForwardingHtlcEventRepository.cs | Declares per-channel evidence queries. |
| src/Data/Repositories/Interfaces/IChannelOperationRequestRepository.cs | Declares committed-budget accounting. |
| src/Data/Repositories/Interfaces/IChannelOpenRecommendationRepository.cs | Defines recommendation persistence operations. |
| src/Data/Repositories/ForwardingHtlcEventRepository.cs | Aggregates volume, fees, and outbound refusals. |
| src/Data/Repositories/ChannelOperationRequestRepository.cs | Sums funds committed to channel opens. |
| src/Data/Repositories/ChannelOpenRecommendationRepository.cs | Implements lifecycle, recycling, and cooldown queries. |
| src/Data/Models/Node.cs | Adds per-node opening configuration. |
| src/Data/Models/ChannelOperationRequest.cs | Identifies finalized requests. |
| src/Data/Models/ChannelOpenRecommendation.cs | Defines recommendation evidence and lifecycle states. |
| src/Data/Models/AuditLog.cs | Adds the recommendation audit object type. |
| src/Data/ApplicationDbContext.cs | Configures recommendation relationships and uniqueness. |
| src/Automapper/MapperProfile.cs | Excludes new navigation properties from node mapping. |
Review effort: Balanced
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds the ChannelOpenRecommendation entity, per-node auto-channel-open settings, one EF Core migration, and four repository query sets — all parameterized LINQ, with a unique (NodeId, PeerPubKey) index backing the upsert. Nothing calls the new repositories yet (not even DI registration), so no attacker-controlled input reaches any of the new code in this PR; the consuming job lands in the next PR. I found no concrete exploit path: no raw SQL, no injection, no reachable authorization or concurrency defect, and safe defaults (feature disabled, Recommendation mode).
Reviewed 14 files at 9efe241. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds a ChannelOpenRecommendation entity, per-node auto-channel-open settings, one EF Core migration, and repository methods (upsert, expire, fail-unrealized-promotions, per-channel HTLC aggregates, budget-committed sums). Every query is EF Core LINQ/ExecuteUpdate — no raw SQL, no string concatenation, so the triage-flagged sql surface has no injection path. The new repositories are internal-facing (invoked by a job arriving in a later PR), take IDs and pubkeys from server-side state, and the upsert's unique index on (NodeId, PeerPubKey) is enforced at the database. No exploitable defect found.
Reviewed 10 files at 99f162b. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds only the data layer for channel-open recommendations: a new entity with a unique (NodeId, PeerPubKey) index, per-node settings columns on Nodes, one EF Core migration, and repository methods (upsert, status-guarded update, expiry, per-channel HTLC aggregates). Despite the "sql" triage flag, every query is parameterized EF Core LINQ — no string-built SQL, no raw execution. There is no new network surface and nothing reads these tables yet, so there is no attacker-reachable path to attack; the concurrency-sensitive paths (upsert race, promotion race) are covered by the unique index and by conditional ExecuteUpdate. No findings.
Reviewed 11 files at 46e25cd. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
There was a problem hiding this comment.
🔒 Automated security review — no issues found
This PR adds the ChannelOpenRecommendation data model, per-node auto-channel-open settings, one EF migration, and repository queries (all parameterized EF Core with atomic ExecuteUpdate for status transitions), plus a node-identity check (GetNodeIdentityError) wired into AddNode and into the channel-open funding path. It also converts ConfirmationModal from a MarkupString body to encoded ChildContent, removing a potential stored-XSS vector. The concurrency-sensitive paths are guarded: the (NodeId, PeerPubKey) unique index backs the upsert read-then-insert race, and UpdateIfStatus is a single conditional UPDATE. Nothing reads the new tables yet, and the identity check uses stored endpoint+macaroon at funding time, which covers later edits of those fields. I found no exploitable defect.
Reviewed 19 files at f00795a. Nothing to report.
Not a guarantee — one diff, no knowledge of your threat model.
🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.
f00795a to
b081365
Compare
252e4e7 to
609998a
Compare
… open request is rejected
609998a to
a26ffdc
Compare


First of a four-PR stack that replaces #615–#621 with the simpler rule from review: open a fixed-size channel to a peer whose route has been earning fees and that we recently couldn't serve for lack of outbound.
Adds the ChannelOpenRecommendation entity, one row per node and peer, holding the evidence (earned fees, amount routed, refusals, usable outbound, capacity) plus the size and fee policy it would open at, with its lifecycle statuses. Node gets the per-node settings: enabled, mode, funding wallet, fixed channel size and a budget with its refresh interval. One migration, AddAutoChannelOpen.
Repositories: recommendations (upsert, expire, fail unrealized promotions, last decision per peer for the cooldown), per-channel aggregates over ForwardingHtlcEvents grouped in the database (earned fees, settled out, INSUFFICIENT_BALANCE refusals), nodes with the feature on, and sats committed to opens since the budget period began. Defaults live in Constants.
Nothing reads this yet; the job comes in the next PR.