Skip to content

Commit

Permalink
AdjustGasPriceForEstimation added
Browse files Browse the repository at this point in the history
  • Loading branch information
giladHaimov committed Jun 17, 2024
1 parent 1b9b5e7 commit 3d7cac8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
1 change: 1 addition & 0 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
49 changes: 19 additions & 30 deletions eth/gasprice/locaFeeMarket/nativediscount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package locaFeeMarket

import (

Check failure on line 3 in eth/gasprice/locaFeeMarket/nativediscount.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.19.x, ubuntu-latest)

File is not `goimports`-ed (goimports)
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"math/big"
)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3d7cac8

Please sign in to comment.