Skip to content

Fix validation blocking async tasks & upgrade mega-evm dependency - #51

Merged
yilongli merged 4 commits into
mainfrom
liquan/fix_async_block
Dec 8, 2025
Merged

Fix validation blocking async tasks & upgrade mega-evm dependency#51
yilongli merged 4 commits into
mainfrom
liquan/fix_async_block

Conversation

@flyq

@flyq flyq commented Dec 8, 2025

Copy link
Copy Markdown
Member

Summary

This PR improves the stateless validator's performance by introducing a thread pool for CPU-intensive validation tasks and upgrades the mega-evm dependency with refactored hardfork implementations.

Purpose

To address two issues encountered in testnet v2:

  1. The asynchronous runtime was blocked by validate_one, resulting in thousands of blocks being validated without the reporter providing any updates. At the time, the server was running both the witness generator and the validator simultaneously; the generator was using 200% CPU, and the validator, with 32 workers, was using 800% CPU.
  2. The issue of the release build size being excessively large. Before the fix, the validator size was 222MB; after the fix, it was 8MB.

Changes

1. Use thread pool for validation to avoid blocking async tasks

  • Wrapped validate_block() call in task::spawn_blocking() to run CPU-intensive validation in a dedicated thread pool
  • This prevents blocking of other async tasks (reporter, tracker, etc.) during validation
  • Adjusted function signatures to properly handle Arc<ChainSpec> for thread-safe sharing

2. Optimize release build profile

  • Changed to lto = "fat" for better link-time optimization
  • Added strip = true to reduce binary size
  • Added panic = "abort" for smaller binary and faster panic handling
  • Removed incremental compilation for release builds

3. Upgrade mega-evm & refactor chainspec hardfork implementation

  • Updated mega-evm to commit 3b28c205c8c2f89730a4dd88abe47e1831c6fac9
  • Replaced local MegaethHardfork and MegaethHardforks definitions with MegaHardfork and MegaHardforks from mega-evm
  • Simplified chain_spec.rs by removing 43 lines of redundant hardfork code
  • Implemented MegaHardforks trait for ChainSpec

Files Changed

  • Cargo.toml - Updated dependencies and release profile
  • Cargo.lock - Updated lockfile
  • bin/stateless-validator/src/main.rs - Added spawn_blocking for validation
  • validator-core/src/chain_spec.rs - Refactored hardfork implementation

@flyq
flyq requested review from Troublor and yilongli December 8, 2025 15:03
@flyq flyq changed the title opt: Optimize validation performance and upgrade mega-evm dependency Fix validation blocking async tasks & upgrade mega-evm dependency Dec 8, 2025
@yilongli
yilongli merged commit 152bb64 into main Dec 8, 2025
4 checks passed
@yilongli
yilongli deleted the liquan/fix_async_block branch December 8, 2025 17:52
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