-
Notifications
You must be signed in to change notification settings - Fork 392
feat!: Add #[non_exhaustive] to ChangeSet structs #1980
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
base: master
Are you sure you want to change the base?
feat!: Add #[non_exhaustive] to ChangeSet structs #1980
Conversation
The persistence test suite will make this work. It's unfortunate we didn't think about that solution earlier. |
c1a34a8
to
49e140f
Compare
…in_txout, local_chain Add #[non_exhaustive] attribute to the ChangeSet structs to prevent downstream crates from exhaustively matching or constructing instances using struct literal syntax, allowing future additions without breaking compatibility. The change improves forward compatibility by allowing new fields to be added without breaking downstream code in future releases.
49e140f
to
e643f83
Compare
I fixed the tests, I don't think they look too bad with the non-exhaustive change sets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wallet::ChangeSet
struct used to be non_exhaustive
, which was reverted after I had argued in #1591 that it shouldn't be.
Why do we now think the sub-changesets should be non_exhaustive
? To restate my point: having your code break is a good thing if you're handling the changeset types manually, because then you're forced to update your persistence. If you force a non-breaking API via non_exhaustive
, users could miss persisting important fields after they had been added.
Ah ok I completely forgot we discussed this last year. It seems we have conflicting goals:
I think a part of the problem is we're trying to support a persistence API that is tightly coupled to our ChangeSet structs. I feel like there should be a way to support both goals. Possibly with some sort of persistence store traits or persistence conformance test suite, maybe both. But I'll do some more thinking on it, and open to any other ideas. |
What you describe here is a BDK-internal data model/serialization logic, which was decided against some time ago. But yeah, if that is the conclusion, I'd be very happy about that outcome (especially if it considers forwards compat.). ;) |
Description
Add #[non_exhaustive] to ChangeSet structs in tx_graph, keychain_txout, local_chain.
Add #[non_exhaustive] attribute to the ChangeSet structs to prevent downstream crates from exhaustively matching or constructing instances using struct literal syntax, allowing future additions without breaking compatibility.
The change improves forward compatibility by allowing new fields to be added without breaking downstream code in future releases.
Notes to the reviewers
The motivation for this is to prevent breaking changes in these structs but will still require downstream persistence crates to implement and support any new fields added.
@ValuedMammal suggested creating a persistence test suite which I think is a great idea but should be done in a separate PR.
Changelog notice
Breaking Changes
#[non_exhaustive]
attribute toChangeSet
structs in tx_graph, keychain_txout, local_chain modules...
) patterns.Checklists
All Submissions:
cargo +nightly fmt
andcargo clippy
before committingNew Features:
Bugfixes: