-
Notifications
You must be signed in to change notification settings - Fork 47
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
Improve metadata handling #1148
Conversation
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.
""
Adjusted, please feel free to re-review it :) |
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 |
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.
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.
pub trait NodeMetadataTrait: TeerexCallIndexes + SidechainCallIndexes {} | ||
impl<T: TeerexCallIndexes + SidechainCallIndexes> NodeMetadataTrait for T {} |
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.
🥳
|
||
#[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()); | ||
} | ||
} |
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.
Can we maybe add this again now?
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.
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
Description updated! Please feel free to edit it if you prefer some other wordings/want to add extra information :) |
Thank you very much, I slightly updated it! |
* 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
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 extendingNodeMetadataTrait
, 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 customizedFrom
implementation forStfError
. We either have to specify the error type explicitly, or remove the customized implementation and usemap_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.