Skip to content

Commit

Permalink
[CCIP-2590] rework
Browse files Browse the repository at this point in the history
  • Loading branch information
valerii-kabisov-cll committed Jul 15, 2024
1 parent e6218a2 commit 9e00c70
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 144 deletions.
2 changes: 1 addition & 1 deletion core/chains/evm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,6 @@ func (h *HashArray) Scan(src interface{}) error {
}

type FeeEstimatorConfigProvider interface {
SetOnRampReader(reader ccip.OnRampReader) error
SetOnRampReader(reader ccip.OnRampReader)
GetDataAvailabilityConfig(ctx context.Context) (destDataAvailabilityOverheadGas, destGasPerDataAvailabilityByte, destDataAvailabilityMultiplierBps int64, err error)
}
5 changes: 2 additions & 3 deletions core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
ccipcachemocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
Expand Down Expand Up @@ -409,7 +408,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
evmEstimator := mocks.NewEvmFeeEstimator(t)
evmEstimator.On("L1Oracle").Return(nil)

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)
gasPriceEstimator := prices.NewDAGasPriceEstimator(evmEstimator, nil, 2e9, 2e9, feeEstimatorConfig) // 200% deviation

var destTokens []cciptypes.Address
Expand Down Expand Up @@ -1408,7 +1407,7 @@ func TestCommitReportingPlugin_calculatePriceUpdates(t *testing.T) {
nil,
tc.daGasPriceDeviationPPB,
tc.execGasPriceDeviationPPB,
estimatorconfig.NewFeeEstimatorConfigService(),
ccipdatamocks.NewFeeEstimatorConfigReader(t),
)

