internal/ethapi: limit number of calls to eth_simulateV1 (#34616)

Later on we can consider making these limits configurable if the
use-case arose.
This commit is contained in:
Sina M 2026-03-30 10:01:12 +02:00 committed by GitHub
parent e585ad3b42
commit ceabc39304
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -841,6 +841,16 @@ func (api *BlockChainAPI) SimulateV1(ctx context.Context, opts simOpts, blockNrO
} else if len(opts.BlockStateCalls) > maxSimulateBlocks {
return nil, &clientLimitExceededError{message: "too many blocks"}
}
var totalCalls int
for _, block := range opts.BlockStateCalls {
if len(block.Calls) > maxSimulateCallsPerBlock {
return nil, &clientLimitExceededError{message: fmt.Sprintf("too many calls in block: %d > %d", len(block.Calls), maxSimulateCallsPerBlock)}
}
totalCalls += len(block.Calls)
if totalCalls > maxSimulateTotalCalls {
return nil, &clientLimitExceededError{message: fmt.Sprintf("too many calls: %d > %d", totalCalls, maxSimulateTotalCalls)}
}
}
if blockNrOrHash == nil {
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
blockNrOrHash = &n

View file

@ -44,6 +44,14 @@ const (
// in a single request.
maxSimulateBlocks = 256
// maxSimulateCallsPerBlock is the maximum number of calls allowed in a
// single simulated block.
maxSimulateCallsPerBlock = 5000
// maxSimulateTotalCalls is the maximum total number of calls allowed
// across all simulated blocks in a single request.
maxSimulateTotalCalls = 10000
// timestampIncrement is the default increment between block timestamps.
timestampIncrement = 12
)