-
Notifications
You must be signed in to change notification settings - Fork 312
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
Introduce TLV for bdk_file_store #1499
Comments
Okay technically we don't need the EncodingEncode each element as:
Where
|
I did a lot of thinking about this. Backwards compat/// Persists an append-only list of changesets (`C`) to a single file.
#[derive(Debug)]
pub struct Store<C, V = C> {
magic_len: usize,
db_file: File,
marker: PhantomData<(V, C)>,
}
impl<V, C> Store<V, C>
where
C: Into<V> + Append,
V: Into<C> + serde::Serialize + serde::de::DeserializeOwned, As you can see there is a new type parameter So in practice you'd have: pub struct MyChangeSetV0_17_0 {... }
pub struct MyChangeSet { ... }
// serde serde etc
pub enum VersionedMyChangeSet {
V0_17_0(MyChangeSetV0_17_0)
Current(MyChangeSet)
}
impl From<MyChangeSet> for VersionedMyChangeSet {
fn from(value: VersionedMyChangeSet) -> MyChangeSet {
// do the obvious
}
} Then you'd set If we do have forwards compatibility we need a length prefix. This can be done by just encoding each entry into a This makes backwards compat optional and straight forward to achieve. You just have to nudge users to create this enum. For wallet we can create When making new changesets for existing types (which for the record I actually think we can avoid) we keep the old one around of course and put Forwards CompatTo do forwards compat we just write the length of each entry before we serialize it. This can be done in a couple of ways. e.g. https://docs.rs/bincode/latest/bincode/config/trait.Options.html#method.serialized_size or by just serialzing to a Now that we have the length, when we decode an entry to a So this gives you forwards compat as long as whatever the future For what it's worth, I discussed with Evan about things we had as breaking changes coming up or speculated and none of them actually were compatible with forwards compat (none of them would be just adding an optional field). |
I agree with @LLFourn's suggestion. I think someone should take this ticket on. |
I later realized the "Forwards Compat" bit is not totally sound. Before trying to do a decode on a higher versioned entry you need to actually check it is higher versioned not just assume so because it failed. It could be a corrupted lower version entry or something else has gone wrong. This means we'd need to know the current version. It's actually kinda possible to do this automatically with bincode if you require |
I would like to give it a try. |
@nymius I've assigned this to you, thanks for jumping in to take this on. |
Can we push this TLV work for the This would let the team focus on #1496 and #1498 changes and we'd only deliver backward compatibility for the beta with |
I discussed this with @evanlinjin and decided this issue can be moved to the 1.0.0-beta milestone. We just need to warn beta users that if they want backward data file compatibility they'll need to use the |
I'd like to know what @nymius and @evanlinjin actually think about whether it's a good idea to actually do this. Before I speculated about how to this but didn't really consider too deeply whether or not it's actually a good idea. We could just leave |
I didn't considered the legitimacy of this as a real production case either. It seemed a good case just for the comments on #1103. |
My 2 sats on this is that file store is 1. a good as a simple example, 2. only really needs to show backward compatibility (not forward), and 3. isn't needed for the 1.0 final release so should be moved out of the 1.0.0-beta milestone. I do think most production apps will use sqlite for single user apps (ie mobile), or sqlx for larger multi-user apps (on servers). In my experience SQL stores are reliable and most devs know how to work with them. Unless someone has a very limited resources device that needs to tightly control dependencies I don't think a flat file based persister will be a very popular wallet data store option. But still as an example and inspiration for anyone who does need a custom data store it's good to have. |
Let's close this for now then. Please see #1661 which documents the state of |
Sub-task for #1103
The text was updated successfully, but these errors were encountered: