limit number of blocks

This commit is contained in:
Sina Mahmoodi 2023-10-24 17:53:14 +02:00
parent e23025876f
commit c02d29d8e4
2 changed files with 13 additions and 0 deletions

View file

@ -1229,6 +1229,13 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
// Note, this function doesn't make any changes in the state/blockchain and is
// useful to execute and retrieve values.
func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) {
if len(opts.BlockStateCalls) == 0 {
// TODO return error code.
return nil, errors.New("invalid params")
} else if len(opts.BlockStateCalls) > maxMulticallBlocks {
// TODO return error code.
return nil, errors.New("invalid params")
}
if blockNrOrHash == nil {
n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
blockNrOrHash = &n

View file

@ -37,6 +37,12 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
const (
// maxMulticallBlocks is the maximum number of blocks that can be simulated
// in a single request.
maxMulticallBlocks = 256
)
// CallBatch is a batch of calls to be simulated sequentially.
type CallBatch struct {
BlockOverrides *BlockOverrides