From 732fcbef9c16e023e66b31abe847c9be0d06c651 Mon Sep 17 00:00:00 2001 From: jlaveracll Date: Thu, 30 Jan 2025 19:17:06 -0300 Subject: [PATCH 1/2] Updates to deploy CCIP Solana to staging --- deployment/environment/memory/chain.go | 40 ++++++++++++-------- deployment/environment/memory/environment.go | 37 ++++++++++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/deployment/environment/memory/chain.go b/deployment/environment/memory/chain.go index 020c6df375a..4a4be78db28 100644 --- a/deployment/environment/memory/chain.go +++ b/deployment/environment/memory/chain.go @@ -40,7 +40,7 @@ type EVMChain struct { Users []*bind.TransactOpts } -type SolanaChain struct { +type SolanaChainConfig struct { Client *solRpc.Client DeployerKey solana.PrivateKey URL string @@ -87,17 +87,21 @@ func getTestSolanaChainSelectors() []uint64 { return result } -func generateSolanaKeypair(t testing.TB) (solana.PrivateKey, string, error) { - // Create a temporary directory that will be cleaned up after the test - tmpDir := t.TempDir() - +func GenerateSolanaKeypair(dir string) (solana.PrivateKey, error) { privateKey, err := solana.NewRandomPrivateKey() if err != nil { - return solana.PrivateKey{}, "", fmt.Errorf("failed to generate private key: %w", err) + return solana.PrivateKey{}, fmt.Errorf("failed to generate private key: %w", err) } // Convert private key bytes to JSON array +<<<<<<< Updated upstream privateKeyBytes := []byte(privateKey) +======= + privateKeyBytes, err := base58.Decode(privateKey.String()) + if err != nil { + return solana.PrivateKey{}, fmt.Errorf("failed to decode private key: %w", err) + } +>>>>>>> Stashed changes // Convert bytes to array of integers for JSON intArray := make([]int, len(privateKeyBytes)) @@ -107,27 +111,31 @@ func generateSolanaKeypair(t testing.TB) (solana.PrivateKey, string, error) { keypairJSON, err := json.Marshal(intArray) if err != nil { - return solana.PrivateKey{}, "", fmt.Errorf("failed to marshal keypair: %w", err) + return solana.PrivateKey{}, fmt.Errorf("failed to marshal keypair: %w", err) } - // Create the keypair file in the temporary directory - keypairPath := filepath.Join(tmpDir, "solana-keypair.json") + // Create the keypair file in the directory + keypairPath := filepath.Join(dir, "solana-keypair.json") if err := os.WriteFile(keypairPath, keypairJSON, 0600); err != nil { - return solana.PrivateKey{}, "", fmt.Errorf("failed to write keypair to file: %w", err) + return solana.PrivateKey{}, fmt.Errorf("failed to write keypair to file: %w", err) } - return privateKey, keypairPath, nil + return privateKey, nil } -func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChain { +func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChainConfig { testSolanaChainSelectors := getTestSolanaChainSelectors() if len(testSolanaChainSelectors) < numChains { t.Fatalf("not enough test solana chain selectors available") } - chains := make(map[uint64]SolanaChain) + + // Create a temporary directory that will be cleaned up after the test + tmpDir := t.TempDir() + + chains := make(map[uint64]SolanaChainConfig) for i := 0; i < numChains; i++ { chainID := testSolanaChainSelectors[i] - admin, keypairPath, err := generateSolanaKeypair(t) + admin, err := GenerateSolanaKeypair(tmpDir) require.NoError(t, err) url, wsURL, err := solChain(t, chainID, &admin) require.NoError(t, err) @@ -135,12 +143,12 @@ func GenerateChainsSol(t *testing.T, numChains int) map[uint64]SolanaChain { balance, err := client.GetBalance(context.Background(), admin.PublicKey(), solRpc.CommitmentConfirmed) require.NoError(t, err) require.NotEqual(t, 0, balance.Value) // auto funded 500000000.000000000 SOL - chains[chainID] = SolanaChain{ + chains[chainID] = SolanaChainConfig{ Client: client, DeployerKey: admin, URL: url, WSURL: wsURL, - KeypairPath: keypairPath, + KeypairPath: tmpDir, } } return chains diff --git a/deployment/environment/memory/environment.go b/deployment/environment/memory/environment.go index 48fa7d71d46..1efcc927284 100644 --- a/deployment/environment/memory/environment.go +++ b/deployment/environment/memory/environment.go @@ -82,7 +82,40 @@ func NewMemoryChains(t *testing.T, numChains int, numUsers int) (map[uint64]depl func NewMemoryChainsSol(t *testing.T, numChains int) map[uint64]deployment.SolChain { mchains := GenerateChainsSol(t, numChains) +<<<<<<< Updated upstream return generateMemoryChainSol(mchains) +======= + + chains := make(map[uint64]deployment.SolChain) + + for cid, chainConfig := range mchains { + chains[cid] = deployment.SolChain{ + Selector: cid, + Client: chainConfig.Client, + DeployerKey: &chainConfig.DeployerKey, + URL: chainConfig.URL, + WSURL: chainConfig.WSURL, + KeypairPath: chainConfig.KeypairPath, + ProgramsPath: ProgramsPath, + Confirm: func(instructions []solana.Instruction, opts ...solCommomUtil.TxModifier) error { + _, err := solCommomUtil.SendAndConfirm( + context.Background(), + chainConfig.Client, + instructions, + chainConfig.DeployerKey, + solRpc.CommitmentConfirmed, + opts..., + ) + if err != nil { + return err + } + return nil + }, + } + } + + return chains +>>>>>>> Stashed changes } func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64, numUsers int) (map[uint64]deployment.Chain, map[uint64][]*bind.TransactOpts) { @@ -137,6 +170,7 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de return chains } +<<<<<<< Updated upstream func generateMemoryChainSol(inputs map[uint64]SolanaChain) map[uint64]deployment.SolChain { chains := make(map[uint64]deployment.SolChain) for cid, chain := range inputs { @@ -161,6 +195,9 @@ func generateMemoryChainSol(inputs map[uint64]SolanaChain) map[uint64]deployment } func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, solChains map[uint64]deployment.SolChain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node { +======= +func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node { +>>>>>>> Stashed changes nodesByPeerID := make(map[string]Node) if numNodes+numBootstraps == 0 { return nodesByPeerID From bd011f7512d5aa1f6f9b665f02ab8e14813707dc Mon Sep 17 00:00:00 2001 From: jlaveracll Date: Thu, 30 Jan 2025 19:20:26 -0300 Subject: [PATCH 2/2] fix merge --- deployment/environment/memory/chain.go | 7 ----- deployment/environment/memory/environment.go | 32 -------------------- 2 files changed, 39 deletions(-) diff --git a/deployment/environment/memory/chain.go b/deployment/environment/memory/chain.go index 4a4be78db28..8d0bfd38840 100644 --- a/deployment/environment/memory/chain.go +++ b/deployment/environment/memory/chain.go @@ -94,14 +94,7 @@ func GenerateSolanaKeypair(dir string) (solana.PrivateKey, error) { } // Convert private key bytes to JSON array -<<<<<<< Updated upstream privateKeyBytes := []byte(privateKey) -======= - privateKeyBytes, err := base58.Decode(privateKey.String()) - if err != nil { - return solana.PrivateKey{}, fmt.Errorf("failed to decode private key: %w", err) - } ->>>>>>> Stashed changes // Convert bytes to array of integers for JSON intArray := make([]int, len(privateKeyBytes)) diff --git a/deployment/environment/memory/environment.go b/deployment/environment/memory/environment.go index 1efcc927284..72b84526a82 100644 --- a/deployment/environment/memory/environment.go +++ b/deployment/environment/memory/environment.go @@ -24,7 +24,6 @@ import ( solRpc "github.com/gagliardetto/solana-go/rpc" - solCommonUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common" "github.com/smartcontractkit/chainlink-common/pkg/logger" ) @@ -82,9 +81,6 @@ func NewMemoryChains(t *testing.T, numChains int, numUsers int) (map[uint64]depl func NewMemoryChainsSol(t *testing.T, numChains int) map[uint64]deployment.SolChain { mchains := GenerateChainsSol(t, numChains) -<<<<<<< Updated upstream - return generateMemoryChainSol(mchains) -======= chains := make(map[uint64]deployment.SolChain) @@ -115,7 +111,6 @@ func NewMemoryChainsSol(t *testing.T, numChains int) map[uint64]deployment.SolCh } return chains ->>>>>>> Stashed changes } func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64, numUsers int) (map[uint64]deployment.Chain, map[uint64][]*bind.TransactOpts) { @@ -170,34 +165,7 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de return chains } -<<<<<<< Updated upstream -func generateMemoryChainSol(inputs map[uint64]SolanaChain) map[uint64]deployment.SolChain { - chains := make(map[uint64]deployment.SolChain) - for cid, chain := range inputs { - chain := chain - chains[cid] = deployment.SolChain{ - Selector: cid, - Client: chain.Client, - DeployerKey: &chain.DeployerKey, - URL: chain.URL, - WSURL: chain.WSURL, - KeypairPath: chain.KeypairPath, - ProgramsPath: ProgramsPath, - Confirm: func(instructions []solana.Instruction, opts ...solCommonUtil.TxModifier) error { - _, err := solCommonUtil.SendAndConfirm( - context.Background(), chain.Client, instructions, chain.DeployerKey, solRpc.CommitmentConfirmed, opts..., - ) - return err - }, - } - } - return chains -} - func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, solChains map[uint64]deployment.SolChain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node { -======= -func NewNodes(t *testing.T, logLevel zapcore.Level, chains map[uint64]deployment.Chain, numNodes, numBootstraps int, registryConfig deployment.CapabilityRegistryConfig) map[string]Node { ->>>>>>> Stashed changes nodesByPeerID := make(map[string]Node) if numNodes+numBootstraps == 0 { return nodesByPeerID