Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matYang committed Sep 15, 2023
1 parent 06b61ba commit 42c5a00
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 54 deletions.
12 changes: 6 additions & 6 deletions core/chains/evm/gas/mocks/evm_fee_estimator.go

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

16 changes: 8 additions & 8 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/assets"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/chainoracles"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/label"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
Expand All @@ -34,7 +34,7 @@ type EvmFeeEstimator interface {
commontypes.HeadTrackable[*evmtypes.Head, common.Hash]

// L1Oracle returns the L1 gas price oracle only if the chain has one, e.g. OP stack L2s and Arbitrum.
L1Oracle() chainoracles.L1Oracle
L1Oracle() rollups.L1Oracle
GetFee(ctx context.Context, calldata []byte, feeLimit uint32, maxFeePrice *assets.Wei, opts ...feetypes.Opt) (fee EvmFee, chainSpecificFeeLimit uint32, err error)
BumpFee(ctx context.Context, originalFee EvmFee, feeLimit uint32, maxFeePrice *assets.Wei, attempts []EvmPriorAttempt) (bumpedFee EvmFee, chainSpecificFeeLimit uint32, err error)

Expand Down Expand Up @@ -68,9 +68,9 @@ func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, ge
df := geCfg.EIP1559DynamicFees()

// create l1Oracle only if it is supported for the chain
var l1Oracle chainoracles.L1Oracle
if chainoracles.IsL1OracleChain(cfg.ChainType()) {
l1Oracle = chainoracles.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType())
var l1Oracle rollups.L1Oracle
if rollups.IsRollupWithL1Support(cfg.ChainType()) {
l1Oracle = rollups.NewL1GasPriceOracle(lggr, ethClient, cfg.ChainType())
}
switch s {
case "Arbitrum":
Expand Down Expand Up @@ -152,13 +152,13 @@ func (fee EvmFee) ValidDynamic() bool {
type WrappedEvmEstimator struct {
EvmEstimator
EIP1559Enabled bool
l1Oracle chainoracles.L1Oracle
l1Oracle rollups.L1Oracle
utils.StartStopOnce
}

var _ EvmFeeEstimator = (*WrappedEvmEstimator)(nil)

func NewWrappedEvmEstimator(e EvmEstimator, eip1559Enabled bool, l1Oracle chainoracles.L1Oracle) EvmFeeEstimator {
func NewWrappedEvmEstimator(e EvmEstimator, eip1559Enabled bool, l1Oracle rollups.L1Oracle) EvmFeeEstimator {
return &WrappedEvmEstimator{
EvmEstimator: e,
EIP1559Enabled: eip1559Enabled,
Expand Down Expand Up @@ -223,7 +223,7 @@ func (e *WrappedEvmEstimator) HealthReport() map[string]error {
return report
}

func (e *WrappedEvmEstimator) L1Oracle() chainoracles.L1Oracle {
func (e *WrappedEvmEstimator) L1Oracle() rollups.L1Oracle {
return e.l1Oracle
}

Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
oraclesMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/chainoracles/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks"
rollupMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks"
)

func TestWrappedEvmEstimator(t *testing.T) {
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
assert.Nil(t, l1Oracle)

// expect l1Oracle
oracle := oraclesMocks.NewL1Oracle(t)
oracle := rollupMocks.NewL1Oracle(t)
estimator = gas.NewWrappedEvmEstimator(e, false, oracle)
l1Oracle = estimator.L1Oracle()
assert.Equal(t, oracle, l1Oracle)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestWrappedEvmEstimator(t *testing.T) {

t.Run("Name", func(t *testing.T) {
evmEstimator := mocks.NewEvmEstimator(t)
oracle := oraclesMocks.NewL1Oracle(t)
oracle := rollupMocks.NewL1Oracle(t)

evmEstimator.On("Name").Return(mockEvmEstimatorName, nil).Once()

Expand All @@ -146,7 +146,7 @@ func TestWrappedEvmEstimator(t *testing.T) {

t.Run("Start and stop calls both EVM estimator and L1Oracle", func(t *testing.T) {
evmEstimator := mocks.NewEvmEstimator(t)
oracle := oraclesMocks.NewL1Oracle(t)
oracle := rollupMocks.NewL1Oracle(t)

evmEstimator.On("Name").Return(mockEvmEstimatorName, nil).Times(4)
evmEstimator.On("Start", mock.Anything).Return(nil).Twice()
Expand All @@ -169,7 +169,7 @@ func TestWrappedEvmEstimator(t *testing.T) {

t.Run("Read calls both EVM estimator and L1Oracle", func(t *testing.T) {
evmEstimator := mocks.NewEvmEstimator(t)
oracle := oraclesMocks.NewL1Oracle(t)
oracle := rollupMocks.NewL1Oracle(t)

evmEstimator.On("Ready").Return(nil).Twice()
oracle.On("Ready").Return(nil).Once()
Expand All @@ -185,7 +185,7 @@ func TestWrappedEvmEstimator(t *testing.T) {

t.Run("HealthReport merges report from EVM estimator and L1Oracle", func(t *testing.T) {
evmEstimator := mocks.NewEvmEstimator(t)
oracle := oraclesMocks.NewL1Oracle(t)
oracle := rollupMocks.NewL1Oracle(t)

evmEstimatorKey := "evm"
evmEstimatorError := errors.New("evm error")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chainoracles
package rollups

import (
"context"
Expand Down Expand Up @@ -62,7 +62,7 @@ const (

var supportedChainTypes = []config.ChainType{config.ChainArbitrum, config.ChainOptimismBedrock}

func IsL1OracleChain(chainType config.ChainType) bool {
func IsRollupWithL1Support(chainType config.ChainType) bool {
return slices.Contains(supportedChainTypes, chainType)
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func (o *l1GasPriceOracle) refresh() (t *time.Timer) {
return
}

func (o *l1GasPriceOracle) L1GasPrice(_ context.Context) (l1GasPrice *assets.Wei, err error) {
func (o *l1GasPriceOracle) GasPrice(_ context.Context) (l1GasPrice *assets.Wei, err error) {
ok := o.IfStarted(func() {
o.l1GasPriceMu.RLock()
l1GasPrice = o.l1GasPrice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chainoracles
package rollups

import (
"fmt"
Expand All @@ -11,8 +11,9 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks"

"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/chainoracles/mocks"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand All @@ -32,11 +33,11 @@ func TestL1GasPriceOracle(t *testing.T) {

oracle := NewL1GasPriceOracle(logger.TestLogger(t), ethClient, config.ChainOptimismBedrock)

_, err := oracle.L1GasPrice(testutils.Context(t))
_, err := oracle.GasPrice(testutils.Context(t))
assert.EqualError(t, err, "L1GasPriceOracle is not started; cannot estimate gas")
})

t.Run("Calling L1GasPrice on started Arbitrum L1Oracle returns Arbitrum l1GasPrice", func(t *testing.T) {
t.Run("Calling GasPrice on started Arbitrum L1Oracle returns Arbitrum l1GasPrice", func(t *testing.T) {
l1BaseFee := big.NewInt(100)

ethClient := mocks.NewETHClient(t)
Expand All @@ -52,13 +53,13 @@ func TestL1GasPriceOracle(t *testing.T) {
require.NoError(t, oracle.Start(testutils.Context(t)))
t.Cleanup(func() { assert.NoError(t, oracle.Close()) })

gasPrice, err := oracle.L1GasPrice(testutils.Context(t))
gasPrice, err := oracle.GasPrice(testutils.Context(t))
require.NoError(t, err)

assert.Equal(t, assets.NewWei(l1BaseFee), gasPrice)
})

t.Run("Calling L1GasPrice on started OPStack L1Oracle returns OPStack l1GasPrice", func(t *testing.T) {
t.Run("Calling GasPrice on started OPStack L1Oracle returns OPStack l1GasPrice", func(t *testing.T) {
l1BaseFee := big.NewInt(200)

ethClient := mocks.NewETHClient(t)
Expand All @@ -74,7 +75,7 @@ func TestL1GasPriceOracle(t *testing.T) {
require.NoError(t, oracle.Start(testutils.Context(t)))
t.Cleanup(func() { assert.NoError(t, oracle.Close()) })

gasPrice, err := oracle.L1GasPrice(testutils.Context(t))
gasPrice, err := oracle.GasPrice(testutils.Context(t))
require.NoError(t, err)

assert.Equal(t, assets.NewWei(l1BaseFee), gasPrice)
Expand Down

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

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chainoracles
package rollups

import (
"context"
Expand All @@ -14,5 +14,5 @@ import (
type L1Oracle interface {
services.ServiceCtx

L1GasPrice(ctx context.Context) (*assets.Wei, error)
GasPrice(ctx context.Context) (*assets.Wei, error)
}

0 comments on commit 42c5a00

Please sign in to comment.