Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions eth/gasestimator/gasestimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/core/vm"
"github.com/XinFinOrg/XDPoSChain/internal/ethapi/override"
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/params"
)
Expand All @@ -39,11 +38,10 @@ import (
// these together, it would be excessively hard to test. Splitting the parts out
// allows testing without needing a proper live chain.
type Options struct {
Config *params.ChainConfig // Chain configuration for hard fork selection
Chain core.ChainContext // Chain context to access past block hashes
Header *types.Header // Header defining the block context to execute in
State *state.StateDB // Pre-state on top of which to estimate the gas
BlockOverrides *override.BlockOverrides // Block overrides to apply during the estimation
Config *params.ChainConfig // Chain configuration for hard fork selection
Chain core.ChainContext // Chain context to access past block hashes
Header *types.Header // Header defining the block context to execute in
State *state.StateDB // Pre-state on top of which to estimate the gas
}

// Estimate returns the lowest possible gas limit that allows the transaction to
Expand All @@ -63,13 +61,7 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin

// Cap the maximum gas allowance according to EIP-7825 if the estimation targets Osaka
if hi > params.MaxTxGas {
blockNumber := opts.Header.Number
if opts.BlockOverrides != nil {
if opts.BlockOverrides.Number != nil {
blockNumber = opts.BlockOverrides.Number.ToInt()
}
}
if opts.Config.IsOsaka(blockNumber) {
if opts.Config.IsOsaka(opts.Header.Number) {
hi = params.MaxTxGas
}
}
Expand Down Expand Up @@ -186,9 +178,6 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil)
dirtyState = opts.State.Copy()
)
if opts.BlockOverrides != nil {
opts.BlockOverrides.Apply(&evmContext)
}
// Lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap).
if msgContext.GasPrice.Sign() == 0 {
Expand Down
16 changes: 7 additions & 9 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,27 +1267,25 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
if err = overrides.Apply(state, nil); err != nil {
return 0, err
}
estimationHeader := header
if blockOverrides != nil {
estimationHeader = blockOverrides.MakeHeader(header)
header = blockOverrides.MakeHeader(header)
}
// Construct the gas estimator option from the user input
opts := &gasestimator.Options{
Config: b.ChainConfig(),
Chain: NewChainContext(ctx, b),
Header: estimationHeader,
BlockOverrides: blockOverrides,
State: state,
Config: b.ChainConfig(),
Chain: NewChainContext(ctx, b),
Header: header,
State: state,
}
// Set any required transaction default, but make sure the gas cap itself is not messed with
// if it was not specified in the original argument list.
if args.Gas == nil {
args.Gas = new(hexutil.Uint64)
}
if err := args.CallDefaults(gasCap, estimationHeader.BaseFee, b.ChainConfig().ChainID); err != nil {
if err := args.CallDefaults(gasCap, header.BaseFee, b.ChainConfig().ChainID); err != nil {
return 0, err
}
call := args.ToMessage(b, estimationHeader.BaseFee, true)
call := args.ToMessage(b, header.BaseFee, true)

// Run the gas estimation andwrap any revertals into a custom return
estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap)
Expand Down
Loading