This file provides guidance to Claude Code when working with the block package of ev-node.
The block package is the core of ev-node's block management system. It handles block creation, validation, synchronization, and submission to the Data Availability (DA) layer. This package implements the block lifecycle from transaction aggregation through to finalization.
- Purpose: Central orchestrator for all block operations
- Key Responsibilities:
- Transaction aggregation into blocks
- Block production and validation
- State synchronization
- DA layer interaction
- P2P block/header gossiping
- Purpose: Collects transactions from mempool and creates blocks
- Modes:
- Normal Mode: Produces blocks at regular intervals (BlockTime)
- Lazy Mode: Only produces blocks when transactions are present or after LazyBlockTime
- Key Functions:
AggregationLoop: Main loop for block productionlazyAggregationLoop: Optimized for low-traffic scenariosnormalAggregationLoop: Regular block production
- Purpose: Keeps the node synchronized with the network
- Key Functions:
SyncLoop: Main synchronization loop- Processes headers from P2P network
- Retrieves block data from DA layer
- Handles header and data caching
- DA Includer: Manages DA blob inclusion proofs and validation
- Submitter: Handles block submission to the DA layer with retry logic
- Retriever: Fetches blocks from the DA layer
- Key Features:
- Multiple DA layer support
- Configurable retry attempts
- Batch submission optimization
- Purpose: Persistent storage for blocks and state
- Key Features:
- Block height tracking
- Block and commit storage
- State root management
- Migration support for namespace changes
- Purpose: Manages blocks awaiting DA inclusion or validation
- Components:
- PendingBase: Base structure for pending blocks
- PendingHeaders: Header queue management
- PendingData: Block data queue management
- Key Features:
- Ordered processing by height
- Validation before acceptance
- Memory-efficient caching
- Purpose: Performance monitoring and observability
- Key Metrics:
- Block production times
- Sync status and progress
- DA layer submission metrics
- Transaction throughput
- Transactions collected from mempool
- Block created with proper header and data
- Block executed through executor
- Block submitted to DA layer
- Block gossiped to P2P network
- Headers received from P2P network
- Headers validated and cached
- Block data retrieved from DA layer
- Blocks applied to state
- Sync progress updated
- Block prepared for submission
- Blob created with block data
- Submission attempted with retries
- Inclusion proof obtained
- Block marked as finalized
BlockTime: Target time between blocks (default: 1s)DABlockTime: DA layer block time (default: 6s)LazyBlockTime: Max time between blocks in lazy mode (default: 60s)
maxSubmitAttempts: Max DA submission retries (30)defaultMempoolTTL: Blocks until tx dropped (25)
- Test individual components in isolation
- Mock external dependencies (DA, executor, sequencer)
- Focus on edge cases and error conditions
- Test component interactions
- Verify block flow from creation to storage
- Test synchronization scenarios
- Measure DA submission performance
- Test batch processing efficiency
- Validate metrics accuracy
- Update DA interfaces in
core/da - Modify
da_includer.gofor inclusion logic - Update
submitter.gofor submission flow - Add retrieval logic in
retriever.go - Update tests and metrics
- Update aggregation logic in
aggregation.go - Adjust timing in Manager configuration
- Update metrics collection
- Test both normal and lazy modes
- Modify
SyncLoopinsync.go - Update pending block handling
- Adjust cache strategies
- Test various network conditions
- Use structured errors with context
- Retry transient failures (network, DA)
- Log errors with appropriate levels
- Maintain sync state consistency
- Handle node restart gracefully
- Batch DA operations when possible
- Use caching to reduce redundant work
- Optimize header validation path
- Monitor goroutine lifecycle
- Profile memory usage in caches
- Validate all headers before processing
- Verify DA inclusion proofs
- Check block signatures
- Prevent DOS through rate limiting
- Validate state transitions
- Enable debug logging for detailed flow
- Monitor metrics for performance issues
- Check pending queues for blockages
- Verify DA layer connectivity
- Inspect cache hit rates
- Use context for cancellation
- Implement graceful shutdown
- Log with structured fields
- Return errors with context
- Use metrics for observability
- Test error conditions thoroughly