move precompile list to own func

This commit is contained in:
Sina Mahmoodi 2023-10-10 16:46:50 +02:00
parent d1ce690e76
commit e23025876f

View file

@ -126,19 +126,15 @@ func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockRe
var ( var (
results = make([]blockResult, len(blocks)) results = make([]blockResult, len(blocks))
// Each tx and all the series of txes shouldn't consume more gas than cap // Each tx and all the series of txes shouldn't consume more gas than cap
globalGasCap = mc.b.RPCGasCap() gp = new(core.GasPool).AddGas(mc.b.RPCGasCap())
gp = new(core.GasPool).AddGas(globalGasCap) precompiles = mc.activePrecompiles(ctx, base)
header = base
blockContext = core.NewEVMBlockContext(header, NewChainContext(ctx, mc.b), nil)
rules = mc.b.ChainConfig().Rules(blockContext.BlockNumber, blockContext.Random != nil, blockContext.Time)
precompiles = vm.ActivePrecompiledContracts(rules).Copy()
numHashes = headers[len(headers)-1].Number.Uint64() - base.Number.Uint64() + 256 numHashes = headers[len(headers)-1].Number.Uint64() - base.Number.Uint64() + 256
) )
// Cache for the block hashes. // Cache for the block hashes.
mc.hashes = make([]common.Hash, numHashes) mc.hashes = make([]common.Hash, numHashes)
for bi, block := range blocks { for bi, block := range blocks {
header = headers[bi] header := headers[bi]
blockContext = core.NewEVMBlockContext(header, NewChainContext(ctx, mc.b), nil) blockContext := core.NewEVMBlockContext(header, NewChainContext(ctx, mc.b), nil)
// Respond to BLOCKHASH requests. // Respond to BLOCKHASH requests.
blockContext.GetHash = func(n uint64) common.Hash { blockContext.GetHash = func(n uint64) common.Hash {
h, err := mc.getBlockHash(ctx, n, base, headers) h, err := mc.getBlockHash(ctx, n, base, headers)
@ -288,6 +284,14 @@ func (mc *multicall) computeBlockHash(ctx context.Context, n uint64, base *types
return common.Hash{}, errors.New("requested block is in future") return common.Hash{}, errors.New("requested block is in future")
} }
func (mc *multicall) activePrecompiles(ctx context.Context, base *types.Header) vm.PrecompiledContracts {
var (
blockContext = core.NewEVMBlockContext(base, NewChainContext(ctx, mc.b), nil)
rules = mc.b.ChainConfig().Rules(blockContext.BlockNumber, blockContext.Random != nil, blockContext.Time)
)
return vm.ActivePrecompiledContracts(rules).Copy()
}
// repairLogs updates the block hash in the logs present in a multicall // repairLogs updates the block hash in the logs present in a multicall
// result object. This is needed as during execution when logs are collected // result object. This is needed as during execution when logs are collected
// the block hash is not known. // the block hash is not known.