-
Notifications
You must be signed in to change notification settings - Fork 382
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
lightning-block-sync
: Implement serialization logic for header Cache
types
#3600
base: main
Are you sure you want to change the base?
Conversation
bed21f8
to
a403bf9
Compare
During syncing, `lightning-block-sync` populates as a block header `Cache` that is crucial to be able to disconnected previously-connected headers cleanly in case of a reorg. Moreover, the `Cache` can have performance benefits as subsequently synced listeners might not necessarily need to lookup all headers again from the chain source. While this `Cache` is ~crucial to the clean operation of `lightning-block-sync`, it was previously not possible to persist it to disk due to an absence of serialization logic implementations for the corresponding sub-types. Here, we do just that (Implement said serialization logic) to allow users to persist the `Cache`. Making use of the serialization logic for all the sub-types, we also switch the `UnboundedCache` type to be a newtype wrapper around a `HashMap` (rather than a straight typedef) and implement TLV-based serialization logic on it.
a403bf9
to
0207228
Compare
I'm not sure I quite understand the desire to serialize this. We use it to keep track of things as we fetch them, but generally shouldn't ever need the cache entries after we connect the blocks (and persist the things that we connected the blocks to). |
Talked with @jkczyz offline about this: AFAIU, we use the cache to keep headers around that might have been connected to another fork. Say we synced a listener up to a certain tip. If it now goes offline, and a reorg happens in the meantime, Additionally, it might bring quite some performance improvements for |
Alternatively (or in addition), we could manually update the cache at each iteration during initialization from the |
This is true if you switch to a new bitcoind, but AFAIU using the same bitcoind (data dir) will always provide us with the missing block (headers).
This seems like a bug we could fix, another way, no? |
I guess we could make the cache append only, but that's ~orthogonal to this PR, IMO.
Right, so if we want to be able to safely handle switiching chain sources, we need to at least support a minimal persisted cache (in LDK Node we restrict it to 100 entries currently, but could even get away with ~
I don't think it's a bug per se. We need to walk for each listener separately to make sure we find the connection points reliably. It would be nice to make use of caching during it though. |
If we want to support this, IMO its pretty weird to require the cache be persisted by a downstream project, rather if we need it (we should check whether we can just remove the header in the disconnect call and not worry about it, I think we probably can) and then store a few block headers/hashes going back in the listeners themselves, cause they're the things responsible for communicating their current chain location, no? |
On LDK Node's end it would be nice to maintain the cache, also as a performance optimization. And IMO we can leave it to the user to decide if/how much data they want to persist. In any case, I'm not sure why we wouldn't want to allow for the cache to be persisted? |
I'm a bit confused, though, the cache should really only be relevant when we're reorging, which shouldn't be common? Why is it a material performance difference? |
During syncing,
lightning-block-sync
populates as a block headerCache
that is crucial to be able to disconnected previously-connected headers cleanly in case of a reorg. Moreover, theCache
can have performance benefits as subsequently synced listeners might not necessarily need to lookup all headers again from the chain source.While this
Cache
is ~crucial to the clean operation oflightning-block-sync
, it was previously not possible to persist it to disk due to an absence of serialization logic implementations for the corresponding sub-types. Here, we do just that (Implement said serialization logic) to allow users to persist theCache
.Making use of the serialization logic for all the sub-types, we also switch the
UnboundedCache
type to be a newtype wrapper around aHashMap
(rather than a straight typedef) and implement TLV-based serialization logic on it.