mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
fix: eth_estimateGas error in zero balance address (#537)
* fix: eth_estimateGas zero balance error * bump version * revert irrelevant auto format * remove isEstimateGas in DoCall * fix CI * bump version --------- Co-authored-by: maskpp <maskpp266@gmail.com>
This commit is contained in:
parent
adde9ce118
commit
bbf42042e2
2 changed files with 7 additions and 46 deletions
|
|
@ -852,7 +852,6 @@ type OverrideAccount struct {
|
||||||
Nonce *hexutil.Uint64 `json:"nonce"`
|
Nonce *hexutil.Uint64 `json:"nonce"`
|
||||||
Code *hexutil.Bytes `json:"code"`
|
Code *hexutil.Bytes `json:"code"`
|
||||||
Balance **hexutil.Big `json:"balance"`
|
Balance **hexutil.Big `json:"balance"`
|
||||||
BalanceAdd **hexutil.Big `json:"balanceAdd"`
|
|
||||||
State *map[common.Hash]common.Hash `json:"state"`
|
State *map[common.Hash]common.Hash `json:"state"`
|
||||||
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
|
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
|
||||||
}
|
}
|
||||||
|
|
@ -875,16 +874,9 @@ func (diff *StateOverride) Apply(state *state.StateDB) error {
|
||||||
state.SetCode(addr, *account.Code)
|
state.SetCode(addr, *account.Code)
|
||||||
}
|
}
|
||||||
// Override account balance.
|
// Override account balance.
|
||||||
if account.Balance != nil && account.BalanceAdd != nil {
|
|
||||||
return fmt.Errorf("account %s has both 'balance' and 'balanceAdd'", addr.Hex())
|
|
||||||
}
|
|
||||||
if account.Balance != nil {
|
if account.Balance != nil {
|
||||||
state.SetBalance(addr, (*big.Int)(*account.Balance))
|
state.SetBalance(addr, (*big.Int)(*account.Balance))
|
||||||
}
|
}
|
||||||
if account.BalanceAdd != nil {
|
|
||||||
balance := big.NewInt(0).Add(state.GetBalance(addr), (*big.Int)(*account.BalanceAdd))
|
|
||||||
state.SetBalance(addr, balance)
|
|
||||||
}
|
|
||||||
if account.State != nil && account.StateDiff != nil {
|
if account.State != nil && account.StateDiff != nil {
|
||||||
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
|
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
|
||||||
}
|
}
|
||||||
|
|
@ -902,11 +894,6 @@ func (diff *StateOverride) Apply(state *state.StateDB) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRPCBalance(balance *big.Int) **hexutil.Big {
|
|
||||||
rpcBalance := (*hexutil.Big)(balance)
|
|
||||||
return &rpcBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
func EstimateL1MsgFee(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64, config *params.ChainConfig) (*big.Int, error) {
|
func EstimateL1MsgFee(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, timeout time.Duration, globalGasCap uint64, config *params.ChainConfig) (*big.Int, error) {
|
||||||
if !config.Scroll.FeeVaultEnabled() {
|
if !config.Scroll.FeeVaultEnabled() {
|
||||||
return big.NewInt(0), nil
|
return big.NewInt(0), nil
|
||||||
|
|
@ -992,13 +979,7 @@ func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash
|
||||||
// Execute the message.
|
// Execute the message.
|
||||||
gp := new(core.GasPool).AddGas(math.MaxUint64)
|
gp := new(core.GasPool).AddGas(math.MaxUint64)
|
||||||
|
|
||||||
signer := types.MakeSigner(b.ChainConfig(), header.Number)
|
result, err := core.ApplyMessage(evm, msg, gp, common.Big0)
|
||||||
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, header.BaseFee, b.ChainConfig().ChainID, signer, state)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := core.ApplyMessage(evm, msg, gp, l1DataFee)
|
|
||||||
if err := vmError(); err != nil {
|
if err := vmError(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1050,26 +1031,6 @@ func (e *revertError) ErrorData() interface{} {
|
||||||
// Note, this function doesn't make and changes in the state/blockchain and is
|
// Note, this function doesn't make and changes in the state/blockchain and is
|
||||||
// useful to execute and retrieve values.
|
// useful to execute and retrieve values.
|
||||||
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
|
func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
|
||||||
// If gasPrice is 0 and no state override is set, make sure
|
|
||||||
// that the account has sufficient balance to cover `l1DataFee`.
|
|
||||||
isGasPriceZero := args.GasPrice == nil || args.GasPrice.ToInt().Cmp(big.NewInt(0)) == 0
|
|
||||||
|
|
||||||
if overrides == nil {
|
|
||||||
overrides = &StateOverride{}
|
|
||||||
}
|
|
||||||
_, isOverrideSet := (*overrides)[args.from()]
|
|
||||||
|
|
||||||
if isGasPriceZero && !isOverrideSet {
|
|
||||||
l1DataFee, err := EstimateL1MsgFee(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap(), s.b.ChainConfig())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
(*overrides)[args.from()] = OverrideAccount{
|
|
||||||
BalanceAdd: newRPCBalance(l1DataFee),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
|
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 0 // Minor version component of the current release
|
VersionMinor = 0 // Minor version component of the current release
|
||||||
VersionPatch = 2 // Patch version component of the current release
|
VersionPatch = 3 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue