Skip to content

Commit

Permalink
Make FeeHistory call Geth compatible and remove ConfiguredChain (#15147)
Browse files Browse the repository at this point in the history
* Make FeeHistory call Geth compatible

* Remove unnecessary ConfiguredClient from estimators

* Update mocks

* Fix FHE tests
  • Loading branch information
dimriou authored Nov 7, 2024
1 parent 340a6bf commit 8ac797e
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func makeTestEvmTxm(
keyStore keystore.Eth) (txmgr.TxManager, gas.EvmFeeEstimator) {
config, dbConfig, evmConfig := MakeTestConfigs(t)

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

lggr := logger.TestLogger(t)
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Client interface {
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
LatestBlockHeight(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)

HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)
HeaderByHash(ctx context.Context, h common.Hash) (*types.Header, error)
Expand Down Expand Up @@ -473,12 +473,12 @@ func (c *chainClient) LatestFinalizedBlock(ctx context.Context) (*evmtypes.Head,
return r.LatestFinalizedBlock(ctx)
}

func (c *chainClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
func (c *chainClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
r, err := c.multiNode.SelectRPC()
if err != nil {
return feeHistory, err
}
return r.FeeHistory(ctx, blockCount, rewardPercentiles)
return r.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
}

func (c *chainClient) CheckTxValidity(ctx context.Context, from common.Address, to common.Address, data []byte) *SendError {
Expand Down
29 changes: 15 additions & 14 deletions core/chains/evm/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/chains/evm/client/null_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ func (nc *NullClient) CheckTxValidity(_ context.Context, _ common.Address, _ com
return nil
}

func (nc *NullClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
func (nc *NullClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
return nil, nil
}
6 changes: 3 additions & 3 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,18 +1093,18 @@ func (r *RPCClient) BalanceAt(ctx context.Context, account common.Address, block
return
}

func (r *RPCClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
func (r *RPCClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
ctx, cancel, ws, http := r.makeLiveQueryCtxAndSafeGetClients(ctx, r.rpcTimeout)
defer cancel()
lggr := r.newRqLggr().With("blockCount", blockCount, "rewardPercentiles", rewardPercentiles)

lggr.Debug("RPC call: evmclient.Client#FeeHistory")
start := time.Now()
if http != nil {
feeHistory, err = http.geth.FeeHistory(ctx, blockCount, nil, rewardPercentiles)
feeHistory, err = http.geth.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
err = r.wrapHTTP(err)
} else {
feeHistory, err = ws.geth.FeeHistory(ctx, blockCount, nil, rewardPercentiles)
feeHistory, err = ws.geth.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
err = r.wrapWS(err)
}
duration := time.Since(start)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (c *SimulatedBackendClient) LINKBalance(ctx context.Context, address common
panic("not implemented")
}

func (c *SimulatedBackendClient) FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
func (c *SimulatedBackendClient) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error) {
panic("not implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/gas/fee_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type FeeHistoryEstimatorConfig struct {

type feeHistoryEstimatorClient interface {
SuggestGasPrice(ctx context.Context) (*big.Int, error)
FeeHistory(ctx context.Context, blockCount uint64, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (feeHistory *ethereum.FeeHistory, err error)
}

type FeeHistoryEstimator struct {
Expand Down Expand Up @@ -235,7 +235,7 @@ func (f *FeeHistoryEstimator) RefreshDynamicPrice() error {
defer cancel()

// RewardPercentile will be used for maxPriorityFeePerGas estimations and connectivityPercentile to set the highest threshold for bumping.
feeHistory, err := f.client.FeeHistory(ctx, max(f.config.BlockHistorySize, 1), []float64{f.config.RewardPercentile, ConnectivityPercentile})
feeHistory, err := f.client.FeeHistory(ctx, max(f.config.BlockHistorySize, 1), nil, []float64{f.config.RewardPercentile, ConnectivityPercentile})
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions core/chains/evm/gas/fee_history_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestFeeHistoryEstimatorGetDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee, baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

blockHistoryLength := 2
cfg := gas.FeeHistoryEstimatorConfig{BlockHistorySize: uint64(blockHistoryLength)}
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestFeeHistoryEstimatorGetDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{BlockHistorySize: 1}

Expand Down Expand Up @@ -303,7 +303,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{big.NewInt(5)},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{
BlockHistorySize: 2,
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

maxFee := (*assets.Wei)(baseFee).AddPercentage(gas.BaseFeeBufferPercentage).Add((*assets.Wei)(maxPriorityFeePerGas))

Expand Down Expand Up @@ -400,7 +400,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{
BlockHistorySize: 1,
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{
BlockHistorySize: 1,
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once()

cfg := gas.FeeHistoryEstimatorConfig{
BlockHistorySize: 1,
Expand Down Expand Up @@ -495,7 +495,7 @@ func TestFeeHistoryEstimatorBumpDynamicFee(t *testing.T) {
BaseFee: []*big.Int{baseFee},
GasUsedRatio: nil,
}
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil)
client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil)

cfg := gas.FeeHistoryEstimatorConfig{
BlockHistorySize: 0,
Expand Down
76 changes: 15 additions & 61 deletions core/chains/evm/gas/mocks/fee_estimator_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ac797e

Please sign in to comment.