Skip to content

Commit

Permalink
Simplify node key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Oct 24, 2024
1 parent 0b3f02e commit eaab702
Show file tree
Hide file tree
Showing 24 changed files with 447 additions and 1,166 deletions.
8 changes: 1 addition & 7 deletions core/scripts/keystone/src/01_deploy_contracts_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (g *deployContracts) Run(args []string) {
onlySetConfig := fs.Bool("onlysetconfig", false, "set the config on the OCR3 contract without deploying the contracts or funding transmitters")
dryRun := fs.Bool("dryrun", false, "dry run, don't actually deploy the contracts and do not fund transmitters")
nodeSetsPath := fs.String("nodesets", "", "Custom node sets location")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
artefactsDir := fs.String("artefacts", "", "Custom artefacts directory location")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")

Expand All @@ -76,15 +75,12 @@ func (g *deployContracts) Run(args []string) {
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}

os.Setenv("ETH_URL", *ethUrl)
os.Setenv("ETH_CHAIN_ID", fmt.Sprintf("%d", *chainID))
os.Setenv("ACCOUNT_KEY", *accountKey)
os.Setenv("INSECURE_SKIP_VERIFY", "true")
deploy(*keylessNodeSetsPath, *nodeSetsPath, *ocrConfigFile, *skipFunding, *dryRun, *onlySetConfig, *artefactsDir, *nodeSetSize)
deploy( *nodeSetsPath, *ocrConfigFile, *skipFunding, *dryRun, *onlySetConfig, *artefactsDir, *nodeSetSize)
}

