-
Notifications
You must be signed in to change notification settings - Fork 906
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
channeld: remove dead HTLCs from htable and free them (eventually) #5882
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 5fa5ad0
@@ -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! */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(ret); | |
assert(ret); | |
assert(channel_get_htlc(channel, sender, 1337)); |
The
channel->htlcs
map was exhibiting unbounded growth, as elements were never removed from it. This was causinglightning_channeld
processes to consume ever-increasing amounts of memory, and iterating over the map was causing ever-increasing CPU utilization. There wereFIXME
comments suggesting that the intention was to remove HTLCs from the map upon their deaths. This PR implements that intention.