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

runtime: validate transactions in parallel #12654

Merged
merged 3 commits into from
Jan 15, 2025
Merged

Conversation

miloserdow
Copy link
Member

@miloserdow miloserdow commented Dec 19, 2024

In the old flow, validation (including signature checks) happened inside verify_and_charge_transaction(). In the new flow, we first run parallel_validate_transactions() to validate and compute the transaction cost (including signature checks) in parallel. Only after a transaction passes validation do we call verify_and_charge_transaction() with the known cost.

graph TD;
    subgraph Old_Flow
    A[Runtime::apply]
    A-->B[self.process_transactions]
    B-->C[process_transaction]
    C-->D[verify_and_charge_transaction]
    D-->E[validate_transaction incl. signature]
    E-->|Valid|F[charge fees & finalize]
    E-->|Invalid|G[reject tx]
    end

    subgraph New_Flow
    A2[Runtime::apply]
    A2-->H[self.process_transactions]
    H-->|parallel|I[parallel_validate_transactions incl. signature]
    I-->|Valid, get cost|J[process_transaction]
    J-->K[verify_and_charge_transaction]
    K-->L[charge fees & finalize]
    I-->|Invalid|M[reject tx early]
    classDef threaded fill:#3240a8,stroke:#333,stroke-width:2px;
    class I threaded;
    end
Loading

(blue = running in parallel)

Testing

The change brings ~20% throughput improvement on n2d-standard-16

1006/1006 blocks applied in 2m at a rate of 7.5129/s. 0s remaining. Skipped 0 blocks. Over last 100 blocks to height 1073: 0 empty blocks, averaging 413.00 Tgas per non-empty block
1007/1007 blocks applied in 2m at a rate of 8.9972/s. 0s remaining. Skipped 0 blocks. Over last 100 blocks to height 1073: 0 empty blocks, averaging 413.00 Tgas per non-empty block

Additionally, profiles before and after the change are available: before, after

@miloserdow miloserdow force-pushed the miloserdow/threaded-sig branch 3 times, most recently from 74e1957 to 1062a13 Compare January 10, 2025 15:35
@miloserdow miloserdow marked this pull request as ready for review January 10, 2025 15:35
@miloserdow miloserdow requested a review from a team as a code owner January 10, 2025 15:35
@miloserdow miloserdow requested a review from akhi3030 January 10, 2025 15:35
@miloserdow miloserdow changed the title WIP: validate transactions in parallel (no trie) Validate transactions in parallel Jan 10, 2025
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 93.96135% with 25 lines in your changes missing coverage. Please review.

Project coverage is 70.72%. Comparing base (cf45cc5) to head (453eaf2).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
runtime/runtime/src/verifier.rs 96.21% 12 Missing ⚠️
.../runtime-params-estimator/src/estimator_context.rs 0.00% 9 Missing ⚠️
chain/chain/src/runtime/mod.rs 93.33% 0 Missing and 2 partials ⚠️
runtime/runtime/src/lib.rs 96.55% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12654      +/-   ##
==========================================
- Coverage   70.72%   70.72%   -0.01%     
==========================================
  Files         848      848              
  Lines      174212   174303      +91     
  Branches   174212   174303      +91     
==========================================
+ Hits       123219   123278      +59     
- Misses      45850    45880      +30     
- Partials     5143     5145       +2     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.35% <0.00%> (-0.01%) ⬇️
linux 69.23% <91.54%> (-0.01%) ⬇️
linux-nightly 70.30% <93.47%> (-0.01%) ⬇️
pytests 1.65% <0.00%> (-0.01%) ⬇️
sanity-checks 1.46% <0.00%> (-0.01%) ⬇️
unittests 70.55% <93.96%> (-0.01%) ⬇️
upgradability 0.20% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@miloserdow miloserdow changed the title Validate transactions in parallel runtime: validate transactions in parallel Jan 10, 2025
@miloserdow miloserdow force-pushed the miloserdow/threaded-sig branch from 1062a13 to 17300fa Compare January 13, 2025 11:35
Copy link
Collaborator

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

As an additional note, I think it might make sense to re-introduce a helper function that combines the validate_transaction and verify_and_charge_transaction so that the tests and the code that doesn't care about parallel validation of transactions doesn't need to change as much as it did.

All that said, all of this looks quite nice, I didn't see any fundamental issues with the approach taken here. Thank you for working on this :)

runtime/runtime/src/verifier.rs Outdated Show resolved Hide resolved
runtime/runtime/src/lib.rs Outdated Show resolved Hide resolved
runtime/runtime/src/lib.rs Outdated Show resolved Hide resolved
chain/chain/src/runtime/mod.rs Outdated Show resolved Hide resolved
chain/chain/src/runtime/mod.rs Outdated Show resolved Hide resolved
Transaction validation and cost computation have been decoupled from
the verification process, streamlining optimizations. The new flow
introduces `parallel_validate_transactions`, which validates
transactions (without using the state) and calculates costs
concurrently. The results are then passed to
`verify_and_charge_transaction`, which now accepts a precomputed
`TransactionCost` instead of recalculating it.
@miloserdow miloserdow force-pushed the miloserdow/threaded-sig branch from 17300fa to 222dda7 Compare January 14, 2025 15:06
@miloserdow miloserdow force-pushed the miloserdow/threaded-sig branch from 222dda7 to 453eaf2 Compare January 14, 2025 15:12
@miloserdow miloserdow added this pull request to the merge queue Jan 15, 2025
Merged via the queue into master with commit abe4a60 Jan 15, 2025
28 checks passed
@miloserdow miloserdow deleted the miloserdow/threaded-sig branch January 15, 2025 14:44
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.

2 participants