diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index f4e5a2a90..7905e7314 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -344,6 +344,7 @@ func (c *BoundContract) estimateGasLimit(opts *TransactOpts, contract *common.Ad Value: value, Data: input, } + //@lfm: no need for price adjustment here as only invoked via contract-invoked txs return c.transactor.EstimateGas(ensureContext(opts.Context), msg) } diff --git a/eth/gasprice/locaFeeMarket/nativediscount.go b/eth/gasprice/locaFeeMarket/nativediscount.go index 7cfffa392..f658cc8ae 100644 --- a/eth/gasprice/locaFeeMarket/nativediscount.go +++ b/eth/gasprice/locaFeeMarket/nativediscount.go @@ -1,6 +1,7 @@ package locaFeeMarket import ( + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/log" "math/big" ) @@ -29,11 +30,19 @@ const ( lfmDebugMode = true //@hhhh ) -//var origGasPriceMap = make(map[common.Hash]big.Int) -// -//func ResetMap() { -// origGasPriceMap = make(map[common.Hash]big.Int) -//} +func AdjustGasPriceForEstimation(_origGasPrice *hexutil.Big, _gas *hexutil.Uint64, _value *hexutil.Big, dataLen int) *hexutil.Big { + if _origGasPrice == nil || _gas == nil || _value == nil { + return _origGasPrice + } + origGasPrice := (*big.Int)(_origGasPrice) + gas := uint64(*_gas) + value := (*big.Int)(_value) + adjusted := origGasPrice + if isNativeTransferTx(gas, value, dataLen) { + adjusted = adjustGasPrice(origGasPrice) + } + return (*hexutil.Big)(adjusted) +} func AdjustGasPrice(origGasPrice *big.Int, gas uint64, value *big.Int, dataLen int) *big.Int { //@lfm if isNativeTransferTx(gas, value, dataLen) { @@ -103,34 +112,14 @@ func adjustGasPrice(origGasPrice *big.Int) *big.Int { adjusted = maxAdjusted } - adjusted = min(adjusted, orig) // sanity check: adjusted gas-price cannot exceed orig - adjusted = min(adjusted, maxAdjusted) // sanity check: adjusted gas-price cannot exceed maxAdjusted value - adjusted = max(adjusted, orig/2) // sanity check: adjusted gas-price cannot go below half of the orig price - + if adjusted != orig { + adjusted = min(adjusted, orig) // sanity check: adjusted gas-price cannot exceed orig + adjusted = min(adjusted, maxAdjusted) // sanity check: adjusted gas-price cannot exceed maxAdjusted value + adjusted = max(adjusted, orig/2) // sanity check: adjusted gas-price cannot go below half of the orig price + } return new(big.Int).SetUint64(adjusted) } -//func AdjustGasPriceArg(actualGasPrice *hexutil.Big, actualGas hexutil.Uint64) *hexutil.Big {@lfm -// if actualGas == nativeTransferTxGas { -// log.Debug("mmx2x: gas price set to ") -// newval := big.NewInt(18000000000) -// return (*hexutil.Big)(newval) -// } -// return actualGasPrice -//} - -//func MapOrigGasPrice(hash common.Hash, price *big.Int) { -// origGasPriceMap[hash] = *price -//} - -//func GetOrigGasPrice(hash common.Hash) *big.Int { -// orig, ok := origGasPriceMap[hash] -// if !ok { -// return nil -// } -// return &orig -//} - func min(a, b uint64) uint64 { if a < b { return a diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 1c12fcdab..47c75f744 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -43,6 +43,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth/gasprice/locaFeeMarket" "github.com/ethereum/go-ethereum/eth/tracers/logger" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" @@ -1005,6 +1006,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr hi uint64 cap uint64 ) + args.GasPrice = locaFeeMarket.AdjustGasPriceForEstimation(args.GasPrice, args.Gas, args.Value, len(args.data())) //@lfm // Use zero address if sender unspecified. if args.From == nil { args.From = new(common.Address)