Merge pull request #529 from XinFinOrg/extend-eth_call_2

extend eth_call and estimateGas api with state override
This commit is contained in:
wgr523 2024-05-07 17:57:18 +08:00 committed by GitHub
commit bfa3bb4f5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 246 additions and 142 deletions

View file

@ -31,23 +31,23 @@ var emptyCodeHash = crypto.Keccak256(nil)
type Code []byte type Code []byte
func (self Code) String() string { func (c Code) String() string {
return string(self) //strings.Join(Disassemble(self), " ") return string(c) //strings.Join(Disassemble(c), " ")
} }
type Storage map[common.Hash]common.Hash type Storage map[common.Hash]common.Hash
func (self Storage) String() (str string) { func (s Storage) String() (str string) {
for key, value := range self { for key, value := range s {
str += fmt.Sprintf("%X : %X\n", key, value) str += fmt.Sprintf("%X : %X\n", key, value)
} }
return return
} }
func (self Storage) Copy() Storage { func (s Storage) Copy() Storage {
cpy := make(Storage) cpy := make(Storage)
for key, value := range self { for key, value := range s {
cpy[key] = value cpy[key] = value
} }
@ -79,6 +79,7 @@ type stateObject struct {
cachedStorage Storage // Storage entry cache to avoid duplicate reads cachedStorage Storage // Storage entry cache to avoid duplicate reads
dirtyStorage Storage // Storage entries that need to be flushed to disk dirtyStorage Storage // Storage entries that need to be flushed to disk
fakeStorage Storage // Fake storage which constructed by caller for debugging purpose.
// Cache flags. // Cache flags.
// When an object is marked suicided it will be delete from the trie // When an object is marked suicided it will be delete from the trie
@ -124,199 +125,236 @@ func newObject(db *StateDB, address common.Address, data Account, onDirty func(a
} }
// EncodeRLP implements rlp.Encoder. // EncodeRLP implements rlp.Encoder.
func (c *stateObject) EncodeRLP(w io.Writer) error { func (s *stateObject) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, c.data) return rlp.Encode(w, s.data)
} }
// setError remembers the first non-nil error it is called with. // setError remembers the first non-nil error it is called with.
func (self *stateObject) setError(err error) { func (s *stateObject) setError(err error) {
if self.dbErr == nil { if s.dbErr == nil {
self.dbErr = err s.dbErr = err
} }
} }
func (self *stateObject) markSuicided() { func (s *stateObject) markSuicided() {
self.suicided = true s.suicided = true
if self.onDirty != nil { if s.onDirty != nil {
self.onDirty(self.Address()) s.onDirty(s.Address())
self.onDirty = nil s.onDirty = nil
} }
} }
func (c *stateObject) touch() { func (s *stateObject) touch() {
c.db.journal = append(c.db.journal, touchChange{ s.db.journal = append(s.db.journal, touchChange{
account: &c.address, account: &s.address,
prev: c.touched, prev: s.touched,
prevDirty: c.onDirty == nil, prevDirty: s.onDirty == nil,
}) })
if c.onDirty != nil { if s.onDirty != nil {
c.onDirty(c.Address()) s.onDirty(s.Address())
c.onDirty = nil s.onDirty = nil
} }
c.touched = true s.touched = true
} }
func (c *stateObject) getTrie(db Database) Trie { func (s *stateObject) getTrie(db Database) Trie {
if c.trie == nil { if s.trie == nil {
var err error var err error
c.trie, err = db.OpenStorageTrie(c.addrHash, c.data.Root) s.trie, err = db.OpenStorageTrie(s.addrHash, s.data.Root)
if err != nil { if err != nil {
c.trie, _ = db.OpenStorageTrie(c.addrHash, common.Hash{}) s.trie, _ = db.OpenStorageTrie(s.addrHash, common.Hash{})
c.setError(fmt.Errorf("can't create storage trie: %v", err)) s.setError(fmt.Errorf("can't create storage trie: %v", err))
} }
} }
return c.trie return s.trie
} }
func (self *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash { func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash {
// If the fake storage is set, only lookup the state here(in the debugging mode)
if s.fakeStorage != nil {
return s.fakeStorage[key]
}
value := common.Hash{} value := common.Hash{}
// Load from DB in case it is missing. // Load from DB in case it is missing.
enc, err := self.getTrie(db).TryGet(key[:]) enc, err := s.getTrie(db).TryGet(key[:])
if err != nil { if err != nil {
self.setError(err) s.setError(err)
return common.Hash{} return common.Hash{}
} }
if len(enc) > 0 { if len(enc) > 0 {
_, content, _, err := rlp.Split(enc) _, content, _, err := rlp.Split(enc)
if err != nil { if err != nil {
self.setError(err) s.setError(err)
} }
value.SetBytes(content) value.SetBytes(content)
} }
return value return value
} }
func (self *stateObject) GetState(db Database, key common.Hash) common.Hash { func (s *stateObject) GetState(db Database, key common.Hash) common.Hash {
value, exists := self.cachedStorage[key] // If the fake storage is set, only lookup the state here(in the debugging mode)
if s.fakeStorage != nil {
return s.fakeStorage[key]
}
value, exists := s.cachedStorage[key]
if exists { if exists {
return value return value
} }
// Load from DB in case it is missing. // Load from DB in case it is missing.
enc, err := self.getTrie(db).TryGet(key[:]) enc, err := s.getTrie(db).TryGet(key[:])
if err != nil { if err != nil {
self.setError(err) s.setError(err)
return common.Hash{} return common.Hash{}
} }
if len(enc) > 0 { if len(enc) > 0 {
_, content, _, err := rlp.Split(enc) _, content, _, err := rlp.Split(enc)
if err != nil { if err != nil {
self.setError(err) s.setError(err)
} }
value.SetBytes(content) value.SetBytes(content)
} }
if (value != common.Hash{}) { if (value != common.Hash{}) {
self.cachedStorage[key] = value s.cachedStorage[key] = value
} }
return value return value
} }
// SetState updates a value in account storage. // SetState updates a value in account storage.
func (self *stateObject) SetState(db Database, key, value common.Hash) { func (s *stateObject) SetState(db Database, key, value common.Hash) {
self.db.journal = append(self.db.journal, storageChange{ // If the fake storage is set, put the temporary state update here.
account: &self.address, if s.fakeStorage != nil {
s.fakeStorage[key] = value
return
}
// If the new value is the same as old, don't set
prev := s.GetState(db, key)
if prev == value {
return
}
// New value is different, update and journal the change
s.db.journal = append(s.db.journal, storageChange{
account: &s.address,
key: key, key: key,
prevalue: self.GetState(db, key), prevalue: prev,
}) })
self.setState(key, value) s.setState(key, value)
} }
func (self *stateObject) setState(key, value common.Hash) { // SetStorage replaces the entire state storage with the given one.
self.cachedStorage[key] = value //
self.dirtyStorage[key] = value // After this function is called, all original state will be ignored and state
// lookup only happens in the fake state storage.
//
// Note this function should only be used for debugging purpose.
func (s *stateObject) SetStorage(storage map[common.Hash]common.Hash) {
// Allocate fake storage if it's nil.
if s.fakeStorage == nil {
s.fakeStorage = make(Storage)
}
for key, value := range storage {
s.fakeStorage[key] = value
}
// Don't bother journal since this function should only be used for
// debugging and the `fake` storage won't be committed to database.
}
if self.onDirty != nil { func (s *stateObject) setState(key, value common.Hash) {
self.onDirty(self.Address()) s.cachedStorage[key] = value
self.onDirty = nil s.dirtyStorage[key] = value
if s.onDirty != nil {
s.onDirty(s.Address())
s.onDirty = nil
} }
} }
// updateTrie writes cached storage modifications into the object's storage trie. // updateTrie writes cached storage modifications into the object's storage trie.
func (self *stateObject) updateTrie(db Database) Trie { func (s *stateObject) updateTrie(db Database) Trie {
tr := self.getTrie(db) tr := s.getTrie(db)
for key, value := range self.dirtyStorage { for key, value := range s.dirtyStorage {
delete(self.dirtyStorage, key) delete(s.dirtyStorage, key)
if (value == common.Hash{}) { if (value == common.Hash{}) {
self.setError(tr.TryDelete(key[:])) s.setError(tr.TryDelete(key[:]))
continue continue
} }
// Encoding []byte cannot fail, ok to ignore the error. // Encoding []byte cannot fail, ok to ignore the error.
v, _ := rlp.EncodeToBytes(bytes.TrimLeft(value[:], "\x00")) v, _ := rlp.EncodeToBytes(bytes.TrimLeft(value[:], "\x00"))
self.setError(tr.TryUpdate(key[:], v)) s.setError(tr.TryUpdate(key[:], v))
} }
return tr return tr
} }
// UpdateRoot sets the trie root to the current root hash of // UpdateRoot sets the trie root to the current root hash of
func (self *stateObject) updateRoot(db Database) { func (s *stateObject) updateRoot(db Database) {
self.updateTrie(db) s.updateTrie(db)
self.data.Root = self.trie.Hash() s.data.Root = s.trie.Hash()
} }
// CommitTrie the storage trie of the object to dwb. // CommitTrie the storage trie of the object to dwb.
// This updates the trie root. // This updates the trie root.
func (self *stateObject) CommitTrie(db Database) error { func (s *stateObject) CommitTrie(db Database) error {
self.updateTrie(db) s.updateTrie(db)
if self.dbErr != nil { if s.dbErr != nil {
return self.dbErr return s.dbErr
} }
root, err := self.trie.Commit(nil) root, err := s.trie.Commit(nil)
if err == nil { if err == nil {
self.data.Root = root s.data.Root = root
} }
return err return err
} }
// AddBalance removes amount from c's balance. // AddBalance removes amount from c's balance.
// It is used to add funds to the destination account of a transfer. // It is used to add funds to the destination account of a transfer.
func (c *stateObject) AddBalance(amount *big.Int) { func (s *stateObject) AddBalance(amount *big.Int) {
// EIP158: We must check emptiness for the objects such that the account // EIP158: We must check emptiness for the objects such that the account
// clearing (0,0,0 objects) can take effect. // clearing (0,0,0 objects) can take effect.
if amount.Sign() == 0 { if amount.Sign() == 0 {
if c.empty() { if s.empty() {
c.touch() s.touch()
} }
return return
} }
c.SetBalance(new(big.Int).Add(c.Balance(), amount)) s.SetBalance(new(big.Int).Add(s.Balance(), amount))
} }
// SubBalance removes amount from c's balance. // SubBalance removes amount from c's balance.
// It is used to remove funds from the origin account of a transfer. // It is used to remove funds from the origin account of a transfer.
func (c *stateObject) SubBalance(amount *big.Int) { func (s *stateObject) SubBalance(amount *big.Int) {
if amount.Sign() == 0 { if amount.Sign() == 0 {
return return
} }
c.SetBalance(new(big.Int).Sub(c.Balance(), amount)) s.SetBalance(new(big.Int).Sub(s.Balance(), amount))
} }
func (self *stateObject) SetBalance(amount *big.Int) { func (s *stateObject) SetBalance(amount *big.Int) {
self.db.journal = append(self.db.journal, balanceChange{ s.db.journal = append(s.db.journal, balanceChange{
account: &self.address, account: &s.address,
prev: new(big.Int).Set(self.data.Balance), prev: new(big.Int).Set(s.data.Balance),
}) })
self.setBalance(amount) s.setBalance(amount)
} }
func (self *stateObject) setBalance(amount *big.Int) { func (s *stateObject) setBalance(amount *big.Int) {
self.data.Balance = amount s.data.Balance = amount
if self.onDirty != nil { if s.onDirty != nil {
self.onDirty(self.Address()) s.onDirty(s.Address())
self.onDirty = nil s.onDirty = nil
} }
} }
func (self *stateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)) *stateObject { func (s *stateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)) *stateObject {
stateObject := newObject(db, self.address, self.data, onDirty) stateObject := newObject(db, s.address, s.data, onDirty)
if self.trie != nil { if s.trie != nil {
stateObject.trie = db.db.CopyTrie(self.trie) stateObject.trie = db.db.CopyTrie(s.trie)
} }
stateObject.code = self.code stateObject.code = s.code
stateObject.dirtyStorage = self.dirtyStorage.Copy() stateObject.dirtyStorage = s.dirtyStorage.Copy()
stateObject.cachedStorage = self.dirtyStorage.Copy() stateObject.cachedStorage = s.dirtyStorage.Copy()
stateObject.suicided = self.suicided stateObject.suicided = s.suicided
stateObject.dirtyCode = self.dirtyCode stateObject.dirtyCode = s.dirtyCode
stateObject.deleted = self.deleted stateObject.deleted = s.deleted
return stateObject return stateObject
} }
@ -325,81 +363,81 @@ func (self *stateObject) deepCopy(db *StateDB, onDirty func(addr common.Address)
// //
// Returns the address of the contract/account // Returns the address of the contract/account
func (c *stateObject) Address() common.Address { func (s *stateObject) Address() common.Address {
return c.address return s.address
} }
// Code returns the contract code associated with this object, if any. // Code returns the contract code associated with this object, if any.
func (self *stateObject) Code(db Database) []byte { func (s *stateObject) Code(db Database) []byte {
if self.code != nil { if s.code != nil {
return self.code return s.code
} }
if bytes.Equal(self.CodeHash(), emptyCodeHash) { if bytes.Equal(s.CodeHash(), emptyCodeHash) {
return nil return nil
} }
code, err := db.ContractCode(self.addrHash, common.BytesToHash(self.CodeHash())) code, err := db.ContractCode(s.addrHash, common.BytesToHash(s.CodeHash()))
if err != nil { if err != nil {
self.setError(fmt.Errorf("can't load code hash %x: %v", self.CodeHash(), err)) s.setError(fmt.Errorf("can't load code hash %x: %v", s.CodeHash(), err))
} }
self.code = code s.code = code
return code return code
} }
func (self *stateObject) SetCode(codeHash common.Hash, code []byte) { func (s *stateObject) SetCode(codeHash common.Hash, code []byte) {
prevcode := self.Code(self.db.db) prevcode := s.Code(s.db.db)
self.db.journal = append(self.db.journal, codeChange{ s.db.journal = append(s.db.journal, codeChange{
account: &self.address, account: &s.address,
prevhash: self.CodeHash(), prevhash: s.CodeHash(),
prevcode: prevcode, prevcode: prevcode,
}) })
self.setCode(codeHash, code) s.setCode(codeHash, code)
} }
func (self *stateObject) setCode(codeHash common.Hash, code []byte) { func (s *stateObject) setCode(codeHash common.Hash, code []byte) {
self.code = code s.code = code
self.data.CodeHash = codeHash[:] s.data.CodeHash = codeHash[:]
self.dirtyCode = true s.dirtyCode = true
if self.onDirty != nil { if s.onDirty != nil {
self.onDirty(self.Address()) s.onDirty(s.Address())
self.onDirty = nil s.onDirty = nil
} }
} }
func (self *stateObject) SetNonce(nonce uint64) { func (s *stateObject) SetNonce(nonce uint64) {
self.db.journal = append(self.db.journal, nonceChange{ s.db.journal = append(s.db.journal, nonceChange{
account: &self.address, account: &s.address,
prev: self.data.Nonce, prev: s.data.Nonce,
}) })
self.setNonce(nonce) s.setNonce(nonce)
} }
func (self *stateObject) setNonce(nonce uint64) { func (s *stateObject) setNonce(nonce uint64) {
self.data.Nonce = nonce s.data.Nonce = nonce
if self.onDirty != nil { if s.onDirty != nil {
self.onDirty(self.Address()) s.onDirty(s.Address())
self.onDirty = nil s.onDirty = nil
} }
} }
func (self *stateObject) CodeHash() []byte { func (s *stateObject) CodeHash() []byte {
return self.data.CodeHash return s.data.CodeHash
} }
func (self *stateObject) Balance() *big.Int { func (s *stateObject) Balance() *big.Int {
return self.data.Balance return s.data.Balance
} }
func (self *stateObject) Nonce() uint64 { func (s *stateObject) Nonce() uint64 {
return self.data.Nonce return s.data.Nonce
} }
func (self *stateObject) Root() common.Hash { func (s *stateObject) Root() common.Hash {
return self.data.Root return s.data.Root
} }
// Never called, but must be present to allow stateObject to be used // Never called, but must be present to allow stateObject to be used
// as a vm.Account interface that also satisfies the vm.ContractRef // as a vm.Account interface that also satisfies the vm.ContractRef
// interface. Interfaces are awesome. // interface. Interfaces are awesome.
func (self *stateObject) Value() *big.Int { func (s *stateObject) Value() *big.Int {
panic("Value on stateObject should never be called") panic("Value on stateObject should never be called")
} }

View file

@ -387,6 +387,15 @@ func (self *StateDB) SetState(addr common.Address, key, value common.Hash) {
} }
} }
// SetStorage replaces the entire storage for the specified account with given
// storage. This function should only be used for debugging.
func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common.Hash) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetStorage(storage)
}
}
// Suicide marks the given account as suicided. // Suicide marks the given account as suicided.
// This clears the account balance. // This clears the account balance.
// //

