diff --git a/core/scripts/keystone/src/01_provision_keystone.go b/core/scripts/keystone/src/01_provision_keystone.go index 4e775acb86a..3ea1504660c 100644 --- a/core/scripts/keystone/src/01_provision_keystone.go +++ b/core/scripts/keystone/src/01_provision_keystone.go @@ -3,10 +3,12 @@ package src import ( "flag" "fmt" - helpers "github.com/smartcontractkit/chainlink/core/scripts/common" - kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "os" "path/filepath" + "strconv" + + helpers "github.com/smartcontractkit/chainlink/core/scripts/common" + kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" ) type provisionKeystone struct{} @@ -32,7 +34,7 @@ func (g *provisionKeystone) Run(args []string) { preprovison := fs.Bool("preprovision", false, "Preprovision crib") // provisioning flags - ethUrl := fs.String("ethurl", "", "URL of the Ethereum node") + ethURL := fs.String("ethurl", "", "URL of the Ethereum node") accountKey := fs.String("accountkey", "", "private key of the account to deploy from") ocrConfigFile := fs.String("ocrfile", "ocr_config.json", "path to OCR config file") p2pPort := fs.Int64("p2pport", 6690, "p2p port") @@ -44,7 +46,7 @@ func (g *provisionKeystone) Run(args []string) { err := fs.Parse(args) - if err != nil || (!*preprovison && (*ethUrl == "" || *accountKey == "")) { + if err != nil || (!*preprovison && (*ethURL == "" || *accountKey == "")) { fs.Usage() os.Exit(1) } @@ -80,8 +82,8 @@ func (g *provisionKeystone) Run(args []string) { // Kinda hacky but it prevents us from refactoring the setupenv function which // is used in many other places - os.Setenv("ETH_URL", *ethUrl) - os.Setenv("ETH_CHAIN_ID", fmt.Sprintf("%d", *chainID)) + os.Setenv("ETH_URL", *ethURL) + os.Setenv("ETH_CHAIN_ID", strconv.FormatInt(*chainID, 10)) os.Setenv("ACCOUNT_KEY", *accountKey) os.Setenv("INSECURE_SKIP_VERIFY", "true") env := helpers.SetupEnv(false) @@ -208,7 +210,7 @@ func provisionWorkflowDON( // We don't technically need the capability registry as a dependency // as we just use it for a sanity check // We could remove it so that we can execute provisioning in parallel - deployKeystoneWorkflowsTo(nodeSet, reg, chainID) + deployKeystoneWorkflowsTo(nodeSet, reg) return onchainMeta } diff --git a/core/scripts/keystone/src/02_deploy_keystone_workflows.go b/core/scripts/keystone/src/02_deploy_keystone_workflows.go index 5eeadf90f57..cce15f8d2e0 100644 --- a/core/scripts/keystone/src/02_deploy_keystone_workflows.go +++ b/core/scripts/keystone/src/02_deploy_keystone_workflows.go @@ -6,10 +6,11 @@ import ( "text/template" "github.com/ethereum/go-ethereum/accounts/abi/bind" + kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" ) -func deployKeystoneWorkflowsTo(nodeSet NodeSet, reg kcr.CapabilitiesRegistryInterface, chainID int64) { +func deployKeystoneWorkflowsTo(nodeSet NodeSet, reg kcr.CapabilitiesRegistryInterface) { fmt.Println("Deploying Keystone workflow jobs") caps, err := reg.GetCapabilities(&bind.CallOpts{}) PanicErr(err) @@ -36,14 +37,14 @@ func deployKeystoneWorkflowsTo(nodeSet NodeSet, reg kcr.CapabilitiesRegistryInte } } - feedIds := []string{} + feedIDs := []string{} for _, feed := range feeds { - feedIds = append(feedIds, fmt.Sprintf("0x%x", feed.id)) + feedIDs = append(feedIDs, fmt.Sprintf("0x%x", feed.id)) } workflowConfig := WorkflowJobSpecConfig{ JobSpecName: "keystone_workflow", WorkflowOwnerAddress: "0x1234567890abcdef1234567890abcdef12345678", - FeedIDs: feedIds, + FeedIDs: feedIDs, TargetID: testnetWrite.GetID(), ConsensusID: ocr3.GetID(), TriggerID: streams.GetID(), diff --git a/core/scripts/keystone/src/02_provision_capabilities_registry.go b/core/scripts/keystone/src/02_provision_capabilities_registry.go index 88b100d1987..0eb8e8c3ed9 100644 --- a/core/scripts/keystone/src/02_provision_capabilities_registry.go +++ b/core/scripts/keystone/src/02_provision_capabilities_registry.go @@ -8,7 +8,6 @@ import ( kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" ) - func provisionCapabillitiesRegistry(env helpers.Environment, nodeSets NodeSets, chainID int64, artefactsDir string) kcr.CapabilitiesRegistryInterface { fmt.Printf("Provisioning capabilities registry on chain %d\n", chainID) ctx := context.Background() diff --git a/core/scripts/keystone/src/02_provision_crib.go b/core/scripts/keystone/src/02_provision_crib.go index eb2f7912d2d..e07b5c28aed 100644 --- a/core/scripts/keystone/src/02_provision_crib.go +++ b/core/scripts/keystone/src/02_provision_crib.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" ocrcommontypes "github.com/smartcontractkit/libocr/commontypes" "gopkg.in/yaml.v3" @@ -154,7 +155,6 @@ func generatePostprovisionConfig( forwarderAddress string, capabillitiesRegistryAddress string, ) Helm { - nodes := make(map[string]Node) nodeNames := []string{} var capabilitiesBootstrapper *ocrcommontypes.BootstrapperLocator @@ -243,7 +243,7 @@ func generateOverridesToml( ExternalRegistry: toml.ExternalRegistry{ Address: ptr(externalRegistryAddress), NetworkID: ptr("evm"), - ChainID: ptr(fmt.Sprintf("%d", chainID)), + ChainID: ptr(strconv.FormatInt(chainID, 10)), }, Peering: toml.P2P{ V2: toml.P2PV2{ @@ -278,7 +278,7 @@ func generateOverridesToml( // New function to generate Ingress func generateIngress(nodeNames []string) Ingress { - var hosts []Host + hosts := make([]Host, 0, len(nodeNames)) for _, nodeName := range nodeNames { host := Host{ @@ -289,7 +289,7 @@ func generateIngress(nodeNames []string) Ingress { Path: "/", Backend: Backend{ Service: Service{ - Name: fmt.Sprintf("app-%s", nodeName), + Name: "app-" + nodeName, Port: Port{ Number: 6688, }, diff --git a/core/scripts/keystone/src/02_provision_forwarder_contract.go b/core/scripts/keystone/src/02_provision_forwarder_contract.go index 8c0395f3d5c..4cc3d7f70fa 100644 --- a/core/scripts/keystone/src/02_provision_forwarder_contract.go +++ b/core/scripts/keystone/src/02_provision_forwarder_contract.go @@ -8,7 +8,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder" ) - func deployForwarder( env helpers.Environment, artefacts string, diff --git a/core/scripts/keystone/src/02_provision_ocr3_capability.go b/core/scripts/keystone/src/02_provision_ocr3_capability.go index 55738d9038d..f994de49248 100644 --- a/core/scripts/keystone/src/02_provision_ocr3_capability.go +++ b/core/scripts/keystone/src/02_provision_ocr3_capability.go @@ -2,6 +2,7 @@ package src import ( "bytes" + "strconv" "text/template" "context" @@ -12,10 +13,11 @@ import ( ksdeploy "github.com/smartcontractkit/chainlink/deployment/keystone" + "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + helpers "github.com/smartcontractkit/chainlink/core/scripts/common" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/ocr3_capability" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" - "github.com/smartcontractkit/libocr/offchainreporting2plus/types" ) func provisionOCR3( @@ -37,7 +39,6 @@ func provisionOCR3( nodeSet, chainID, p2pPort, - artefactsDir, onchainMeta, ) @@ -54,7 +55,6 @@ func deployOCR3Contract( ocrConf := generateOCR3Config( nodeSet, configFile, - env.ChainID, ) if o.OCR3 != nil { @@ -63,6 +63,7 @@ func deployOCR3Contract( latestConfigDigestBytes, err := o.OCR3.LatestConfigDetails(nil) PanicErr(err) latestConfigDigest, err := types.BytesToConfigDigest(latestConfigDigestBytes.ConfigDigest[:]) + PanicErr(err) cc := ocrConfToContractConfig(ocrConf, latestConfigDigestBytes.ConfigCount) digester := evm.OCR3CapabilityOffchainConfigDigester{ @@ -92,7 +93,7 @@ func deployOCR3Contract( return o, true } -func generateOCR3Config(nodeSet NodeSet, configFile string, chainID int64) ksdeploy.Orc2drOracleConfig { +func generateOCR3Config(nodeSet NodeSet, configFile string) ksdeploy.Orc2drOracleConfig { topLevelCfg := mustReadOCR3Config(configFile) cfg := topLevelCfg.OracleConfig cfg.OCRSecrets = deployment.XXXGenerateTestOCRSecrets() @@ -120,7 +121,6 @@ func deployOCR3JobSpecsTo( nodeSet NodeSet, chainID int64, p2pPort int64, - artefactsDir string, onchainMeta *onchainMeta, ) { ocrAddress := onchainMeta.OCR3.Address().Hex() @@ -141,7 +141,7 @@ func deployOCR3JobSpecsTo( spec = createBootstrapJobSpec(bootstrapSpecConfig) } else { oc := OracleJobSpecConfig{ - JobSpecName: fmt.Sprintf("ocr3_oracle"), + JobSpecName: "ocr3_oracle", OCRConfigContractAddress: ocrAddress, OCRKeyBundleID: nodeKeys[i].OCR2BundleID, BootstrapURI: fmt.Sprintf("%s@%s:%d", nodeKeys[0].P2PPeerID, nodeSet.Nodes[0].ServiceName, p2pPort), @@ -159,9 +159,9 @@ func deployOCR3JobSpecsTo( fmt.Printf("Replaying from block: %d\n", onchainMeta.SetConfigTxBlock) fmt.Printf("EVM Chain ID: %d\n\n", chainID) api.withFlags(api.methods.ReplayFromBlock, func(fs *flag.FlagSet) { - err := fs.Set("block-number", fmt.Sprint(onchainMeta.SetConfigTxBlock)) + err := fs.Set("block-number", strconv.FormatUint(onchainMeta.SetConfigTxBlock, 10)) helpers.PanicErr(err) - err = fs.Set("evm-chain-id", fmt.Sprint(chainID)) + err = fs.Set("evm-chain-id", strconv.FormatInt(chainID, 10)) helpers.PanicErr(err) }).mustExec() } diff --git a/core/scripts/keystone/src/02_provision_ocr3_capability_test.go b/core/scripts/keystone/src/02_provision_ocr3_capability_test.go index f6d82e669fa..1c639860d63 100644 --- a/core/scripts/keystone/src/02_provision_ocr3_capability_test.go +++ b/core/scripts/keystone/src/02_provision_ocr3_capability_test.go @@ -12,7 +12,7 @@ import ( func TestGenerateOCR3Config(t *testing.T) { // Generate OCR3 config nodeSet := downloadNodeSets(1337, "./testdata/node_sets.json", 4) - config := generateOCR3Config(nodeSet.Workflow, "./testdata/SampleConfig.json", 1337) + config := generateOCR3Config(nodeSet.Workflow, "./testdata/SampleConfig.json") matchOffchainConfig := match.Custom("OffchainConfig", func(s any) (any, error) { // coerce the value to a string diff --git a/core/scripts/keystone/src/02_provision_streams_trigger_capability.go b/core/scripts/keystone/src/02_provision_streams_trigger_capability.go index 4b3e31a1e20..e0c33e6f710 100644 --- a/core/scripts/keystone/src/02_provision_streams_trigger_capability.go +++ b/core/scripts/keystone/src/02_provision_streams_trigger_capability.go @@ -55,7 +55,7 @@ type feed struct { // we create a bridge for each feed bridgeName string - bridgeUrl string + bridgeURL string } func v3FeedID(id [32]byte) [32]byte { @@ -88,12 +88,12 @@ var feeds = []feed{ func setupStreamsTrigger( env helpers.Environment, nodeSet NodeSet, - chainId int64, + chainID int64, p2pPort int64, ocrConfigFilePath string, artefactsDir string, ) { - fmt.Printf("Deploying streams trigger for chain %d\n", chainId) + fmt.Printf("Deploying streams trigger for chain %d\n", chainID) fmt.Printf("Using OCR config file: %s\n", ocrConfigFilePath) fmt.Printf("Deploying Mercury V0.3 contracts\n") @@ -107,7 +107,7 @@ func setupStreamsTrigger( fmt.Printf("FeedID: %x\n", feed.id) fmt.Printf("FeedName: %s\n", feed.name) fmt.Printf("BridgeName: %s\n", feed.bridgeName) - fmt.Printf("BridgeURL: %s\n", feed.bridgeUrl) + fmt.Printf("BridgeURL: %s\n", feed.bridgeURL) latestConfigDetails, err := verifier.LatestConfigDetails(nil, feed.id) PanicErr(err) @@ -116,7 +116,7 @@ func setupStreamsTrigger( digester := mercury.NewOffchainConfigDigester( feed.id, - big.NewInt(chainId), + big.NewInt(chainID), verifier.Address(), ocrtypes.ConfigDigestPrefixMercuryV02, ) @@ -149,7 +149,7 @@ func setupStreamsTrigger( } fmt.Printf("Deploying OCR2 job specs for feed %s\n", feed.name) - deployOCR2JobSpecsForFeed(nodeSet, verifier, feed, chainId, p2pPort) + deployOCR2JobSpecsForFeed(nodeSet, verifier, feed, chainID, p2pPort) } fmt.Println("Finished deploying streams trigger") @@ -198,7 +198,7 @@ func deployMercuryV03Contracts(env helpers.Environment, artefactsDir string) ver return o.Verifier } -func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.VerifierInterface, feed feed, chainId int64, p2pPort int64) { +func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.VerifierInterface, feed feed, chainID int64, p2pPort int64) { // we assign the first node as the bootstrap node for i, n := range nodeSet.NodeKeys { // parallel arrays @@ -206,7 +206,7 @@ func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.Verifi jobSpecName := "" jobSpecStr := "" - upsertBridge(api, feed.bridgeName, feed.bridgeUrl) + upsertBridge(api, feed.bridgeName, feed.bridgeURL) if i == 0 { // Prepare data for Bootstrap Job @@ -214,7 +214,7 @@ func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.Verifi FeedName: feed.name, VerifierAddress: verifier.Address().Hex(), FeedID: fmt.Sprintf("%x", feed.id), - ChainID: chainId, + ChainID: chainID, } // Create Bootstrap Job @@ -222,7 +222,7 @@ func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.Verifi } else { // Prepare data for Mercury V3 Job mercuryData := MercuryV3JobSpecData{ - FeedName: fmt.Sprintf("feed-%s", feed.name), + FeedName: "feed-" + feed.name, BootstrapHost: fmt.Sprintf("%s@%s:%d", nodeSet.NodeKeys[0].P2PPeerID, nodeSet.Nodes[0].ServiceName, p2pPort), VerifierAddress: verifier.Address().Hex(), Bridge: feed.bridgeName, @@ -231,7 +231,7 @@ func deployOCR2JobSpecsForFeed(nodeSet NodeSet, verifier verifierContract.Verifi LinkFeedID: fmt.Sprintf("%x", feeds[1].id), NativeFeedID: fmt.Sprintf("%x", feeds[2].id), OCRKeyBundleID: n.OCR2BundleID, - ChainID: chainId, + ChainID: chainID, } // Create Mercury V3 Job @@ -316,7 +316,7 @@ type MercuryV3JobSpecData struct { // createMercuryV3BootstrapJob creates a bootstrap job specification using the provided data. func createMercuryV3BootstrapJob(data MercuryV3BootstrapJobSpecData) (name string, jobSpecStr string) { - name = fmt.Sprintf("boot-%s", data.FeedName) + name = "boot-" + data.FeedName data.Name = name fmt.Printf("Creating bootstrap job (%s):\nverifier address: %s\nfeed name: %s\nfeed ID: %s\nchain ID: %d\n", @@ -336,7 +336,7 @@ func createMercuryV3BootstrapJob(data MercuryV3BootstrapJobSpecData) (name strin // createMercuryV3OracleJob creates a Mercury V3 job specification using the provided data. func createMercuryV3OracleJob(data MercuryV3JobSpecData) (name string, jobSpecStr string) { - name = fmt.Sprintf("mercury-%s", data.FeedName) + name = "mercury-" + data.FeedName data.Name = name fmt.Printf("Creating ocr2 job(%s):\nOCR key bundle ID: %s\nverifier address: %s\nbridge: %s\nnodeCSAKey: %s\nfeed name: %s\nfeed ID: %s\nlink feed ID: %s\nnative feed ID: %s\nchain ID: %d\n", data.Name, data.OCRKeyBundleID, data.VerifierAddress, data.Bridge, data.NodeCSAKey, data.FeedName, data.FeedID, data.LinkFeedID, data.NativeFeedID, data.ChainID) @@ -368,6 +368,7 @@ func strToBytes32(str string) [32]byte { func upsertBridge(api *nodeAPI, name string, eaURL string) { u, err := url.Parse(eaURL) + helpers.PanicErr(err) url := models.WebURL(*u) // Confirmations and MinimumContractPayment are not used, so we can leave them as 0 b := bridges.BridgeTypeRequest{ @@ -441,7 +442,6 @@ func generateMercuryOCR2Config(nca []NodeKeys) MercuryOCR2Config { offchainPubKeysBytes := []ocrtypes.OffchainPublicKey{} for _, n := range nca { - pkBytesFixed := strToBytes32(n.OCR2OffchainPublicKey) offchainPubKeysBytes = append(offchainPubKeysBytes, ocrtypes.OffchainPublicKey(pkBytesFixed)) } @@ -491,12 +491,13 @@ func generateMercuryOCR2Config(nca []NodeKeys) MercuryOCR2Config { int(f), // f onchainConfig, ) + PanicErr(err) signerAddresses, err := evm.OnchainPublicKeyToAddress(signers) PanicErr(err) - var offChainTransmitters [][32]byte - for _, n := range nca { - offChainTransmitters = append(offChainTransmitters, strToBytes32(n.CSAPublicKey)) + offChainTransmitters := make([][32]byte, len(nca)) + for i, n := range nca { + offChainTransmitters[i] = strToBytes32(n.CSAPublicKey) } config := MercuryOCR2Config{ diff --git a/core/scripts/keystone/src/88_capabilities_registry_helpers.go b/core/scripts/keystone/src/88_capabilities_registry_helpers.go index 3e958f72ff9..6d70ae8ea96 100644 --- a/core/scripts/keystone/src/88_capabilities_registry_helpers.go +++ b/core/scripts/keystone/src/88_capabilities_registry_helpers.go @@ -5,6 +5,7 @@ import ( "context" "encoding/hex" "encoding/json" + "errors" "fmt" "log" "strings" @@ -56,7 +57,7 @@ func extractRevertReason(errData string, a abi.ABI) (string, string, error) { return errName, string(b), nil } } - return "", "", fmt.Errorf("revert Reason could not be found for given abistring") + return "", "", errors.New("revert Reason could not be found for given abistring") } func (c *CapabilityRegistryProvisioner) testCallContract(method string, args ...interface{}) error { @@ -260,7 +261,7 @@ func (b *baseCapability) BindToRegistry(reg kcr.CapabilitiesRegistryInterface) { func (b *baseCapability) GetHashedCID() [32]byte { if b.registry == nil { - panic(fmt.Errorf("registry not bound to capability, cannot get hashed capability ID")) + panic(errors.New("registry not bound to capability, cannot get hashed capability ID")) } return mustHashCapabilityID(b.registry, b.capability) @@ -417,7 +418,7 @@ func MergeCapabilitySets(sets ...CapabilitySet) CapabilitySet { } func (c *CapabilitySet) Capabilities() []kcr.CapabilitiesRegistryCapability { - var definitions []kcr.CapabilitiesRegistryCapability + definitions := make([]kcr.CapabilitiesRegistryCapability, 0, len(*c)) for _, cap := range *c { definitions = append(definitions, cap.Capability()) } @@ -426,7 +427,7 @@ func (c *CapabilitySet) Capabilities() []kcr.CapabilitiesRegistryCapability { } func (c *CapabilitySet) IDs() []string { - var strings []string + strings := make([]string, 0, len(*c)) for _, cap := range *c { strings = append(strings, fmt.Sprintf("%s@%s", cap.Capability().LabelledName, cap.Capability().Version)) } @@ -435,7 +436,7 @@ func (c *CapabilitySet) IDs() []string { } func (c *CapabilitySet) HashedIDs(reg kcr.CapabilitiesRegistryInterface) [][32]byte { - var ids [][32]byte + ids := make([][32]byte, 0, len(*c)) for _, cap := range *c { cap.BindToRegistry(reg) ids = append(ids, cap.GetHashedCID()) @@ -445,7 +446,7 @@ func (c *CapabilitySet) HashedIDs(reg kcr.CapabilitiesRegistryInterface) [][32]b } func (c *CapabilitySet) Configs(reg kcr.CapabilitiesRegistryInterface) []kcr.CapabilitiesRegistryCapabilityConfiguration { - var configs []kcr.CapabilitiesRegistryCapabilityConfiguration + configs := make([]kcr.CapabilitiesRegistryCapabilityConfiguration, 0, len(*c)) for _, cap := range *c { cap.BindToRegistry(reg) configs = append(configs, cap.Config()) @@ -504,7 +505,7 @@ func (n *NodeOperator) BindToRegistry(reg kcr.CapabilitiesRegistryInterface) { func (n *NodeOperator) SetCapabilityRegistryIssuedID(receipt *gethTypes.Receipt) uint32 { if n.reg == nil { - panic(fmt.Errorf("registry not bound to node operator, cannot set ID")) + panic(errors.New("registry not bound to node operator, cannot set ID")) } // We'll need more complex handling for multiple node operators // since we'll need to handle log ordering diff --git a/core/scripts/keystone/src/88_contracts_helpers.go b/core/scripts/keystone/src/88_contracts_helpers.go index 65271fca9dc..239ac940607 100644 --- a/core/scripts/keystone/src/88_contracts_helpers.go +++ b/core/scripts/keystone/src/88_contracts_helpers.go @@ -107,8 +107,8 @@ func LoadOnchainMeta(artefactsDir string, env helpers.Environment) *onchainMeta if !contractExists(s.OCR, env) { fmt.Printf("OCR contract at %s does not exist\n", s.OCR.Hex()) } else { - ocr3, err := ocr3_capability.NewOCR3Capability(s.OCR, env.Ec) - PanicErr(err) + ocr3, e := ocr3_capability.NewOCR3Capability(s.OCR, env.Ec) + PanicErr(e) hydrated.OCR3 = ocr3 } } @@ -117,8 +117,8 @@ func LoadOnchainMeta(artefactsDir string, env helpers.Environment) *onchainMeta if !contractExists(s.Forwarder, env) { fmt.Printf("Forwarder contract at %s does not exist\n", s.Forwarder.Hex()) } else { - fwdr, err := forwarder.NewKeystoneForwarder(s.Forwarder, env.Ec) - PanicErr(err) + fwdr, e := forwarder.NewKeystoneForwarder(s.Forwarder, env.Ec) + PanicErr(e) hydrated.Forwarder = fwdr } } @@ -127,8 +127,8 @@ func LoadOnchainMeta(artefactsDir string, env helpers.Environment) *onchainMeta if !contractExists(s.CapabilitiesRegistry, env) { fmt.Printf("CapabilityRegistry contract at %s does not exist\n", s.CapabilitiesRegistry.Hex()) } else { - cr, err := capabilities_registry.NewCapabilitiesRegistry(s.CapabilitiesRegistry, env.Ec) - PanicErr(err) + cr, e := capabilities_registry.NewCapabilitiesRegistry(s.CapabilitiesRegistry, env.Ec) + PanicErr(e) hydrated.CapabilitiesRegistry = cr } } @@ -140,8 +140,8 @@ func LoadOnchainMeta(artefactsDir string, env helpers.Environment) *onchainMeta fmt.Printf("Verifier contract at %s does not exist\n", s.Verifier.Hex()) hydrated.InitializedVerifierAddress = ZeroAddress } else { - verifier, err := verifierContract.NewVerifier(s.Verifier, env.Ec) - PanicErr(err) + verifier, e := verifierContract.NewVerifier(s.Verifier, env.Ec) + PanicErr(e) hydrated.Verifier = verifier } } @@ -151,8 +151,8 @@ func LoadOnchainMeta(artefactsDir string, env helpers.Environment) *onchainMeta fmt.Printf("VerifierProxy contract at %s does not exist\n", s.VerifierProxy.Hex()) hydrated.InitializedVerifierAddress = ZeroAddress } else { - verifierProxy, err := verifier_proxy.NewVerifierProxy(s.VerifierProxy, env.Ec) - PanicErr(err) + verifierProxy, e := verifier_proxy.NewVerifierProxy(s.VerifierProxy, env.Ec) + PanicErr(e) hydrated.VerifierProxy = verifierProxy } } @@ -175,11 +175,8 @@ func ContractsAlreadyDeployed(artefactsDir string) bool { } _, err = os.Stat(deployedContractsFilePath(artefactsDir)) - if err != nil { - return false - } - return true + return err == nil } func deployedContractsFilePath(artefactsDir string) string { diff --git a/core/scripts/keystone/src/88_jobspecs_helpers.go b/core/scripts/keystone/src/88_jobspecs_helpers.go index 4c106ead505..0e6cc3a043a 100644 --- a/core/scripts/keystone/src/88_jobspecs_helpers.go +++ b/core/scripts/keystone/src/88_jobspecs_helpers.go @@ -17,7 +17,7 @@ type WorkflowSpec struct { } type JobSpec struct { - Id string + ID string Name string BootstrapSpec BootSpec OffChainReporting2OracleSpec OCRSpec @@ -30,7 +30,7 @@ func upsertJob(api *nodeAPI, jobSpecName string, jobSpecStr string) { for _, job := range *jobs { if job.Name == jobSpecName { fmt.Printf("Job already exists: %s, replacing..\n", jobSpecName) - api.withArg(job.Id).mustExec(api.methods.DeleteJob) + api.withArg(job.ID).mustExec(api.methods.DeleteJob) break } } @@ -47,7 +47,7 @@ func clearJobs(api *nodeAPI) { jobs := mustJSON[[]JobSpec](jobsResp) for _, job := range *jobs { fmt.Printf("Deleting job: %s\n", job.Name) - api.withArg(job.Id).mustExec(api.methods.DeleteJob) + api.withArg(job.ID).mustExec(api.methods.DeleteJob) } fmt.Println("All jobs have been deleted.") } diff --git a/core/scripts/keystone/src/88_ocr_helpers.go b/core/scripts/keystone/src/88_ocr_helpers.go index f27d161ecb6..6ad8f0761f0 100644 --- a/core/scripts/keystone/src/88_ocr_helpers.go +++ b/core/scripts/keystone/src/88_ocr_helpers.go @@ -4,8 +4,9 @@ import ( "encoding/hex" "github.com/ethereum/go-ethereum/common" - ksdeploy "github.com/smartcontractkit/chainlink/deployment/keystone" "github.com/smartcontractkit/libocr/offchainreporting2/types" + + ksdeploy "github.com/smartcontractkit/chainlink/deployment/keystone" ) func ocrConfToContractConfig(ocrConf ksdeploy.Orc2drOracleConfig, configCount uint32) types.ContractConfig { diff --git a/core/scripts/keystone/src/99_app.go b/core/scripts/keystone/src/99_app.go index 6e7f134d9e6..c4b508277d9 100644 --- a/core/scripts/keystone/src/99_app.go +++ b/core/scripts/keystone/src/99_app.go @@ -13,10 +13,11 @@ import ( "strings" "sync" - clsessions "github.com/smartcontractkit/chainlink/v2/core/sessions" "github.com/urfave/cli" "go.uber.org/zap/zapcore" + clsessions "github.com/smartcontractkit/chainlink/v2/core/sessions" + helpers "github.com/smartcontractkit/chainlink/core/scripts/common" "github.com/smartcontractkit/chainlink/v2/core/cmd" clcmd "github.com/smartcontractkit/chainlink/v2/core/cmd" @@ -49,7 +50,10 @@ func newApp(n NodeWthCreds, writer io.Writer) (*clcmd.Shell, *cli.App) { &cmd.MemoryCookieStore{}, logger, ) - cookieAuth.Authenticate(context.Background(), sr) + + _, err = cookieAuth.Authenticate(context.Background(), sr) + PanicErr(err) + http := cmd.NewAuthenticatedHTTPClient( logger, clientOpts, diff --git a/core/scripts/keystone/src/99_crib_client.go b/core/scripts/keystone/src/99_crib_client.go index 0bf1610a4dd..ec977a9384f 100644 --- a/core/scripts/keystone/src/99_crib_client.go +++ b/core/scripts/keystone/src/99_crib_client.go @@ -58,9 +58,6 @@ func (m *CribClient) getCLNodes() ([]NodeWthCreds, error) { Host: deployment.Host, Path: "", } - if err != nil { - return nil, err - } node := NodeWthCreds{ // We dont handle both in-cluster and out-of-cluster deployments diff --git a/core/scripts/keystone/src/99_fetch_keys.go b/core/scripts/keystone/src/99_fetch_keys.go index 732578a8dae..9fdd6d877a1 100644 --- a/core/scripts/keystone/src/99_fetch_keys.go +++ b/core/scripts/keystone/src/99_fetch_keys.go @@ -104,7 +104,7 @@ type OCR2AptosKBTrimmed struct { AptosOnchainPublicKey string `json:"AptosOnchainPublicKey"` // ocr2on_aptos_ } -func mustFetchNodeKeys(chainId int64, nodes []NodeWthCreds, createAptosKeys bool) []NodeKeys { +func mustFetchNodeKeys(chainID int64, nodes []NodeWthCreds, createAptosKeys bool) []NodeKeys { nodeKeys := []NodeKeys{} for _, n := range nodes { @@ -112,12 +112,12 @@ func mustFetchNodeKeys(chainId int64, nodes []NodeWthCreds, createAptosKeys bool // Get eth key eKey := api.mustExec(api.methods.ListETHKeys) ethKeys := mustJSON[[]presenters.ETHKeyResource](eKey) - ethAddress, err := findFirstGoodEthKeyAddress(chainId, *ethKeys) + ethAddress, err := findFirstGoodEthKeyAddress(chainID, *ethKeys) helpers.PanicErr(err) var aptosAccount string if createAptosKeys { - aptosAccount = getOrCreateAptosKey(api, err) + aptosAccount = getOrCreateAptosKey(api) } // Get p2p key @@ -213,10 +213,10 @@ func createAptosOCR2KB(ocr2Bundles *cmd.OCR2KeyBundlePresenters, expectedBundleL // getOrCreateAptosKey returns the Aptos account of the node. // // If the node has no Aptos keys, it creates one and returns the account. -func getOrCreateAptosKey(api *nodeAPI, err error) string { +func getOrCreateAptosKey(api *nodeAPI) string { api.output.Reset() aKeysClient := cmd.NewAptosKeysClient(api.methods) - err = aKeysClient.ListKeys(&cli.Context{App: api.app}) + err := aKeysClient.ListKeys(&cli.Context{App: api.app}) helpers.PanicErr(err) var aptosKeys []presenters.AptosKeyResource helpers.PanicErr(json.Unmarshal(api.output.Bytes(), &aptosKeys)) diff --git a/core/scripts/keystone/src/99_k8s_client.go b/core/scripts/keystone/src/99_k8s_client.go index 4844b88edba..e4885e53a19 100644 --- a/core/scripts/keystone/src/99_k8s_client.go +++ b/core/scripts/keystone/src/99_k8s_client.go @@ -2,6 +2,7 @@ package src import ( "context" + "errors" "fmt" "log" "sort" @@ -77,7 +78,7 @@ func (m *K8sClient) GetDeploymentsWithConfigMap() ([]DeploymentWithConfigMap, er return nil, err } if len(deployments.Items) == 0 { - return nil, fmt.Errorf("no deployments found, is your nodeset deployed?") + return nil, errors.New("no deployments found, is your nodeset deployed?") } deploymentsWithConfigMaps := []DeploymentWithConfigMap{} @@ -86,7 +87,7 @@ func (m *K8sClient) GetDeploymentsWithConfigMap() ([]DeploymentWithConfigMap, er return nil, err } if len(ingressList.Items) == 0 { - return nil, fmt.Errorf("no ingress found, is your nodeset deployed?") + return nil, errors.New("no ingress found, is your nodeset deployed?") } for _, deployment := range deployments.Items { diff --git a/core/scripts/keystone/src/external-adapter/99_external_adapter.go b/core/scripts/keystone/src/external-adapter/99_external_adapter.go index 537091bb1ac..8af035f30fd 100644 --- a/core/scripts/keystone/src/external-adapter/99_external_adapter.go +++ b/core/scripts/keystone/src/external-adapter/99_external_adapter.go @@ -119,7 +119,10 @@ func externalAdapter(initialValue float64, port string, pctBounds float64) *http // Create and start the test server ea := &httptest.Server{ Listener: listener, - Config: &http.Server{Handler: handler}, + Config: &http.Server{ + Handler: handler, + ReadHeaderTimeout: 5 * time.Second, + }, } ea.Start() @@ -132,6 +135,7 @@ func externalAdapter(initialValue float64, port string, pctBounds float64) *http // It ensures that the value stays within the specified bounds. func adjustValue(start, step, floor, ceiling float64) float64 { // Randomly choose to increase or decrease the value + // #nosec G404 if rand.Intn(2) == 0 { step = -step } diff --git a/shell.nix b/shell.nix index e3b187dcd96..5d5e6f53312 100644 --- a/shell.nix +++ b/shell.nix @@ -65,7 +65,6 @@ in ''} ''; - GOROOT = "${go}/share/go"; PGDATA = "db"; CL_DATABASE_URL = "postgresql://chainlink:chainlink@localhost:5432/chainlink_test?sslmode=disable"; }