Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

staking miner: reuse ws conn for remote-ext #4849

Merged
merged 30 commits into from
Feb 18, 2022

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Feb 4, 2022

Builds on top of #4716

It passes the already established WebSocket connection down to remote externalities to re-use the already established connection for that part.

In addition this PR introduces a SharedRpcClient abstraction with a RPC API with macros to make things a little bit cleaner and easier to understand I hope.

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Feb 4, 2022
@niklasad1 niklasad1 added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Feb 4, 2022
@emostov
Copy link
Contributor

emostov commented Feb 4, 2022

From what I understand the changes lgtm. I looked at the diff via https://github.com/paritytech/polkadot/compare/na-staking-miner-playground..na-staking-miner-reuse-ws-conn#

To make sure I understand please let me know if the following is correct:

&*client => deref's to the inner value and then we get a simple pointer it. This is used when the compiler knows client won't get dropped before the function it is getting passed too executes.

client.clone() => gives us a new Arc, increasing the reference counter. We need to use this when we spawn a new thread that is not guaranteed to finish before client goes out of scope in the current function or we need to create some struct (like Ext) that will need to have a thread safe ref to the client

@niklasad1
Copy link
Member Author

niklasad1 commented Feb 4, 2022

You got everything correct Zeke again :)

Yeah, we could wrap Arc<WsClient> in a new type and impl Deref trait to get rid of that horrible syntax

@kianenigma kianenigma self-requested a review February 15, 2022 09:54

/// Dry run an extrinsic at a given block. Return SCALE encoded ApplyExtrinsicResult.
#[method(name = "system_dryRun", aliases = ["system_dryRunAt"])]
async fn dry_run(&self, extrinsic: &Bytes, at: Option<&Hash>) -> RpcResult<Bytes>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Hash is Copy and making it a ref doesn't make sense

Copy link
Member Author

Choose a reason for hiding this comment

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

fair enough, it was more to have a uniform API since all other methods takes that params by ref but sure I can change that.

#[derive(Clone, Debug)]
pub(crate) struct SharedRpcClient(Arc<WsClient>);

impl Deref for SharedRpcClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

noice

Ok(Self(Arc::new(client)))
}

/// Get the storage item.
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 expect this doc to explain how this is different than self.storage. In the same spirit, I would name it decode_storage or get_storage_decoded.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

very nice refactors, appreciated!

@niklasad1
Copy link
Member Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 75dd6c7 into master Feb 18, 2022
@paritytech-processbot paritytech-processbot bot deleted the na-staking-miner-reuse-ws-conn branch February 18, 2022 11:41
ordian added a commit that referenced this pull request Feb 22, 2022
* master: (27 commits)
  Bump `tokio` to 1.17.0 (#4965)
  bump transaction_version (#4956)
  Bump tracing-subscriber from 0.3.8 to 0.3.9 (#4954)
  staking miner: reuse ws conn for remote-ext (#4849)
  Revert "collator-protocol: short-term fixes for connectivity (#4640)" (#4914)
  Bump tracing from 0.1.30 to 0.1.31 (#4941)
  Better spam slots handling (#4845)
  Bump proc-macro-crate from 1.1.0 to 1.1.2 (#4936)
  corrected paras code validation event comments (#4932)
  Companion for refactor election score #10834 (#4927)
  Companion CI: Make sure to pass the update crates properly (#4928)
  update digest to v0.10.2 (#4907)
  Companion for #10832 (#4918)
  Companion for `Remove u32_trait` (#4920)
  Bump serde_json from 1.0.78 to 1.0.79 (#4916)
  Bump rand from 0.8.4 to 0.8.5 (#4917)
  Remove stale migrations post 9.16 release (#4848)
  Add proxy type for Kappa Sigma Mu (#4851)
  Baseline weights for `force_apply_min_commission` (#4896)
  Allow two Parachains to swap (#4772)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants