Skip to content

Commit

Permalink
Remove legacy chains from job orm
Browse files Browse the repository at this point in the history
 - This removes evm cfg loading into jobs str8 from db
  • Loading branch information
ilija42 committed Nov 1, 2023
1 parent 24de8af commit cb930b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 61 deletions.
2 changes: 1 addition & 1 deletion core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func NewJobPipelineV2(t testing.TB, cfg pipeline.BridgeConfig, jpcfg JobPipeline
lggr := logger.TestLogger(t)
prm := pipeline.NewORM(db, lggr, dbCfg, jpcfg.MaxSuccessfulRuns())
btORM := bridges.NewORM(db, lggr, dbCfg)
jrm := job.NewORM(db, legacyChains, prm, btORM, keyStore, lggr, dbCfg)
jrm := job.NewORM(db, prm, btORM, keyStore, lggr, dbCfg)
pr := pipeline.NewRunner(prm, btORM, jpcfg, cfg, legacyChains, keyStore.Eth(), keyStore.VRF(), lggr, restrictedHTTPClient, unrestrictedHTTPClient)
return JobPipelineV2TestHelper{
prm,
Expand Down
4 changes: 2 additions & 2 deletions core/internal/cltest/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func MustInsertV2JobSpec(t *testing.T, db *sqlx.DB, transmitterAddress common.Ad
PipelineSpecID: pipelineSpec.ID,
}

jorm := job.NewORM(db, nil, nil, nil, nil, logger.TestLogger(t), configtest.NewTestGeneralConfig(t).Database())
jorm := job.NewORM(db, nil, nil, nil, logger.TestLogger(t), configtest.NewTestGeneralConfig(t).Database())
err = jorm.InsertJob(&jb)
require.NoError(t, err)
return jb
Expand Down Expand Up @@ -619,7 +619,7 @@ func MustInsertKeeperJob(t *testing.T, db *sqlx.DB, korm keeper.ORM, from ethkey
tlg := logger.TestLogger(t)
prm := pipeline.NewORM(db, tlg, cfg.Database(), cfg.JobPipeline().MaxSuccessfulRuns())
btORM := bridges.NewORM(db, tlg, cfg.Database())
jrm := job.NewORM(db, nil, prm, btORM, nil, tlg, cfg.Database())
jrm := job.NewORM(db, prm, btORM, nil, tlg, cfg.Database())
err = jrm.InsertJob(&jb)
require.NoError(t, err)
return jb
Expand Down
6 changes: 1 addition & 5 deletions core/internal/cltest/job_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
)

const (
Expand Down Expand Up @@ -66,9 +64,7 @@ func getORMs(t *testing.T, db *sqlx.DB) (jobORM job.ORM, pipelineORM pipeline.OR
lggr := logger.TestLogger(t)
pipelineORM = pipeline.NewORM(db, lggr, config.Database(), config.JobPipeline().MaxSuccessfulRuns())
bridgeORM := bridges.NewORM(db, lggr, config.Database())
cc := evmtest.NewChainRelayExtenders(t, evmtest.TestChainOpts{DB: db, GeneralConfig: config, KeyStore: keyStore.Eth()})
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(cc)
jobORM = job.NewORM(db, legacyChains, pipelineORM, bridgeORM, keyStore, lggr, config.Database())
jobORM = job.NewORM(db, pipelineORM, bridgeORM, keyStore, lggr, config.Database())
t.Cleanup(func() { jobORM.Close() })
return
}
2 changes: 1 addition & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
sessionORM = sessions.NewORM(db, cfg.WebServer().SessionTimeout().Duration(), globalLogger, cfg.Database(), auditLogger)
mercuryORM = mercury.NewORM(db, globalLogger, cfg.Database())
pipelineRunner = pipeline.NewRunner(pipelineORM, bridgeORM, cfg.JobPipeline(), cfg.WebServer(), legacyEVMChains, keyStore.Eth(), keyStore.VRF(), globalLogger, restrictedHTTPClient, unrestrictedHTTPClient)
jobORM = job.NewORM(db, legacyEVMChains, pipelineORM, bridgeORM, keyStore, globalLogger, cfg.Database())
jobORM = job.NewORM(db, pipelineORM, bridgeORM, keyStore, globalLogger, cfg.Database())
txmORM = txmgr.NewTxStore(db, globalLogger, cfg.Database())
)

Expand Down
68 changes: 16 additions & 52 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/smartcontractkit/chainlink-relay/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -85,35 +83,25 @@ type ORMConfig interface {
}

type orm struct {
q pg.Q
legacyChains evm.LegacyChainContainer
keyStore keystore.Master
pipelineORM pipeline.ORM
lggr logger.SugaredLogger
cfg pg.QConfig
bridgeORM bridges.ORM
q pg.Q
keyStore keystore.Master
pipelineORM pipeline.ORM
lggr logger.SugaredLogger
cfg pg.QConfig
bridgeORM bridges.ORM
}

var _ ORM = (*orm)(nil)

func NewORM(
db *sqlx.DB,
legacyChains evm.LegacyChainContainer,
pipelineORM pipeline.ORM,
bridgeORM bridges.ORM,
keyStore keystore.Master, // needed to validation key properties on new job creation
lggr logger.Logger,
cfg pg.QConfig,
) *orm {
func NewORM(db *sqlx.DB, pipelineORM pipeline.ORM, bridgeORM bridges.ORM, keyStore keystore.Master, lggr logger.Logger, cfg pg.QConfig) *orm {
namedLogger := logger.Sugared(lggr.Named("JobORM"))
return &orm{
q: pg.NewQ(db, namedLogger, cfg),
legacyChains: legacyChains,
keyStore: keyStore,
pipelineORM: pipelineORM,
bridgeORM: bridgeORM,
lggr: namedLogger,
cfg: cfg,
q: pg.NewQ(db, namedLogger, cfg),
keyStore: keyStore,
pipelineORM: pipelineORM,
bridgeORM: bridgeORM,
lggr: namedLogger,
cfg: cfg,
}
}
func (o *orm) Close() error {
Expand Down Expand Up @@ -704,29 +692,12 @@ func (o *orm) FindJobs(offset, limit int) (jobs []Job, count int, err error) {
if err != nil {
return err
}
for i := range jobs {
err = multierr.Combine(err, o.LoadConfigVars(&jobs[i]))
}

return nil
})
return jobs, int(count), err
}

func (o *orm) LoadConfigVars(jb *Job) error {
if jb.OCROracleSpec != nil {
ch, err := o.legacyChains.Get(jb.OCROracleSpec.EVMChainID.String())
if err != nil {
return err
}
newSpec, err := LoadConfigVarsOCR(ch.Config().EVM().OCR(), ch.Config().OCR(), *jb.OCROracleSpec)
if err != nil {
return err
}
jb.OCROracleSpec = newSpec
}
return nil
}

func LoadDefaultVRFPollPeriod(vrfs VRFSpec) *VRFSpec {
if vrfs.PollPeriod == 0 {
vrfs.PollPeriod = 5 * time.Second
Expand Down Expand Up @@ -842,7 +813,7 @@ func (o *orm) FindJobWithoutSpecErrors(id int32) (jb Job, err error) {
return jb, errors.Wrap(err, "FindJobWithoutSpecErrors failed")
}

return jb, o.LoadConfigVars(&jb)
return jb, nil
}

// FindSpecErrorsByJobIDs returns all jobs spec errors by jobs IDs
Expand Down Expand Up @@ -931,7 +902,7 @@ func (o *orm) findJob(jb *Job, col string, arg interface{}, qopts ...pg.QOpt) er
if err != nil {
return errors.Wrap(err, "findJob failed")
}
return o.LoadConfigVars(jb)
return nil
}

func (o *orm) FindJobIDsWithBridge(name string) (jids []int32, err error) {
Expand Down Expand Up @@ -1174,13 +1145,6 @@ func (o *orm) FindJobsByPipelineSpecIDs(ids []int32) ([]Job, error) {
if err != nil {
return err
}
for i := range jbs {
err = o.LoadConfigVars(&jbs[i])
//We must return the jobs even if the chainID is disabled
if err != nil && !errors.Is(err, chains.ErrNoSuchChainID) {
return err
}
}

return nil
})
Expand Down

0 comments on commit cb930b8

Please sign in to comment.