Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channeld: remove dead HTLCs from htable and free them (eventually) #5882

Merged

Conversation

whitslack
Copy link
Collaborator

The channel->htlcs map was exhibiting unbounded growth, as elements were never removed from it. This was causing lightning_channeld processes to consume ever-increasing amounts of memory, and iterating over the map was causing ever-increasing CPU utilization. There were FIXME comments suggesting that the intention was to remove HTLCs from the map upon their deaths. This PR implements that intention.

The channel->htlcs map was exhibiting unbounded growth, as elements were
never removed from it. This was causing lightning_channeld processes to
consume ever-increasing amounts of memory, and iterating over the map
was causing ever-increasing CPU utilization. There were FIXME comments
suggesting that the intention was to remove HTLCs from the map upon
their deaths. This commit implements that intention.

Changelog-Fixed: channeld no longer retains dead HTLCs in memory.
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

ACK 5fa5ad0

@vincenzopalazzo vincenzopalazzo added this to the v23.02 milestone Jan 6, 2023
@@ -71,7 +71,6 @@ static inline struct htlc *htlc_get(struct htlc_map *htlcs, u64 id, enum side ow
return NULL;
}

/* FIXME: Move these out of the hash! */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe drop a short comment on what dead precisely means for safety-of-deletion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe whoever named the function originally should write the comment. I almost deleted the function entirely since it's an implementation detail that doesn't belong in the public interface (i.e., the header file), but I left it there to minimize the diff.

channeld/full_channel.c Show resolved Hide resolved
Copy link
Collaborator

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

Looks good, would like a few improvements to test but could be done immediately in followup

I removed the key deletion and made sure the test as-is fails.


memset(&r, 0, sizeof(r));
sha256(&rhash, &r, sizeof(r));

assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
dummy_routing, NULL, NULL, NULL)
== CHANNEL_ERR_ADD_OK);
htlc = channel_get_htlc(channel, sender, 1337);
Copy link
Collaborator

Choose a reason for hiding this comment

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

please make 1337 a variable and use it everywhere

@@ -318,9 +319,9 @@ static void send_and_fulfill_htlc(struct channel *channel,
assert(ret);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert(ret);
assert(ret);
assert(channel_get_htlc(channel, sender, 1337));

@@ -297,8 +299,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
assert(ret);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert(ret);
assert(ret);
assert(channel_get_htlc(channel, sender, 1337));

@endothermicdev endothermicdev merged commit acfb63e into ElementsProject:master Jan 20, 2023
@whitslack whitslack deleted the actually-remove-htlcs branch February 5, 2023 01:56
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.

4 participants