r := &CommitReportingPlugin{
Expand Down
5 changes: 1 addition & 4 deletions core/services/ocr2/plugins/ccip/ccipexec/initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ func NewExecServices(ctx context.Context, lggr logger.Logger, jb job.Job, srcPro
}

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
err = feeEstimatorConfig.SetOnRampReader(onRampReader)
if err != nil {
return nil, fmt.Errorf("NewExecServices set onRampReader to FeeEstimatorService: %w", err)
}
feeEstimatorConfig.SetOnRampReader(onRampReader)

srcCommitStore, err := srcProvider.NewCommitStoreReader(ctx, offRampConfig.CommitStore)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
ccipcachemocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
Expand Down Expand Up @@ -425,9 +424,7 @@ func TestExecutionReportingPlugin_buildReport(t *testing.T) {
p.metricsCollector = ccip.NoopMetricsCollector
p.commitStoreReader = commitStore

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := ccipdatamocks.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

lp := lpMocks.NewLogPoller(t)
offRampReader, err := v1_0_0.NewOffRamp(logger.TestLogger(t), utils.RandomAddress(), nil, lp, nil, nil, feeEstimatorConfig)
Expand Down Expand Up @@ -1819,9 +1816,7 @@ func Test_prepareTokenExecData(t *testing.T) {
}

func encodeExecutionReport(t *testing.T, report cciptypes.ExecReport) []byte {
feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := ccipdatamocks.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

reader, err := v1_2_0.NewOffRamp(logger.TestLogger(t), utils.RandomAddress(), nil, nil, nil, nil, feeEstimatorConfig)
require.NoError(t, err)
Expand Down
7 changes: 2 additions & 5 deletions core/services/ocr2/plugins/ccip/estimatorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ func NewFeeEstimatorConfigService() *FeeEstimatorConfigService {

// SetOnRampReader Sets the onRamp reader instance.
// must be called once for each instance.
func (c *FeeEstimatorConfigService) SetOnRampReader(reader ccip.OnRampReader) error {
if c.onRampReader != nil {
return errors.New("OnRampReader already set in the FeeEstimatorConfigService")
}
func (c *FeeEstimatorConfigService) SetOnRampReader(reader ccip.OnRampReader) {
c.onRampReader = reader
return nil
return

Check failure on line 22 in core/services/ocr2/plugins/ccip/estimatorconfig/config.go

View workflow job for this annotation

GitHub Actions / lint

S1023: redundant `return` statement (gosimple)
}

// GetDataAvailabilityConfig Returns dynamic config data availability parameters.
Expand Down
17 changes: 8 additions & 9 deletions core/services/ocr2/plugins/ccip/estimatorconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
Expand All @@ -22,9 +22,8 @@ func TestFeeEstimatorConfigService(t *testing.T) {

onRampReader := mocks.NewOnRampReader(t)
_, _, _, err := svc.GetDataAvailabilityConfig(ctx)
assert.Error(t, err)
assert.NoError(t, svc.SetOnRampReader(onRampReader))
assert.Error(t, svc.SetOnRampReader(onRampReader))
require.Error(t, err)
svc.SetOnRampReader(onRampReader)

onRampReader.On("GetDynamicConfig", ctx).
Return(ccip.OnRampDynamicConfig{
Expand All @@ -34,13 +33,13 @@ func TestFeeEstimatorConfigService(t *testing.T) {
}, nil).Once()

destDataAvailabilityOverheadGas, destGasPerDataAvailabilityByte, destDataAvailabilityMultiplierBps, err := svc.GetDataAvailabilityConfig(ctx)
assert.NoError(t, err)
assert.Equal(t, expectedDestDataAvailabilityOverheadGas, destDataAvailabilityOverheadGas)
assert.Equal(t, expectedDestGasPerDataAvailabilityByte, destGasPerDataAvailabilityByte)
assert.Equal(t, expectedDestDataAvailabilityMultiplierBps, destDataAvailabilityMultiplierBps)
require.NoError(t, err)
require.Equal(t, expectedDestDataAvailabilityOverheadGas, destDataAvailabilityOverheadGas)
require.Equal(t, expectedDestGasPerDataAvailabilityByte, destGasPerDataAvailabilityByte)
require.Equal(t, expectedDestDataAvailabilityMultiplierBps, destDataAvailabilityMultiplierBps)

onRampReader.On("GetDynamicConfig", ctx).
Return(ccip.OnRampDynamicConfig{}, errors.New("test")).Once()
_, _, _, err = svc.GetDataAvailabilityConfig(ctx)
assert.Error(t, err)
require.Error(t, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/factory"
onRampMock "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
ccipdatamocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_0_0"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_2_0"
)
Expand Down Expand Up @@ -194,9 +193,7 @@ func TestCommitStoreReaders(t *testing.T) {
lm := new(rollupMocks.L1Oracle)
ge.On("L1Oracle").Return(lm)

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

maxGasPrice := big.NewInt(1e8)
c10r, err := factory.NewCommitStoreReader(lggr, factory.NewEvmVersionFinder(), ccipcalc.EvmAddrToGeneric(addr), ec, lp, feeEstimatorConfig) // ge, maxGasPrice
Expand Down Expand Up @@ -418,11 +415,7 @@ func TestNewCommitStoreReader(t *testing.T) {
lp.On("RegisterFilter", mock.Anything, mock.Anything).Return(nil)
}

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
onRampReader.On("GetDynamicConfig", context.Background()).
Return(cciptypes.OnRampDynamicConfig{}, nil).Maybe()
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

_, err = factory.NewCommitStoreReader(logger.TestLogger(t), factory.NewEvmVersionFinder(), addr, c, lp, feeEstimatorConfig)
if tc.expectedErr != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
onRampMock "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
ccipdatamocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_0_0"
)

Expand All @@ -25,9 +24,7 @@ func TestCommitStore(t *testing.T) {
addr := cciptypes.Address(utils.RandomAddress().String())
lp := mocks2.NewLogPoller(t)

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

lp.On("RegisterFilter", mock.Anything, mock.Anything).Return(nil)
versionFinder := newMockVersionFinder(ccipconfig.CommitStore, *semver.MustParse(versionStr), nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
onRampMock "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
ccipdatamocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_0_0"
)

Expand All @@ -26,9 +25,7 @@ func TestOffRamp(t *testing.T) {
addr := cciptypes.Address(utils.RandomAddress().String())
lp := mocks2.NewLogPoller(t)

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

expFilterNames := []string{
logpoller.FilterName(v1_0_0.EXEC_EXECUTION_STATE_CHANGES, addr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
)

//go:generate mockery --quiet --name FeeEstimatorConfigReader --filename fee_estimator_config_reader_mock.go --case=underscore
type FeeEstimatorConfigReader interface {
GetDataAvailabilityConfig(ctx context.Context) (destDAOverheadGas, destGasPerDAByte, destDAMultiplierBps int64, err error)
}

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
Expand Up @@ -28,11 +28,10 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/factory"
onRampMock "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
ccipdatamocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_0_0"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_2_0"
)
Expand Down Expand Up @@ -195,9 +194,7 @@ func setupOffRampReaderTH(t *testing.T, version string) offRampReaderTH {
require.Fail(t, "Unknown version: ", version)
}

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

// Create the version-specific reader.
reader, err := factory.NewOffRampReader(log, factory.NewEvmVersionFinder(), ccipcalc.EvmAddrToGeneric(offRampAddress), bc, lp, nil, nil, true, feeEstimatorConfig)
Expand Down Expand Up @@ -407,9 +404,7 @@ func TestNewOffRampReader(t *testing.T) {
require.NoError(t, err)
c := evmclientmocks.NewClient(t)

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

c.On("CallContract", mock.Anything, mock.Anything, mock.Anything).Return(b, nil)
addr := ccipcalc.EvmAddrToGeneric(utils.RandomAddress())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/v1_0_0"
)
Expand All @@ -27,9 +26,7 @@ func TestExecutionReportEncodingV100(t *testing.T) {
ProofFlagBits: big.NewInt(133),
}

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := mocks.NewOnRampReader(t)
require.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := mocks.NewFeeEstimatorConfigReader(t)

offRamp, err := v1_0_0.NewOffRamp(logger.TestLogger(t), utils.RandomAddress(), nil, lpmocks.NewLogPoller(t), nil, nil, feeEstimatorConfig)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
mock_contracts "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/mocks/v1_0_0"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipcalc"
onRampMock "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
ccipdatamocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/rpclib"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/rpclib/rpclibmocks"
)
Expand Down Expand Up @@ -190,9 +189,7 @@ func Test_LogsAreProperlyMarkedAsFinalized(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
offrampAddress := utils.RandomAddress()

feeEstimatorConfig := estimatorconfig.NewFeeEstimatorConfigService()
onRampReader := onRampMock.NewOnRampReader(t)
assert.NoError(t, feeEstimatorConfig.SetOnRampReader(onRampReader))
feeEstimatorConfig := ccipdatamocks.NewFeeEstimatorConfigReader(t)

lp := mocks.NewLogPoller(t)
lp.On("LatestBlock", mock.Anything).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *OnRamp) GetDynamicConfig(ctx context.Context) (cciptypes.OnRampDynamicC
if o.onRamp == nil {
return cciptypes.OnRampDynamicConfig{}, fmt.Errorf("onramp not initialized")
}
legacyDynamicConfig, err := o.onRamp.GetDynamicConfig(nil)
legacyDynamicConfig, err := o.onRamp.GetDynamicConfig(&bind.CallOpts{Context: ctx})
if err != nil {
return cciptypes.OnRampDynamicConfig{}, err
}
Expand Down Expand Up @@ -165,8 +165,8 @@ func (o *OnRamp) GetSendRequestsBetweenSeqNums(ctx context.Context, seqNumMin, s
return res, nil
}

func (o *OnRamp) RouterAddress(context.Context) (cciptypes.Address, error) {
config, err := o.onRamp.GetDynamicConfig(nil)
func (o *OnRamp) RouterAddress(ctx context.Context) (cciptypes.Address, error) {
config, err := o.onRamp.GetDynamicConfig(&bind.CallOpts{Context: ctx})
if err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 9e00c70

Please sign in to comment.