Skip to content

Reserve a share of the auto channel open budget for chosen peers - #689

Merged
markettes merged 5 commits into
feat/auto-channel-open-swap-out-warningfrom
feat/auto-channel-open-reserved-peers
Dec 2, 2026
Merged

markettes merged 5 commits into
feat/auto-channel-open-swap-out-warningfrom
feat/auto-channel-open-reserved-peers

Conversation

@markettes

Copy link
Copy Markdown
Contributor

Some peers, like Loop, are worth a channel whether or not routing evidence points at them. A node can now reserve a share of its auto channel open budget for peers picked from the registered nodes, each with its own percentage.

A reserved peer skips the evidence rule: it qualifies when its usable outbound is below the low-outbound threshold, or when we have no channel to it at all, and then opens at the node's default fee. Reserved peers are planned first.

The reservation is hard. Ordinary peers only spend the unreserved part of the budget; a reserved peer spends its own share first, then the unreserved part. ChannelOpenBudget keeps that ledger from what each peer was committed this period.

Reserved peers are set on the Nodes page and point at the peer's Node row, so deleting a node drops its reservations. Routing Management badges reserved recommendations and shows each share's spend. The dev launch config gets easier thresholds and the Loop image moves to v0.36.0.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@markettes
markettes added this pull request to stack #663 November 27, 2026 16:58

@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 per-node "reserved channel open peers": operators pick registered nodes that skip the routing-evidence rule and get a reserved percentage of the auto channel open budget, with reserved peers planned first and spent against their own share via the new ChannelOpenBudget ledger. The budget arithmetic, cascade-deleting schema, and repository are sound; the one real concern is authorization: the new reserved-peer field is saved through a page that grants every NodeManager edit rights over every node, and reserved peers bypass the evidence gate that previously constrained where a node's hot wallet would auto-open channels.

Reviewed 16 files at 81ba1cb. 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/auto-channel-open-reserved-peers branch from 81ba1cb to 1bcebed Compare November 30, 2026 15:07
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:07
@markettes
markettes force-pushed the feat/auto-channel-open-reserved-peers branch from 1bcebed to 81e8e13 Compare November 30, 2026 15:10

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

Concurrent reservation replacements can exceed the node’s budget, while non-atomic settings saves and planner-cap handling can leave inconsistent configurations and block eligible peers.

4 open issues
1 file not reviewed
  • src/Migrations/20261127161511_AddReservedChannelOpenPeers.Designer.cs: Generated file
What changed in this PR

Adds per-peer budget reservations to NodeGuard’s automatic channel opening, allowing selected registered peers to qualify without routing evidence while protecting their allocated shares.

Changes:

  • Adds reservation storage, validation, per-peer spending accounting, and reserved-first planning.
  • Adds reservation editing on Nodes and spending indicators on Routing Management.
  • Extends tests and documentation, relaxes development thresholds, and updates the Loop image.
