mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-16 13:06:40 +00:00
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:
parent
e585ad3b42
commit
ceabc39304
2 changed files with 18 additions and 0 deletions
|
|
@ -841,6 +841,16 @@ func (api *BlockChainAPI) SimulateV1(ctx context.Context, opts simOpts, blockNrO
|
||||||
} else if len(opts.BlockStateCalls) > maxSimulateBlocks {
|
} else if len(opts.BlockStateCalls) > maxSimulateBlocks {
|
||||||
return nil, &clientLimitExceededError{message: "too many blocks"}
|
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 {
|
if blockNrOrHash == nil {
|
||||||
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
||||||
blockNrOrHash = &n
|
blockNrOrHash = &n
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,14 @@ const (
|
||||||
// in a single request.
|
// in a single request.
|
||||||
maxSimulateBlocks = 256
|
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 is the default increment between block timestamps.
|
||||||
timestampIncrement = 12
|
timestampIncrement = 12
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue