Split composite DB index on htlc_infos
table
#2946
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We were previously using a composite index on both the
channel_id
and thecommitment_number
in thehtlc_infos
table. This table is used to store historical HTLC information to be able to publish penalty txs when a malicious peer publishes a revoked commitment. This table is usually the largest DB table on nodes that relay a lot of payments, because it grows with the number of HTLCs received and sent (and only shrinks when channels are closed or spliced).Using a composite index makes sense, but leads to increased memory usage compared to separate indices, thus reducing performance because this is a table on which we write a lot, but almost never read (only when we detect a revoked force-close). The read performance doesn't seem to be negatively impacted anyway when splitting the indices, and the memory usage is greatly improved.
The migration may take some time depending on the size of the table, but we cannot get around this.
Thanks to @DerEwige for the performance investigation that lead to this change (see #2932 for more details).