File Description
test/​NodeGuard.Tests/​ValidationHelperTests.cs Tests reservation validation.
test/​NodeGuard.Tests/​Services/​ChannelOpenPromotionServiceTests.cs Tests default-fee promotion for reserved peers.
test/​NodeGuard.Tests/​Services/​ChannelOpenInitiatorServiceTests.cs Tests reserved-peer eligibility and priority.
test/​NodeGuard.Tests/​Services/​ChannelOpenBudgetTests.cs Tests reserved and general budget accounting.
test/​NodeGuard.Tests/​Jobs/​AutoChannelOpenJobTests.cs Tests reserved-peer job behavior.
test/​NodeGuard.Tests/​Data/​Repositories/​ReservedChannelOpenPeerRepositoryTests.cs Tests reservation replacement and clearing.
test/​NodeGuard.Tests/​Data/​Repositories/​ChannelOperationRequestRepositoryTests.cs Tests commitments grouped by peer.
src/​Services/​ChannelOpenPromotionService.cs Allows default fees for reserved-peer recommendations.
src/​Services/​ChannelOpenInitiatorService.cs Prioritizes reserved peers and checks their budget.
src/​Services/​ChannelOpenBudget.cs Introduces the per-peer budget ledger.
src/​Program.cs Registers the reservation repository.
src/​Pages/​RoutingManagement.razor Displays reserved badges and share spending.
src/​Pages/​Nodes.razor Adds reservation selection and percentage editing.
src/​Migrations/​ApplicationDbContextModelSnapshot.cs Records the updated database model.
src/​Migrations/​20261127161511_AddReservedChannelOpenPeers.Designer.cs Captures migration model metadata.
src/​Migrations/​20261127161511_AddReservedChannelOpenPeers.cs Adds reservations and the recommendation flag.
src/​Jobs/​AutoChannelOpenJob.cs Integrates reserved snapshots and budget spending.
src/​Helpers/​ValidationHelper.cs Validates peer selections and share totals.
src/​Data/​Repositories/​ReservedChannelOpenPeerRepository.cs Loads and replaces reservations.
src/​Data/​Repositories/​NodeRepository.cs Loads selectable nodes and reservation relationships.
src/​Data/​Repositories/​Interfaces/​IReservedChannelOpenPeerRepository.cs Defines reservation persistence operations.
src/​Data/​Repositories/​Interfaces/​INodeRepository.cs Adds node-picker retrieval.
src/​Data/​Repositories/​Interfaces/​IChannelOperationRequestRepository.cs Defines per-peer commitment retrieval.
src/​Data/​Repositories/​ChannelOperationRequestRepository.cs Groups committed capacity by destination peer.
src/​Data/​Repositories/​ChannelOpenRecommendationRepository.cs Preserves reserved status and prioritizes display order.
src/​Data/​Models/​ReservedChannelOpenPeer.cs Defines a peer’s reserved budget share.
src/​Data/​Models/​Node.cs Adds the reservations relationship.
src/​Data/​Models/​ChannelOpenRecommendation.cs Marks reserved-peer recommendations.
src/​Data/​ApplicationDbContext.cs Configures reservation relationships and uniqueness.
src/​Automapper/​MapperProfile.cs Excludes reservations from node mapping.
docs/​auto-channel-open.md Documents reservations, accounting, and limitations.
docker/​loop/​docker-compose.yml Updates Loop to v0.36.0-beta.
.vscode/​launch.json Relaxes development qualification thresholds.

Review effort: Balanced

Comment thread src/Jobs/AutoChannelOpenJob.cs Resolved
Comment thread src/Jobs/AutoChannelOpenJob.cs Resolved
Comment thread src/Pages/Nodes.razor Resolved
@markettes
markettes force-pushed the feat/auto-channel-open-reserved-peers branch from 81e8e13 to 6fa1a74 Compare November 30, 2026 15:17
@markettes
markettes force-pushed the feat/auto-channel-open-reserved-peers branch from 6fa1a74 to 42961de Compare December 1, 2026 10:02

@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

This PR adds reserved channel-open peers (per-peer budget shares that skip the earning-evidence rule), a ChannelOpenBudget ledger splitting spend between reserved shares and the general pool, and a swap-out forecast gate that keeps auto-mode promotions as recommendations when the automatic swap-out would take the new outbound. The budget math, per-peer committed-sats query, cascade deletes, unique constraint, and the fail-closed treatment of an unreadable balance all hold up; the reserved-peers write path is only reachable from the role-gated Nodes page and validated server-side before saving. The only defect found is cosmetic: the hot-wallet confirmation modal now passes the swap-out warning through the HTML-encoded Body parameter with literal
tags, which display as text instead of line breaks.

Reviewed Lunar-Rails/NodeGuard #689 at 42961de — 0 inline finding(s), 0 not anchorable, 1 below the posting threshold.

1 lower-severity observation(s)
  • LOW · correctness — Swap-out warning shows literal

    in hot-wallet confirmation modal (src/Pages/ChannelRequests.razor line 571)
    No exploit; a UI regression. The warning text is now interpolated into ConfirmationModal's Body parameter, which ConfirmationModal renders HTML-encoded (its own comment: 'a body never renders as raw markup... use ChildContent for one that needs formatting'). When a swap-out warning exists and the wallet is hot, the operator sees the literal text '

    ' in the confirmation dialog instead of paragraph breaks, making the warning about immediately losing the new channel's outbound harder to read. The pre-PR code rendered the same content as encoded ChildContent paragraphs, which displayed correctly.

    <ConfirmationModal
        @ref="_approveOperationConfirmationModal"
        Title="Are you sure?"
        OkLabel="Yes, I am sure"
        OnCancel="@ApproveOperationCloseConfirmationModal"
        OnSubmit="@ApproveOperationSubmitConfirmationModal">
        <p>You selected a hot wallet. This means that the system will automatically use the funds in it without the need of manual approval. Are you sure you want to perform this operation?</p>
        @if (_swapOutWarning != null)
        {
            <p>@_swapOutWarning</p>
        }
    </ConfirmationModal>

