Skip to content

Commit

Permalink
changes after review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
giladHaimov committed Sep 5, 2024
1 parent e76deee commit aa9f0f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 81 deletions.
1 change: 0 additions & 1 deletion consensus/satoshi/satoshi.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func New(
candidateHubABI: cABI,
signer: types.NewEIP155Signer(chainConfig.ChainID),
}

return c
}

Expand Down
4 changes: 2 additions & 2 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/gasprice/locaFeeMarket"
"github.com/ethereum/go-ethereum/eth/gasprice/lfm"
"github.com/ethereum/go-ethereum/rlp"
)

Expand Down Expand Up @@ -170,7 +170,7 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
//@lfm RPC invocation route: adjust tx gas price
if data.OrigGasPrice == nil {
data.OrigGasPrice = data.GasPrice
data.GasPrice = locaFeeMarket.AdjustGasPrice(data.Gas, data.Value, data.To, data.Data, data.OrigGasPrice)
data.GasPrice = lfm.AdjustGasPrice(data.Gas, data.Value, data.To, data.Data, data.OrigGasPrice)
}
tx.setDecoded(&data, len(b))
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package locaFeeMarket
package lfm

import (
"bytes"
Expand Down Expand Up @@ -49,8 +49,10 @@ var (
debugDiscountedGasPrice = new(big.Int).SetUint64(18_000_000_000)

errNotFunctionInvocation = errors.New("tx is not a function invocation")
)

//-------
// white-listed erc20 map
var (
btcLstContract = common.HexToAddress("0xTBD")

internalErc20Whitelist = map[common.Address]bool{
Expand Down Expand Up @@ -109,66 +111,6 @@ func calcCoreTransferDiscountedGasPrice(networkGasPrice *big.Int) *big.Int {
return internalCalcDiscountedGasPrice(networkGasPrice)
}

func obsolete__internalCalcDiscountedGasPrice(networkGasPrice *big.Int) *big.Int {
networkPrice := networkGasPrice.Uint64()
const MEAN = historicalMeanGasPrice
const LOW_WATERMARK = (700*MEAN)/1000
var discounted uint64

switch {
case networkPrice <= LOW_WATERMARK:
discounted = networkPrice // no discount
case networkPrice <= MEAN:
discounted = LOW_WATERMARK
case networkPrice <= MEAN+789473684:
discounted = MEAN + 220850187
case networkPrice <= MEAN+1578947368:
discounted = MEAN + 229206660
case networkPrice <= MEAN+2368421053:
discounted = MEAN + 237511346
case networkPrice <= MEAN+3157894737:
discounted = MEAN + 245739149
case networkPrice <= MEAN+3947368421:
discounted = MEAN + 253865910
case networkPrice <= MEAN+4736842105:
discounted = MEAN + 261868680
case networkPrice <= MEAN+5526315789:
discounted = MEAN + 269725961
case networkPrice <= MEAN+6315789474:
discounted = MEAN + 277417917
case networkPrice <= MEAN+7105263158:
discounted = MEAN + 284926545
case networkPrice <= MEAN+7894736842:
discounted = MEAN + 292235799
case networkPrice <= MEAN+8684210526:
discounted = MEAN + 299331682
case networkPrice <= MEAN+9473684211:
discounted = MEAN + 306202288
case networkPrice <= MEAN+10263157895:
discounted = MEAN + 312837812
case networkPrice <= MEAN+11052631579:
discounted = MEAN + 319230518
case networkPrice <= MEAN+11842105263:
discounted = MEAN + 325374683
case networkPrice <= MEAN+12631578947:
discounted = MEAN + 331266505
case networkPrice <= MEAN+13421052632:
discounted = MEAN + 336903992
case networkPrice <= MEAN+14210526316:
discounted = MEAN + 342286837
default:
discounted = maxDiscountedGasPrice
}

if discounted != networkPrice {
discounted = min(discounted, networkPrice) // sanity check: discounted gas-price cannot exceed networkPrice
discounted = min(discounted, maxDiscountedGasPrice) // sanity check: discounted gas-price cannot exceed maxDiscountedGasPrice value
discounted = max(discounted, networkPrice/2) // sanity check: discounted gas-price cannot go below half of the networkPrice price
}
return new(big.Int).SetUint64(discounted)
}


/**
discrete steps for the sigmoid function sig(x) = 1 / (1 + e^(-3 * (x - 0.8)))
where x denotes the historical mean, slightly modified for simplicity
Expand Down Expand Up @@ -302,17 +244,3 @@ func validApproveData(functionSelector []byte, dataLen int) bool {
func eq(a []byte, b []byte) bool {
return bytes.Equal(a, b)
}

func min(a, b uint64) uint64 {
if a < b {
return a
}
return b
}

func max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +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/gasprice/lfm"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
Expand Down Expand Up @@ -1006,7 +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, args.To, args.data()) //@lfm
args.GasPrice = lfm.AdjustGasPriceForEstimation(args.GasPrice, args.Gas, args.Value, args.To, args.data()) //@lfm
// Use zero address if sender unspecified.
if args.From == nil {
args.From = new(common.Address)
Expand Down

0 comments on commit aa9f0f7

Please sign in to comment.