Open KnowWhoami opened 1 month ago
@evanlinjin could this happen with the changes in #1514?
Thanks for writing up this ticket.
The intended usecase of bdk_file_store
is with BDK structures. With BDK, we never read after writing.
Maybe we can structure things to be more fool-proof. Need to think more on this.
Thanks @KnowWhoami. Maybe Store::open
should always seek the file cursor to EOF? If this is truly a bug then I'm surprised all the tests and examples work how we expect using the file store
If this is truly a bug then I'm surprised all the tests and examples work how we expect using the file store
- while that's because in tests which considers opening the pre-existing Store -> we often run
aggregate_changesets
api that internally calls theiter_changesets
api's which iterates over the stored changesets in order to collect all the stored changesets but it also changes the file pointer of Store and thus moves it to the end of file.
The intended usecase of bdk_file_store is with BDK structures. With BDK, we never read after writing. Maybe we can structure things to be more fool-proof. Need to think more on this.
Yeah that's true, BDK wallet Api's don't care much about internal working of database , they just need to read the db to get required changesets and append's new one if found any. That's it.
But since bdk_file_store
is mainly developed for the downstream users so that they can directly used it in their BDK based wallets.
So this bug should be taken into consideration.
Describe the bug
let's say a
Store
instance initially containschangeset1
stored in its file. https://github.com/bitcoindevkit/bdk/blob/d99b3ef4b449a5c7b8facf04db3cb9be829a0ac1/crates/file_store/src/store.rs#L14Then after opening the store instance using
Store::open
and appending a new changeset (changeset2
) usingappend_changeset
, the store will only containchangeset2
, notchangeset1 + changeset2
.https://github.com/bitcoindevkit/bdk/blob/d99b3ef4b449a5c7b8facf04db3cb9be829a0ac1/crates/file_store/src/store.rs#L73 https://github.com/bitcoindevkit/bdk/blob/d99b3ef4b449a5c7b8facf04db3cb9be829a0ac1/crates/file_store/src/store.rs#L162
To Reproduce
Expected behavior
store
-> its file pointer must be set to end.Build environment
Fedora 37
rustc 1.81.0-nightly (f21554f7f 2024-06-08)
nightly-2024-06-09-x86_64-unknown-linux-gnu