Skip to content

perf(app): parallelize per-tx gas classification in checkTotalBlockGas#3399

Open
amir-deris wants to merge 3 commits intomainfrom
amir/plt-324-concurrent-block-gas-calculation
Open

perf(app): parallelize per-tx gas classification in checkTotalBlockGas#3399
amir-deris wants to merge 3 commits intomainfrom
amir/plt-324-concurrent-block-gas-calculation

Conversation

@amir-deris
Copy link
Copy Markdown
Contributor

@amir-deris amir-deris commented May 6, 2026

Summary

checkTotalBlockGas iterates every tx in a proposed block to compute total gas. Each tx's classification (EVM check, gasless check, gas extraction) is independent, making the loop a natural fan-out target.

Changes

  • checkTotalBlockGas — replaced the serial loop with a two-phase design:
    • Phase 1 (parallel): up to 32 concurrent goroutines, one per tx, each calling classifyTxForGas. Results are written into a pre-allocated []txGasResult slice indexed by position (no lock needed on the slice).
    • Phase 2 (serial): single pass over results for malicious-tx detection, overflow-safe accumulation, and MaxGasWanted/MaxGas limit enforcement.
  • classifyTxForGas — extracted helper that owns all per-tx logic. EVM txs (the vast majority) run fully unlocked. The non-EVM IsTxGasless path takes a ctxMu mutex because sdk.Context wraps a CacheMultiStore that is not goroutine-safe.
  • txGasResult — small struct (gasWanted, gasContrib, skip, malicious) that carries each tx's outcome between phases.
  • Dropped nonzeroTxsCnt — it was declared and incremented but never read.

Safety

  • No data races: each goroutine owns its results[i] slot; ctxMu serializes the only shared-state reader (IsTxGasless).
  • On typical EVM-heavy blocks ctxMu is uncontested — oracle-vote txs are the only non-EVM path that acquires it.
  • Semantics of the overflow check and gas-limit enforcement are unchanged; they moved to the serial accumulation phase where the running total is available.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 6, 2026, 4:44 PM

@amir-deris amir-deris changed the title Added concurrent gas calculation for tx in the block perf(app): parallelize per-tx gas classification in checkTotalBlockGas May 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 69.69697% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.04%. Comparing base (6dfc44c) to head (f8f2841).

Files with missing lines Patch % Lines
app/app.go 69.69% 13 Missing and 7 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3399   +/-   ##
=======================================
  Coverage   59.03%   59.04%           
=======================================
  Files        2102     2102           
  Lines      173237   173256   +19     
=======================================
+ Hits       102277   102291   +14     
- Misses      62083    62086    +3     
- Partials     8877     8879    +2     
Flag Coverage Δ
sei-chain-pr 50.71% <69.69%> (?)
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
app/app.go 69.89% <69.69%> (+0.04%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amir-deris amir-deris requested a review from codchen May 6, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant