Skip to content
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

Add separate identity-iota-core, identity-account-storage crates #693

Merged
merged 27 commits into from
Mar 14, 2022

Conversation

HenriqueNogara
Copy link
Contributor

@HenriqueNogara HenriqueNogara commented Mar 7, 2022

Description of change

Split identity-iota and identity-account into identity-iota-core and identity-account-core.

Links to any relevant issues

#669

Type of change

  • Bug fix (a non-breaking change which fixes an issue)
  • Enhancement (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Fix

How the change has been tested

All existing tests are still present.

Change checklist

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@HenriqueNogara HenriqueNogara marked this pull request as ready for review March 7, 2022 21:50
@HenriqueNogara HenriqueNogara added Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. Chore Tedious, typically non-functional change labels Mar 7, 2022
Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of the overall approach but there are still dependencies that can be removed like iota-client in identity-iota-core and we should discuss the finer-details.

  1. I think we have to delay this PR until both Update Stronghold #691 and Overhaul CredentialValidator, add PresentationValidator #599 have been merged unfortunately, since they both alter many of the files moved in this PR. I do not think the merge conflicts would be easily resolvable without losing changes otherwise.

  2. We should decide whether to keep the iota_core and account_core modules in the top-level identity crate or re-export their types under the iota and account modules respectively. I am leaning towards re-exporting the types at the top-level for convenience to developers unless it doesn't make sense (e.g. the documentation and doc-comments still refer to those types under iota_core). We should probably not re-export those types in the sub-crates, however, i.e. do not re-export identity_iota_core::IotaDocument from identity_iota.

  3. There are some dependencies like iota-client which can be removed/replaced with bee-message. Edit: if necessary we can re-export MessageId from identity-iota-core to avoid having to add the bee-message dependency anywhere else.

  4. Error handling is a bit tricky since errors are just bubbled up from the sub-crates now. It's probably fine to leave it as-is for this PR? Not sure.

bindings/wasm/src/did/wasm_document_metadata.rs Outdated Show resolved Hide resolved
identity-account-core/Cargo.toml Outdated Show resolved Hide resolved
identity/Cargo.toml Outdated Show resolved Hide resolved
identity/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines 104 to 116
#[cfg(feature = "account")]
#[cfg_attr(docsrs, doc(cfg(feature = "account")))]
pub mod account_core {
//! Storage Trait and Types definitions

pub use identity_account_core::crypto::*;
pub use identity_account_core::error::*;
pub use identity_account_core::identity::*;
pub use identity_account_core::storage::*;
pub use identity_account_core::stronghold::*;
pub use identity_account_core::types::*;
pub use identity_account_core::utils::*;
}
Copy link
Contributor

@cycraig cycraig Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: I think we should re-export types from the _core crates under the non-core namespace (unless there are conflicts). That is, move all these pub use identity_account_core lines under pub mod account. Similarly for identity_iota_core and identity_iota.

All this does is simplify imports and allow us to sub-divide crates as much as we want without causing breaking changes to the external interface, which I think is desirable. The Error and Result instances are a problem, I'm not sure if we want to adopt a convention of prefixing the crate name onto those like in this PR where e.g. IotaCoreError is used instead of just Error? Not sure, need to decide and implement the convention everywhere.

Copy link
Contributor

@cycraig cycraig Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convenience of condensed imports may not be worth any confusion, just to be clear. Edit: weighed against the benefit of not causing breaking changes when we re-organise internal crates, of course, assuming we consider identity the external API and not the constituent crates as well.

Copy link
Contributor

@olivereanderson olivereanderson Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I agree with re-exporting types from _core crates under the non-core namespace in identity because consumers of the main identity are likely not interested in how it is organized internally. This same principle also applies to errors hence I would prefer to avoid variants/names like IotaCoreError if possible.

I am less sure about how much re-exports from sub(-sub) crates to unified modules in identity protect us against introducing breaking changes in the external API upon further sub-division however. The types in our public API need to be interchangeable between minor versions, but cargo may not be able to "understand" that the types are actually still the same when their origin has changed from one sub crate to another. It might be possible to help express the compatibility of types between minor versions by using something like the semver trick however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to avoid variants/names like IotaCoreError if possible.

The problem is that we cannot export two Error enums of the same name under identity::iota from identity_iota and identity_iota_core without changing the name of one or the other.

If we cannot avoid breaking changes by re-exporting types then I am somewhat less in favour of re-exporting them. The semver trick is fascinating but we should hopefully not plan to use it as a crutch.

identity-iota-core/Cargo.toml Outdated Show resolved Hide resolved
identity-did/src/document/core_document.rs Outdated Show resolved Hide resolved
identity-account/src/updates/update.rs Outdated Show resolved Hide resolved
identity-account/src/updates/update.rs Outdated Show resolved Hide resolved
identity-account-core/src/error.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@cycraig cycraig changed the title Chore/split identity iota Add identity-iota-core, identity-account-storage crates Mar 14, 2022
Copy link
Contributor

@cycraig cycraig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! I pushed some commits to fix the last few comments, hopefully without causing too many merge conflicts for the epic branch.

@HenriqueNogara HenriqueNogara merged commit 34bb77a into dev Mar 14, 2022
@HenriqueNogara HenriqueNogara deleted the chore/split-identity-iota branch March 14, 2022 12:45
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has been merged now, but: looks good to me. Just one comment unrelated to the split.

@@ -48,7 +49,7 @@ features = ["blake2b"]

[dev-dependencies]
proptest = { version = "1.0.0", default-features = false, features = ["std"] }
tokio = { version = "1.15", default-features = false, features = ["macros"] }
tokio = { version = "1.17.0", default-features = false, features = ["macros"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually specify the highest possible version if we don't require it? To maximize compatibility within our crates and for our users, shouldn't we specify the lowest possible version that still satisfies our needs?

Copy link
Contributor

@cycraig cycraig Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure of the circumstances in which we should not update to the latest version of Rust dependencies, particularly when they are semver compatible (edit: since as a library we're pulling in the latest compatible version automatically anyway).

In this case I found it prudent specifically because tokio 1.17.0 contains fixes to avoid panics.

I'll keep it in mind that we may not want to update all dependencies for compatibility reasons, especially if those updates contain API-breaking changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no such justification for strum, however. I just wanted the latest version (and forgot to update it everywhere).

@cycraig cycraig changed the title Add identity-iota-core, identity-account-storage crates Add separate identity-iota-core, identity-account-storage crates Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change A change to the API that requires a major release. Part of "Changed" section in changelog Chore Tedious, typically non-functional change Rust Related to the core Rust code. Becomes part of the Rust changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants