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

Improve metadata handling #1148

Merged
merged 8 commits into from
Jan 20, 2023
Merged

Improve metadata handling #1148

merged 8 commits into from
Jan 20, 2023

Conversation

Kailai-Wang
Copy link
Contributor

@Kailai-Wang Kailai-Wang commented Jan 12, 2023

This PR tries to add a more generic parent trait NodeMetadataTrait that is bound by variant call indexes traits. With that, it can simplify the metadata extension by only extending NodeMetadataTrait, instead of modifying the trait bound across multiple files.

This PR also tried to solve #1145 initially. However, the compile type error persists, see the comment in app-libs/stf/src/trusted_call.rs. It's about the conflicts between standard convert and customized From implementation for StfError. We either have to specify the error type explicitly, or remove the customized implementation and use map_err directly. For now, we'll leave it as it is because it's actually the easiest way to address the compile error.

Something similar: https://stackoverflow.com/questions/37347311/how-is-there-a-conflicting-implementation-of-from-when-using-a-generic-type.

Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

""

core-primitives/node-api/metadata-provider/src/lib.rs Outdated Show resolved Hide resolved
@Kailai-Wang
Copy link
Contributor Author

Adjusted, please feel free to re-review it :)

@Kailai-Wang
Copy link
Contributor Author

some network issue in last CI: https://github.com/integritee-network/worker/actions/runs/3959520470

Unfortunately I don't have permissions to re-run it

Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your fixes! I only have one comment, and I would like to ask you to update the description of the PR, as some things were not implemented now.

Comment on lines +40 to +41
pub trait NodeMetadataTrait: TeerexCallIndexes + SidechainCallIndexes {}
impl<T: TeerexCallIndexes + SidechainCallIndexes> NodeMetadataTrait for T {}
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

Comment on lines 89 to 117

#[cfg(test)]
mod tests {
use super::*;
use std::assert_matches::assert_matches;

#[derive(Default)]
struct NodeMetadataMock;

impl NodeMetadataMock {
fn get_one(&self) -> u32 {
1
}
}
#[test]
fn get_from_meta_data_returns_error_if_not_set() {
let repo = NodeMetadataRepository::<NodeMetadataMock>::default();

assert_matches!(repo.get_from_metadata(|m| m.get_one()), Err(Error::MetadataNotSet));
}

#[test]
fn get_from_metadata_works() {
let repo = NodeMetadataRepository::<NodeMetadataMock>::default();
repo.set_metadata(NodeMetadataMock);

assert_eq!(1, repo.get_from_metadata(|m| m.get_one()).unwrap());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we maybe add this again now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we maybe add this again now?

Sure, just added it. To do it I had to loosen the trait bound, which I think is OK: it's fine to have the get_from_metadata interface for a wider type of T, but in the real logic we expect MetadataType to be bound by NodeMetadataTrait

@clangenb clangenb added A0-core Affects a core part B1-releasenotes C1-low 📌 Does not elevate a release containing this beyond "low priority" E0-breaksnothing labels Jan 20, 2023
@Kailai-Wang
Copy link
Contributor Author

Description updated! Please feel free to edit it if you prefer some other wordings/want to add extra information :)

@clangenb
Copy link
Contributor

Thank you very much, I slightly updated it!

@clangenb clangenb merged commit aeb3038 into integritee-network:master Jan 20, 2023
@Kailai-Wang Kailai-Wang deleted the 1145-explicit-type branch January 20, 2023 18:54
m-yahya pushed a commit to olisystems/BEST-Energy that referenced this pull request Feb 17, 2023
* try to use a more generic trait

* fix compile

* add more comments

* revert to old metadata getter

* minor adjustment

* make clippy happy

* add back the tests and loosen the trait bound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-core Affects a core part B1-releasenotes C1-low 📌 Does not elevate a release containing this beyond "low priority" E0-breaksnothing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants