Skip to content

Commit

Permalink
Rename job spec params (#15051)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin authored Oct 31, 2024
1 parent 6b29cdb commit 885baff
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 324 deletions.
13 changes: 7 additions & 6 deletions core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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")
})
}
81 changes: 9 additions & 72 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Loading

0 comments on commit 885baff

Please sign in to comment.