// deploy does the following:
Expand All @@ -94,7 +90,6 @@ func (g *deployContracts) Run(args []string) {
// 4. Writes the deployed contract addresses to a file
// 5. Funds the transmitters
func deploy(
keylessNodeSetsPath string,
nodeSetsPath string,
configFile string,
skipFunding bool,
Expand All @@ -105,7 +100,6 @@ func deploy(
) {
env := helpers.SetupEnv(false)
ocrConfig := generateOCR3Config(
keylessNodeSetsPath,
configFile,
env.ChainID,
nodeSetsPath,
Expand Down
7 changes: 1 addition & 6 deletions core/scripts/keystone/src/02_deploy_jobspecs_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (g *deployJobSpecs) Run(args []string) {
p2pPort := fs.Int64("p2pport", 6690, "p2p port")
onlyReplay := fs.Bool("onlyreplay", false, "only replay the block from the OCR3 contract setConfig transaction")
templatesLocation := fs.String("templates", "", "Custom templates location")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
nodeSetsPath := fs.String("nodesets", "", "Custom node sets location")
artefactsDir := fs.String("artefacts", "", "Custom artefacts directory location")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")
Expand All @@ -48,20 +47,16 @@ func (g *deployJobSpecs) Run(args []string) {
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}
if *templatesLocation == "" {
*templatesLocation = "templates"
}

nodes := downloadKeylessNodeSets(*keylessNodeSetsPath, *nodeSetSize).Workflow.Nodes
nodes := downloadNodeSets(*chainID, *nodeSetsPath, *nodeSetSize).Workflow.Nodes
deployedContracts, err := LoadDeployedContracts(*artefactsDir)
PanicErr(err)

jobspecs := genSpecs(
*nodeSetsPath,
*keylessNodeSetsPath,
*templatesLocation,
*chainID, *p2pPort, deployedContracts.OCRContract.Hex(),
*nodeSetSize,
Expand Down
20 changes: 7 additions & 13 deletions core/scripts/keystone/src/03_deploy_streams_trigger_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func (g *deployStreamsTrigger) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError)
chainID := fs.Int64("chainid", 1337, "chain id")
ocrConfigFile := fs.String("ocrfile", "ocr_config.json", "path to OCR config file")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
nodeSetsPath := fs.String("nodesets", "", "Custom node sets location")
force := fs.Bool("force", false, "Force deployment")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")
Expand All @@ -122,9 +121,6 @@ func (g *deployStreamsTrigger) Run(args []string) {
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}

os.Setenv("ETH_URL", *ethUrl)
os.Setenv("ETH_CHAIN_ID", fmt.Sprintf("%d", *chainID))
Expand All @@ -135,7 +131,6 @@ func (g *deployStreamsTrigger) Run(args []string) {

setupMercuryV03(
env,
*keylessNodeSetsPath,
*ocrConfigFile,
*chainID,
*nodeSetsPath,
Expand All @@ -145,17 +140,16 @@ func (g *deployStreamsTrigger) Run(args []string) {
}

// See /core/services/ocr2/plugins/mercury/integration_test.go
func setupMercuryV03(env helpers.Environment, keylessNodeSetsPath string, ocrConfigFilePath string, chainId int64, nodeSetsPath string, nodeSetSize int, force bool) {
func setupMercuryV03(env helpers.Environment, ocrConfigFilePath string, chainId int64, nodeSetsPath string, nodeSetSize int, force bool) {
fmt.Printf("Deploying streams trigger for chain %d\n", chainId)
fmt.Printf("Using OCR config file: %s\n", ocrConfigFilePath)
fmt.Printf("Using keyless node sets: %s\n", keylessNodeSetsPath)
fmt.Printf("Using node sets: %s\n", nodeSetsPath)
fmt.Printf("Force: %t\n\n", force)

fmt.Printf("Deploying Mercury V0.3 contracts\n")
_, _, _, verifier := deployMercuryV03Contracts(env)

nodeSets := downloadNodeSets(keylessNodeSetsPath, chainId, nodeSetsPath, nodeSetSize)
nodeSets := downloadNodeSets(chainId, nodeSetsPath, nodeSetSize)

fmt.Printf("Generating OCR3 config\n")
ocrConfig := generateMercuryOCR2Config(nodeSets.StreamsTrigger.NodeKeys[1:]) // skip the bootstrap node
Expand Down Expand Up @@ -187,7 +181,7 @@ func setupMercuryV03(env helpers.Environment, keylessNodeSetsPath string, ocrCon
PanicErr(err)

fmt.Printf("Deploying OCR2 job specs for feed %s\n", feed.name)
deployOCR2JobSpecsForFeed(nodeSets.StreamsTrigger.NodeKeys, nodeSets.StreamsTrigger.Nodes, verifier, feed, chainId, force)
deployOCR2JobSpecsForFeed(nodeSets.StreamsTrigger, verifier, feed, chainId, force)
}

fmt.Println("Finished deploying streams trigger")
Expand Down Expand Up @@ -251,11 +245,11 @@ func deployMercuryV03Contracts(env helpers.Environment) (linkToken *link_token_i
return
}

func deployOCR2JobSpecsForFeed(nca []NodeKeys, nodes []*NodeWthCreds, verifier *verifierContract.Verifier, feed feed, chainId int64, force bool) {
func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier *verifierContract.Verifier, feed feed, chainId int64, force bool) {
// we assign the first node as the bootstrap node
for i, n := range nca {
for i, n := range nodeSet.NodeKeys {
// parallel arrays
api := newNodeAPI(nodes[i])
api := newNodeAPI(nodeSet.Nodes[i])
jobSpecName := ""
jobSpecStr := ""

Expand All @@ -276,7 +270,7 @@ func deployOCR2JobSpecsForFeed(nca []NodeKeys, nodes []*NodeWthCreds, verifier *
// Prepare data for Mercury V3 Job
mercuryData := MercuryV3JobSpecData{
FeedName: fmt.Sprintf("feed-%s", feed.name),
BootstrapHost: fmt.Sprintf("%s@%s:%s", nca[0].P2PPeerID, nodes[0].ServiceName, "6690"),
BootstrapHost: fmt.Sprintf("%s@%s:%s", nodeSet.NodeKeys[0].P2PPeerID, nodeSet.Nodes[0].ServiceName, "6690"),
VerifierAddress: verifier.Address().Hex(),
Bridge: feed.bridgeName,
NodeCSAKey: n.CSAPublicKey,
Expand Down
16 changes: 6 additions & 10 deletions core/scripts/keystone/src/03_gen_crib_cluster_overrides_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ func (g *generateCribClusterOverridesPostprovision) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError)
chainID := fs.Int64("chainid", 1337, "chain id")
outputPath := fs.String("outpath", "-", "the path to output the generated overrides (use '-' for stdout)")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of noes in a nodeset")
nodeSetsPath := fs.String("nodesets", "", "Custom node sets location")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
artefactsDir := fs.String("artefacts", "", "Custom artefacts directory location")

err := fs.Parse(args)
Expand All @@ -174,14 +173,11 @@ func (g *generateCribClusterOverridesPostprovision) Run(args []string) {
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}

contracts, err := LoadDeployedContracts(*artefactsDir)
helpers.PanicErr(err)

chart := generatePostprovisionConfig(keylessNodeSetsPath, chainID, nodeSetsPath, contracts, *nodeSetSize)
chart := generatePostprovisionConfig(*chainID, *nodeSetsPath, *nodeSetSize, contracts)

yamlData, err := yaml.Marshal(chart)
helpers.PanicErr(err)
Expand All @@ -195,8 +191,8 @@ func (g *generateCribClusterOverridesPostprovision) Run(args []string) {
}
}

func generatePostprovisionConfig(keylessNodeSetsPath *string, chainID *int64, nodeSetsPath *string, contracts deployedContracts, nodeSetSize int) Helm {
nodeSets := downloadNodeSets(*keylessNodeSetsPath, *chainID, *nodeSetsPath, nodeSetSize)
func generatePostprovisionConfig(chainID int64, nodeSetsPath string, nodeSetSize int, contracts deployedContracts) Helm {
nodeSets := downloadNodeSets(chainID, nodeSetsPath, nodeSetSize)

nodes := make(map[string]Node)
nodeNames := []string{}
Expand All @@ -210,7 +206,7 @@ func generatePostprovisionConfig(keylessNodeSetsPath *string, chainID *int64, no
// we assign capabilitiesBootstrapper after we generate overrides so that
// we do not include the bootstrapper config to itself
overridesToml := generateOverridesToml(
*chainID,
chainID,
contracts.CapabilityRegistry.Hex(),
"",
"",
Expand All @@ -234,7 +230,7 @@ func generatePostprovisionConfig(keylessNodeSetsPath *string, chainID *int64, no
nodeName := fmt.Sprintf("%d-%snode%d", nodeSetIndex, nodeSet.Prefix, i+2)
nodeNames = append(nodeNames, nodeName)
overridesToml := generateOverridesToml(
*chainID,
chainID,
contracts.CapabilityRegistry.Hex(),
nodeKey.EthAddress,
contracts.ForwarderContract.Hex(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
func TestGeneratePostprovisionConfig(t *testing.T) {
chainID := int64(1337)
nodeSetsPath := "./testdata/node_sets.json"
keylessNodeSetsPath := "./testdata/keyless_node_sets.json"

contracts := deployedContracts{
OCRContract: [20]byte{0: 1},
Expand All @@ -22,7 +21,7 @@ func TestGeneratePostprovisionConfig(t *testing.T) {

nodeSetSize := 5

chart := generatePostprovisionConfig(&keylessNodeSetsPath, &chainID, &nodeSetsPath, contracts, nodeSetSize)
chart := generatePostprovisionConfig(chainID, nodeSetsPath, nodeSetSize, contracts)

yamlData, err := yaml.Marshal(chart)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions core/scripts/keystone/src/04_delete_ocr3_jobs_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func (g *deleteJobs) Name() string {

func (g *deleteJobs) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError)
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
chainID := fs.Int64("chainid", 1337, "chain id")
nodeSetsPath := fs.String("nodes", "", "Custom node sets location")
artefactsDir := fs.String("artefacts", "", "Custom artefacts directory location")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")

Expand All @@ -54,16 +55,16 @@ func (g *deleteJobs) Run(args []string) {
if *artefactsDir == "" {
*artefactsDir = defaultArtefactsDir
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}

deployedContracts, err := LoadDeployedContracts(*artefactsDir)
if err != nil {
fmt.Println("Error loading deployed contracts, skipping:", err)
return
}
nodes := downloadKeylessNodeSets(*keylessNodeSetsPath, *nodeSetSize).Workflow.Nodes
nodes := downloadNodeSets(*chainID, *nodeSetsPath, *nodeSetSize).Workflow.Nodes

for _, node := range nodes {
api := newNodeAPI(node)
Expand Down
9 changes: 5 additions & 4 deletions core/scripts/keystone/src/06_deploy_workflows_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ func (g *deployWorkflows) Name() string {

func (g *deployWorkflows) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError)
chainID := fs.Int64("chainid", 1337, "chain id")
workflowFile := fs.String("workflow", "workflow.yml", "path to workflow file")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
nodeSets := fs.String("nodes", "", "Custom node sets location")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")
err := fs.Parse(args)
if err != nil || workflowFile == nil || *workflowFile == "" || nodeSetSize == nil || *nodeSetSize == 0 {
fs.Usage()
os.Exit(1)
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
if *nodeSets == "" {
*nodeSets = defaultNodeSetsPath
}
fmt.Println("Deploying workflows")

nodes := downloadKeylessNodeSets(*keylessNodeSetsPath, *nodeSetSize).Workflow.Nodes
nodes := downloadNodeSets(*chainID, *nodeSets, *nodeSetSize).Workflow.Nodes

if _, err = os.Stat(*workflowFile); err != nil {
PanicErr(errors.New("toml file does not exist"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (c *provisionCR) Run(args []string) {
chainID := fs.Int64("chainid", 1337, "Chain ID of the Ethereum network to deploy to")
accountKey := fs.String("accountkey", "", "Private key of the account to deploy from")
nodeSetsPath := fs.String("nodesets", "", "Custom node sets location")
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
artefactsDir := fs.String("artefacts", "", "Custom artefacts directory location")
nodeSetSize := fs.Int("nodeSetSize", 5, "Number of nodes in a nodeset")

Expand All @@ -49,9 +48,6 @@ func (c *provisionCR) Run(args []string) {
if *nodeSetsPath == "" {
*nodeSetsPath = defaultNodeSetsPath
}
if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}

os.Setenv("ETH_URL", *ethUrl)
os.Setenv("ETH_CHAIN_ID", fmt.Sprintf("%d", *chainID))
Expand All @@ -63,7 +59,6 @@ func (c *provisionCR) Run(args []string) {
reg := getOrDeployCapabilitiesRegistry(ctx, *artefactsDir, env)

nodeSets := downloadNodeSets(
*keylessNodeSetsPath,
*chainID,
*nodeSetsPath,
*nodeSetSize,
Expand Down
9 changes: 3 additions & 6 deletions core/scripts/keystone/src/07_delete_workflows_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func (g *deleteWorkflows) Name() string {

func (g *deleteWorkflows) Run(args []string) {
fs := flag.NewFlagSet(g.Name(), flag.ExitOnError)
keylessNodeSetsPath := fs.String("nodes", "", "Custom keyless node sets location")
chainID := fs.Int64("chainid", 1337, "chain id")
nodeSetsPath := fs.String("nodes", "", "Custom node sets location")
nodeSetSize := fs.Int("nodeSetSize", 5, "number of nodes in a nodeset")

err := fs.Parse(args)
Expand All @@ -33,11 +34,7 @@ func (g *deleteWorkflows) Run(args []string) {
os.Exit(1)
}

if *keylessNodeSetsPath == "" {
*keylessNodeSetsPath = defaultKeylessNodeSetsPath
}

nodes := downloadKeylessNodeSets(*keylessNodeSetsPath, *nodeSetSize).Workflow.Nodes
nodes := downloadNodeSets(*chainID, *nodeSetsPath, *nodeSetSize).Workflow.Nodes

for _, node := range nodes {
output := &bytes.Buffer{}
Expand Down
3 changes: 1 addition & 2 deletions core/scripts/keystone/src/88_gen_jobspecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ type donHostSpec struct {

func genSpecs(
nodeSetsPath string,
keylessNodeSetsPath string,
templatesDir string,
chainID int64,
p2pPort int64,
ocrConfigContractAddress string,
nodeSetSize int,
) donHostSpec {
workflowNodes := downloadNodeSets(keylessNodeSetsPath, chainID, nodeSetsPath, nodeSetSize).Workflow
workflowNodes := downloadNodeSets(chainID, nodeSetsPath, nodeSetSize).Workflow
workflowNodeKeys := nodeKeysToKsDeployNodeKeys(workflowNodes.NodeKeys)
nodes := workflowNodes.Nodes
bootstrapNode := workflowNodeKeys[0]
Expand Down
3 changes: 1 addition & 2 deletions core/scripts/keystone/src/88_gen_jobspecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ func (d *donHostSpec) ToString() string {

func TestGenSpecs(t *testing.T) {
nodeSetsPath := "./testdata/node_sets.json"
keylessNodeSetsPath := "./testdata/keyless_node_sets.json"
chainID := int64(1337)
p2pPort := int64(6690)
contractAddress := "0xB29934624cAe3765E33115A9530a13f5aEC7fa8A"

specs := genSpecs(nodeSetsPath, keylessNodeSetsPath, "../templates", chainID, p2pPort, contractAddress, 4)
specs := genSpecs(nodeSetsPath, "../templates", chainID, p2pPort, contractAddress, 4)
snaps.MatchSnapshot(t, specs.ToString())
}
4 changes: 2 additions & 2 deletions core/scripts/keystone/src/88_gen_ocr3_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func mustReadConfig(fileName string) (output ksdeploy.TopLevelConfigSource) {
return mustReadJSON[ksdeploy.TopLevelConfigSource](fileName)
}

func generateOCR3Config(keylessNodeSetsPath string, configFile string, chainID int64, nodeSetsPath string, nodeSetSize int) ksdeploy.Orc2drOracleConfig {
func generateOCR3Config(configFile string, chainID int64, nodeSetsPath string, nodeSetSize int) ksdeploy.Orc2drOracleConfig {
topLevelCfg := mustReadConfig(configFile)
cfg := topLevelCfg.OracleConfig
nodeSets := downloadNodeSets(keylessNodeSetsPath, chainID, nodeSetsPath, nodeSetSize)
nodeSets := downloadNodeSets(chainID, nodeSetsPath, nodeSetSize)
c, err := ksdeploy.GenerateOCR3Config(cfg, nodeKeysToKsDeployNodeKeys(nodeSets.Workflow.NodeKeys[1:])) // skip the bootstrap node
helpers.PanicErr(err)
return c
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/keystone/src/88_gen_ocr3_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestGenerateOCR3Config(t *testing.T) {
// Generate OCR3 config
config := generateOCR3Config("./testdata/keyless_node_sets.json", "./testdata/SampleConfig.json", 1337, "./testdata/node_sets.json", 4)
config := generateOCR3Config("./testdata/SampleConfig.json", 1337, "./testdata/node_sets.json", 4)

matchOffchainConfig := match.Custom("OffchainConfig", func(s any) (any, error) {
// coerce the value to a string
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/keystone/src/99_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewRedialBackoff() backoff.Backoff {
}
}

func newApp(n *NodeWthCreds, writer io.Writer) (*clcmd.Shell, *cli.App) {
func newApp(n NodeWthCreds, writer io.Writer) (*clcmd.Shell, *cli.App) {
client := &clcmd.Shell{
Renderer: clcmd.RendererJSON{Writer: writer},
AppFactory: clcmd.ChainlinkAppFactory{},
Expand Down Expand Up @@ -59,7 +59,7 @@ type nodeAPI struct {
clientMethod func(*cli.Context) error
}

func newNodeAPI(n *NodeWthCreds) *nodeAPI {
func newNodeAPI(n NodeWthCreds) *nodeAPI {
output := &bytes.Buffer{}
methods, app := newApp(n, output)

Expand Down
Loading

0 comments on commit eaab702

Please sign in to comment.