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

Bound parallel verification of transactions #2387

Merged
merged 11 commits into from Mar 27, 2024

Conversation

raychu86
Copy link
Contributor

@raychu86 raychu86 commented Mar 12, 2024

Motivation

This PR bounds the memory usage during transactions verification by introducing MAX_PARALLEL_DEPLOY_VERIFICATIONS and MAX_PARALLEL_EXECUTE_VERIFICATIONS, where we verify a limited number of transactions at once instead of all at once. Previously the unbounded verification could lead to OOM errors when a node is forced to verify many large/expensive transactions at once.

Profiling memory usage of verification gives us some insights -

#2376 (comment)

Deployment: The maximum RAM to verify a 1M constraint program is 2GB.
Execution: The maximum RAM for a 1 or 31-depth 1M constraint call execution is negligible, but to be safe we could assume 10MB.

For an upper bound of 10GB of memory dedicated to transaction verification, we set the following values to:

MAX_PARALLEL_DEPLOY_VERIFICATIONS: 5
MAX_PARALLEL_EXECUTE_VERIFICATIONS: 1000

This means we verify deployments first (in chunks of 5), then executions after (in chunks of 1000).

Copy link
Contributor

@ljedrz ljedrz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@vicsn vicsn left a comment

Choose a reason for hiding this comment

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

Works like a charm

@raychu86
Copy link
Contributor Author

@vicsn Since the pre-speculate verification PR - #2376 was merged, this PR had to be updated with the same change on the VM::speculate side.

Copy link
Contributor

@vicsn vicsn left a comment

Choose a reason for hiding this comment

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

LGTM, just two questions

));
}
// Verify the transaction.
match self.check_transaction(transaction, None, &mut rng) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I should have noticed this earlier, but be aware: if a malicious validator inserts a deployment into their Batch Proposal with a malformed verifying key, this thread may panic, causing all transmissions to be sent back into the mempool queue for verification.

The only way I see us preventing this is to perform validation on transactions of validator Batch Proposals before signing them.

I will make sure we have a consensus test case for this to reproduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, we should wrap the call with a handle_halting macro, like we do for other functions that have the capability of panicking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added panic catchers in check_transaction and updated the test - fbe604d

Copy link
Contributor

@vicsn vicsn left a comment

Choose a reason for hiding this comment

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

LGTM for real now

@howardwu howardwu merged commit 2cbf34a into mainnet-staging Mar 27, 2024
80 checks passed
@howardwu howardwu deleted the bounded-parallel-verification branch March 27, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants