From b3171d008f43b12cc494868790390823f8405dae Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 27 Sep 2024 10:30:51 -0500 Subject: [PATCH] fix linter issues --- common/client/multi_node.go | 4 +- common/headtracker/head_tracker.go | 16 ++- .../capabilities/targets/write_target_test.go | 12 +- .../chains/evm/gas/block_history_estimator.go | 6 +- .../evm/gas/rollups/arbitrum_l1_oracle.go | 57 +------- core/chains/evm/gas/rollups/l1_oracle.go | 3 - core/chains/evm/gas/rollups/l1_oracle_test.go | 128 ------------------ .../chains/evm/gas/rollups/mocks/l1_oracle.go | 114 +--------------- core/chains/evm/gas/rollups/op_l1_oracle.go | 50 ------- .../evm/gas/rollups/zkSync_l1_oracle.go | 17 --- .../evm/headtracker/head_tracker_test.go | 12 +- core/cmd/prompter.go | 2 +- .../ocr2/plugins/llo/integration_test.go | 3 +- core/services/pipeline/getters.go | 2 +- 14 files changed, 35 insertions(+), 391 deletions(-) diff --git a/common/client/multi_node.go b/common/client/multi_node.go index c9250a1d620..00ec436d9ab 100644 --- a/common/client/multi_node.go +++ b/common/client/multi_node.go @@ -2,6 +2,7 @@ package client import ( "context" + "errors" "fmt" "math" "math/big" @@ -687,9 +688,8 @@ func aggregateTxResults(resultsByCode sendTxErrors) (txResult error, err error) // We assume that primary node would never report false positive txResult for a transaction. // Thus, if such case occurs it's probably due to misconfiguration or a bug and requires manual intervention. if hasSevereErrors { - const errMsg = "found contradictions in nodes replies on SendTransaction: got success and severe error" // return success, since at least 1 node has accepted our broadcasted Tx, and thus it can now be included onchain - return successResults[0], fmt.Errorf(errMsg) + return successResults[0], errors.New("found contradictions in nodes replies on SendTransaction: got success and severe error") } // other errors are temporary - we are safe to return success diff --git a/common/headtracker/head_tracker.go b/common/headtracker/head_tracker.go index 8546d856b67..d309ced0cda 100644 --- a/common/headtracker/head_tracker.go +++ b/common/headtracker/head_tracker.go @@ -434,10 +434,10 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) backfill(ctx context.Context, hea } if head.BlockHash() != latestFinalizedHead.BlockHash() { - const errMsg = "expected finalized block to be present in canonical chain" - ht.log.With("finalized_block_number", latestFinalizedHead.BlockNumber(), "finalized_hash", latestFinalizedHead.BlockHash(), - "canonical_chain_block_number", head.BlockNumber(), "canonical_chain_hash", head.BlockHash()).Criticalf(errMsg) - return fmt.Errorf(errMsg) + ht.log.Criticalw("Finalized block missing from conical chain", + "finalized_block_number", latestFinalizedHead.BlockNumber(), "finalized_hash", latestFinalizedHead.BlockHash(), + "canonical_chain_block_number", head.BlockNumber(), "canonical_chain_hash", head.BlockHash()) + return FinalizedMissingError[BLOCK_HASH]{latestFinalizedHead.BlockHash(), head.BlockHash()} } l = l.With("latest_finalized_block_hash", latestFinalizedHead.BlockHash(), @@ -454,6 +454,14 @@ func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) backfill(ctx context.Context, hea return } +type FinalizedMissingError[BLOCK_HASH types.Hashable] struct { + Finalized, Canonical BLOCK_HASH +} + +func (e FinalizedMissingError[BLOCK_HASH]) Error() string { + return fmt.Sprintf("finalized block %s missing from canonical chain %s", e.Finalized, e.Canonical) +} + func (ht *headTracker[HTH, S, ID, BLOCK_HASH]) fetchAndSaveHead(ctx context.Context, n int64, hash BLOCK_HASH) (HTH, error) { ht.log.Debugw("Fetching head", "blockHeight", n, "blockHash", hash) head, err := ht.client.HeadByHash(ctx, hash) diff --git a/core/capabilities/targets/write_target_test.go b/core/capabilities/targets/write_target_test.go index 96df31bd3cc..499f4f9b29b 100644 --- a/core/capabilities/targets/write_target_test.go +++ b/core/capabilities/targets/write_target_test.go @@ -120,11 +120,11 @@ func TestWriteTarget(t *testing.T) { }) t.Run("passes gas limit set on config to the chain writer", func(t *testing.T) { - configGasLimit, err := values.NewMap(map[string]any{ + configGasLimit, err2 := values.NewMap(map[string]any{ "Address": forwarderAddr, "GasLimit": 500000, }) - require.NoError(t, err) + require.NoError(t, err2) req := capabilities.CapabilityRequest{ Metadata: validMetadata, Config: configGasLimit, @@ -134,16 +134,16 @@ func TestWriteTarget(t *testing.T) { meta := types.TxMeta{WorkflowExecutionID: &req.Metadata.WorkflowExecutionID, GasLimit: big.NewInt(500000)} cw.On("SubmitTransaction", mock.Anything, "forwarder", "report", mock.Anything, mock.Anything, forwarderAddr, &meta, mock.Anything).Return(types.ErrSettingTransactionGasLimitNotSupported) - _, err2 := writeTarget.Execute(ctx, req) + _, err2 = writeTarget.Execute(ctx, req) require.Error(t, err2) }) t.Run("retries without gas limit when ChainWriter's SubmitTransaction returns error due to gas limit not supported", func(t *testing.T) { - configGasLimit, err := values.NewMap(map[string]any{ + configGasLimit, err2 := values.NewMap(map[string]any{ "Address": forwarderAddr, "GasLimit": 500000, }) - require.NoError(t, err) + require.NoError(t, err2) req := capabilities.CapabilityRequest{ Metadata: validMetadata, Config: configGasLimit, @@ -165,7 +165,7 @@ func TestWriteTarget(t *testing.T) { Inputs: validInputs, } - _, err2 := writeTarget.Execute(ctx, req) + _, err2 = writeTarget.Execute(ctx, req) require.Error(t, err2) }) diff --git a/core/chains/evm/gas/block_history_estimator.go b/core/chains/evm/gas/block_history_estimator.go index 0386d92a0d6..02aaa06cc14 100644 --- a/core/chains/evm/gas/block_history_estimator.go +++ b/core/chains/evm/gas/block_history_estimator.go @@ -340,9 +340,9 @@ func (b *BlockHistoryEstimator) haltBumping(attempts []EvmPriorAttempt) error { } // Return error to prevent bumping if gas price is nil or if EIP1559 is enabled and tip cap is nil if maxGasPrice == nil || (b.eConfig.EIP1559DynamicFees() && maxTipCap == nil) { - errorMsg := fmt.Sprintf("%d percentile price is not set. This is likely because there aren't any valid transactions to estimate from. Preventing bumping until valid price is available to compare", percentile) - b.logger.Debugf(errorMsg) - return errors.New(errorMsg) + err := fmt.Errorf("%d percentile price is not set. This is likely because there aren't any valid transactions to estimate from. Preventing bumping until valid price is available to compare", percentile) + b.logger.Debugw("Bumping halted", "err", err) + return err } // Get the latest CheckInclusionBlocks from block history for fee cap check below blockHistory := b.getBlocks() diff --git a/core/chains/evm/gas/rollups/arbitrum_l1_oracle.go b/core/chains/evm/gas/rollups/arbitrum_l1_oracle.go index d758dc711e9..e332d31125f 100644 --- a/core/chains/evm/gas/rollups/arbitrum_l1_oracle.go +++ b/core/chains/evm/gas/rollups/arbitrum_l1_oracle.go @@ -13,15 +13,11 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - gethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" - "github.com/smartcontractkit/chainlink/v2/common/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype" ) type ArbL1GasOracle interface { @@ -35,7 +31,6 @@ type arbitrumL1Oracle struct { client l1OracleClient pollPeriod time.Duration logger logger.SugaredLogger - chainType chaintype.ChainType l1GasPriceAddress string gasPriceMethod string @@ -93,7 +88,6 @@ func NewArbitrumL1GasOracle(lggr logger.Logger, ethClient l1OracleClient) (*arbi client: ethClient, pollPeriod: PollPeriod, logger: logger.Sugared(logger.Named(lggr, "L1GasOracle(arbitrum)")), - chainType: chaintype.ChainArbitrum, l1GasPriceAddress: l1GasPriceAddress, gasPriceMethod: gasPriceMethod, @@ -112,10 +106,6 @@ func (o *arbitrumL1Oracle) Name() string { return o.logger.Name() } -func (o *arbitrumL1Oracle) ChainType(_ context.Context) chaintype.ChainType { - return o.chainType -} - func (o *arbitrumL1Oracle) Start(ctx context.Context) error { return o.StartOnce(o.Name(), func() error { go o.run() @@ -184,24 +174,18 @@ func (o *arbitrumL1Oracle) fetchL1GasPrice(ctx context.Context) (price *big.Int, precompile := common.HexToAddress(o.l1GasPriceAddress) callData, err = o.l1GasPriceMethodAbi.Pack(o.gasPriceMethod) if err != nil { - errMsg := "failed to pack calldata for arbitrum L1 gas price method" - o.logger.Errorf(errMsg) - return nil, fmt.Errorf("%s: %w", errMsg, err) + return nil, fmt.Errorf("failed to pack calldata for arbitrum L1 gas price method: %w", err) } b, err = o.client.CallContract(ctx, ethereum.CallMsg{ To: &precompile, Data: callData, }, nil) if err != nil { - errMsg := "gas oracle contract call failed" - o.logger.Errorf(errMsg) - return nil, fmt.Errorf("%s: %w", errMsg, err) + return nil, fmt.Errorf("gas oracle contract call failed: %w", err) } if len(b) != 32 { // returns uint256; - errMsg := fmt.Sprintf("return data length (%d) different than expected (%d)", len(b), 32) - o.logger.Criticalf(errMsg) - return nil, fmt.Errorf(errMsg) + return nil, fmt.Errorf("return data length (%d) different than expected (%d)", len(b), 32) } price = new(big.Int).SetBytes(b) return price, nil @@ -229,41 +213,6 @@ func (o *arbitrumL1Oracle) GasPrice(_ context.Context) (l1GasPrice *assets.Wei, return } -// Gets the L1 gas cost for the provided transaction at the specified block num -// If block num is not provided, the value on the latest block num is used -func (o *arbitrumL1Oracle) GetGasCost(ctx context.Context, tx *gethtypes.Transaction, blockNum *big.Int) (*assets.Wei, error) { - ctx, cancel := context.WithTimeout(ctx, client.QueryTimeout) - defer cancel() - var callData, b []byte - var err error - - if callData, err = o.l1GasCostMethodAbi.Pack(o.gasCostMethod, tx.To(), false, tx.Data()); err != nil { - return nil, fmt.Errorf("failed to pack calldata for %s L1 gas cost estimation method: %w", o.chainType, err) - } - - precompile := common.HexToAddress(o.l1GasCostAddress) - b, err = o.client.CallContract(ctx, ethereum.CallMsg{ - To: &precompile, - Data: callData, - }, blockNum) - if err != nil { - errorMsg := fmt.Sprintf("gas oracle contract call failed: %v", err) - o.logger.Errorf(errorMsg) - return nil, fmt.Errorf(errorMsg) - } - - var l1GasCost *big.Int - - if len(b) != 8+2*32 { // returns (uint64 gasEstimateForL1, uint256 baseFee, uint256 l1BaseFeeEstimate); - errorMsg := fmt.Sprintf("return data length (%d) different than expected (%d)", len(b), 8+2*32) - o.logger.Critical(errorMsg) - return nil, fmt.Errorf(errorMsg) - } - l1GasCost = new(big.Int).SetBytes(b[:8]) - - return assets.NewWei(l1GasCost), nil -} - // callGetPricesInArbGas calls ArbGasInfo.getPricesInArbGas() on the precompile contract ArbGasInfoAddress. // // @return (per L2 tx, per L1 calldata unit, per storage allocation) diff --git a/core/chains/evm/gas/rollups/l1_oracle.go b/core/chains/evm/gas/rollups/l1_oracle.go index 41951755986..772dc542ed1 100644 --- a/core/chains/evm/gas/rollups/l1_oracle.go +++ b/core/chains/evm/gas/rollups/l1_oracle.go @@ -8,7 +8,6 @@ import ( "time" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" "github.com/smartcontractkit/chainlink-common/pkg/services" @@ -25,8 +24,6 @@ type L1Oracle interface { services.Service GasPrice(ctx context.Context) (*assets.Wei, error) - GetGasCost(ctx context.Context, tx *types.Transaction, blockNum *big.Int) (*assets.Wei, error) - ChainType(ctx context.Context) chaintype.ChainType } type l1OracleClient interface { diff --git a/core/chains/evm/gas/rollups/l1_oracle_test.go b/core/chains/evm/gas/rollups/l1_oracle_test.go index 7a28523d396..3432723c144 100644 --- a/core/chains/evm/gas/rollups/l1_oracle_test.go +++ b/core/chains/evm/gas/rollups/l1_oracle_test.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -21,7 +20,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" ) func TestL1Oracle(t *testing.T) { @@ -195,129 +193,3 @@ func TestL1Oracle_GasPrice(t *testing.T) { assert.Equal(t, assets.NewWei(new(big.Int).Mul(gasPriceL2, gasPerPubByteL2)), gasPrice) }) } - -func TestL1Oracle_GetGasCost(t *testing.T) { - t.Parallel() - - t.Run("Calling GetGasCost on started Arbitrum L1Oracle returns Arbitrum getL1Fee", func(t *testing.T) { - l1GasCost := big.NewInt(100) - baseFee := utils.Uint256ToBytes32(big.NewInt(1000)) - l1BaseFeeEstimate := utils.Uint256ToBytes32(big.NewInt(500)) - blockNum := big.NewInt(1000) - toAddress := utils.RandomAddress() - callData := []byte{1, 2, 3, 4, 5, 6, 7} - l1GasCostMethodAbi, err := abi.JSON(strings.NewReader(GasEstimateL1ComponentAbiString)) - require.NoError(t, err) - - tx := types.NewTx(&types.LegacyTx{ - Nonce: 42, - To: &toAddress, - Data: callData, - }) - result := common.LeftPadBytes(l1GasCost.Bytes(), 8) - result = append(result, baseFee...) - result = append(result, l1BaseFeeEstimate...) - - ethClient := mocks.NewL1OracleClient(t) - ethClient.On("CallContract", mock.Anything, mock.IsType(ethereum.CallMsg{}), mock.IsType(&big.Int{})).Run(func(args mock.Arguments) { - callMsg := args.Get(1).(ethereum.CallMsg) - blockNumber := args.Get(2).(*big.Int) - var payload []byte - payload, err = l1GasCostMethodAbi.Pack("gasEstimateL1Component", toAddress, false, callData) - require.NoError(t, err) - require.Equal(t, payload, callMsg.Data) - require.Equal(t, blockNum, blockNumber) - }).Return(result, nil) - - oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainArbitrum) - require.NoError(t, err) - - gasCost, err := oracle.GetGasCost(tests.Context(t), tx, blockNum) - require.NoError(t, err) - require.Equal(t, assets.NewWei(l1GasCost), gasCost) - }) - - t.Run("Calling GetGasCost on started Kroma L1Oracle returns error", func(t *testing.T) { - blockNum := big.NewInt(1000) - tx := types.NewTx(&types.LegacyTx{}) - - ethClient := mocks.NewL1OracleClient(t) - oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainKroma) - require.NoError(t, err) - - _, err = oracle.GetGasCost(tests.Context(t), tx, blockNum) - require.Error(t, err, "L1 gas cost not supported for this chain: kroma") - }) - - t.Run("Calling GetGasCost on started OPStack L1Oracle returns OPStack getL1Fee", func(t *testing.T) { - l1GasCost := big.NewInt(100) - blockNum := big.NewInt(1000) - toAddress := utils.RandomAddress() - callData := []byte{1, 2, 3} - l1GasCostMethodAbi, err := abi.JSON(strings.NewReader(GetL1FeeAbiString)) - require.NoError(t, err) - - tx := types.NewTx(&types.LegacyTx{ - Nonce: 42, - To: &toAddress, - Data: callData, - }) - - encodedTx, err := tx.MarshalBinary() - require.NoError(t, err) - - ethClient := mocks.NewL1OracleClient(t) - ethClient.On("CallContract", mock.Anything, mock.IsType(ethereum.CallMsg{}), mock.IsType(&big.Int{})).Run(func(args mock.Arguments) { - callMsg := args.Get(1).(ethereum.CallMsg) - blockNumber := args.Get(2).(*big.Int) - var payload []byte - payload, err = l1GasCostMethodAbi.Pack("getL1Fee", encodedTx) - require.NoError(t, err) - require.Equal(t, payload, callMsg.Data) - require.Equal(t, blockNum, blockNumber) - }).Return(common.BigToHash(l1GasCost).Bytes(), nil) - - oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock) - require.NoError(t, err) - - gasCost, err := oracle.GetGasCost(tests.Context(t), tx, blockNum) - require.NoError(t, err) - require.Equal(t, assets.NewWei(l1GasCost), gasCost) - }) - - t.Run("Calling GetGasCost on started Scroll L1Oracle returns Scroll getL1Fee", func(t *testing.T) { - l1GasCost := big.NewInt(100) - blockNum := big.NewInt(1000) - toAddress := utils.RandomAddress() - callData := []byte{1, 2, 3} - l1GasCostMethodAbi, err := abi.JSON(strings.NewReader(GetL1FeeAbiString)) - require.NoError(t, err) - - tx := types.NewTx(&types.LegacyTx{ - Nonce: 42, - To: &toAddress, - Data: callData, - }) - - encodedTx, err := tx.MarshalBinary() - require.NoError(t, err) - - ethClient := mocks.NewL1OracleClient(t) - ethClient.On("CallContract", mock.Anything, mock.IsType(ethereum.CallMsg{}), mock.IsType(&big.Int{})).Run(func(args mock.Arguments) { - callMsg := args.Get(1).(ethereum.CallMsg) - blockNumber := args.Get(2).(*big.Int) - var payload []byte - payload, err = l1GasCostMethodAbi.Pack("getL1Fee", encodedTx) - require.NoError(t, err) - require.Equal(t, payload, callMsg.Data) - require.Equal(t, blockNum, blockNumber) - }).Return(common.BigToHash(l1GasCost).Bytes(), nil) - - oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainScroll) - require.NoError(t, err) - - gasCost, err := oracle.GetGasCost(tests.Context(t), tx, blockNum) - require.NoError(t, err) - require.Equal(t, assets.NewWei(l1GasCost), gasCost) - }) -} diff --git a/core/chains/evm/gas/rollups/mocks/l1_oracle.go b/core/chains/evm/gas/rollups/mocks/l1_oracle.go index 25bb3a2db59..747df06e83a 100644 --- a/core/chains/evm/gas/rollups/mocks/l1_oracle.go +++ b/core/chains/evm/gas/rollups/mocks/l1_oracle.go @@ -3,17 +3,11 @@ package mocks import ( - big "math/big" + context "context" assets "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" - chaintype "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype" - - context "context" - mock "github.com/stretchr/testify/mock" - - types "github.com/ethereum/go-ethereum/core/types" ) // L1Oracle is an autogenerated mock type for the L1Oracle type @@ -29,52 +23,6 @@ func (_m *L1Oracle) EXPECT() *L1Oracle_Expecter { return &L1Oracle_Expecter{mock: &_m.Mock} } -// ChainType provides a mock function with given fields: ctx -func (_m *L1Oracle) ChainType(ctx context.Context) chaintype.ChainType { - ret := _m.Called(ctx) - - if len(ret) == 0 { - panic("no return value specified for ChainType") - } - - var r0 chaintype.ChainType - if rf, ok := ret.Get(0).(func(context.Context) chaintype.ChainType); ok { - r0 = rf(ctx) - } else { - r0 = ret.Get(0).(chaintype.ChainType) - } - - return r0 -} - -// L1Oracle_ChainType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ChainType' -type L1Oracle_ChainType_Call struct { - *mock.Call -} - -// ChainType is a helper method to define mock.On call -// - ctx context.Context -func (_e *L1Oracle_Expecter) ChainType(ctx interface{}) *L1Oracle_ChainType_Call { - return &L1Oracle_ChainType_Call{Call: _e.mock.On("ChainType", ctx)} -} - -func (_c *L1Oracle_ChainType_Call) Run(run func(ctx context.Context)) *L1Oracle_ChainType_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *L1Oracle_ChainType_Call) Return(_a0 chaintype.ChainType) *L1Oracle_ChainType_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *L1Oracle_ChainType_Call) RunAndReturn(run func(context.Context) chaintype.ChainType) *L1Oracle_ChainType_Call { - _c.Call.Return(run) - return _c -} - // Close provides a mock function with given fields: func (_m *L1Oracle) Close() error { ret := _m.Called() @@ -178,66 +126,6 @@ func (_c *L1Oracle_GasPrice_Call) RunAndReturn(run func(context.Context) (*asset return _c } -// GetGasCost provides a mock function with given fields: ctx, tx, blockNum -func (_m *L1Oracle) GetGasCost(ctx context.Context, tx *types.Transaction, blockNum *big.Int) (*assets.Wei, error) { - ret := _m.Called(ctx, tx, blockNum) - - if len(ret) == 0 { - panic("no return value specified for GetGasCost") - } - - var r0 *assets.Wei - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *types.Transaction, *big.Int) (*assets.Wei, error)); ok { - return rf(ctx, tx, blockNum) - } - if rf, ok := ret.Get(0).(func(context.Context, *types.Transaction, *big.Int) *assets.Wei); ok { - r0 = rf(ctx, tx, blockNum) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*assets.Wei) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, *types.Transaction, *big.Int) error); ok { - r1 = rf(ctx, tx, blockNum) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// L1Oracle_GetGasCost_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetGasCost' -type L1Oracle_GetGasCost_Call struct { - *mock.Call -} - -// GetGasCost is a helper method to define mock.On call -// - ctx context.Context -// - tx *types.Transaction -// - blockNum *big.Int -func (_e *L1Oracle_Expecter) GetGasCost(ctx interface{}, tx interface{}, blockNum interface{}) *L1Oracle_GetGasCost_Call { - return &L1Oracle_GetGasCost_Call{Call: _e.mock.On("GetGasCost", ctx, tx, blockNum)} -} - -func (_c *L1Oracle_GetGasCost_Call) Run(run func(ctx context.Context, tx *types.Transaction, blockNum *big.Int)) *L1Oracle_GetGasCost_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*types.Transaction), args[2].(*big.Int)) - }) - return _c -} - -func (_c *L1Oracle_GetGasCost_Call) Return(_a0 *assets.Wei, _a1 error) *L1Oracle_GetGasCost_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *L1Oracle_GetGasCost_Call) RunAndReturn(run func(context.Context, *types.Transaction, *big.Int) (*assets.Wei, error)) *L1Oracle_GetGasCost_Call { - _c.Call.Return(run) - return _c -} - // HealthReport provides a mock function with given fields: func (_m *L1Oracle) HealthReport() map[string]error { ret := _m.Called() diff --git a/core/chains/evm/gas/rollups/op_l1_oracle.go b/core/chains/evm/gas/rollups/op_l1_oracle.go index 11babc5ca5d..9aa20f4f880 100644 --- a/core/chains/evm/gas/rollups/op_l1_oracle.go +++ b/core/chains/evm/gas/rollups/op_l1_oracle.go @@ -14,12 +14,9 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" - gethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" - "github.com/smartcontractkit/chainlink/v2/common/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype" @@ -31,7 +28,6 @@ type optimismL1Oracle struct { client l1OracleClient pollPeriod time.Duration logger logger.SugaredLogger - chainType chaintype.ChainType l1OracleAddress string l1GasPriceMu sync.RWMutex @@ -192,7 +188,6 @@ func newOpStackL1GasOracle(lggr logger.Logger, ethClient l1OracleClient, chainTy client: ethClient, pollPeriod: PollPeriod, logger: logger.Sugared(logger.Named(lggr, fmt.Sprintf("L1GasOracle(%s)", chainType))), - chainType: chainType, l1OracleAddress: precompileAddress, isEcotone: false, @@ -220,10 +215,6 @@ func (o *optimismL1Oracle) Name() string { return o.logger.Name() } -func (o *optimismL1Oracle) ChainType(_ context.Context) chaintype.ChainType { - return o.chainType -} - func (o *optimismL1Oracle) Start(ctx context.Context) error { return o.StartOnce(o.Name(), func() error { go o.run() @@ -309,47 +300,6 @@ func (o *optimismL1Oracle) GasPrice(_ context.Context) (l1GasPrice *assets.Wei, return } -// Gets the L1 gas cost for the provided transaction at the specified block num -// If block num is not provided, the value on the latest block num is used -func (o *optimismL1Oracle) GetGasCost(ctx context.Context, tx *gethtypes.Transaction, blockNum *big.Int) (*assets.Wei, error) { - ctx, cancel := context.WithTimeout(ctx, client.QueryTimeout) - defer cancel() - var callData, b []byte - var err error - if o.chainType == chaintype.ChainKroma { - return nil, fmt.Errorf("L1 gas cost not supported for this chain: %s", o.chainType) - } - // Append rlp-encoded tx - var encodedtx []byte - if encodedtx, err = tx.MarshalBinary(); err != nil { - return nil, fmt.Errorf("failed to marshal tx for gas cost estimation: %w", err) - } - if callData, err = o.getL1FeeMethodAbi.Pack(getL1FeeMethod, encodedtx); err != nil { - return nil, fmt.Errorf("failed to pack calldata for %s L1 gas cost estimation method: %w", o.chainType, err) - } - - precompile := common.HexToAddress(o.l1OracleAddress) - b, err = o.client.CallContract(ctx, ethereum.CallMsg{ - To: &precompile, - Data: callData, - }, blockNum) - if err != nil { - errorMsg := fmt.Sprintf("gas oracle contract call failed: %v", err) - o.logger.Errorf(errorMsg) - return nil, fmt.Errorf(errorMsg) - } - - var l1GasCost *big.Int - if len(b) != 32 { // returns uint256; - errorMsg := fmt.Sprintf("return data length (%d) different than expected (%d)", len(b), 32) - o.logger.Critical(errorMsg) - return nil, fmt.Errorf(errorMsg) - } - l1GasCost = new(big.Int).SetBytes(b) - - return assets.NewWei(l1GasCost), nil -} - func (o *optimismL1Oracle) GetDAGasPrice(ctx context.Context) (*big.Int, error) { err := o.checkForUpgrade(ctx) if err != nil { diff --git a/core/chains/evm/gas/rollups/zkSync_l1_oracle.go b/core/chains/evm/gas/rollups/zkSync_l1_oracle.go index c2941233545..94d2e05ac02 100644 --- a/core/chains/evm/gas/rollups/zkSync_l1_oracle.go +++ b/core/chains/evm/gas/rollups/zkSync_l1_oracle.go @@ -15,11 +15,8 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/utils" - gethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype" ) // Reads L2-specific precompiles and caches the l1GasPrice set by the L2. @@ -28,7 +25,6 @@ type zkSyncL1Oracle struct { client l1OracleClient pollPeriod time.Duration logger logger.SugaredLogger - chainType chaintype.ChainType systemContextAddress string gasPerPubdataMethod string @@ -65,7 +61,6 @@ func NewZkSyncL1GasOracle(lggr logger.Logger, ethClient l1OracleClient) *zkSyncL client: ethClient, pollPeriod: PollPeriod, logger: logger.Sugared(logger.Named(lggr, "L1GasOracle(zkSync)")), - chainType: chaintype.ChainZkSync, systemContextAddress: SystemContextAddress, gasPerPubdataMethod: SystemContext_gasPerPubdataByteMethod, @@ -83,10 +78,6 @@ func (o *zkSyncL1Oracle) Name() string { return o.logger.Name() } -func (o *zkSyncL1Oracle) ChainType(_ context.Context) chaintype.ChainType { - return o.chainType -} - func (o *zkSyncL1Oracle) Start(ctx context.Context) error { return o.StartOnce(o.Name(), func() error { go o.run() @@ -185,14 +176,6 @@ func (o *zkSyncL1Oracle) GasPrice(_ context.Context) (l1GasPrice *assets.Wei, er return } -// Gets the L1 gas cost for the provided transaction at the specified block num -// If block num is not provided, the value on the latest block num is used -func (o *zkSyncL1Oracle) GetGasCost(ctx context.Context, tx *gethtypes.Transaction, blockNum *big.Int) (*assets.Wei, error) { - //Unused method, so not implemented - // And its not possible to know gas consumption of a transaction before its executed, since zkSync only posts the state difference - return nil, fmt.Errorf("unimplemented") -} - // GetL2GasPrice calls SystemContract.gasPrice() on the zksync system precompile contract. // // @return (The current gasPrice on L2: same as tx.gasPrice) diff --git a/core/chains/evm/headtracker/head_tracker_test.go b/core/chains/evm/headtracker/head_tracker_test.go index 8e846d3122c..5534a6aa10c 100644 --- a/core/chains/evm/headtracker/head_tracker_test.go +++ b/core/chains/evm/headtracker/head_tracker_test.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "github.com/jmoiron/sqlx" "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -21,16 +22,13 @@ import ( "golang.org/x/exp/maps" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" - "github.com/smartcontractkit/chainlink-common/pkg/services" - "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest" - - "github.com/jmoiron/sqlx" - + "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" + "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + commonht "github.com/smartcontractkit/chainlink/v2/common/headtracker" htmocks "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks" commontypes "github.com/smartcontractkit/chainlink/v2/common/headtracker/types" evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" @@ -925,7 +923,7 @@ func testHeadTrackerBackfill(t *testing.T, newORM func(t *testing.T) headtracker htu.ethClient.On("LatestFinalizedBlock", mock.Anything).Return(h14Orphaned, nil).Once() err := htu.headTracker.Backfill(ctx, h15) - require.EqualError(t, err, "expected finalized block to be present in canonical chain") + require.ErrorAs(t, err, &commonht.FinalizedMissingError[common.Hash]{}) }) t.Run("Marks all blocks in chain that are older than finalized", func(t *testing.T) { htu := newHeadTrackerUniverse(t, opts{Heads: heads, FinalityTagEnabled: true}) diff --git a/core/cmd/prompter.go b/core/cmd/prompter.go index 84f930c6243..a5e67c5692e 100644 --- a/core/cmd/prompter.go +++ b/core/cmd/prompter.go @@ -92,5 +92,5 @@ func withTerminalResetter(f func()) { } func clearLine() { - fmt.Printf("\r" + strings.Repeat(" ", 60) + "\r") + fmt.Print("\r" + strings.Repeat(" ", 60) + "\r") } diff --git a/core/services/ocr2/plugins/llo/integration_test.go b/core/services/ocr2/plugins/llo/integration_test.go index 2e49e989462..a6de2172346 100644 --- a/core/services/ocr2/plugins/llo/integration_test.go +++ b/core/services/ocr2/plugins/llo/integration_test.go @@ -191,8 +191,7 @@ func setConfig(t *testing.T, donID uint32, steve *bind.TransactOpts, backend *ba func TestIntegration_LLO(t *testing.T) { testStartTimeStamp := time.Now() donID := uint32(995544) - multiplier, err := decimal.NewFromString("1e18") - require.NoError(t, err) + multiplier := decimal.New(1, 18) expirationWindow := time.Hour / time.Second reqs := make(chan request) diff --git a/core/services/pipeline/getters.go b/core/services/pipeline/getters.go index bbeb0050d68..1dff20f5bf4 100644 --- a/core/services/pipeline/getters.go +++ b/core/services/pipeline/getters.go @@ -147,7 +147,7 @@ func JSONWithVarExprs(jsExpr string, vars Vars, allowErrors bool) GetterFunc { } keypath, is := maybeKeypath.(string) if !is { - return nil, errors.Wrapf(ErrBadInput, fmt.Sprintf("you cannot use %s in your JSON", chainlinkKeyPath)) + return nil, errors.Wrap(ErrBadInput, fmt.Sprintf("you cannot use %s in your JSON", chainlinkKeyPath)) } newVal, err := vars.Get(keypath) if err != nil {