synapsecns / sanguine

Synapse Monorepo
MIT License
35 stars 25 forks source link

[Submitter]: Cap TX count in chainConfirmQueue #2750

Closed trajan0x closed 1 week ago

trajan0x commented 2 weeks ago

see thhis single batch w/ 9,800 receipt requests:

image
greptile-apps[bot] commented 2 weeks ago

To cap the TX count in chainConfirmQueue, modify the function in ethergo/submitter/queue.go as follows:

func (t *txSubmitterImpl) chainConfirmQueue(parentCtx context.Context, chainID *big.Int, txes []db.TX) (err error) {
    ctx, span := t.metrics.Tracer().Start(parentCtx, "submitter.chainConfirmQueue")
    defer func() {
        metrics.EndSpanWithErr(span, err)
    }()

    chainClient, err := t.fetcher.GetClient(ctx, chainID)
    if err != nil {
        return fmt.Errorf("could not get client: %w", err)
    }

    nonceMap := groupTxesByNonce(txes)
    const maxBatchSize = 1000 // Set the maximum batch size
    for nonce := range nonceMap {
        for i := 0; i < len(nonceMap[nonce]); i += maxBatchSize {
            end := i + maxBatchSize
            if end > len(nonceMap[nonce]) {
                end = len(nonceMap[nonce])
            }
            batch := nonceMap[nonce][i:end]
            err = t.checkAndSetConfirmation(ctx, chainClient, batch)
            if err != nil {
                return fmt.Errorf("could not check and set confirmation: %w", err)
            }
        }
    }
    return nil
}

References

/ethergo/submitter/queue.go

Ask Greptile