Skip to content

Commit 7b328ee

Browse files
committed
updates
1 parent 6b93c94 commit 7b328ee

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

block/aggregation.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,56 @@ func (m *Manager) AggregationLoop(ctx context.Context) {
3838
// Lazy Aggregator mode.
3939
// In Lazy Aggregator mode, blocks are built only when there are
4040
// transactions or every LazyBlockTime.
41+
errChan := make(chan error)
4142
if m.config.Node.LazyMode {
42-
if err := m.lazyAggregationLoop(ctx, blockTimer); err != nil {
43-
if errors.Is(err, ErrNoRecover) {
44-
panic(err)
45-
} else {
46-
m.logger.Error("error in lazy aggregation loop", "error", err)
43+
m.lazyAggregationLoop(ctx, blockTimer, errChan)
44+
select {
45+
case err := <-errChan:
46+
if err != nil {
47+
if errors.Is(err, ErrNoRecover) {
48+
panic(err)
49+
} else {
50+
m.logger.Error("error in lazy aggregation loop", "error", err)
51+
}
4752
}
53+
default:
4854
}
4955
} else {
50-
if err := m.normalAggregationLoop(ctx, blockTimer); err != nil {
51-
if errors.Is(err, ErrNoRecover) {
52-
panic(err)
53-
} else {
54-
m.logger.Error("error in normal aggregation loop", "error", err)
56+
m.normalAggregationLoop(ctx, blockTimer, errChan)
57+
select {
58+
case err := <-errChan:
59+
if err != nil {
60+
if errors.Is(err, ErrNoRecover) {
61+
panic(err)
62+
} else {
63+
m.logger.Error("error in normal aggregation loop", "error", err)
64+
}
5565
}
66+
default:
5667
}
5768
}
5869
}
5970

60-
func (m *Manager) lazyAggregationLoop(ctx context.Context, blockTimer *time.Timer) error {
71+
func (m *Manager) lazyAggregationLoop(ctx context.Context, blockTimer *time.Timer, errChan chan<- error) {
6172
// lazyTimer triggers block publication even during inactivity
6273
lazyTimer := time.NewTimer(0)
6374
defer lazyTimer.Stop()
6475

6576
for {
6677
select {
6778
case <-ctx.Done():
68-
return nil
79+
return
6980

7081
case <-lazyTimer.C:
7182
m.logger.Debug("Lazy timer triggered block production")
7283
if err := m.produceBlock(ctx, "lazy_timer", lazyTimer, blockTimer); err != nil {
73-
return err
84+
errChan <- err
7485
}
7586

7687
case <-blockTimer.C:
7788
if m.txsAvailable {
7889
if err := m.produceBlock(ctx, "block_timer", lazyTimer, blockTimer); err != nil {
79-
return err
90+
errChan <- err
8091
}
8192
m.txsAvailable = false
8293
} else {
@@ -107,17 +118,17 @@ func (m *Manager) produceBlock(ctx context.Context, mode string, lazyTimer, bloc
107118
return nil
108119
}
109120

110-
func (m *Manager) normalAggregationLoop(ctx context.Context, blockTimer *time.Timer) error {
121+
func (m *Manager) normalAggregationLoop(ctx context.Context, blockTimer *time.Timer, errChan chan<- error) {
111122
for {
112123
select {
113124
case <-ctx.Done():
114-
return nil
125+
return
115126
case <-blockTimer.C:
116127
// Define the start time for the block production period
117128
start := time.Now()
118129

119130
if err := m.publishBlock(ctx); err != nil && ctx.Err() == nil {
120-
return fmt.Errorf("error while publishing block: %w", err)
131+
errChan <- fmt.Errorf("error while publishing block: %w", err)
121132
}
122133

123134
m.logger.Debug("Successfully published block")

block/lazy_aggregation_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestLazyAggregationLoop_BlockTimerTrigger(t *testing.T) {
9999
blockTimer := time.NewTimer(0) // Fire immediately first time
100100
defer blockTimer.Stop()
101101

102-
require.NoError(m.lazyAggregationLoop(ctx, blockTimer))
102+
m.lazyAggregationLoop(ctx, blockTimer, make(chan<- error, 0))
103103
}()
104104

105105
// Wait for at least one block to be published
@@ -137,7 +137,7 @@ func TestLazyAggregationLoop_LazyTimerTrigger(t *testing.T) {
137137
blockTimer := time.NewTimer(0) // Fire immediately first time
138138
defer blockTimer.Stop()
139139

140-
require.NoError(m.lazyAggregationLoop(ctx, blockTimer))
140+
m.lazyAggregationLoop(ctx, blockTimer, make(chan<- error, 0))
141141
}()
142142

143143
// Wait for the first publish call triggered by the initial immediate lazyTimer fire
@@ -186,7 +186,9 @@ func TestLazyAggregationLoop_PublishError(t *testing.T) {
186186
blockTimer := time.NewTimer(0)
187187
defer blockTimer.Stop()
188188

189-
require.Error(m.lazyAggregationLoop(ctx, blockTimer))
189+
errChan := make(chan error, 1)
190+
m.lazyAggregationLoop(ctx, blockTimer, errChan)
191+
require.Error(<-errChan)
190192
}()
191193

192194
// Wait for the first publish attempt (which will fail)
@@ -265,7 +267,7 @@ func TestLazyAggregationLoop_TxNotification(t *testing.T) {
265267
// Start with a timer that won't fire immediately
266268
blockTimer := time.NewTimer(blockTime)
267269
defer blockTimer.Stop()
268-
require.NoError(m.lazyAggregationLoop(ctx, blockTimer))
270+
m.lazyAggregationLoop(ctx, blockTimer, make(chan<- error, 0))
269271
}()
270272

271273
// Wait for the initial lazy timer to fire and publish a block
@@ -367,7 +369,7 @@ func TestNormalAggregationLoop_TxNotification(t *testing.T) {
367369
blockTimer := time.NewTimer(blockTime)
368370
defer blockTimer.Stop()
369371

370-
require.NoError(m.normalAggregationLoop(ctx, blockTimer))
372+
m.normalAggregationLoop(ctx, blockTimer, make(chan<- error, 0))
371373
}()
372374

373375
// Wait for the first block to be published by the timer

node/full_node_integration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ func (s *FullNodeTestSuite) TestSubmitBlocksToDA() {
255255
require.NoError(err)
256256
currentDAHeight := s.node.blockManager.GetDAIncludedHeight()
257257
pendingHeaders, _ := s.node.blockManager.PendingHeaders().GetPendingHeaders()
258-
s.T().Logf("Post-trigger check %d - Height: %d, DA Height: %d, Pending: %d",
259-
i, currentHeight, currentDAHeight, len(pendingHeaders))
258+
s.T().Logf("Post-trigger check %d - Height: %d, DA Height: %d, Pending: %d", i, currentHeight, currentDAHeight, len(pendingHeaders))
260259
}
261260

262261
// Final assertions with more detailed error messages

0 commit comments

Comments
 (0)