Skip to content

Commit e58b588

Browse files
committed
limit parallel calls in batch rpc
1 parent ed71059 commit e58b588

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/libs/libblockdata/getblockdata.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,19 @@ func GetValidBlockDataFromRpc(blockNumbers []uint64) []*common.BlockData {
174174
numBatches := (totalBlocks + int(rpcBatchSize) - 1) / int(rpcBatchSize)
175175

176176
var wg sync.WaitGroup
177+
maxConcurrentBatches := 4
178+
semaphore := make(chan struct{}, maxConcurrentBatches)
177179

178-
// Process blocks in parallel batches
180+
// Process blocks in parallel batches with concurrency limit
179181
for batchIndex := 0; batchIndex < numBatches; batchIndex++ {
180182
wg.Add(1)
181183
go func(batchIdx int) {
182184
defer wg.Done()
183185

186+
// Acquire semaphore
187+
semaphore <- struct{}{}
188+
defer func() { <-semaphore }()
189+
184190
start := batchIdx * int(rpcBatchSize)
185191
end := min(start+int(rpcBatchSize), totalBlocks)
186192

0 commit comments

Comments
 (0)