Skip to content

Commit

Permalink
add dry option; return useful config
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed Nov 19, 2024
1 parent 3cadac2 commit 5ef45b6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
9 changes: 5 additions & 4 deletions deployment/keystone/changeset/deploy_ocr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func DeployOCR3(env deployment.Environment, config interface{}) (deployment.Chan
return deployment.ChangesetOutput{AddressBook: ab}, nil
}

func ConfigureOCR3Contract(lggr logger.Logger, env deployment.Environment, ab deployment.AddressBook, registryChainSel uint64, nodes []string, cfg kslib.OracleConfigWithSecrets) (deployment.ChangesetOutput, error) {
err := kslib.ConfigureOCR3ContractFromJD(&env, registryChainSel, nodes, ab, &cfg)
func ConfigureOCR3Contract(lggr logger.Logger, env deployment.Environment, cfg kslib.ConfigureOCR3Config) (deployment.ChangesetOutput, error) {

_, err := kslib.ConfigureOCR3ContractFromJD(&env, cfg)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to configure OCR3Capability: %w", err)
}

return deployment.ChangesetOutput{AddressBook: ab}, nil
// does not create any new addresses
return deployment.ChangesetOutput{}, nil
}
51 changes: 36 additions & 15 deletions deployment/keystone/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,45 +423,62 @@ func ConfigureOCR3Contract(env *deployment.Environment, chainSel uint64, dons []
return nil
}

func ConfigureOCR3ContractFromJD(env *deployment.Environment, chainSel uint64, nodeIDs []string, addrBook deployment.AddressBook, cfg *OracleConfigWithSecrets) error {
registryChain, ok := env.Chains[chainSel]
type ConfigureOCR3Resp struct {
Orc2drOracleConfig
}

type ConfigureOCR3Config struct {
ChainSel uint64
NodeIDs []string
OCR3Config *OracleConfigWithSecrets
DryRun bool
}

func ConfigureOCR3ContractFromJD(env *deployment.Environment, cfg ConfigureOCR3Config) (*ConfigureOCR3Resp, error) {

//func ConfigureOCR3ContractFromJD(env *deployment.Environment, chainSel uint64, nodeIDs []string, addrBook deployment.AddressBook, cfg *OracleConfigWithSecrets) (*ConfigureOCR3Resp, error) {
registryChain, ok := env.Chains[cfg.ChainSel]
if !ok {
return fmt.Errorf("chain %d not found in environment", chainSel)
return nil, fmt.Errorf("chain %d not found in environment", cfg.ChainSel)
}
contractSetsResp, err := GetContractSets(env.Logger, &GetContractSetsRequest{
Chains: env.Chains,
AddressBook: addrBook,
AddressBook: env.ExistingAddresses,
})
if err != nil {
return fmt.Errorf("failed to get contract sets: %w", err)
return nil, fmt.Errorf("failed to get contract sets: %w", err)
}
contracts, ok := contractSetsResp.ContractSets[chainSel]
contracts, ok := contractSetsResp.ContractSets[cfg.ChainSel]
if !ok {
return fmt.Errorf("failed to get contract set for chain %d", chainSel)
return nil, fmt.Errorf("failed to get contract set for chain %d", cfg.ChainSel)
}
contract := contracts.OCR3
if contract == nil {
return fmt.Errorf("no ocr3 contract found for chain %d", chainSel)
return nil, fmt.Errorf("no ocr3 contract found for chain %d", cfg.ChainSel)
}
nodes, err := NodesFromJD("nodes", nodeIDs, env.Offchain)
nodes, err := NodesFromJD("nodes", cfg.NodeIDs, env.Offchain)
if err != nil {
return err
return nil, err
}
var ocr2nodes []*ocr2Node
for _, node := range nodes {
n, err := newOcr2NodeFromJD(&node, chainSel)
n, err := newOcr2NodeFromJD(&node, cfg.ChainSel)
if err != nil {
return fmt.Errorf("failed to create ocr2 node from clo node: %w", err)
return nil, fmt.Errorf("failed to create ocr2 node from clo node %v: %w", node, err)
}
ocr2nodes = append(ocr2nodes, n)
}
_, err = configureOCR3contract(configureOCR3Request{
cfg: cfg,
r, err := configureOCR3contract(configureOCR3Request{
cfg: cfg.OCR3Config,
chain: registryChain,
contract: contract,
nodes: ocr2nodes,
dryRun: cfg.DryRun,
})
return err
return &ConfigureOCR3Resp{
Orc2drOracleConfig: r.ocrConfig,
}, nil

}

type registerCapabilitiesRequest struct {
Expand Down Expand Up @@ -965,6 +982,7 @@ type configureOCR3Request struct {
chain deployment.Chain
contract *kocr3.OCR3Capability
nodes []*ocr2Node
dryRun bool
}
type configureOCR3Response struct {
ocrConfig Orc2drOracleConfig
Expand All @@ -979,6 +997,9 @@ func configureOCR3contract(req configureOCR3Request) (*configureOCR3Response, er
if err != nil {
return nil, fmt.Errorf("failed to generate OCR3 config: %w", err)
}
if req.dryRun {
return &configureOCR3Response{ocrConfig}, nil
}
tx, err := req.contract.SetConfig(req.chain.DeployerKey,
ocrConfig.Signers,
ocrConfig.Transmitters,
Expand Down

0 comments on commit 5ef45b6

Please sign in to comment.