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

staking miner: spawn separate task for each block #4716

Merged
merged 14 commits into from
Feb 7, 2022

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Jan 13, 2022

This PR makes a couple of optimizations:

  • move the extrinsic construction and remote-externalities (view) per block into a separate tokio task.
  • handle JsonRpseeError::RestartNeeded explicitly if that occurs the connection is closed and the client is useless after that, except some buffered responses on subscriptions but it doesn't help because we need the account state (via RPC calls) which will fail.
  • update jsonrpsee

However, I haven't been able to quantify that the optimizations compared to current one so you know, so it's just my hunch that it and headers should be never be missed because of buffer subscriptions gets full and dropped.

@github-actions github-actions bot added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jan 13, 2022
@niklasad1 niklasad1 changed the title [WIP]: staking miner: spawn submit_and_watch xt in separate task. staking miner: spawn submit_and_watch xt in separate task. Jan 24, 2022
@niklasad1 niklasad1 added 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. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jan 24, 2022
@niklasad1 niklasad1 marked this pull request as ready for review January 24, 2022 11:01
vec![],
).await?;
// grab an externalities without staking, just the election snapshot.
let mut ext = match crate::create_election_ext::<Runtime, Block>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Beyond the scope of this PR, but wondering if it makes sense to parallize check_versions & ensure_signed_phase & create_election_ext - so we can start creating the election_ext immediatley and if its not the correct version or the signed phase we can send a message to the thread of create_election_ext to stop?

Copy link
Member Author

@niklasad1 niklasad1 Jan 24, 2022

Choose a reason for hiding this comment

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

Should be possible but the lowest hanging fruit is to re-use the existing ws connection and to pass Arc<WsClient> into remote ext instead of creating a new connection for each create_election_ext I think.

My hunch is that it takes a couple of seconds to establish a new ws connection.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah makes sense - what you are saying might be a good issue for interviewing as well cc @kianenigma


if ensure_no_previous_solution::<Runtime, Block>(&mut ext, &signer.account).await.is_err() {
log::debug!(target: LOG_TARGET, "We already have a solution in this phase, skipping.");
return;
Copy link
Contributor

@emostov emostov Jan 24, 2022

Choose a reason for hiding this comment

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

In the same vein as my note above, maybe ensure_no_previous_solution & mine_with & get_account_info could be parralized to so we start mining as soon as we have the ext and then stop if there already is a solution?

Copy link
Contributor

@emostov emostov left a comment

Choose a reason for hiding this comment

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

lgtm

@niklasad1 niklasad1 changed the title staking miner: spawn submit_and_watch xt in separate task. staking miner: spawn separate task for each block Jan 25, 2022
@@ -59,3 +59,10 @@ docker run --rm -it \
-e URI=wss://your-node:9944 \
staking-miner dry-run
```

### Test locally
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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.

Looks broadly good to me. If tested and works in westend, then can merge ahead. Thanks!

@kianenigma
Copy link
Contributor

However, I haven't been able to quantify that the optimizations compared to current one so you know, so it's just my hunch that it and headers should be never be missed because of buffer subscriptions gets full and dropped.

All in all, I would argue that for now we don't necessarily need to care too much about optimisations etc. At this point, my main concern would be for the code to be maintainable. The two main steps to achieve this are:

  1. Make it independent of the runtime (which is our next objective)
  2. Keep the code relatively simple and clean (which I can say IMO is and this PR also helps).

@niklasad1
Copy link
Member Author

Yeah, you made that clear. Yes tested both on the local dev chain and westend but not remember which commit of this I tested.

I realized that the logs from jsonrpsee doesn't work anymore here because jsonrpsee migrated to tracing should fine to skip for now?

@niklasad1 niklasad1 merged commit 666f317 into master Feb 7, 2022
@niklasad1 niklasad1 deleted the na-staking-miner-playground branch February 7, 2022 10:21
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.

3 participants