Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to deploy CCIP Solana to staging #16160

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type EVMChain struct {
Users []*bind.TransactOpts
}

type SolanaChain struct {
type SolanaChainConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep this named SolanaChain? I understand it collides with other SolanaChain names but we also have EVMChain in this file and would probably want to be consistent with those.

Client *solRpc.Client
DeployerKey solana.PrivateKey
URL string
Expand Down Expand Up @@ -87,13 +87,10 @@ 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
Expand All @@ -107,40 +104,44 @@ 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)
client := solRpc.New(url)
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
Expand Down
55 changes: 30 additions & 25 deletions deployment/environment/memory/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -82,7 +81,36 @@ 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)
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
}

func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64, numUsers int) (map[uint64]deployment.Chain, map[uint64][]*bind.TransactOpts) {
Expand Down Expand Up @@ -137,29 +165,6 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de
return chains
}

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 {
nodesByPeerID := make(map[string]Node)
if numNodes+numBootstraps == 0 {
Expand Down
Loading