Skip to content

Commit

Permalink
Update DA oracle config struct members to pointers (#15008)
Browse files Browse the repository at this point in the history
* Update DA oracle config struct members to pointers

* Update tests and remake config docs

* suggestions and fix docs_test

* fix config test
  • Loading branch information
ogtownsend authored Oct 30, 2024
1 parent c162226 commit b585654
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-crabs-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#bugfix Update DA oracle config struct members to pointers
11 changes: 9 additions & 2 deletions core/capabilities/ccip/ocrimpls/contract_transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,22 @@ type TestDAOracleConfig struct {
evmconfig.DAOracle
}

func (d *TestDAOracleConfig) OracleType() toml.DAOracleType { return toml.DAOracleOPStack }
func (d *TestDAOracleConfig) OracleType() *toml.DAOracleType {
oracleType := toml.DAOracleOPStack
return &oracleType
}

func (d *TestDAOracleConfig) OracleAddress() *types.EIP55Address {
a, err := types.NewEIP55Address("0x420000000000000000000000000000000000000F")
if err != nil {
panic(err)
}
return &a
}
func (d *TestDAOracleConfig) CustomGasPriceCalldata() string { return "" }

func (d *TestDAOracleConfig) CustomGasPriceCalldata() *string {
return nil
}

func (g *TestGasEstimatorConfig) BlockHistory() evmconfig.BlockHistory {
return &TestBlockHistoryConfig{}
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/config/chain_scoped_gas_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type daOracleConfig struct {
c toml.DAOracle
}

func (d *daOracleConfig) OracleType() toml.DAOracleType {
func (d *daOracleConfig) OracleType() *toml.DAOracleType {
return d.c.OracleType
}

Expand All @@ -137,11 +137,11 @@ func (d *daOracleConfig) OracleAddress() *types.EIP55Address {
}

// CustomGasPriceCalldata returns the calldata for a custom gas price API.
func (d *daOracleConfig) CustomGasPriceCalldata() string {
if d.c.OracleType == toml.DAOracleCustomCalldata {
func (d *daOracleConfig) CustomGasPriceCalldata() *string {
if d.c.OracleType != nil && *d.c.OracleType == toml.DAOracleCustomCalldata {
return d.c.CustomGasPriceCalldata
}
return ""
return nil
}

type limitJobTypeConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ type BlockHistory interface {
}

type DAOracle interface {
OracleType() toml.DAOracleType
OracleType() *toml.DAOracleType
OracleAddress() *types.EIP55Address
CustomGasPriceCalldata() string
CustomGasPriceCalldata() *string
}

type FeeHistory interface {
Expand Down
31 changes: 27 additions & 4 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@ func (u *FeeHistoryEstimator) setFrom(f *FeeHistoryEstimator) {
}

type DAOracle struct {
OracleType DAOracleType
OracleType *DAOracleType
OracleAddress *types.EIP55Address
CustomGasPriceCalldata string
CustomGasPriceCalldata *string
}

type DAOracleType string
Expand All @@ -784,6 +784,25 @@ const (
DAOracleCustomCalldata = DAOracleType("custom_calldata")
)

func (o *DAOracle) ValidateConfig() (err error) {
if o.OracleType != nil {
if *o.OracleType == DAOracleOPStack {
if o.OracleAddress == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "OracleAddress", Msg: "required for 'opstack' oracle types"})
}
}
if *o.OracleType == DAOracleCustomCalldata {
if o.OracleAddress == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "OracleAddress", Msg: "required for 'custom_calldata' oracle types"})
}
if o.CustomGasPriceCalldata == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "CustomGasPriceCalldata", Msg: "required for 'custom_calldata' oracle type"})
}
}
}
return
}

