Skip to content

Commit 9a26cd5

Browse files
committed
Merge branch 'andrius/audit-fixes-2026-05-14' into 'main'
fix(M-01): drop log-batch parallelism, default log_range to 1000 See merge request flarenetwork/FSP/flare-system-c-chain-indexer!84
2 parents 7527b8b + 6d43aa6 commit 9a26cd5

3 files changed

Lines changed: 12 additions & 25 deletions

File tree

config.example.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ mode = "full" # "full" (default) or "fsp"
33
start_index = 0 # start block; set only when history_drop = 0.
44
stop_index = 0 # stop block; set 0 to index indefinitely
55
history_epochs = 0 # FSP mode only: 0=last 2 hours, >0=number of reward epochs to keep/index from
6-
num_parallel_req = 100 # number of parallel requests to the chain
7-
batch_size = 1000 # the number of blocks that will be pushed to a database in a batch (should be divisible by num_parallel_req)
8-
log_range = 1024 # max blocks per eth_getLogs request; set to your RPC's getLogs cap (typically 100-10000)
6+
num_parallel_req = 100 # concurrency cap for block (eth_getBlockByNumber) and receipt (eth_getTransactionReceipt) fetches during history catchup
7+
batch_size = 1000 # number of blocks committed to the database in a single transaction during history catchup
8+
log_range = 1000 # max blocks per eth_getLogs request during history catchup; set to your RPC's getLogs cap (typically 100-10000)
99
new_block_check_millis = 1000 # interval for checking for new blocks
1010
confirmations = 1 # number of confirmations for latest block queries
1111
no_new_blocks_delay_warning = 60 # max allowed delay between consecutive processed blocks before warning; 0 disables warning

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
defaultChainType chain.ChainType = chain.ChainTypeAvax
2626
defaultIndexerMode = IndexerModeFull
2727
defaultFspIndexLookbackSeconds = uint64(2 * time.Hour / time.Second)
28-
defaultLogRange = uint64(1024)
28+
defaultLogRange = uint64(1000)
2929
)
3030

3131
var (

internal/core/engine.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,30 +313,17 @@ func (ci *Engine) obtainLogsBatch(
313313
) (*logsBatch, error) {
314314
lgBatch := new(logsBatch)
315315
startTime := time.Now()
316-
numRequests := ci.params.BatchSize / ci.params.LogRange
317-
perRunner := numRequests / uint64(ci.params.NumParallelReq)
318316

319317
for _, logInfo := range ci.params.CollectLogs {
320-
eg, ctx := errgroup.WithContext(ctx)
321-
322-
for i := 0; i < ci.params.NumParallelReq; i++ {
323-
start := batchIx + perRunner*ci.params.LogRange*uint64(i)
324-
stop := batchIx + perRunner*ci.params.LogRange*uint64(i+1)
325-
326-
eg.Go(func() error {
327-
return ci.requestLogs(
328-
ctx,
329-
lgBatch,
330-
logInfo,
331-
start,
332-
stop,
333-
lastBlockNumInRound,
334-
)
335-
})
336-
}
318+
for fromBlock := batchIx; fromBlock <= lastBlockNumInRound; fromBlock += ci.params.LogRange {
319+
toBlock := min(fromBlock+ci.params.LogRange-1, lastBlockNumInRound)
337320

338-
if err := eg.Wait(); err != nil {
339-
return nil, err
321+
logs, err := ci.fetchLogsChunk(ctx, logInfo, fromBlock, toBlock)
322+
if err != nil {
323+
return nil, err
324+
}
325+
326+
lgBatch.logs = append(lgBatch.logs, logs...)
340327
}
341328
}
342329

0 commit comments

Comments
 (0)