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

staking miner: Check the queue one last time before submission #4819

Merged
merged 37 commits into from
Mar 4, 2022

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Jan 31, 2022

Builds on #4716

Closing #3740

@github-actions github-actions bot added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jan 31, 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 Feb 4, 2022
@niklasad1 niklasad1 changed the title [WIP]: staking miner: Check the queue one last time before submission staking miner: Check the queue one last time before submission Feb 4, 2022
@niklasad1 niklasad1 marked this pull request as ready for review February 4, 2022 16:50
@niklasad1
Copy link
Member Author

@kianenigma can you take another look at this? I tried to address your grumbles and I hope I got it right this time

.map_err::<Error<T>, _>(Into::into)?
.unwrap_or_default();

for (_score, idx) in indices {
Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda wanted to rewrite this with .any() but I realized async code in closures it still a PITA right?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's possible but then we need convert the futures to a stream or batch them together.

Something like FuturesOrdered or JSON-RPC batch request might make this is little bit nicer to read.

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.

LGTM, as a bonus test, you can try and run this against wesntend or kusama (you probably need to "fake" the linked runtime spec version).

@niklasad1
Copy link
Member Author

niklasad1 commented Mar 1, 2022

LGTM, as a bonus test, you can try and run this against wesntend or kusama (you probably need to "fake" the linked runtime spec version).

Running it right now, I'll keep you posted.

EDIT: works just won the election on westend

@niklasad1
Copy link
Member Author

@emostov can you take another look at this as well?

let rpc2 = rpc.clone();
let account = signer.account.clone();

let signed_phase_fut = tokio::spawn(async move {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we do this here to prevent heavy network usage from create_election_ext and then again right before submitting to make sure its not pointless to submit?

I think its fine for now, but in the future I think we should look into only doing it right before submitting. Even if it ends up with a lot of wasted network usage it should be fine as long as we are not executing this function righter before the signed phase, since that is when we want to be really fast to get the solution in. But if there fear is that this will be executing at the end of the sign phase I think its fine because we will have awhile until the next signed phase, so the extra network usage won't slow itself down. (Assuming its just traffic to a node on the local network)

Copy link
Member Author

@niklasad1 niklasad1 Mar 3, 2022

Choose a reason for hiding this comment

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

I assume we do this here to prevent heavy network usage from create_election_ext and then again right before submitting to make sure its not pointless to submit?

Yeah

Even if it ends up with a lot of wasted network usage it should be fine as long as we are not executing this function righter before the signed phase, since that is when we want to be really fast to get the solution in.

I'm just afraid that it will flood the JSON-RPC client and it can't keep up with all pending calls because fetching the entire pallet data is quite large (even if the future is dropped the client has to process to responses to check whether it's a valid call). This will occur on every block if we try to do everything in parallel.

Thus, I think we could try to make a subscription to the Phase and only spawn these tasks if it's Phase::Signed then
I'd be okay in spawning the huge calls in parallel but we could try to benchmark this just to be on the safe side. I could be wrong :)

@niklasad1
Copy link
Member Author

bot merge

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