|
5 | 5 | "fmt" |
6 | 6 | "math/big" |
7 | 7 | "sort" |
8 | | - "sync" |
9 | 8 | "sync/atomic" |
10 | 9 | "time" |
11 | 10 |
|
@@ -108,30 +107,6 @@ func (c *Committer) Start(ctx context.Context) { |
108 | 107 |
|
109 | 108 | c.cleanupProcessedStagingBlocks() |
110 | 109 |
|
111 | | - if config.Cfg.Publisher.Mode == "parallel" { |
112 | | - var wg sync.WaitGroup |
113 | | - publishInterval := interval / 2 |
114 | | - if publishInterval <= 0 { |
115 | | - publishInterval = interval |
116 | | - } |
117 | | - wg.Add(2) |
118 | | - go func() { |
119 | | - defer wg.Done() |
120 | | - c.runPublishLoop(ctx, publishInterval) |
121 | | - }() |
122 | | - // allow the publisher to start before the committer |
123 | | - time.Sleep(publishInterval) |
124 | | - go func() { |
125 | | - defer wg.Done() |
126 | | - c.runCommitLoop(ctx, interval) |
127 | | - }() |
128 | | - <-ctx.Done() |
129 | | - wg.Wait() |
130 | | - log.Info().Msg("Committer shutting down") |
131 | | - c.publisher.Close() |
132 | | - return |
133 | | - } |
134 | | - |
135 | 110 | c.runCommitLoop(ctx, interval) |
136 | 111 | log.Info().Msg("Committer shutting down") |
137 | 112 | c.publisher.Close() |
@@ -162,9 +137,20 @@ func (c *Committer) runCommitLoop(ctx context.Context, interval time.Duration) { |
162 | 137 | log.Debug().Msg("No block data to commit") |
163 | 138 | continue |
164 | 139 | } |
165 | | - if err := c.commit(ctx, blockDataToCommit); err != nil { |
166 | | - log.Error().Err(err).Msg("Error committing blocks") |
167 | | - } |
| 140 | + go func() { |
| 141 | + highest := blockDataToCommit[len(blockDataToCommit)-1].Block.Number.Uint64() |
| 142 | + if err := c.publisher.PublishBlockData(blockDataToCommit); err != nil { |
| 143 | + log.Error().Err(err).Msg("Failed to publish block data to kafka") |
| 144 | + return |
| 145 | + } |
| 146 | + c.lastPublishedBlock.Store(highest) |
| 147 | + }() |
| 148 | + go func() { |
| 149 | + if err := c.commit(ctx, blockDataToCommit); err != nil { |
| 150 | + log.Error().Err(err).Msg("Error committing blocks") |
| 151 | + } |
| 152 | + c.cleanupProcessedStagingBlocks() |
| 153 | + }() |
168 | 154 | } |
169 | 155 | } |
170 | 156 | } |
@@ -458,18 +444,6 @@ func (c *Committer) commit(ctx context.Context, blockData []common.BlockData) er |
458 | 444 | log.Debug().Str("metric", "main_storage_insert_duration").Msgf("MainStorage.InsertBlockData duration: %f", time.Since(mainStorageStart).Seconds()) |
459 | 445 | metrics.MainStorageInsertDuration.Observe(time.Since(mainStorageStart).Seconds()) |
460 | 446 |
|
461 | | - if config.Cfg.Publisher.Mode == "default" { |
462 | | - highest := highestBlock.Number.Uint64() |
463 | | - go func() { |
464 | | - if err := c.publisher.PublishBlockData(blockData); err != nil { |
465 | | - log.Error().Err(err).Msg("Failed to publish block data to kafka") |
466 | | - return |
467 | | - } |
468 | | - c.lastPublishedBlock.Store(highest) |
469 | | - c.cleanupProcessedStagingBlocks() |
470 | | - }() |
471 | | - } |
472 | | - |
473 | 447 | c.lastCommittedBlock.Store(highestBlock.Number.Uint64()) |
474 | 448 | go c.cleanupProcessedStagingBlocks() |
475 | 449 |
|
|
0 commit comments