From 885baff9479e935e0fc34d9f52214a32c158eac5 Mon Sep 17 00:00:00 2001 From: george-dorin <120329946+george-dorin@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:50:31 +0200 Subject: [PATCH] Rename job spec params (#15051) --- core/services/job/job_orm_test.go | 13 +- core/services/job/models.go | 81 +------- core/services/job/models_test.go | 242 ++---------------------- core/services/job/orm.go | 6 +- core/services/ocr2/validate/validate.go | 8 +- core/testdata/testspecs/v2_specs.go | 21 +- 6 files changed, 47 insertions(+), 324 deletions(-) diff --git a/core/services/job/job_orm_test.go b/core/services/job/job_orm_test.go index 83216bdb645..bc6ec0d6ea2 100644 --- a/core/services/job/job_orm_test.go +++ b/core/services/job/job_orm_test.go @@ -2014,7 +2014,7 @@ func mustInsertPipelineRun(t *testing.T, orm pipeline.ORM, j job.Job) pipeline.R return run } -func TestORM_CreateJob_OCR2_With_OEV(t *testing.T) { +func TestORM_CreateJob_OCR2_With_AdaptiveSend(t *testing.T) { ctx := testutils.Context(t) customChainID := big.New(testutils.NewRandomEVMChainID()) @@ -2039,17 +2039,18 @@ func TestORM_CreateJob_OCR2_With_OEV(t *testing.T) { jobORM := NewTestORM(t, db, pipelineORM, bridgesORM, keyStore) - oevTransmitterKey := cltest.MustGenerateRandomKey(t) + adaptiveSendKey := cltest.MustGenerateRandomKey(t) - jb, err := ocr2validate.ValidatedOracleSpecToml(testutils.Context(t), config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMWithOEVSpecMinimal(cltest.DefaultOCR2Key.ID(), transmitterID.String(), oevTransmitterKey.EIP55Address.String()), nil) + jb, err := ocr2validate.ValidatedOracleSpecToml(testutils.Context(t), config.OCR2(), config.Insecure(), testspecs.GetOCR2EVMWithAdaptiveSendSpecMinimal(cltest.DefaultOCR2Key.ID(), transmitterID.String(), adaptiveSendKey.EIP55Address.String()), nil) require.NoError(t, err) + require.Equal(t, "arbitrary-value", jb.AdaptiveSendSpec.Metadata["arbitraryParam"]) t.Run("unknown transmitter address", func(t *testing.T) { - require.ErrorContains(t, jobORM.CreateJob(ctx, &jb), "failed to validate oev.TransmitterAddress: no EVM key matching") + require.ErrorContains(t, jobORM.CreateJob(ctx, &jb), "failed to validate AdaptiveSendSpec.TransmitterAddress: no EVM key matching") }) t.Run("multiple jobs", func(t *testing.T) { - keyStore.Eth().XXXTestingOnlyAdd(ctx, oevTransmitterKey) - require.NoError(t, jobORM.CreateJob(ctx, &jb), "failed to validate oev.TransmitterAddress: no EVM key matching") + keyStore.Eth().XXXTestingOnlyAdd(ctx, adaptiveSendKey) + require.NoError(t, jobORM.CreateJob(ctx, &jb), "failed to validate AdaptiveSendSpec.TransmitterAddress: no EVM key matching") }) } diff --git a/core/services/job/models.go b/core/services/job/models.go index c35548041dc..5054abd08b5 100644 --- a/core/services/job/models.go +++ b/core/services/job/models.go @@ -185,7 +185,7 @@ type Job struct { CCIPSpecID *int32 CCIPSpec *CCIPSpec CCIPBootstrapSpecID *int32 - OEVConfig *OEVConfig `toml:"oev"` + AdaptiveSendSpec *AdaptiveSendSpec `toml:"adaptiveSend"` JobSpecErrors []SpecError Type Type `toml:"type"` SchemaVersion uint32 `toml:"schemaVersion"` @@ -1062,88 +1062,25 @@ type CCIPSpec struct { PluginConfig JSONConfig `toml:"pluginConfig"` } -type OEVConfig struct { +type AdaptiveSendSpec struct { TransmitterAddress *evmtypes.EIP55Address `toml:"transmitterAddress"` ContractAddress *evmtypes.EIP55Address `toml:"contractAddress"` - Builders []string `toml:"builders"` - Hints []string `toml:"hints"` - Refund []OEVRefund `toml:"refund"` - PriceDelay time.Duration `toml:"priceDelay"` + Delay time.Duration `toml:"delay"` + Metadata JSONConfig `toml:"metadata"` } -type OEVRefund struct { - Address *evmtypes.EIP55Address `toml:"address"` - Percent int `toml:"percent"` -} - -func (o *OEVConfig) Validate() error { +func (o *AdaptiveSendSpec) Validate() error { if o.TransmitterAddress == nil { - return errors.New("no OEVTransmitterAddress found") + return errors.New("no AdaptiveSendSpec.TransmitterAddress found") } if o.ContractAddress == nil { - return errors.New("no OEVContractAddress found") - } - - if o.Builders == nil { - return errors.New("no OEVBuilders found") - } - - if len(o.Builders) == 0 { - return errors.New("OEVBuilders expects at least one builder, none given") - } - - if containsEmptyElement(o.Builders) { - return errors.Errorf("OEVBuilders should not contain empty element %q", o.Builders) - } - - if o.Hints == nil { - return errors.New("no OEVHints found") - } - if len(o.Hints) == 0 { - return errors.New("OEVHints expects at least one hint, none given") - } - - if containsEmptyElement(o.Hints) { - return errors.Errorf("OEVHints should not contain empty element %q", o.Hints) - } - - if o.Refund == nil { - return errors.New("no OEVRefund found") - } - - if o.PriceDelay.Seconds() <= 1 { - return errors.New("OEVPriceDelay not set or smaller than 1s") - } - - if o.Refund == nil { - return errors.New("no OEVRefund found") - } - - totalRefundPercent := 0 - for _, r := range o.Refund { - if r.Address == nil { - return errors.New("OEVRefund.Address should not be empty") - } - - if r.Percent <= 0 || r.Percent > 100 { - return errors.New("OEVRefund.Percent should be between 1 and 100") - } - totalRefundPercent += r.Percent + return errors.New("no AdaptiveSendSpec.ContractAddress found") } - if totalRefundPercent > 100 { - return errors.New("the sum of all OEVRefund.Percent should not be greater than 100") + if o.Delay.Seconds() <= 1 { + return errors.New("AdaptiveSendSpec.Delay not set or smaller than 1s") } return nil } - -func containsEmptyElement(s []string) bool { - for _, str := range s { - if str == "" { - return true - } - } - return false -} diff --git a/core/services/job/models_test.go b/core/services/job/models_test.go index 93ccaaf4299..a21a4553219 100644 --- a/core/services/job/models_test.go +++ b/core/services/job/models_test.go @@ -353,258 +353,50 @@ func TestWorkflowSpec_Validate(t *testing.T) { }) } -func TestOEVConfig(t *testing.T) { +func TestAdaptiveSendConfig(t *testing.T) { tests := []struct { name string shouldError bool expectedErrorMessage string - config job.OEVConfig + config job.AdaptiveSendSpec }{ { - name: "OEVTransmitterAddress not set", + name: "AdaptiveSendSpec.TransmitterAddress not set", shouldError: true, - expectedErrorMessage: "no OEVTransmitterAddress found", - config: job.OEVConfig{ + expectedErrorMessage: "no AdaptiveSendSpec.TransmitterAddress found", + config: job.AdaptiveSendSpec{ TransmitterAddress: nil, ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"calldata"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, + Delay: time.Second * 30, }, }, { - name: "OEVContractAddress not set", + name: "AdaptiveSendSpec.ContractAddress not set", shouldError: true, - expectedErrorMessage: "no OEVContractAddress found", - config: job.OEVConfig{ + expectedErrorMessage: "no AdaptiveSendSpec.ContractAddress found", + config: job.AdaptiveSendSpec{ TransmitterAddress: ptr(cltest.NewEIP55Address()), ContractAddress: nil, - Builders: []string{"builder1", "builder2"}, - Hints: []string{"calldata"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVBuilder not set", - shouldError: true, - expectedErrorMessage: "no OEVBuilders found", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: nil, - Hints: []string{"calldata"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVBuilder empty", - shouldError: true, - expectedErrorMessage: "OEVBuilders expects at least one builder", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{}, - Hints: []string{"calldata"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVBuilder has empty element", - shouldError: true, - expectedErrorMessage: "OEVBuilders should not contain empty element", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "", "builder2"}, - Hints: []string{"calldata"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVHints not set", - shouldError: true, - expectedErrorMessage: "no OEVHints found", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: nil, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, + Delay: time.Second * 30, }, }, { - name: "OEVHints empty", + name: "AdaptiveSendSpec.Delay not set", shouldError: true, - expectedErrorMessage: "OEVHints expects at least one hint", - config: job.OEVConfig{ + expectedErrorMessage: "AdaptiveSendSpec.Delay not set or smaller than 1s", + config: job.AdaptiveSendSpec{ TransmitterAddress: ptr(cltest.NewEIP55Address()), ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, }, }, { - name: "OEVHints has empty element", + name: "AdaptiveSendSpec.Delay set to 50ms", shouldError: true, - expectedErrorMessage: "OEVHints should not contain empty element", - config: job.OEVConfig{ + expectedErrorMessage: "AdaptiveSendSpec.Delay not set or smaller than 1s", + config: job.AdaptiveSendSpec{ TransmitterAddress: ptr(cltest.NewEIP55Address()), ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "", "hint2"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVPriceDelay not set", - shouldError: true, - expectedErrorMessage: "OEVPriceDelay not set or smaller than 1s", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 1, - }, - }, - }, - }, - { - name: "OEVPriceDelay set to 50ms", - shouldError: true, - expectedErrorMessage: "OEVPriceDelay not set or smaller than 1s", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 0, - }, - }, - PriceDelay: time.Millisecond * 50, - }, - }, - { - name: "OEVRefund not set", - shouldError: true, - expectedErrorMessage: "no OEVRefund found", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVRefund.Address not set", - shouldError: true, - expectedErrorMessage: "OEVRefund.Address should not be empty", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - Refund: []job.OEVRefund{ - { - Percent: 1, - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVRefund.Percent not set", - shouldError: true, - expectedErrorMessage: "OEVRefund.Percent should be between 1 and 100", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - }, - }, - PriceDelay: time.Second * 30, - }, - }, - { - name: "OEVRefund.Percent over 100", - shouldError: true, - expectedErrorMessage: "the sum of all OEVRefund.Percent should not be greater than 100", - config: job.OEVConfig{ - TransmitterAddress: ptr(cltest.NewEIP55Address()), - ContractAddress: ptr(cltest.NewEIP55Address()), - Builders: []string{"builder1", "builder2"}, - Hints: []string{"hint1", "hint2"}, - Refund: []job.OEVRefund{ - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 50, - }, - { - Address: ptr(cltest.NewEIP55Address()), - Percent: 51, - }, - }, - PriceDelay: time.Second * 30, + Delay: time.Millisecond * 50, }, }, } diff --git a/core/services/job/orm.go b/core/services/job/orm.go index e875686a2d1..a86da5f7111 100644 --- a/core/services/job/orm.go +++ b/core/services/job/orm.go @@ -304,10 +304,10 @@ func (o *orm) CreateJob(ctx context.Context, jb *Job) error { } } - if jb.OEVConfig != nil { - err = validateKeyStoreMatchForRelay(ctx, jb.OCR2OracleSpec.Relay, tx.keyStore, jb.OEVConfig.TransmitterAddress.String()) + if jb.AdaptiveSendSpec != nil { + err = validateKeyStoreMatchForRelay(ctx, jb.OCR2OracleSpec.Relay, tx.keyStore, jb.AdaptiveSendSpec.TransmitterAddress.String()) if err != nil { - return fmt.Errorf("failed to validate oev.TransmitterAddress: %w", err) + return fmt.Errorf("failed to validate AdaptiveSendSpec.TransmitterAddress: %w", err) } } diff --git a/core/services/ocr2/validate/validate.go b/core/services/ocr2/validate/validate.go index d631e3761c8..40e2c11c3e7 100644 --- a/core/services/ocr2/validate/validate.go +++ b/core/services/ocr2/validate/validate.go @@ -73,7 +73,7 @@ func ValidatedOracleSpecToml(ctx context.Context, config OCR2Config, insConf Ins if err = validateTimingParameters(config, insConf, spec); err != nil { return jb, err } - if err = validateOEVSpec(ctx, jb); err != nil { + if err = validateAdaptiveSendSpec(ctx, jb); err != nil { return jb, err } return jb, nil @@ -381,9 +381,9 @@ func validateOCR2LLOSpec(jsonConfig job.JSONConfig) error { return pkgerrors.Wrap(pluginConfig.Validate(), "LLO PluginConfig is invalid") } -func validateOEVSpec(ctx context.Context, spec job.Job) error { - if spec.OEVConfig != nil { - return spec.OEVConfig.Validate() +func validateAdaptiveSendSpec(ctx context.Context, spec job.Job) error { + if spec.AdaptiveSendSpec != nil { + return spec.AdaptiveSendSpec.Validate() } return nil } diff --git a/core/testdata/testspecs/v2_specs.go b/core/testdata/testspecs/v2_specs.go index 5e3073f4ff5..d3d72467a83 100644 --- a/core/testdata/testspecs/v2_specs.go +++ b/core/testdata/testspecs/v2_specs.go @@ -951,7 +951,7 @@ targets: inputs: consensus_output: $(a-consensus.outputs) ` -var OCR2EVMSpecMinimalWithOEVTemplate = ` +var OCR2EVMSpecMinimalWithAdaptiveSendTemplate = ` type = "offchainreporting2" schemaVersion = 1 name = "%s" @@ -979,21 +979,14 @@ juelsPerFeeCoinSource = """ [relayConfig] chainID = 0 -[oev] +[adaptiveSend] transmitterAddress = '%s' contractAddress = '0xF67D0290337bca0847005C7ffD1BC75BA9AAE6e4' -builders = ['flashbots','rsync'] -hints = ['calldata'] -priceDelay = '30s' - -[[oev.refund]] -address = '0xc6f339D45474FEf53a20CCe132b03541d8FAE6DE' -percent = 40 -[[oev.refund]] -address = '0x01F5b01FcB4042BcBa451f0409c780c77b98de05' -percent = 49 +delay = '30s' +[adaptiveSend.metadata] +arbitraryParam = 'arbitrary-value' ` -func GetOCR2EVMWithOEVSpecMinimal(keyBundle, transmitterID, transmitterAddressOEV string) string { - return fmt.Sprintf(OCR2EVMSpecMinimalWithOEVTemplate, uuid.New(), keyBundle, transmitterID, transmitterAddressOEV) +func GetOCR2EVMWithAdaptiveSendSpecMinimal(keyBundle, transmitterID, secondaryTransmitterAddress string) string { + return fmt.Sprintf(OCR2EVMSpecMinimalWithAdaptiveSendTemplate, uuid.New(), keyBundle, transmitterID, secondaryTransmitterAddress) }