🤖 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

This PR adds per-peer reserved shares of the auto channel-open budget: a new ReservedChannelOpenPeers table and repository, budget splitting in ChannelOpenBudget, an evidence-skipping path in the planner, and UI on the Nodes page. The security-relevant surfaces held up: the raw SQL lock interpolates only an int, share validation runs server-side before the only write path, the unique index and cascade deletes back the invariants, and the job is single-run with eager-loaded peer data. One LOW: the no-fee-policy guard is skipped for reserved peers that already have channels, so a policy-fetch gap opens the channel at the node default fee the guard exists to avoid.

Reviewed Lunar-Rails/NodeGuard #689 at ac37d71 — 0 inline finding(s), 0 not anchorable, 1 below the posting threshold.

1 lower-severity observation(s)
  • LOW · correctness — Reserved peer with channels but no captured fee policy opens at node default (src/Services/ChannelOpenInitiatorService.cs line 178)
    RejectOnEvidence rejects a peer when peer.OutboundPolicy is null because, per the guard's own comment, opening at the node default would undercut what we already charge that peer. RejectReserved skips that check: a reserved peer with CapacitySats > 0 goes straight to RejectNotShortNow, so when the policy lookup in BuildPeerSnapshots yields nothing (policyByChanId null or missing the chan id), the plan is created with InheritedFeeRatePpm = null. ChannelOpenPromotionService then accepts null for IsReservedPeer and the channel opens at the node default — in AutoChannelOpenMode.Auto with no human reviewing the price. Not attacker-steerable (the reserved peer operator cannot force the policy fetch to fail), so this is a pricing/correctness regression, not an exploit: fee revenue on the new channel is silently mispriced.

        // A swap service is paid by our own payments, not forwards, so it never earns the evidence above.
        private static string? RejectReserved(PeerSnapshot peer, ChannelOpenInitiatorTunables t)
        {
            // No channel yet: there is no price to copy and the default is all there is.
            if (peer.CapacitySats == 0)
            {
                return null;
            }
    
            // With channels but no captured policy, the node default would undercut what we charge this peer.
            if (peer.OutboundPolicy == null)
            {
                return "no outbound fee policy reported for any channel to the peer";
            }
    
            return RejectNotShortNow(peer, t);
        }

🤖 Automated security review. It never pushes, approves or blocks; a suggestion applies only when you click Commit suggestion.

@markettes
markettes force-pushed the feat/auto-channel-open-reserved-peers branch from ac37d71 to 1813fad Compare December 1, 2026 12:21
Comment thread src/Pages/Nodes.razor Resolved

@Jossec101 Jossec101 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.

Reserved peers only have unit tests so far (budget, job, repository, validation). Could we add an e2e scenario next to AutoChannelOpen_EarningRouteRunsOutOfOutbound_RecommendsThenOpensAFixedSizeChannel? Something like:

  • Reserve a peer the node has no channel with, with no forwards or refusals at all, and check the job recommends it as reserved at the node's default fee and the channel opens.
  • Set a budget where only the reserved share is left, and check an ordinary peer with evidence is skipped while the reserved one still opens.

A reserved peer with no channel to copy a fee from used to open at the
node default. Each reservation now carries a mandatory fee rate and base
fee, set on the Nodes page, and the channel opens at those instead.

Adds e2e scenarios for a reserved peer with no channel and for a budget
with only the reserved share left.
@markettes
markettes requested a review from Jossec101 December 2, 2026 12:08

@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

The PR adds operator-configured reserved peers for auto channel open: a new ReservedChannelOpenPeers table, UI on the Nodes page, an in-memory budget ledger, and evidence-skipping qualification in the planner. I checked the trust boundaries: the only writer of reservations is the Blazor-server Nodes page (FinanceManager/NodeManager/Superadmin role, page-level [Authorize]) with server-side validation of share ranges and sums; the FOR UPDATE lock serializes concurrent replacements; the interpolated SQL in the row lock uses an int nodeId, not injectable; fee values are [Required] and non-null-checked before promotion; the job's node query eagerly loads PeerNode so the null-forgiving lookups are backed. Budget math clamps negative headroom at use sites, so no overspend path is reachable. No exploitable defect found.

Reviewed 16 files at 4287271. 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 merged commit bc2c4de into main Dec 2, 2026
11 checks passed
@markettes
markettes deleted the feat/auto-channel-open-reserved-peers branch December 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants