Merge pull request #43 from sei-protocol/tony/fix-gasestimator

Pass custom precompiles in gasestimator
This commit is contained in:
codchen 2025-03-04 11:11:10 +08:00 committed by GitHub
commit 7e26589b67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 23 additions and 15 deletions

View file

@ -41,6 +41,7 @@ type Options struct {
Chain core.ChainContext // Chain context to access past block hashes Chain core.ChainContext // Chain context to access past block hashes
Header *types.Header // Header defining the block context to execute in Header *types.Header // Header defining the block context to execute in
State vm.StateDB // Pre-state on top of which to estimate the gas State vm.StateDB // Pre-state on top of which to estimate the gas
CustomPrecompiles map[common.Address]vm.PrecompiledContract
ErrorRatio float64 // Allowed overestimation ratio for faster estimation termination ErrorRatio float64 // Allowed overestimation ratio for faster estimation termination
} }
@ -217,7 +218,7 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil) evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil)
dirtyState = opts.State.Copy() dirtyState = opts.State.Copy()
evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true}, nil) evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true}, opts.CustomPrecompiles)
) )
dirtyState.SetEVM(evm) dirtyState.SetEVM(evm)

View file

@ -1199,6 +1199,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
Header: header, Header: header,
State: state, State: state,
ErrorRatio: estimateGasErrorRatio, ErrorRatio: estimateGasErrorRatio,
CustomPrecompiles: b.GetCustomPrecompiles(),
} }
if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil {
@ -1238,6 +1239,7 @@ func DoEstimateGasAfterCalls(ctx context.Context, b Backend, args TransactionArg
Header: header, Header: header,
State: state, State: state,
ErrorRatio: estimateGasErrorRatio, ErrorRatio: estimateGasErrorRatio,
CustomPrecompiles: b.GetCustomPrecompiles(),
} }
if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil { if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil {

View file

@ -595,6 +595,7 @@ func (b testBackend) BloomStatus() (uint64, uint64) { panic("implement me") }
func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {
panic("implement me") panic("implement me")
} }
func (b testBackend) GetCustomPrecompiles() map[common.Address]vm.PrecompiledContract { return nil }
func TestEstimateGas(t *testing.T) { func TestEstimateGas(t *testing.T) {
t.Parallel() t.Parallel()

View file

@ -96,6 +96,8 @@ type Backend interface {
SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64) BloomStatus() (uint64, uint64)
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
GetCustomPrecompiles() map[common.Address]vm.PrecompiledContract
} }
func GetAPIs(apiBackend Backend) []rpc.API { func GetAPIs(apiBackend Backend) []rpc.API {

View file

@ -342,3 +342,5 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)
} }
func (b *backendMock) Engine() consensus.Engine { return nil } func (b *backendMock) Engine() consensus.Engine { return nil }
func (b *backendMock) GetCustomPrecompiles() map[common.Address]vm.PrecompiledContract { return nil }