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

Optimise PVF precompilation before entering active set #5090

Closed
wants to merge 5 commits into from

Conversation

AndreiEres
Copy link
Contributor

@AndreiEres AndreiEres commented Jul 21, 2024

Closes #5125

As noticed @sandreim in #4791 (comment), logic of PVF precompilation is not optimal if the node prepares for its following active sets. It would decompress and send PVFs to the Validation Backend it already has.

To solve it, added a new call ensure_pvf to the ValidationBackend, which gets hashes for not yet prepared PVFs. This way, a session before entering the active set while precompiling PVFs we can avoid wasting CPU time for decompressing already prepared PVFs.

Calls to the ValidationBackend are batched. We use three queues: pending for PVFs that definitely need preparation, waiting for new PVFs and processed for already precompiled. We send the hashes from waiting queue to the ValidationBackend only after we've processed everything in the pending queue.

@AndreiEres AndreiEres changed the title Optimise PVF preparation [WIP] Optimise PVF preparation Jul 21, 2024
Base automatically changed from AndreiEres/prepare-pvf to master July 22, 2024 17:04
@paritytech-ci paritytech-ci requested a review from a team as a code owner July 22, 2024 17:04
@AndreiEres AndreiEres force-pushed the AndreiEres/optimize-prepare-pvf branch from d244219 to 78a57ce Compare July 23, 2024 09:42
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 1/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6777119

@AndreiEres AndreiEres added T0-node This PR/Issue is related to the topic “node”. T8-polkadot This PR/Issue is related to/affects the Polkadot network. labels Jul 23, 2024
@AndreiEres AndreiEres self-assigned this Jul 23, 2024
@AndreiEres AndreiEres changed the title [WIP] Optimise PVF preparation Optimise PVF preparation Jul 24, 2024
@AndreiEres AndreiEres changed the title Optimise PVF preparation Optimise PVF precompilation Jul 24, 2024
@AndreiEres AndreiEres changed the title Optimise PVF precompilation Optimise PVF precompilation before entering active set Jul 24, 2024
Copy link
Contributor

@alexggh alexggh left a comment

Choose a reason for hiding this comment

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

Overall, the changes look correct.

However, I'm not sure if this is even a problem that needs to be fixed, the authority set changes every 4 sessions(4h) on kusama and every 6 sessions(24h) on polkadot, also if we are out of the active set we should have the necessary CPU to run the decompress logic once, the downside is that the state machine is a bit more complicated.


let Some(session_index) = session_index(sender, relay_parent).await else { return };
if state.session_index.map_or(true, |i| session_index > i) {
state.waiting.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This if block is big enough, that it can be extracted out in a state.maybe_init_on_new_session().

// PVF host won't prepare the same code hash twice, so here we just avoid extra communication
already_prepared_code_hashes: HashSet<ValidationCodeHash>,
executor_params: Option<ExecutorParams>,
waiting: HashSet<ValidationCodeHash>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Let's add some comments what each collection represents.


/// Checks if artifacts by provided validation code hashes and executor parameters are either
/// prepared or preparing, and returns the hashes of artifacts that do not meet this criterion.
pub fn ensure(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I don't think ensure is the right naming for this function since it doesn't makes sure of anything, I would go with something like:
GetUnprepared, ListUnprepared, ArePrepared, to make it clear this is just a query.

let new_session_index = new_session_index(sender, state.session_index, leaf.hash).await;
if new_session_index.is_some() {
state.session_index = new_session_index;
state.already_prepared_code_hashes.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this be fixed by simply not clearing this or clearing it more infrequent let's say every 24h ?

@AndreiEres
Copy link
Contributor Author

Closed as redundand

@AndreiEres AndreiEres closed this Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”. T8-polkadot This PR/Issue is related to/affects the Polkadot network.
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Do not process already compiled PVFs in the session before entering active set
3 participants