Skip to content

Integrate resource manager into ChannelManager#4468

Draft
elnosh wants to merge 13 commits intolightningdevkit:mainfrom
elnosh:resource-mgr-readonly-integration
Draft

Integrate resource manager into ChannelManager#4468
elnosh wants to merge 13 commits intolightningdevkit:mainfrom
elnosh:resource-mgr-readonly-integration

Conversation

@elnosh
Copy link
Contributor

@elnosh elnosh commented Mar 6, 2026

Builds on top of #4409

It adds a ReadOnlyResourceManager wrapper that is integrated into the ChannelManager. In this iteration, the forwarding outcome would be logged but if instructed to fail an HTLC, it won't do so.

A couple things to mention:

  • The replay of HTLCs on restart will have different timestamps than the ones on shutdown. This could cause slightly different values when resolved depending on how long the time offline was.
  • The resolution of HTLCs that were recommended to fail will not affect reputation or revenue since those are not keep track of by the resource manager.
  • It only works with std.
  • resource manager trait and impl #4409 added a ResourceManager trait. Here, it is not actually using it and instead just doing it as Option<ReadOnlyResourceManager> to avoid doing dyn ReadOnlyResourceManager. This is because it is intended to just be enabled by a user config and not actually expecting a type from the user when starting the channel manager. So perhaps that commit introducing the trait could be removed.

elnosh and others added 13 commits February 27, 2026 16:53
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.

Co-authored-by: Carla Kirk-Cohen <kirkcohenc@gmail.com>
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.
Implements a wrapper around the DefaultResourceManager. The main purpose
to silently handle an HTLC not found error. In read-only mode, the
ChannelManager will only log the forwarding outcome suggestions from the
resource manager but not fail HTLCs if instructed to do so. Since HTLCs
suggested to be failed are not stored by the DefaultResourceManager, a
subsequent call from the ChannelManager to resolve this HTLC would
return an error because it does not know about it. In this case, the
error is discarded.
- max_accepted_htlcs and max_htlc_value_in_flight_msat values in the
channel are required when adding new channels in the resource manager.

- get_outbound_htlcs helper will be used during restart to replay
  pending HTLCs.
Integrates the ReadOnlyResourceManager into the ChannelManager. This can
be enabled by the enable_resource_manager field added in the UserConfig.

The main 4 call sites are when adding/removing channels and add/resolve
forwarded HTLCs. The add_htlc call into the resource manager is done before
the queue_add_htlc on the outgoing channel.

In read-only mode, it will only log the forwarding outcome suggestion
from the resource manager and use the accountable signal suggested.

Note that it only works in std given that we need access to the time.
@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

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