@@ -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" )
0 commit comments