You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make MonitorUpdatingPersister change persist type based on size #3770
One thing that smaller LDK clients might want is to use MonitorUpdatingPersister in many cases, but not if the ChannelMonitor is only, say, a few KiB when serialized. This avoids the overhead of compaction later if the actual monitor being persisted is tiny anyway.
I think this should be quite easy to do so tagging as a good first issue.
If the storage layer is remote and high latency I think it could be? I guess in theory if we're really careful about the lookup logic (and the KVStore is async) we could do the loading in parallel (though its still a few more requests) but we'd still have to wait on compaction (without a background-compaction task running, which would require a generic spawn method...). Seems much easier to just check the length and skip some code for the common case :)
If I understand it correctly, this is special casing for channels at the beginning of their life and when they grow, the node will switch over to persisting updates and compaction anyway?
To me it isn't quite clear if this is really worth it. If the hit is significant, it is also a problem when the channel has outgrown the 'small' stage anyway?
If I understand it correctly, this is special casing for channels at the beginning of their life and when they grow, the node will switch over to persisting updates and compaction anyway?
Yes.
To me it isn't quite clear if this is really worth it. If the hit is significant, it is also a problem when the channel has outgrown the 'small' stage anyway?
Its more a recognition of two very different cases - if you're running an "edge node" that is just a wallet making occasional payments, then you're likely to never hit the "large" stage, and thus avoiding the compaction overhead is a really nice optimization. If you're a larger node that is forwarding/processing many payments, you're very likely to hit the "large" stage and the compaction penalty is worth it to avoid the writes.
At what size would the "large" stage be entered then typically and how many htlcs/channel updates is that? A channel monitor of a few kb, that doesn't sound like all that many updates?
Yea, dunno, we'd have to figure that out. I imagine most mobile nodes probably make in the 100s to low 1000s of payments in their entire lifetime, probably fewer on a single channel once you consider splicing and the like. 10KiB or whatever should be plenty for 100 or 250 payments.
Its more a recognition of two very different cases
It sounds like if you wanted to make this automatic, the metric you'd really want to evaluate to switch this behavior isn't so much monitor size, as one of these:
Frequency of updates to the channel
Latency of updates to the channel (more difficult)
The monitor size is a decent reflection of the number of updates to the channel[1], but with no perception of time it's impossible to evaluate whether it's being stored by a tenured edge node, or a routing node. I think if you took time into account, perhaps by using the block delta between the funding tx and chain tip to estimate update frequency, you could make a more informed assessment.
However, I worry that automating the behavior selection is not really following the "principle of least astonishment."
I would think that routing nodes rarely move to the edge, and edge nodes rarely become routing nodes (more often, a routing node starts small and may appear like an edge). And furthermore, I know what my node is likely to be; especially if I'm a Lightning developer and managing this on behalf of users, such as in a mobile wallet.
For that matter, varying the behavior per channel seems to make node persistence more difficult to reason about. Different channels could persist different ways on my node, depending on a size threshold. Which means they can change without me doing anything. I would think that if the reason for variation is the use case, then one behavior is correct for all channels stored by the node.
In that light, I'd just leave this a configurable behavior, which I think it is now.
[1] I recognize that size is being used here to evaluate the storage write size, not the number of updates. But I think that is why the discussion is unclear. Compared to update count/frequency, it's much harder to know the storage configuration of a given node, and what the throughput/latency tradeoff is like.
I think the intent of the proposed change is to optimize for the edge-node case with remote storage. Even an edge node may make enough payments to get a monitor up to 10s of KiB in size, at which point network-level effects like TCP slowstart may dominate the actual network latency. For a "power-user" edge node, we really want to use the MonitorUpdatingPersister, but paying the extra RTT cost of cleanup on load for every edge node is not a great tradeoff either.
For a routing node, it still seems to me like a size-based threshold may be something they want, purely as it (very marginally) reduces IO throughput for under-utilized or new channels. Writing out updates (padded to 4KiB or more depending on the storage medium) and then consolidating when the whole monitor is only a few KiB isn't really the right tradeoff no matter what. Of course a routing node is expected to surpass the threshold very quickly, so it shouldn't really make a substantial difference, but it seems strictly better to write out full updates in this case than not.
Indeed, this does lead to a bit of behavior shift, but I think the important metrics wouldn't change - first of all, if you happened to look at storage right after compaction, the stored contents would be identical to a full monitor persistence so I wouldn't really say that this materially changes the way that logic would interact with the stored data (you already have to handle the case of having no in-flight updates!). It also shouldn't materially change the IO throughput or write count for any node, just a fairly marginal strict reduction for routing nodes with fresh channels.
At what size would the "large" stage be entered then typically and how many htlcs/channel updates is that? A channel monitor of a few kb, that doesn't sound like all that many updates?
For our probing node running ldk-node with network storage (EFS), at around 20,000 updates over the single channel the average probe duration starts to increase substantially. p75 starts to creep up after about 3,000.
I see in the PR it's configurable. I think as long as that's the case, developers who don't want the variation in behavior can set the minimum size to 0.
eta: Also, I'm still not sure I like that it varies across channels, rather than a consistent behavior on a node.
Perhaps wait for developers who do want/need the variation in behavior to show up and only then implement? I think the "principle of least astonishment" is worth considering.
Perhaps wait for developers who do want/need the variation in behavior to show up and only then implement? I think the "principle of least astonishment" is worth considering.
Well, we likely do want to enable MUP in LDK Node, especially when persisting vs. remote storage/VSS. The question is whether it's preferable to always use MUP, even for very small monitors. I'd be reluctant to expose a setting in LDK Node for this, as I don't think our users would have better insight into which way to go than we do.
Perhaps wait for developers who do want/need the variation in behavior to show up and only then implement? I think the "principle of least astonishment" is worth considering.
FWIW I think the "principle of least astonishment" is served perfectly fine by changing the MUP to persist full monitors when they're small - there's no material difference in user-visible behavior between persisting full monitors and small ones, except the performance changes (i.e. we definitely can't persist full monitors that are huge). When persisting small monitors, its no difference from hitting the cleanup ID where we delete the updates anyway. Because of this I still think this change is strictly better than the current version.
there's no material difference in user-visible behavior between persisting full monitors and small ones
That's clear. I was thinking of least astonishment in reasoning about and resolving potential problems. Basically what @domZippilli mentions in #3770 (comment).
In this case, I would define 'strictly better' as a performance increase without an increase in complexity.
Well, we likely do want to enable MUP in LDK Node, especially when persisting vs. remote storage/VSS. The question is whether it's preferable to always use MUP, even for very small monitors. I'd be reluctant to expose a setting in LDK Node for this, as I don't think our users would have better insight into which way to go than we do.
It does seem to me like this enhanced MUP is preferable and should be used by default in LDK node. Otherwise it's ticking time bomb for poor user experience. As for exposing a setting, if you mean allowing people to choose which persister I'd say no. But I think allowing users to choose the monitor size where the behaviour change occurs makes sense given the various storage backends that only the user knows.
I'll limit my comments to how this manifests for ldk-node since that's come up here as well.
ticking time bomb for poor user experience
I guess the thing that perplexes me is, at some threshold of monitor size, the bomb goes off anyway. I get that initial UX is the most important, but I don't see why you'd want (presumably, your most active) users to start getting a lot of storage latency after, say, a few months of usage. Like in some beautiful, increasingly likely future where someone is paying a lot of Square merchants with Lightning using a ldk-node powered wallet.
So, I still think it should be a binary decision with consistent behavior on either pole of the bit. You can do that with the threshold setting, like 0 or usize::MAX, but as a compromise, I would consider an enum of AlwaysWriteIncrementalUpdates(0)/StartIncrementalUpdatesAtSize(usize)/AlwaysWriteWholeMonitors(usize::MAX) to put it in terms of the resulting behavior, in very plain language.
(eta: And probably you would make the number of pending updates something you can configure, too, at that point, if the reason incremental updates are an issue is listing and reading them)
(eta: not saying threshold should be a usize; it probably shouldn't. But it was last time I looked)
I guess the thing that perplexes me is, at some threshold of monitor size, the bomb goes off anyway. I get that initial UX is the most important, but I don't see why you'd want (presumably, your most active) users to start getting a lot of storage latency after, say, a few months of usage.
I'm confused: the proposed change is to switch to MUP after a certain threshold, based on the assumption that for monitors below that threshold persisting full monitors is more efficient as you avoid the consolidation step. Why would switching to MUP after some time result in "users to start getting a lot of storage latency"?
Why would switching to MUP after some time result in "users to start getting a lot of storage latency"?
@tnull it's possible I'm confused. I was under the impression that the whole reason for doing this was a concern about the compaction leading to perceived latency for users.
From Joost:
This avoids the overhead of compaction later if the actual monitor being persisted is tiny anyway.
Is this significant if the channel monitor is small anyway?
Then from Matt:
If the storage layer is remote and high latency I think it could be? [...snip...] Seems much easier to just check the length and skip some code for the common case :)
I remember now that Joost, early on, replied with what I am trying to say here:
If I understand it correctly, this is special casing for channels at the beginning of their life and when they grow, the node will switch over to persisting updates and compaction anyway?
To me it isn't quite clear if this is really worth it. If the hit is significant, it is also a problem when the channel has outgrown the 'small' stage anyway?
In other words, if this is a "ticking time bomb," then I think we are just adjusting the clock. Eventually the size threshold is crossed and the MUP's incremental writes + occasional compaction start happening. If that's bad at 1 byte, it's also bad at 10240 bytes. Thus, I still question if this is worth the cognitive overhead.
I would rather see a solution for compaction that happens out of the way of user interaction, but the comments also seemed to imply that making the compaction async or background was a large lift.
For what it's worth, if the concern in ldk-node is persisting with something like object storage hosting VSS, I think a channel size where E2E of writing the whole monitors wouldn't be comparable to writing incremental updates is probably much higher than 10KiB. Even on poor network, the bandwidth-delay product of that storage is likely to be high enough that E2E writing 100KiB or even 1MB would be very similar to the E2E to store 10KiB. Been a while since I did such profiling but it's on that order with object storage I have used the most.
The time bomb I'm referring to is with the default persister as it exists in LDK node today. As the monitors grow in size payment latency slowly increases to the point where it's unusable. And permanently so, not just sporadically as compaction happens. As a user this was surprising behaviour that would be good to eliminate with a better default
@tnull it's possible I'm confused. I was under the impression that the whole reason for doing this was a concern about the compaction leading to perceived latency for users.
Yes, a latency that only makes sense to avoid as long as it's not dominated by the latency stemming from persisting full monitor, i.e., under a certain size threshold, presumably.
In other words, if this is a "ticking time bomb," then I think we are just adjusting the clock.
Right, see Austin's post above: the 'ticking timebomb' for remote pesistence is not employing MUP at all, as monitors will eventually get larger and larger.
Eventually the size threshold is crossed and the MUP's incremental writes + occasional compaction start happening.
Yeah, I don't think this was what the concern was about, AFAIU.
I would rather see a solution for compaction that happens out of the way of user interaction, but the comments also seemed to imply that making the compaction async or background was a large lift.
Well, running regular compaction in the background could make sense, although it's orthogonal to this PR.
For what it's worth, if the concern in ldk-node is persisting with something like object storage hosting VSS, I think a channel size where E2E of writing the whole monitors wouldn't be comparable to writing incremental updates is probably much higher than 10KiB. Even on poor network, the bandwidth-delay product of that storage is likely to be high enough that E2E writing 100KiB or even 1MB would be very similar to the E2E to store 10KiB. Been a while since I did such profiling but it's on that order with object storage I have used the most.
Well, that's actually the question, which can probably only be really answered by substantial modelling/profiling/simulations or real-world measurements: can we always expect that the latency is the dominant factor, even if (full) monitor sizes would get large? If yes, we shouldn't employ MUP at all. If not, where is the right threshold from which on we should switch to MUP?
the 'ticking timebomb' for remote pesistence is not employing MUP at all, as monitors will eventually get larger and larger
I think that's a confusing metaphor. I happen to have first-hand experience with exploding things, and writing a lot of whole monitors for every update. They're very different. Bombs change state very rapidly at a threshold (fuse), whereas the latency of whole monitors is a gradual worsening of conditions. Like broken AC, or that poor frog people keep trying to metaphorically cook.
The "enhanced MUP" incorporates a byte-size threshold, upon which it will instantly change the way it works, hopefully without surprising an engineer and creating much "blast radius," to extend the metaphor. As such, I don't think ldk-node should use it without leaking some of the abstraction, and exposing tunable values. Austin and I both seem to agree on at least one that should be exposed.
Ah, okay, I had misunderstood the "explosion" that this was referring to - referring to the sudden increase in compaction time rather than the sudden increase in persistence latency. The reason I suggested a relatively low threshold for switching modes (eg a few TCP packets) was to ensure the mode switch happens early and isn't a rare case but rather something most wallets run into, and certainly any wallet dev will run into. Any forwarding node will obviously hit this in the first days of operation, so its really just something for mobile wallets, and even there you'll ~always hit it in testing if you're a developer testing your wallet, its just an easy optimization for those not.
I'm fine with making it configurable, of course, though I'm skeptical turning it off is ever the right answer, just something someone might want to do in development to ensure they handle the increased startup latency well.
Activity
0xZaddyy commentedon May 14, 2025
can i work on this sir?
TheBlueMatt commentedon May 15, 2025
Sure!
joostjager commentedon May 15, 2025
Is this significant if the channel monitor is small anyway?
TheBlueMatt commentedon May 15, 2025
If the storage layer is remote and high latency I think it could be? I guess in theory if we're really careful about the lookup logic (and the KVStore is async) we could do the loading in parallel (though its still a few more requests) but we'd still have to wait on compaction (without a background-compaction task running, which would require a generic
spawnmethod...). Seems much easier to just check the length and skip some code for the common case :)joostjager commentedon May 15, 2025
If I understand it correctly, this is special casing for channels at the beginning of their life and when they grow, the node will switch over to persisting updates and compaction anyway?
To me it isn't quite clear if this is really worth it. If the hit is significant, it is also a problem when the channel has outgrown the 'small' stage anyway?
TheBlueMatt commentedon May 19, 2025
Yes.
Its more a recognition of two very different cases - if you're running an "edge node" that is just a wallet making occasional payments, then you're likely to never hit the "large" stage, and thus avoiding the compaction overhead is a really nice optimization. If you're a larger node that is forwarding/processing many payments, you're very likely to hit the "large" stage and the compaction penalty is worth it to avoid the writes.
joostjager commentedon May 19, 2025
At what size would the "large" stage be entered then typically and how many htlcs/channel updates is that? A channel monitor of a few kb, that doesn't sound like all that many updates?
TheBlueMatt commentedon May 19, 2025
Yea, dunno, we'd have to figure that out. I imagine most mobile nodes probably make in the 100s to low 1000s of payments in their entire lifetime, probably fewer on a single channel once you consider splicing and the like. 10KiB or whatever should be plenty for 100 or 250 payments.
domZippilli commentedon Jun 18, 2025
It sounds like if you wanted to make this automatic, the metric you'd really want to evaluate to switch this behavior isn't so much monitor size, as one of these:
The monitor size is a decent reflection of the number of updates to the channel[1], but with no perception of time it's impossible to evaluate whether it's being stored by a tenured edge node, or a routing node. I think if you took time into account, perhaps by using the block delta between the funding tx and chain tip to estimate update frequency, you could make a more informed assessment.
However, I worry that automating the behavior selection is not really following the "principle of least astonishment."
I would think that routing nodes rarely move to the edge, and edge nodes rarely become routing nodes (more often, a routing node starts small and may appear like an edge). And furthermore, I know what my node is likely to be; especially if I'm a Lightning developer and managing this on behalf of users, such as in a mobile wallet.
For that matter, varying the behavior per channel seems to make node persistence more difficult to reason about. Different channels could persist different ways on my node, depending on a size threshold. Which means they can change without me doing anything. I would think that if the reason for variation is the use case, then one behavior is correct for all channels stored by the node.
In that light, I'd just leave this a configurable behavior, which I think it is now.
[1] I recognize that size is being used here to evaluate the storage write size, not the number of updates. But I think that is why the discussion is unclear. Compared to update count/frequency, it's much harder to know the storage configuration of a given node, and what the throughput/latency tradeoff is like.
TheBlueMatt commentedon Jun 18, 2025
I think the intent of the proposed change is to optimize for the edge-node case with remote storage. Even an edge node may make enough payments to get a monitor up to 10s of KiB in size, at which point network-level effects like TCP slowstart may dominate the actual network latency. For a "power-user" edge node, we really want to use the
MonitorUpdatingPersister, but paying the extra RTT cost of cleanup on load for every edge node is not a great tradeoff either.For a routing node, it still seems to me like a size-based threshold may be something they want, purely as it (very marginally) reduces IO throughput for under-utilized or new channels. Writing out updates (padded to 4KiB or more depending on the storage medium) and then consolidating when the whole monitor is only a few KiB isn't really the right tradeoff no matter what. Of course a routing node is expected to surpass the threshold very quickly, so it shouldn't really make a substantial difference, but it seems strictly better to write out full updates in this case than not.
Indeed, this does lead to a bit of behavior shift, but I think the important metrics wouldn't change - first of all, if you happened to look at storage right after compaction, the stored contents would be identical to a full monitor persistence so I wouldn't really say that this materially changes the way that logic would interact with the stored data (you already have to handle the case of having no in-flight updates!). It also shouldn't materially change the IO throughput or write count for any node, just a fairly marginal strict reduction for routing nodes with fresh channels.
amackillop commentedon Jun 19, 2025
For our probing node running ldk-node with network storage (EFS), at around 20,000 updates over the single channel the average probe duration starts to increase substantially. p75 starts to creep up after about 3,000.
TheBlueMatt commentedon Jun 30, 2025
Do y'all have any further thoughts here, @domZippilli or @amackillop?
domZippilli commentedon Jun 30, 2025
I see in the PR it's configurable. I think as long as that's the case, developers who don't want the variation in behavior can set the minimum size to
0.eta: Also, I'm still not sure I like that it varies across channels, rather than a consistent behavior on a node.
joostjager commentedon Jul 1, 2025
Perhaps wait for developers who do want/need the variation in behavior to show up and only then implement? I think the "principle of least astonishment" is worth considering.
tnull commentedon Jul 1, 2025
Well, we likely do want to enable MUP in LDK Node, especially when persisting vs. remote storage/VSS. The question is whether it's preferable to always use MUP, even for very small monitors. I'd be reluctant to expose a setting in LDK Node for this, as I don't think our users would have better insight into which way to go than we do.
TheBlueMatt commentedon Jul 1, 2025
FWIW I think the "principle of least astonishment" is served perfectly fine by changing the MUP to persist full monitors when they're small - there's no material difference in user-visible behavior between persisting full monitors and small ones, except the performance changes (i.e. we definitely can't persist full monitors that are huge). When persisting small monitors, its no difference from hitting the cleanup ID where we delete the updates anyway. Because of this I still think this change is strictly better than the current version.
joostjager commentedon Jul 2, 2025
That's clear. I was thinking of least astonishment in reasoning about and resolving potential problems. Basically what @domZippilli mentions in #3770 (comment).
In this case, I would define 'strictly better' as a performance increase without an increase in complexity.
amackillop commentedon Jul 4, 2025
It does seem to me like this enhanced MUP is preferable and should be used by default in LDK node. Otherwise it's ticking time bomb for poor user experience. As for exposing a setting, if you mean allowing people to choose which persister I'd say no. But I think allowing users to choose the monitor size where the behaviour change occurs makes sense given the various storage backends that only the user knows.
domZippilli commentedon Jul 7, 2025
I'll limit my comments to how this manifests for
ldk-nodesince that's come up here as well.I guess the thing that perplexes me is, at some threshold of monitor size, the bomb goes off anyway. I get that initial UX is the most important, but I don't see why you'd want (presumably, your most active) users to start getting a lot of storage latency after, say, a few months of usage. Like in some beautiful, increasingly likely future where someone is paying a lot of Square merchants with Lightning using a ldk-node powered wallet.
So, I still think it should be a binary decision with consistent behavior on either pole of the bit. You can do that with the threshold setting, like
0orusize::MAX, but as a compromise, I would consider an enum ofAlwaysWriteIncrementalUpdates(0)/StartIncrementalUpdatesAtSize(usize)/AlwaysWriteWholeMonitors(usize::MAX)to put it in terms of the resulting behavior, in very plain language.(eta: And probably you would make the number of pending updates something you can configure, too, at that point, if the reason incremental updates are an issue is listing and reading them)
(eta: not saying threshold should be a usize; it probably shouldn't. But it was last time I looked)
tnull commentedon Jul 8, 2025
I'm confused: the proposed change is to switch to MUP after a certain threshold, based on the assumption that for monitors below that threshold persisting full monitors is more efficient as you avoid the consolidation step. Why would switching to MUP after some time result in "users to start getting a lot of storage latency"?
domZippilli commentedon Jul 8, 2025
@tnull it's possible I'm confused. I was under the impression that the whole reason for doing this was a concern about the compaction leading to perceived latency for users.
From Joost:
Then from Matt:
I remember now that Joost, early on, replied with what I am trying to say here:
In other words, if this is a "ticking time bomb," then I think we are just adjusting the clock. Eventually the size threshold is crossed and the MUP's incremental writes + occasional compaction start happening. If that's bad at 1 byte, it's also bad at 10240 bytes. Thus, I still question if this is worth the cognitive overhead.
I would rather see a solution for compaction that happens out of the way of user interaction, but the comments also seemed to imply that making the compaction async or background was a large lift.
For what it's worth, if the concern in ldk-node is persisting with something like object storage hosting VSS, I think a channel size where E2E of writing the whole monitors wouldn't be comparable to writing incremental updates is probably much higher than 10KiB. Even on poor network, the bandwidth-delay product of that storage is likely to be high enough that E2E writing 100KiB or even 1MB would be very similar to the E2E to store 10KiB. Been a while since I did such profiling but it's on that order with object storage I have used the most.
amackillop commentedon Jul 8, 2025
The time bomb I'm referring to is with the default persister as it exists in LDK node today. As the monitors grow in size payment latency slowly increases to the point where it's unusable. And permanently so, not just sporadically as compaction happens. As a user this was surprising behaviour that would be good to eliminate with a better default
tnull commentedon Jul 9, 2025
Yes, a latency that only makes sense to avoid as long as it's not dominated by the latency stemming from persisting full monitor, i.e., under a certain size threshold, presumably.
Right, see Austin's post above: the 'ticking timebomb' for remote pesistence is not employing MUP at all, as monitors will eventually get larger and larger.
Yeah, I don't think this was what the concern was about, AFAIU.
Well, running regular compaction in the background could make sense, although it's orthogonal to this PR.
Well, that's actually the question, which can probably only be really answered by substantial modelling/profiling/simulations or real-world measurements: can we always expect that the latency is the dominant factor, even if (full) monitor sizes would get large? If yes, we shouldn't employ MUP at all. If not, where is the right threshold from which on we should switch to MUP?
domZippilli commentedon Jul 9, 2025
I think that's a confusing metaphor. I happen to have first-hand experience with exploding things, and writing a lot of whole monitors for every update. They're very different. Bombs change state very rapidly at a threshold (fuse), whereas the latency of whole monitors is a gradual worsening of conditions. Like broken AC, or that poor frog people keep trying to metaphorically cook.
The "enhanced MUP" incorporates a byte-size threshold, upon which it will instantly change the way it works, hopefully without surprising an engineer and creating much "blast radius," to extend the metaphor. As such, I don't think
ldk-nodeshould use it without leaking some of the abstraction, and exposing tunable values. Austin and I both seem to agree on at least one that should be exposed.TheBlueMatt commentedon Jul 17, 2025
Ah, okay, I had misunderstood the "explosion" that this was referring to - referring to the sudden increase in compaction time rather than the sudden increase in persistence latency. The reason I suggested a relatively low threshold for switching modes (eg a few TCP packets) was to ensure the mode switch happens early and isn't a rare case but rather something most wallets run into, and certainly any wallet dev will run into. Any forwarding node will obviously hit this in the first days of operation, so its really just something for mobile wallets, and even there you'll ~always hit it in testing if you're a developer testing your wallet, its just an easy optimization for those not.
I'm fine with making it configurable, of course, though I'm skeptical turning it off is ever the right answer, just something someone might want to do in development to ensure they handle the increased startup latency well.