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.
Description
The
Store::open
method doesn't recovers the previousStore
state saved in the file and emplaces the file pointer just after the magic bytes prefix, this later is agravated byStore::append_changeset
which sets the file pointer after the last written changeset. The combination of both causes the lost of any previous changeset there may have been in the file.Is natural to think this shouldn't be the expected behavior, as @KnowWhoami pointed out in #1517, and the
Store
should recover the previous changesets stored in the file store.The approach proposed in #1632 triggered a discussion about more changes in
Store
, which motivated the current refactor.Besides the fix for #1517, the following methods have been changed/renamed/repurposed in Store:
create
: create file and retrieve store, if exists fail.load
: load changesets from file, aggregate them and return aggregated changeset andStore
. If there are problems with decoding, fail.dump
: aggregate all changesets and return them.load_or_create
: try load or fallback to create.Fixes #1517.
Overrides #1632.
Notes to the reviewers
Load return type is
Result<(Option<C>, Store), StoreErrorWithDump>
to allow methods which doesn't useWalletPersister
to get the aggregated changeset right away.Dump is kept to allow
WalletPersister::initialize
method to retrieve the aggregated changeset without forcing the inclusion of the additional parameters needed bystore::load
to the trait, which would also affect therusqlite
implementation.Changelog notice
Added:
StoreError
enum, which includesIo
,Bincode
andInvalidMagicBytes
.README
forfile store
.Changed:
Store::create_new
toStore::create
, with new return type:Result<Self, StoreError>
Store::open
toStore::load
, with new return type:Result<(Option<C>, Self), StoreErrorWithDump<C>>
Store::open_or_create
toStore::load_or_create
, with new return type:Result<(Option<C>, Self), StoreErrorWithDump<C>>
Store::aggregate_changesets
toStore::dump
, with new return type:Result<Option<C>, StoreErrorWithDump<C>>
FileError
toStoreError
AggregateChangesetsError
toStoreErrorWithDump
, which now can include all the variants ofStoreError
in the error field.Deleted:
IterError
deleted.Checklists
All Submissions:
I've signed all my commitsI followed the contribution guidelinesI rancargo fmt
andcargo clippy
before committingNew Features:
I've added tests for the new featureI've added docs for the new featureBugfixes:
This pull request breaks the existing APII've added tests to reproduce the issue which are now passingI'm linking the issue being fixed by this PR