Skip to content

Commit

Permalink
remove jobspec from changeset output
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Feb 1, 2025
1 parent 604f633 commit 9b2a044
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 62 deletions.
2 changes: 0 additions & 2 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func DeployChainContractsChangeset(env deployment.Environment, c DeployChainCont
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: newAddresses,
Jobs: nil,
JobSpecs: nil,
}, nil
}

Expand Down
3 changes: 0 additions & 3 deletions deployment/ccip/changeset/cs_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ func DeployHomeChainChangeset(env deployment.Environment, cfg DeployHomeChainCon
}

return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
Jobs: nil,
}, nil
}

Expand Down
52 changes: 33 additions & 19 deletions deployment/ccip/changeset/cs_jobspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
ccip "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestJobSpecChangeset(t *testing.T) {
t.Parallel()
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Chains: 1,
Nodes: 4,
var err error
tenv, _ := testhelpers.NewMemoryEnvironment(t, testhelpers.WithNoJobsAndContracts())
e := tenv.Env
nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain)
require.NoError(t, err)
e, err = commonchangeset.ApplyChangesets(t, e, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.DeployHomeChainChangeset),
Config: changeset.DeployHomeChainConfig{
HomeChainSel: tenv.HomeChainSel,
RMNDynamicConfig: testhelpers.NewTestRMNDynamicConfig(),
RMNStaticConfig: testhelpers.NewTestRMNStaticConfig(),
NodeOperators: testhelpers.NewTestNodeOperator(e.Chains[tenv.HomeChainSel].DeployerKey.From),
NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{
testhelpers.TestNodeOperator: nodes.NonBootstraps().PeerIDs(),
},
},
},
})
// TODO: Replace this with a changeset which proposes the jobs, and returns job ids.
output, err := changeset.CCIPCapabilityJobspecChangeset(e, nil)
require.NoError(t, err)
require.NotNil(t, output.JobSpecs)
nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain)
output, err := changeset.CCIPCapabilityJobspecChangeset(e, nil)
require.NoError(t, err)
require.NotEmpty(t, output.Jobs)
nodeIDs := make(map[string]struct{})
for _, job := range output.Jobs {
require.NotEmpty(t, job.JobID)
require.NotEmpty(t, job.Spec)
require.NotEmpty(t, job.Node)
nodeIDs[job.Node] = struct{}{}
_, err = ccip.ValidatedCCIPSpec(job.Spec)
require.NoError(t, err)
}
for _, node := range nodes {
jobs, exists := output.JobSpecs[node.NodeID]
require.True(t, exists)
require.NotNil(t, jobs)
for _, job := range jobs {
_, err = ccip.ValidatedCCIPSpec(job)
require.NoError(t, err)
}
_, ok := nodeIDs[node.NodeID]
require.True(t, ok)
}
}

Expand All @@ -44,5 +58,5 @@ func TestJobSpecChangesetIdempotent(t *testing.T) {
// as the job specs are already created in the first call
output, err := changeset.CCIPCapabilityJobspecChangeset(e.Env, nil)
require.NoError(t, err)
require.Empty(t, output.JobSpecs)
require.Empty(t, output.Jobs)
}
2 changes: 0 additions & 2 deletions deployment/ccip/changeset/cs_prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ func DeployPrerequisitesChangeset(env deployment.Environment, cfg DeployPrerequi
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
Jobs: nil,
}, nil
}

Expand Down
17 changes: 5 additions & 12 deletions deployment/ccip/changeset/testhelpers/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
Expand Down Expand Up @@ -243,19 +242,13 @@ func (d *DeployedEnv) TimelockContracts(t *testing.T) map[uint64]*proposalutils.
}

func (d *DeployedEnv) SetupJobs(t *testing.T) {
ctx := testcontext.Get(t)
out, err := changeset.CCIPCapabilityJobspecChangeset(d.Env, struct{}{})
require.NoError(t, err)
for nodeID, jobs := range out.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := d.Env.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
require.NoError(t, err)
}
require.NotEmpty(t, out.Jobs)
for _, job := range out.Jobs {
require.NotEmpty(t, job.JobID)
require.NotEmpty(t, job.Spec)
require.NotEmpty(t, job.Node)
}
// Wait for plugins to register filters?
// TODO: Investigate how to avoid.
Expand Down
28 changes: 27 additions & 1 deletion deployment/ccip/changeset/v1_5/cs_jobspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"fmt"

jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
Expand Down Expand Up @@ -69,8 +71,32 @@ func JobSpecsForLanesChangeset(env deployment.Environment, c JobSpecsForLanesCon
if err != nil {
return deployment.ChangesetOutput{}, err
}
// Now we propose the job specs to the offchain system.
var Jobs []deployment.ProposedJob
for nodeID, jobs := range nodesToJobSpecs {
for _, job := range jobs {
Jobs = append(Jobs, deployment.ProposedJob{
Node: nodeID,
Spec: job,
})
res, err := env.Offchain.ProposeJob(env.GetContext(),
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
if err != nil {
// If we fail to propose a job, we should return an error and the jobs we've already proposed.
// This is so that we can retry the proposal with manual intervention.
// JOBID will be empty if the proposal failed.
return deployment.ChangesetOutput{
Jobs: Jobs,
}, fmt.Errorf("failed to propose job: %w", err)
}
Jobs[len(Jobs)-1].JobID = res.Proposal.JobId
}
}
return deployment.ChangesetOutput{
JobSpecs: nodesToJobSpecs,
Jobs: Jobs,
}, nil
}

Expand Down
2 changes: 0 additions & 2 deletions deployment/changeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type ProposedJob struct {
// The address book here should contain only new addresses created in
// this changeset.
type ChangesetOutput struct {
// Deprecated: Prefer Jobs instead.
JobSpecs map[string][]string `deprecated:"true"`
Jobs []ProposedJob
Proposals []timelock.MCMSWithTimelockProposal
AddressBook AddressBook
Expand Down
1 change: 0 additions & 1 deletion deployment/common/changeset/save_existing.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func SaveExistingContractsChangeset(env deployment.Environment, cfg ExistingCont
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
Jobs: nil,
}, nil
}
20 changes: 0 additions & 20 deletions deployment/common/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (

mapset "github.com/deckarep/golang-set/v2"

jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
)
Expand Down Expand Up @@ -51,23 +48,6 @@ func ApplyChangesets(t *testing.T, e deployment.Environment, timelockContractsPe
} else {
addresses = currentEnv.ExistingAddresses
}
if out.JobSpecs != nil {
// TODO: Delete this when out.JobSpecs are no longer in use.
ctx := testcontext.Get(t)
for nodeID, jobs := range out.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := currentEnv.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
if err != nil {
return e, fmt.Errorf("failed to propose job: %w", err)
}
}
}
}
if out.Jobs != nil {
// do nothing, as these jobs auto-accept.
}
Expand Down

0 comments on commit 9b2a044

Please sign in to comment.