func (o DAOracleType) IsValid() bool {
switch o {
case "", DAOracleOPStack, DAOracleArbitrum, DAOracleZKSync, DAOracleCustomCalldata:
Expand All @@ -793,11 +812,15 @@ func (o DAOracleType) IsValid() bool {
}

func (d *DAOracle) setFrom(f *DAOracle) {
d.OracleType = f.OracleType
if v := f.OracleType; v != nil {
d.OracleType = v
}
if v := f.OracleAddress; v != nil {
d.OracleAddress = v
}
d.CustomGasPriceCalldata = f.CustomGasPriceCalldata
if v := f.CustomGasPriceCalldata; v != nil {
d.CustomGasPriceCalldata = v
}
}

type KeySpecificConfig []KeySpecific
Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewEstimator(lggr logger.Logger, ethClient feeEstimatorClient, chaintype ch
"priceMax", geCfg.PriceMax(),
"priceMin", geCfg.PriceMin(),
"estimateLimit", geCfg.EstimateLimit(),
"daOracleType", geCfg.DAOracle().OracleType(),
"daOracleAddress", geCfg.DAOracle().OracleAddress(),
)
df := geCfg.EIP1559DynamicFees()
Expand Down
30 changes: 20 additions & 10 deletions core/chains/evm/gas/rollups/custom_calldata_da_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
Expand All @@ -28,9 +29,10 @@ type customCalldataDAOracle struct {
pollPeriod time.Duration
logger logger.SugaredLogger

daOracleConfig evmconfig.DAOracle
daGasPriceMu sync.RWMutex
daGasPrice priceEntry
daOracleAddress common.Address
daCustomCalldata string
daGasPriceMu sync.RWMutex
daGasPrice priceEntry

chInitialized chan struct{}
chStop services.StopChan
Expand All @@ -41,18 +43,26 @@ type customCalldataDAOracle struct {
// whatever function is specified in the DAOracle's CustomGasPriceCalldata field. This allows for more flexibility when
// chains have custom DA gas calculation methods.
func NewCustomCalldataDAOracle(lggr logger.Logger, ethClient l1OracleClient, chainType chaintype.ChainType, daOracleConfig evmconfig.DAOracle) (*customCalldataDAOracle, error) {
if daOracleConfig.OracleType() != toml.DAOracleCustomCalldata {
return nil, fmt.Errorf("expected %s oracle type, got %s", toml.DAOracleCustomCalldata, daOracleConfig.OracleType())
if daOracleConfig.OracleType() == nil {
return nil, errors.New("OracleType is required for CustomCalldataDAOracle but was nil")
}
if daOracleConfig.CustomGasPriceCalldata() == "" {
if *daOracleConfig.OracleType() != toml.DAOracleCustomCalldata {
return nil, fmt.Errorf("expected %s oracle type, got %s", toml.DAOracleCustomCalldata, *daOracleConfig.OracleType())
}
if daOracleConfig.OracleAddress() == nil || *daOracleConfig.OracleAddress() == "" {
return nil, errors.New("OracleAddress is required for CustomCalldataDAOracle but was nil or empty")
}
if daOracleConfig.CustomGasPriceCalldata() == nil || *daOracleConfig.CustomGasPriceCalldata() == "" {
return nil, errors.New("CustomGasPriceCalldata is required")
}
oracleAddress := *daOracleConfig.OracleAddress()
return &customCalldataDAOracle{
client: ethClient,
pollPeriod: PollPeriod,
logger: logger.Sugared(logger.Named(lggr, fmt.Sprintf("CustomCalldataDAOracle(%s)", chainType))),

daOracleConfig: daOracleConfig,
daOracleAddress: oracleAddress.Address(),
daCustomCalldata: *daOracleConfig.CustomGasPriceCalldata(),

chInitialized: make(chan struct{}),
chStop: make(chan struct{}),
Expand Down Expand Up @@ -152,14 +162,14 @@ func (o *customCalldataDAOracle) GasPrice(_ context.Context) (daGasPrice *assets
}

func (o *customCalldataDAOracle) getCustomCalldataGasPrice(ctx context.Context) (*big.Int, error) {
daOracleAddress := o.daOracleConfig.OracleAddress().Address()
calldata := strings.TrimPrefix(o.daOracleConfig.CustomGasPriceCalldata(), "0x")
calldata := strings.TrimPrefix(o.daCustomCalldata, "0x")
calldataBytes, err := hex.DecodeString(calldata)
if err != nil {
return nil, fmt.Errorf("failed to decode custom fee method calldata: %w", err)
}

b, err := o.client.CallContract(ctx, ethereum.CallMsg{
To: &daOracleAddress,
To: &o.daOracleAddress,
Data: calldataBytes,
}, nil)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/gas/rollups/da_oracle_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ type TestDAOracle struct {
toml.DAOracle
}

func (d *TestDAOracle) OracleType() toml.DAOracleType {
func (d *TestDAOracle) OracleType() *toml.DAOracleType {
return d.DAOracle.OracleType
}

func (d *TestDAOracle) OracleAddress() *types.EIP55Address {
return d.DAOracle.OracleAddress
}

func (d *TestDAOracle) CustomGasPriceCalldata() string {
func (d *TestDAOracle) CustomGasPriceCalldata() *string {
return d.DAOracle.CustomGasPriceCalldata
}

Expand All @@ -31,9 +31,9 @@ func CreateTestDAOracle(t *testing.T, oracleType toml.DAOracleType, oracleAddres

return &TestDAOracle{
DAOracle: toml.DAOracle{
OracleType: oracleType,
OracleType: &oracleType,
OracleAddress: &oracleAddr,
CustomGasPriceCalldata: customGasPriceCalldata,
CustomGasPriceCalldata: &customGasPriceCalldata,
},
}
}
8 changes: 7 additions & 1 deletion core/chains/evm/gas/rollups/l1_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rollups

import (
"context"
"errors"
"fmt"
"math/big"
"slices"
Expand Down Expand Up @@ -56,7 +57,12 @@ func NewL1GasOracle(lggr logger.Logger, ethClient l1OracleClient, chainType chai
var l1Oracle L1Oracle
var err error
if daOracle != nil {
switch daOracle.OracleType() {
oracleType := daOracle.OracleType()
if oracleType == nil {
return nil, errors.New("required field OracleType is nil in non-nil DAOracle config")
}

switch *oracleType {
case toml.DAOracleOPStack:
l1Oracle, err = NewOpStackL1GasOracle(lggr, ethClient, chainType, daOracle)
case toml.DAOracleArbitrum:
Expand Down
Loading

0 comments on commit b585654

Please sign in to comment.