-
Notifications
You must be signed in to change notification settings - Fork 707
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
Conversation
d244219
to
78a57ce
Compare
The CI pipeline was cancelled due to failure one of the required jobs. |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 ?
Closed as redundand |
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 andprocessed
for already precompiled. We send the hashes fromwaiting
queue to the ValidationBackend only after we've processed everything in thepending
queue.