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

Allow sub-contexts to have different Error types with functions to inject errors into Self::Error #2844

Closed
5 tasks
soareschen opened this issue Nov 8, 2022 · 0 comments
Assignees
Labels
I: refactoring O: relayer-next Objective: work toward relayer v2
Milestone

Comments

@soareschen
Copy link
Contributor

Summary

Currently, context traits containing sub-contexts, such as HasRuntime and HasRelayTypes, require the sub-contexts such as Self::Runtime, Self::SrcChain, and Self::DstChain to have the same Error associated type as Self::Error. This was done initially for easier understanding of the code.

However, it can be restrictive to require all contexts to share the same concrete error type, especially if the concrete contexts are defined in different crates. As an example, to workaround having a common Error type, the concrete runtime context TokioRuntimeContext is parameterized with a generic Error type, so that it can set its Error associated type to be the same as the Error type in the concrete chain or relay contexts.

A better design would be to allow each contexts to have their own abstract Error types, and require injection functions to inject errors into the parent context. For example, the HasRuntime trait can be redefined as follows:

pub trait HasRuntime: InjectError<<Self::Runtime as HasError>::Error> {
    type Runtime: HasError;

    fn runtime(&self) -> &Self::Runtime;
}

When the parent context calls any methods from the sub-context, they can then use Self::inject_error to inject error types like Self::Runtime::Error into Self::Error.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate milestone (priority) applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: refactoring O: relayer-next Objective: work toward relayer v2
Projects
Archived in project
Development

No branches or pull requests

1 participant