Skip to content

Commit ee94697

Browse files
author
tac0turtle
committed
fix test, build and lint
1 parent c067304 commit ee94697

File tree

10 files changed

+74
-14
lines changed

10 files changed

+74
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Ev-node is the basis of the Evolve Stack. For more in-depth information about Ev
1111
## Using Evolve
1212

1313
Evolve supports multiple sync modes:
14+
1415
- **Hybrid sync**: Sync from both DA layer and P2P network (default when peers are configured)
1516
- **DA-only sync**: Sync exclusively from DA layer by leaving P2P peers empty (see [Configuration Guide](docs/learn/config.md#da-only-sync-mode))
1617
- **P2P-priority sync**: Prioritize P2P with DA as fallback

block/CLAUDE.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The block package is the core of ev-node's block management system. It handles b
99
## Core Components
1010

1111
### Manager (`manager.go`)
12+
1213
- **Purpose**: Central orchestrator for all block operations
1314
- **Key Responsibilities**:
1415
- Transaction aggregation into blocks
@@ -18,6 +19,7 @@ The block package is the core of ev-node's block management system. It handles b
1819
- P2P block/header gossiping
1920

2021
### Aggregation (`aggregation.go`, `lazy_aggregation_test.go`)
22+
2123
- **Purpose**: Collects transactions from mempool and creates blocks
2224
- **Modes**:
2325
- **Normal Mode**: Produces blocks at regular intervals (BlockTime)
@@ -28,6 +30,7 @@ The block package is the core of ev-node's block management system. It handles b
2830
- `normalAggregationLoop`: Regular block production
2931

3032
### Synchronization (`sync.go`, `sync_test.go`)
33+
3134
- **Purpose**: Keeps the node synchronized with the network
3235
- **Key Functions**:
3336
- `SyncLoop`: Main synchronization loop
@@ -36,6 +39,7 @@ The block package is the core of ev-node's block management system. It handles b
3639
- Handles header and data caching
3740

3841
### Data Availability (`da_includer.go`, `submitter.go`, `retriever.go`)
42+
3943
- **DA Includer**: Manages DA blob inclusion proofs and validation
4044
- **Submitter**: Handles block submission to the DA layer with retry logic
4145
- **Retriever**: Fetches blocks from the DA layer
@@ -45,6 +49,7 @@ The block package is the core of ev-node's block management system. It handles b
4549
- Batch submission optimization
4650

4751
### Storage (`store.go`, `store_test.go`)
52+
4853
- **Purpose**: Persistent storage for blocks and state
4954
- **Key Features**:
5055
- Block height tracking
@@ -53,6 +58,7 @@ The block package is the core of ev-node's block management system. It handles b
5358
- Migration support for namespace changes
5459

5560
### Pending Blocks (`pending_base.go`, `pending_headers.go`, `pending_data.go`)
61+
5662
- **Purpose**: Manages blocks awaiting DA inclusion or validation
5763
- **Components**:
5864
- **PendingBase**: Base structure for pending blocks
@@ -64,6 +70,7 @@ The block package is the core of ev-node's block management system. It handles b
6470
- Memory-efficient caching
6571

6672
### Metrics (`metrics.go`, `metrics_helpers.go`)
73+
6774
- **Purpose**: Performance monitoring and observability
6875
- **Key Metrics**:
6976
- Block production times
@@ -74,20 +81,23 @@ The block package is the core of ev-node's block management system. It handles b
7481
## Key Workflows
7582

7683
### Block Production Flow
84+
7785
1. Transactions collected from mempool
7886
2. Block created with proper header and data
7987
3. Block executed through executor
8088
4. Block submitted to DA layer
8189
5. Block gossiped to P2P network
8290

8391
### Synchronization Flow
92+
8493
1. Headers received from P2P network
8594
2. Headers validated and cached
8695
3. Block data retrieved from DA layer
8796
4. Blocks applied to state
8897
5. Sync progress updated
8998

9099
### DA Submission Flow
100+
91101
1. Block prepared for submission
92102
2. Blob created with block data
93103
3. Submission attempted with retries
@@ -97,47 +107,55 @@ The block package is the core of ev-node's block management system. It handles b
97107
## Configuration
98108

99109
### Time Parameters
110+
100111
- `BlockTime`: Target time between blocks (default: 1s)
101112
- `DABlockTime`: DA layer block time (default: 6s)
102113
- `LazyBlockTime`: Max time between blocks in lazy mode (default: 60s)
103114

104115
### Limits
116+
105117
- `maxSubmitAttempts`: Max DA submission retries (30)
106118
- `defaultMempoolTTL`: Blocks until tx dropped (25)
107119

108120
## Testing Strategy
109121

110122
### Unit Tests
123+
111124
- Test individual components in isolation
112125
- Mock external dependencies (DA, executor, sequencer)
113126
- Focus on edge cases and error conditions
114127

115128
### Integration Tests
129+
116130
- Test component interactions
117131
- Verify block flow from creation to storage
118132
- Test synchronization scenarios
119133

120134
### Performance Tests (`da_speed_test.go`)
135+
121136
- Measure DA submission performance
122137
- Test batch processing efficiency
123138
- Validate metrics accuracy
124139

125140
## Common Development Tasks
126141

127142
### Adding a New DA Feature
143+
128144
1. Update DA interfaces in `core/da`
129145
2. Modify `da_includer.go` for inclusion logic
130146
3. Update `submitter.go` for submission flow
131147
4. Add retrieval logic in `retriever.go`
132148
5. Update tests and metrics
133149

134150
### Modifying Block Production
151+
135152
1. Update aggregation logic in `aggregation.go`
136153
2. Adjust timing in Manager configuration
137154
3. Update metrics collection
138155
4. Test both normal and lazy modes
139156

140157
### Implementing New Sync Strategy
158+
141159
1. Modify `SyncLoop` in `sync.go`
142160
2. Update pending block handling
143161
3. Adjust cache strategies
@@ -182,4 +200,4 @@ The block package is the core of ev-node's block management system. It handles b
182200
- Log with structured fields
183201
- Return errors with context
184202
- Use metrics for observability
185-
- Test error conditions thoroughly
203+
- Test error conditions thoroughly

block/da_includer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ func (m *Manager) incrementDAIncludedHeight(ctx context.Context) error {
7474

7575
// Update sequencer metrics if the sequencer supports it
7676
if seq, ok := m.sequencer.(MetricsRecorder); ok {
77-
seq.RecordMetrics(m.gasPrice, 0, coreda.StatusSuccess, m.pendingHeaders.numPendingHeaders(), newHeight)
77+
gasPrice, err := m.da.GasPrice(ctx)
78+
if err != nil {
79+
m.logger.Error().Err(err).Msg("failed to get gas price")
80+
return err
81+
}
82+
seq.RecordMetrics(gasPrice, 0, coreda.StatusSuccess, m.pendingHeaders.numPendingHeaders(), newHeight)
7883
}
7984

8085
return nil

block/da_includer_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,14 @@ func TestIncrementDAIncludedHeight_WithMetricsRecorder(t *testing.T) {
421421
expectedDAIncludedHeight := startDAIncludedHeight + 1
422422
m.daIncludedHeight.Store(startDAIncludedHeight)
423423

424+
// Set up mock DA
425+
mockDA := mocks.NewMockDA(t)
426+
mockDA.On("GasPrice", mock.Anything).Return(1.5, nil).Once()
427+
m.da = mockDA
428+
424429
// Set up mock sequencer with metrics
425430
mockSequencer := new(MockSequencerWithMetrics)
426431
m.sequencer = mockSequencer
427-
m.gasPrice = 1.5 // Set a test gas price
428432

429433
// Mock the store calls needed for PendingHeaders initialization
430434
// First, clear the existing Height mock from newTestManager
@@ -462,6 +466,7 @@ func TestIncrementDAIncludedHeight_WithMetricsRecorder(t *testing.T) {
462466
store.AssertExpectations(t)
463467
exec.AssertExpectations(t)
464468
mockSequencer.AssertExpectations(t)
469+
mockDA.AssertExpectations(t)
465470
}
466471

467472
// Note: It is not practical to unit test a CompareAndSwap failure for incrementDAIncludedHeight

block/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ func getManager(t *testing.T, da da.DA, gasPrice float64, gasMultiplier float64)
4747
headerCache: cache.NewCache[types.SignedHeader](),
4848
dataCache: cache.NewCache[types.Data](),
4949
logger: logger,
50-
gasPrice: gasPrice,
51-
gasMultiplier: gasMultiplier,
5250
lastStateMtx: &sync.RWMutex{},
5351
metrics: NopMetrics(),
5452
store: mockStore,
@@ -212,6 +210,7 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
212210
ctx := context.Background()
213211

214212
mockDA := mocks.NewMockDA(t)
213+
mockDA.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
215214
m, _ := getManager(t, mockDA, -1, -1)
216215

217216
header1, data1 := types.GetRandomBlock(uint64(1), 5, chainID)
@@ -250,6 +249,7 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
250249
ctx := context.Background()
251250

252251
mockDA := mocks.NewMockDA(t)
252+
mockDA.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
253253
m, _ := getManager(t, mockDA, -1, -1)
254254

255255
header1, data1 := types.GetRandomBlock(uint64(1), 5, chainID)

block/publish_block_p2p_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ func setupBlockManager(t *testing.T, ctx context.Context, workDir string, mainKV
215215
nil,
216216
nil,
217217
NopMetrics(),
218-
1.,
219-
1.,
220218
DefaultManagerOptions(),
221219
)
222220
require.NoError(t, err)

block/submitter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func submitToDA[T any](
8585
submittedAll := false
8686
var backoff time.Duration
8787
attempt := 0
88-
88+
8989
// Get gas price from DA layer
9090
initialGasPrice, err := m.da.GasPrice(ctx)
9191
if err != nil {
@@ -144,7 +144,7 @@ func submitToDA[T any](
144144
remaining = notSubmitted
145145
marshaled = notSubmittedMarshaled
146146
backoff = 0
147-
147+
148148
// Get gas multiplier from DA layer and adjust price
149149
gasMultiplier, multErr := m.da.GasMultiplier(ctx)
150150
if multErr != nil {
@@ -161,7 +161,7 @@ func submitToDA[T any](
161161
// Record failed DA submission (will retry)
162162
m.recordDAMetrics("submission", DAModeFail)
163163
backoff = m.config.DA.BlockTime.Duration * time.Duration(m.config.DA.MempoolTTL)
164-
164+
165165
// Get gas multiplier from DA layer and increase price for retry
166166
gasMultiplier, multErr := m.da.GasMultiplier(ctx)
167167
if multErr != nil {

block/submitter_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ func newTestManagerWithDA(t *testing.T, da *mocks.MockDA) (m *Manager) {
4646
)
4747

4848
// Set up DA mock to return gas parameters
49-
da.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
50-
da.On("GasMultiplier", mock.Anything).Return(2.0, nil).Maybe()
49+
if da != nil {
50+
da.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
51+
da.On("GasMultiplier", mock.Anything).Return(2.0, nil).Maybe()
52+
}
5153

5254
return &Manager{
5355
da: da,
@@ -192,6 +194,8 @@ func TestSubmitDataToDA_Failure(t *testing.T) {
192194
daError: tc.daError,
193195
mockDASetup: func(da *mocks.MockDA, gasPriceHistory *[]float64, daError error) {
194196
da.ExpectedCalls = nil
197+
da.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
198+
da.On("GasMultiplier", mock.Anything).Return(2.0, nil).Maybe()
195199
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
196200
Run(func(args mock.Arguments) { *gasPriceHistory = append(*gasPriceHistory, args.Get(2).(float64)) }).
197201
Return(nil, daError)
@@ -227,6 +231,8 @@ func TestSubmitHeadersToDA_Failure(t *testing.T) {
227231
daError: tc.daError,
228232
mockDASetup: func(da *mocks.MockDA, gasPriceHistory *[]float64, daError error) {
229233
da.ExpectedCalls = nil
234+
da.On("GasPrice", mock.Anything).Return(1.0, nil).Maybe()
235+
da.On("GasMultiplier", mock.Anything).Return(2.0, nil).Maybe()
230236
da.On("SubmitWithOptions", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
231237
Run(func(args mock.Arguments) { *gasPriceHistory = append(*gasPriceHistory, args.Get(2).(float64)) }).
232238
Return(nil, daError)

docs/learn/config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ Evolve supports running nodes that sync exclusively from the Data Availability (
6262
**To enable DA-only sync mode:**
6363

6464
1. **Leave P2P peers empty** (default behavior):
65+
6566
```yaml
6667
p2p:
6768
peers: "" # Empty or omit this field entirely
6869
```
69-
70+
7071
2. **Configure DA connection** (required):
72+
7173
```yaml
7274
da:
7375
address: "your-da-service:port"
@@ -78,6 +80,7 @@ Evolve supports running nodes that sync exclusively from the Data Availability (
7880
3. **Optional**: You can still configure P2P listen address for potential future connections, but without peers, no P2P networking will occur.
7981

8082
When running in DA-only mode, the node will:
83+
8184
- ✅ Sync blocks and headers from the DA layer
8285
- ✅ Validate transactions and maintain state
8386
- ✅ Serve RPC requests

0 commit comments

Comments
 (0)