View file

@ -653,6 +653,58 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
return res[:], state.Error() return res[:], state.Error()
} }
// OverrideAccount indicates the overriding fields of account during the execution
// of a message call.
// Note, state and stateDiff can't be specified at the same time. If state is
// set, message execution will only use the data in the given state. Otherwise
// if statDiff is set, all diff will be applied first and then execute the call
// message.
type OverrideAccount struct {
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutil.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[common.Hash]common.Hash `json:"state"`
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
}
// StateOverride is the collection of overridden accounts.
type StateOverride map[common.Address]OverrideAccount
// Apply overrides the fields of specified accounts into the given state.
func (diff *StateOverride) Apply(state *state.StateDB) error {
if diff == nil {
return nil
}
for addr, account := range *diff {
// Override account nonce.
if account.Nonce != nil {
state.SetNonce(addr, uint64(*account.Nonce))
}
// Override account(contract) code.
if account.Code != nil {
state.SetCode(addr, *account.Code)
}
// Override account balance.
if account.Balance != nil {
state.SetBalance(addr, (*big.Int)(*account.Balance))
}
if account.State != nil && account.StateDiff != nil {
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
}
// Replace entire state if caller requires.
if account.State != nil {
state.SetStorage(addr, *account.State)
}
// Apply state diff into specified accounts.
if account.StateDiff != nil {
for key, value := range *account.StateDiff {
state.SetState(addr, key, value)
}
}
}
return nil
}
func (s *PublicBlockChainAPI) GetBlockSignersByHash(ctx context.Context, blockHash common.Hash) ([]common.Address, error) { func (s *PublicBlockChainAPI) GetBlockSignersByHash(ctx context.Context, blockHash common.Hash) ([]common.Address, error) {
block, err := s.b.GetBlock(ctx, blockHash) block, err := s.b.GetBlock(ctx, blockHash)
if err != nil || block == nil { if err != nil || block == nil {
@ -1113,13 +1165,16 @@ type CallArgs struct {
Data hexutil.Bytes `json:"data"` Data hexutil.Bytes `json:"data"`
} }
func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, vmCfg vm.Config, timeout time.Duration) ([]byte, uint64, bool, error, error) { func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, vmCfg vm.Config, timeout time.Duration) ([]byte, uint64, bool, error, error) {
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now()) defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
statedb, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) statedb, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if statedb == nil || err != nil { if statedb == nil || err != nil {
return nil, 0, false, err, nil return nil, 0, false, err, nil
} }
if err := overrides.Apply(statedb); err != nil {
return nil, 0, false, err, nil
}
// Set sender address or use a default if none specified // Set sender address or use a default if none specified
addr := args.From addr := args.From
if addr == (common.Address{}) { if addr == (common.Address{}) {
@ -1229,12 +1284,12 @@ func (e *revertError) ErrorData() interface{} {
// Call executes the given transaction on the state for the given block number. // Call executes the given transaction on the state for the given block number.
// It doesn't make and changes in the state/blockchain and is useful to execute and retrieve values. // It doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.
func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Bytes, error) { func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Bytes, error) {
if blockNrOrHash == nil { if blockNrOrHash == nil {
latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
blockNrOrHash = &latest blockNrOrHash = &latest
} }
result, _, failed, err, vmErr := DoCall(ctx, s.b, args, *blockNrOrHash, vm.Config{}, 5*time.Second) result, _, failed, err, vmErr := DoCall(ctx, s.b, args, *blockNrOrHash, overrides, vm.Config{}, 5*time.Second)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1246,13 +1301,15 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
return (hexutil.Bytes)(result), vmErr return (hexutil.Bytes)(result), vmErr
} }
func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Uint64, error) { func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) {
// Retrieve the base state and mutate it with any overrides // Retrieve the base state and mutate it with any overrides
state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || err != nil { if state == nil || err != nil {
return 0, err return 0, err
} }
if err = overrides.Apply(state); err != nil {
return 0, err
}
// Binary search the gas requirement, as it may be higher than the amount used // Binary search the gas requirement, as it may be higher than the amount used
var ( var (
lo uint64 = params.TxGas - 1 lo uint64 = params.TxGas - 1
@ -1275,7 +1332,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
executable := func(gas uint64) (bool, []byte, error, error) { executable := func(gas uint64) (bool, []byte, error, error) {
args.Gas = hexutil.Uint64(gas) args.Gas = hexutil.Uint64(gas)
res, _, failed, err, vmErr := DoCall(ctx, b, args, blockNrOrHash, vm.Config{}, 0) res, _, failed, err, vmErr := DoCall(ctx, b, args, blockNrOrHash, nil, vm.Config{}, 0)
if err != nil { if err != nil {
if errors.Is(err, vm.ErrOutOfGas) || errors.Is(err, core.ErrIntrinsicGas) { if errors.Is(err, vm.ErrOutOfGas) || errors.Is(err, core.ErrIntrinsicGas) {
return false, nil, nil, nil // Special case, raise gas limit return false, nil, nil, nil // Special case, raise gas limit
@ -1345,12 +1402,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
// EstimateGas returns an estimate of the amount of gas needed to execute the // EstimateGas returns an estimate of the amount of gas needed to execute the
// given transaction against the current pending block. // given transaction against the current pending block.
func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) {
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
if blockNrOrHash != nil { if blockNrOrHash != nil {
bNrOrHash = *blockNrOrHash bNrOrHash = *blockNrOrHash
} }
return DoEstimateGas(ctx, s.b, args, bNrOrHash) return DoEstimateGas(ctx, s.b, args, bNrOrHash, overrides)
} }
// ExecutionResult groups all structured logs emitted by the EVM // ExecutionResult groups all structured logs emitted by the EVM