Skip to content

Commit

Permalink
Fix linter warns
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Nov 1, 2024
1 parent 2482bbc commit e262cf7
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 82 deletions.
16 changes: 9 additions & 7 deletions core/scripts/keystone/src/01_provision_keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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")
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions core/scripts/keystone/src/02_deploy_keystone_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/keystone/src/02_provision_crib.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"

ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -154,7 +155,6 @@ func generatePostprovisionConfig(
forwarderAddress string,
capabillitiesRegistryAddress string,
) Helm {

nodes := make(map[string]Node)
nodeNames := []string{}
var capabilitiesBootstrapper *ocrcommontypes.BootstrapperLocator
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/forwarder"
)


func deployForwarder(
env helpers.Environment,
artefacts string,
Expand Down
16 changes: 8 additions & 8 deletions core/scripts/keystone/src/02_provision_ocr3_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package src

import (
"bytes"
"strconv"
"text/template"

"context"
Expand All @@ -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(
Expand All @@ -37,7 +39,6 @@ func provisionOCR3(
nodeSet,
chainID,
p2pPort,
artefactsDir,
onchainMeta,
)

Expand All @@ -54,7 +55,6 @@ func deployOCR3Contract(
ocrConf := generateOCR3Config(
nodeSet,
configFile,
env.ChainID,
)

if o.OCR3 != nil {
Expand All @@ -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{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -120,7 +121,6 @@ func deployOCR3JobSpecsTo(
nodeSet NodeSet,
chainID int64,
p2pPort int64,
artefactsDir string,
onchainMeta *onchainMeta,
) {
ocrAddress := onchainMeta.OCR3.Address().Hex()
Expand All @@ -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),
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -116,7 +116,7 @@ func setupStreamsTrigger(

digester := mercury.NewOffchainConfigDigester(
feed.id,
big.NewInt(chainId),
big.NewInt(chainID),
verifier.Address(),
ocrtypes.ConfigDigestPrefixMercuryV02,
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -198,31 +198,31 @@ 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
api := newNodeAPI(nodeSet.Nodes[i])
jobSpecName := ""
jobSpecStr := ""

upsertBridge(api, feed.bridgeName, feed.bridgeUrl)
upsertBridge(api, feed.bridgeName, feed.bridgeURL)

if i == 0 {
// Prepare data for Bootstrap Job
bootstrapData := MercuryV3BootstrapJobSpecData{
FeedName: feed.name,
VerifierAddress: verifier.Address().Hex(),
FeedID: fmt.Sprintf("%x", feed.id),
ChainID: chainId,
ChainID: chainID,
}

// Create Bootstrap Job
jobSpecName, jobSpecStr = createMercuryV3BootstrapJob(bootstrapData)
} 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,
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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{
Expand Down
Loading

0 comments on commit e262cf7

Please sign in to comment.