[WIP] Add facility to assure backwards compatibility for objects that need to remain backwards compatibility#75
Draft
derekpierre wants to merge 1 commit intonucypher:mainfrom
Draft
Conversation
…objects that need to remain backwards compatible for the long-term eg. objects that get persisted to some type of storage.
7 tasks
Codecov Report
@@ Coverage Diff @@
## main #75 +/- ##
==========================================
+ Coverage 21.22% 21.48% +0.26%
==========================================
Files 16 16
Lines 3176 3188 +12
==========================================
+ Hits 674 685 +11
- Misses 2502 2503 +1
|
Contributor
|
I like this proposal as-it-is, I think it solves our short & medium-term needs. For the long-term, I think there could be something clever we could do with Rust traits and Adopter pattern to enforce backward compatibility (or lack thereof) for protocol objects. See the rough sketch below: // Assuming ProtocolObjectV1 and ProtocolObjectV2 are defined somewhere
// Error that may occur during migration
pub struct MigrationError;
// Trait for objects that can be migrated to another version
pub trait Migratable<T> {
fn migrate(&self) -> Result<T, MigrationError>;
}
// Implement Migratable for ProtocolObjectV1 to ProtocolObjectV2
impl Migratable<ProtocolObjectV2> for ProtocolObjectV1 {
fn migrate(&self) -> Result<ProtocolObjectV2, MigrationError> {
// Write actual migration logic
Ok(...)
}
}
// "Seal" that stops external code from implementing the ImmutableProtocolObject trait
trait ImmutableProtocolObjectSealed {}
// Trait for objects that shouldn't be migrated
pub trait ImmutableProtocolObject: ImmutableProtocolObjectSealed {}
// Implement the "seal" for ProtocolObjectV1
impl ImmutableProtocolObjectSealed for ProtocolObjectV1 {}
// We also should implement ImmutableProtocolObject for ProtocolObjectV1
impl ImmutableProtocolObject for ProtocolObjectV1 {}With this code, rules about backward compatibility would be checked and enforced by a compiler. If it looks interesting, I can create a stand-alone PoC at some point. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type of PR:
Required reviews:
What this does:
We need a facility to assure that some objects remain backwards compatible. Examples of where this is needed is for protocol objects that may be persisted and then processed by later versions of the
nucypher-corelibrary eg. MessageKits i.e. encrypted data. These protocol types need to be "perpetually" backwards compatible. If any backwards incompatible changes are needed for types that are supposed to always remain backwards compatible, then a brand new type should be created/added.There are legacy protocol object types that have already made major version changes that should have remained backwards compatible; it's possible that it was versioned during development but earlier versions were never released.
Existing legacy objects that probably need to be specified as "must remain backwards compatible" on such a facility is established:
Issues fixed/closed:
Why it's needed:
Notes for reviewers: