Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic fee types cleanup #14602

Merged
merged 13 commits into from
Oct 9, 2024
5 changes: 5 additions & 0 deletions .changeset/curvy-eyes-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Update dynamic fee types to align with geth #internal
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func makeTestEvmTxm(
keyStore keystore.Eth) (txmgr.TxManager, gas.EvmFeeEstimator) {
config, dbConfig, evmConfig := MakeTestConfigs(t)

estimator, err := gas.NewEstimator(logger.TestLogger(t), ethClient, config, evmConfig.GasEstimator())
estimator, err := gas.NewEstimator(logger.TestLogger(t), ethClient, config.ChainType(), evmConfig.GasEstimator())
require.NoError(t, err, "failed to create gas estimator")

lggr := logger.TestLogger(t)
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/gas/arbitrum_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func TestArbitrumEstimator(t *testing.T) {

o := gas.NewArbitrumEstimator(logger.Test(t), &arbConfig{}, feeEstimatorClient, l1Oracle)
fee := gas.DynamicFee{
FeeCap: assets.NewWeiI(42),
TipCap: assets.NewWeiI(5),
GasFeeCap: assets.NewWeiI(42),
GasTipCap: assets.NewWeiI(5),
}
_, err = o.BumpDynamicFee(tests.Context(t), fee, maxGasPrice, nil)
assert.EqualError(t, err, "dynamic fees are not implemented for this estimator")
Expand Down
54 changes: 39 additions & 15 deletions core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand All @@ -23,6 +24,7 @@ import (
commonfee "github.com/smartcontractkit/chainlink/v2/common/fee"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand Down Expand Up @@ -76,10 +78,6 @@ const BumpingHaltedLabel = "Tx gas bumping halted since price exceeds current bl

var _ EvmEstimator = &BlockHistoryEstimator{}

type chainConfig interface {
ChainType() chaintype.ChainType
}

type estimatorGasEstimatorConfig interface {
EIP1559DynamicFees() bool
BumpThreshold() uint64
Expand All @@ -95,9 +93,9 @@ type BlockHistoryEstimator struct {
services.StateMachine
ethClient feeEstimatorClient
chainID *big.Int
config chainConfig
chaintype chaintype.ChainType
eConfig estimatorGasEstimatorConfig
bhConfig BlockHistoryConfig
bhConfig evmconfig.BlockHistory
// NOTE: it is assumed that blocks will be kept sorted by
// block number ascending
blocks []evmtypes.Block
Expand Down Expand Up @@ -125,11 +123,11 @@ type BlockHistoryEstimator struct {
// NewBlockHistoryEstimator returns a new BlockHistoryEstimator that listens
// for new heads and updates the base gas price dynamically based on the
// configured percentile of gas prices in that block
func NewBlockHistoryEstimator(lggr logger.Logger, ethClient feeEstimatorClient, cfg chainConfig, eCfg estimatorGasEstimatorConfig, bhCfg BlockHistoryConfig, chainID *big.Int, l1Oracle rollups.L1Oracle) EvmEstimator {
func NewBlockHistoryEstimator(lggr logger.Logger, ethClient feeEstimatorClient, chaintype chaintype.ChainType, eCfg estimatorGasEstimatorConfig, bhCfg evmconfig.BlockHistory, chainID *big.Int, l1Oracle rollups.L1Oracle) EvmEstimator {
return &BlockHistoryEstimator{
ethClient: ethClient,
chainID: chainID,
config: cfg,
chaintype: chaintype,
eConfig: eCfg,
bhConfig: bhCfg,
blocks: make([]evmtypes.Block, 0),
Expand Down Expand Up @@ -376,15 +374,15 @@ func (b *BlockHistoryEstimator) haltBumping(attempts []EvmPriorAttempt) error {
// feecap must >= tipcap+basefee for the block, otherwise there
// is no way this could have been included, and we must bail
// out of the check
attemptFeeCap := attempt.DynamicFee.FeeCap
attemptTipCap := attempt.DynamicFee.TipCap
attemptFeeCap := attempt.DynamicFee.GasFeeCap
attemptTipCap := attempt.DynamicFee.GasTipCap
if attemptFeeCap.Cmp(attemptTipCap.Add(b.BaseFeePerGas)) < 0 {
sufficientFeeCap = false
break
}
}
if sufficientFeeCap && attempt.DynamicFee.TipCap.Cmp(maxTipCap) > 0 {
return fmt.Errorf("transaction %s has tip cap of %s, which is above percentile=%d%% (percentile tip cap: %s): %w", attempt.TxHash, attempt.DynamicFee.TipCap, percentile, maxTipCap, commonfee.ErrConnectivity)
if sufficientFeeCap && attempt.DynamicFee.GasTipCap.Cmp(maxTipCap) > 0 {
return fmt.Errorf("transaction %s has tip cap of %s, which is above percentile=%d%% (percentile tip cap: %s): %w", attempt.TxHash, attempt.DynamicFee.GasTipCap, percentile, maxTipCap, commonfee.ErrConnectivity)
}
}
return nil
Expand Down Expand Up @@ -434,8 +432,8 @@ func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei
if err != nil {
return fee, err
}
fee.FeeCap = feeCap
fee.TipCap = tipCap
fee.GasFeeCap = feeCap
fee.GasTipCap = tipCap
return
}

Expand Down Expand Up @@ -827,7 +825,7 @@ func (b *BlockHistoryEstimator) getPricesFromBlocks(blocks []evmtypes.Block, eip
b.logger.Warnw(fmt.Sprintf("Block %v is not usable, %s", block.Number, err.Error()), "block", block, "err", err)
}
for _, tx := range block.Transactions {
if b.IsUsable(tx, block, b.config.ChainType(), b.eConfig.PriceMin(), b.logger) {
if b.IsUsable(tx, block, b.chaintype, b.eConfig.PriceMin(), b.logger) {
gp := b.EffectiveGasPrice(block, tx)
if gp == nil {
b.logger.Warnw("Unable to get gas price for tx", "tx", tx, "block", block)
Expand Down Expand Up @@ -976,3 +974,29 @@ func (b *BlockHistoryEstimator) EffectiveTipCap(block evmtypes.Block, tx evmtype
return nil
}
}

// Int64ToHex converts an int64 into go-ethereum's hex representation
func Int64ToHex(n int64) string {
return hexutil.EncodeBig(big.NewInt(n))
jmank88 marked this conversation as resolved.
Show resolved Hide resolved
}

// HexToInt64 performs the inverse of Int64ToHex
// Returns 0 on invalid input
func HexToInt64(input interface{}) int64 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and a few other places in BHE. I just moved them, nothing new was added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they need to be exported?

switch v := input.(type) {
case string:
big, err := hexutil.DecodeBig(v)
if err != nil {
return 0
}
return big.Int64()
case []byte:
big, err := hexutil.DecodeBig(string(v))
if err != nil {
return 0
}
return big.Int64()
default:
return 0
}
}
Loading
Loading