Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Channel open recommendations: data model and per-node settings - #659

Merged
markettes merged 4 commits into
mainfrom
feat/simple-auto-channel-open-data
Nov 30, 2026
Merged

markettes merged 4 commits into
mainfrom
feat/simple-auto-channel-open-data

Conversation

@markettes

Copy link
Copy Markdown
Contributor

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.

@markettes
markettes requested a review from Jossec101 October 30, 2026 18:06
@markettes
markettes added this pull request to stack #663 October 30, 2026 18:07
@markettes
markettes force-pushed the feat/simple-auto-channel-open-data branch from d9a5091 to ded13c5 Compare October 30, 2026 18:26
Jossec101
Jossec101 previously approved these changes Nov 12, 2026
@markettes
markettes force-pushed the feat/simple-auto-channel-open-data branch from ded13c5 to 2e30003 Compare November 16, 2026 18:02
Comment thread src/Helpers/Constants.cs Resolved

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

@markettes
markettes requested a review from Jossec101 November 26, 2026 11:11
Jossec101
Jossec101 previously approved these changes Nov 26, 2026

@lunar-patrol lunar-patrol Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

@markettes
markettes force-pushed the feat/simple-auto-channel-open-data branch from f00795a to b081365 Compare November 26, 2026 17:51
@markettes
markettes force-pushed the feat/simple-auto-channel-open-data branch 2 times, most recently from 252e4e7 to 609998a Compare November 30, 2026 15:07
@markettes
markettes force-pushed the feat/simple-auto-channel-open-data branch from 609998a to a26ffdc Compare November 30, 2026 15:10
@markettes
markettes merged commit db10c7e into main Nov 30, 2026
6 checks passed
@markettes
markettes deleted the feat/simple-auto-channel-open-data branch November 30, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants