Skip to content

Add get origin client function#1235

Closed
fewensa wants to merge 6 commits intoparitytech:masterfrom
darwinia-network:message-client-origin
Closed

Add get origin client function#1235
fewensa wants to merge 6 commits intoparitytech:masterfrom
darwinia-network:message-client-origin

Conversation

@fewensa
Copy link
Copy Markdown
Contributor

@fewensa fewensa commented Dec 1, 2021

In this way, a healthy original client can be obtained, Only use Any to return, because there is no relay-client-substrate package dependent on this library.
This is not necessarily a good method, but it is indeed a solution.

After do that, If we create a customized relay strategy. we can get an original client from relay_reference

let client: &relay_client_substrate::Client<RialtoChain> = relay_reference.lane_source_client.origin_client().downcast_ref().unwrap();

In doing so, the biggest advantage is that third-party applications can get a client that will not lose the connection, because this has been processed in the message-lane-loop .

@svyatonik
Copy link
Copy Markdown
Contributor

In doing so, the biggest advantage is that third-party applications can get a client that will not lose the connection, because this has been processed in the message-lane-loop .

Is it the only advantage? I assume that you're creating strategy using initial clients and then if disconnect occurs, loop is able to recover and your strategy isn't, right? Then imo the simplest way is to impl TargetClient/SourceClient for some struct like that (could probably be rewritten without Mutexes, but the idea is in common shared data of the cloneable client):

struct SharedSourceClient {
  shared_data: Arc<Mutex<SharedSourceClientData>>,
}

struct SharedSourceClientData {
  substrate_client: relay_substrate_client::Client<YourChain>,
}

impl RelayClient for SharedSourceClient {
  fn reconnect() {
    self.shared_data.lock().await.client.reconnect();
  }
}

Then you may simply return errors from your strategy and loop will do a reconnect.

If you have other usages for this origin_client, please comment. Thanks!

@fewensa
Copy link
Copy Markdown
Contributor Author

fewensa commented Dec 3, 2021

Yes, The purpose of adding this method is to get the client. I will try the method your suggestion.

@fewensa fewensa closed this Dec 10, 2021
@fewensa fewensa deleted the message-client-origin branch February 18, 2022 09:08
svyatonik pushed a commit that referenced this pull request Jul 17, 2023
Bumps [log](https://github.com/rust-lang/log) from 0.4.16 to 0.4.17.
- [Release notes](https://github.com/rust-lang/log/releases)
- [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/log/commits/0.4.17)

---
updated-dependencies:
- dependency-name: log
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants