@@ -3,67 +3,43 @@ package changeset
33import (
44 "context"
55 "fmt"
6- "time"
7-
8- chainsel "github.com/smartcontractkit/chain-selectors"
96
107 jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
118 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/shared/ptypes"
129
1310 "github.com/smartcontractkit/chainlink/deployment"
1411 "github.com/smartcontractkit/chainlink/deployment/data-streams/jd"
1512 "github.com/smartcontractkit/chainlink/deployment/data-streams/jobs"
16- )
17-
18- const (
19- defaultBootstrapJobSpecsTimeout = 120 * time .Second
13+ "github.com/smartcontractkit/chainlink/deployment/data-streams/utils"
2014)
2115
2216var _ deployment.ChangeSetV2 [CsDistributeBootstrapJobSpecsConfig ] = CsDistributeBootstrapJobSpecs {}
2317
2418type CsDistributeBootstrapJobSpecsConfig struct {
25- ChainSelectorEVM uint64
26- Filter * jd.ListFilter
27- }
28-
29- func findConfiguratorAddressByDON (addresses map [string ]deployment.TypeAndVersion , donID uint64 ) (string , error ) {
30- for address , contract := range addresses {
31- if contract .Type == "Configurator" && contract .Labels .Contains (fmt .Sprintf ("don-%d" , donID )) {
32- return address , nil
33- }
34- }
35- return "" , fmt .Errorf ("Configurator contract not found for DON %d" , donID )
19+ ChainSelectorEVM uint64
20+ Filter * jd.ListFilter
21+ ConfiguratorAddress string
3622}
3723
3824type CsDistributeBootstrapJobSpecs struct {}
3925
4026func (CsDistributeBootstrapJobSpecs ) Apply (e deployment.Environment , cfg CsDistributeBootstrapJobSpecsConfig ) (deployment.ChangesetOutput , error ) {
41- ctx , cancel := context .WithTimeout (e .GetContext (), defaultBootstrapJobSpecsTimeout )
27+ ctx , cancel := context .WithTimeout (e .GetContext (), defaultJobSpecsTimeout )
4228 defer cancel ()
4329
44- bootstrapNodes , err := jd .FetchDONBootstrappersFromJD (ctx , e .Offchain , cfg .Filter )
45- if err != nil {
46- return deployment.ChangesetOutput {}, fmt .Errorf ("failed to get workflow don nodes: %w" , err )
47- }
48-
49- chainID , err := chainsel .GetChainIDFromSelector (cfg .ChainSelectorEVM )
50- if err != nil {
51- return deployment.ChangesetOutput {}, fmt .Errorf ("failed to get chain ID from selector: %w" , err )
52- }
53-
54- addresses , err := e .ExistingAddresses .AddressesForChain (cfg .ChainSelectorEVM )
55- if err != nil {
56- return deployment.ChangesetOutput {}, fmt .Errorf ("failed to get existing addresses: %w" , err )
57- }
58-
59- // Search for the Configurator address in the address book by DON ID
60- configuratorAddress , err := findConfiguratorAddressByDON (addresses , cfg .Filter .DONID )
30+ chainID , _ , err := chainAndAddresses (e , cfg .ChainSelectorEVM )
6131 if err != nil {
6232 return deployment.ChangesetOutput {}, err
6333 }
6434
35+ // Add a label to the job spec to identify the related DON
36+ labels := append ([]* ptypes.Label (nil ),
37+ & ptypes.Label {
38+ Key : utils .DonIdentifier (cfg .Filter .DONID , cfg .Filter .DONName ),
39+ })
40+
6541 bootstrapSpec := jobs .NewBootstrapSpec (
66- configuratorAddress ,
42+ cfg . ConfiguratorAddress ,
6743 cfg .Filter .DONID ,
6844 jobs .RelayTypeEVM ,
6945 jobs.RelayConfig {
@@ -76,28 +52,27 @@ func (CsDistributeBootstrapJobSpecs) Apply(e deployment.Environment, cfg CsDistr
7652 return deployment.ChangesetOutput {}, fmt .Errorf ("failed to marshal bootstrap spec: %w" , err )
7753 }
7854
79- // Add a label to the job spec to identify the related DON
80- labels := append ([]* ptypes.Label (nil ),
81- & ptypes.Label {
82- Key : fmt .Sprintf ("don-%d-%s" , cfg .Filter .DONID , cfg .Filter .DONName ),
83- })
55+ bootstrapNodes , err := jd .FetchDONBootstrappersFromJD (ctx , e .Offchain , cfg .Filter )
56+ if err != nil {
57+ return deployment.ChangesetOutput {}, fmt .Errorf ("failed to get workflow don nodes: %w" , err )
58+ }
8459
85- // TODO: For now the implementation uses a very simple approach, in case of partial failures there is a risk
86- // of sending the same job spec multiple times to the same node. We need to understand the implications of this
87- // and decide if we need to implement a more complex approach.
60+ var proposals []* jobv1.ProposeJobRequest
8861 for _ , node := range bootstrapNodes {
89- _ , err = e . Offchain . ProposeJob ( ctx , & jobv1.ProposeJobRequest {
62+ proposals = append ( proposals , & jobv1.ProposeJobRequest {
9063 NodeId : node .Id ,
9164 Spec : string (renderedSpec ),
9265 Labels : labels ,
9366 })
94-
95- if err != nil {
96- return deployment. ChangesetOutput {}, fmt . Errorf ( "failed to propose job: %w" , err )
97- }
67+ }
68+ proposedJobs , err := proposeAllOrNothing ( ctx , e . Offchain , proposals )
69+ if err != nil {
70+ return deployment. ChangesetOutput {}, fmt . Errorf ( "failed to propose all bootstrap jobs: %w" , err )
9871 }
9972
100- return deployment.ChangesetOutput {}, nil
73+ return deployment.ChangesetOutput {
74+ Jobs : proposedJobs ,
75+ }, nil
10176}
10277
10378func (f CsDistributeBootstrapJobSpecs ) VerifyPreconditions (e deployment.Environment , config CsDistributeBootstrapJobSpecsConfig ) error {
0 commit comments