Skip to content

Conversation

@elnosh
Copy link
Contributor

@elnosh elnosh commented Feb 10, 2026

Part of #4384

This PR introduces a ResourceManager trait and DefaultResourceManager implementation of that trait which is based on the proposed mitigation in lightning/bolts#1280.

It only covers the standalone implementation of the mitigation. I have done some testing with integrating it into the ChannelManager but that can be done separately. As mentioned in the issue, the resource manager trait defines these 4 methods to be called from the channel manager:

  • add_channel
  • remove_channel
  • add_htlc
  • resolve_htlc

Integrating into the ChannelManager

  • The ResourceManager is intended to be internal to the ChannelManager rather than users instantiating their own and passing it to a ChannelManager constructor.

  • add/remove_channel should be called when channels are opened/closed.

  • add_htlc: When processing HTLCs, the channel manager would call add_htlc which returns a ForwardingOutcome telling it whether to forward or fail the HTLC along with the accountable signal to use in case that it should be forwarded. For the initial "read-only" mode, the channel manager would log the results but not actually fail the HTLC if it was told to do so. A bit more specific on where it would be called: I think it will be when processing the forward_htlcs before we queue the add_htlc to the outgoing channel

    if let Err((reason, msg)) = optimal_channel.queue_add_htlc(

  • resolve_htlc: Used to tell back the ResourceManager the resolution of an HTLC. It will be used to release bucket resources and update reputation/revenue values internally.

This could have more tests but opening early to get thoughts on design if possible

cc @carlaKC

Implements a decaying average over a rolling
window. It will be used in upcoming commits
by the resource manager to track reputation
and revenue of channels.
The RevenueAverage implemented here will
be used in upcoming commits to track the
incoming revenue that channels have
generated through HTLC forwards.
Resources available in the channel will
be divided into general, congestion and
protected resources. Here we implement
the general bucket with basic denial of
service protections.
Resources available in the channel will
be divided into general, congestion and
protected resources. Here we implement
the bucket resources that will be used
for congestion and protected.
The Channel struct introduced here
has the core information that will be
used by the resource manager to
make forwarding decisions on HTLCs:

- Reputation that this channel has
accrued as an outgoing link in HTLC
forwards.

- Revenue (forwarding fees) that the
channel has earned us as an incoming link.

- Pending HTLCs this channel is currently
holding as an outgoing link.

- Bucket resources that are currently in
use in general, congestion and protected.
Trait that will be used by the
`ChannelManager` to mitigate slow
jamming. Core responsibility will
be to track resource usage to
evaluate HTLC forwarding decisions.
Introduces the DefaultResourceManager
struct. The core of methods that will
be used to inform the HTLC forward
decisions are add/resolve_htlc.

- add_htlc: Based on resource
availability and reputation, it
evaluates whehther to forward or
fail the HTLC.

- resolve_htlc: Releases the
bucket resources used from a
HTLC previously added and updates
the channel's reputation based
on HTLC fees and resolution times.
Adds write and read implementations
to persist the DefaultResourceManager.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 10, 2026

👋 Thanks for assigning @carlaKC as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 95.13837% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.16%. Comparing base (94d1e5e) to head (53a93ed).
⚠️ Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/resource_manager.rs 95.13% 33 Missing and 32 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4409      +/-   ##
==========================================
+ Coverage   86.03%   86.16%   +0.13%     
==========================================
  Files         156      157       +1     
  Lines      103091   104721    +1630     
  Branches   103091   104721    +1630     
==========================================
+ Hits        88690    90235    +1545     
- Misses      11891    11940      +49     
- Partials     2510     2546      +36     
Flag Coverage Δ
tests 86.16% <95.13%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@carlaKC carlaKC self-requested a review February 11, 2026 07:04
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.

2 participants