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

[DPA-1458]: feat(solana): auto deploy programs #1519

Merged
merged 2 commits into from
Dec 30, 2024

Conversation

graham-chainlink
Copy link
Collaborator

@graham-chainlink graham-chainlink commented Dec 30, 2024

By using --upgradeable-program , we can auto deploy programs detected in the mounted path /programs, this reduces the need for consumer of this library to have to deploy the programs themselves, especially with go sdk where deploying a program is not straightforward and involves a decent amount of code, the alternative is to ssh into the docker container and run solana deploy ... but this involves an extra step.

Inspired from https://github.com/smartcontractkit/chainlink-ccip/blob/609f7b0c9734b3cfc1d1a1aea0fd1ddf4c90bd0c/chains/solana/contracts/tests/testutils/anchor.go#L72-L72

JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1458


Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.

Why

The changes introduce a new feature to deploy upgradeable Solana programs at the start of the Solana test validator. This enhancement allows users to specify a map of Solana program names to their corresponding program IDs directly in the blockchain configuration, facilitating a more dynamic and flexible test setup.

What

  • framework/components/blockchain/blockchain.go
    • Added SolanaPrograms map[string]string to the Input struct to allow specifying Solana programs to deploy upon test validator start.
  • framework/components/blockchain/solana.go
    • Introduced a new logic to construct the solana-test-validator command with flags for deploying specified Solana programs. This includes iterating over the SolanaPrograms map from the configuration and appending program deployment flags to the validator startup command.
    • Modified the container entrypoint to utilize the newly constructed command with program deployment flags, facilitating the deployment of specified programs when the Solana test validator starts.

By using `--upgradeable-program` , we can auto deploy programs detected in the mounted path `/programs`, this reduces the need for consumer of this library to have to deploy the programs themselves, especially with go sdk where deploying a program is not straightforward and involves a decent amount of code, the alternative is to ssh into the docker container and run `solana deploy ...` but this involves an extra step.

JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1458
@@ -21,6 +21,10 @@ type Input struct {
// publickey to mint when solana-test-validator starts
PublicKey string `toml:"public_key"`
ContractsDir string `toml:"contracts_dir"`
// programs to deploy on solana-test-validator start
// a map of program name to program id
// there needs to be a matching .so file in contracts_dir
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah,

[solana_config.solana_programs]
mcm = "6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX"

expects the file <contracts_dir>/mcm.so and it will use 6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX as the program id , so it can be looked up later for testing.

also, should programs reside in the root of contracts_dir or in <contracts_dir>/programs?

No strong opinions, i think contracts are programs in solana, but i was basically following the convention in chainlink-ccip

# value is the program id to set for the deployed program instead of auto generating
# useful for deterministic testing
[blockchain_a.solana_programs]
mcm = "6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX"
Copy link
Contributor

Choose a reason for hiding this comment

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

do you think you might expand that topic a bit? for example:

  • how should one load a program with auto-generated id?
  • where should one get that program id from, if auto-generation is not desired?
  • in what way is testing deterministic with static program id? what indeterminism there would be if I used different program ids for programs that are the same, i.e. with the same bytecode? or is program id derived from the bytecode somehow?

it's more than fine to just outline these topics in broad strokes and linking to resources which describe them in more details

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks,

how should one load a program with auto-generated id?

then we do it the normal way, we just do solana deploy program then the program will be deployed with its own program id.

where should one get that program id from, if auto-generation is not desired?

basically just any public key, but usually the developer of the solana program will have one set , eg here for mcm

in what way is testing deterministic with static program id? what indeterminism there would be if I used different program ids for programs that are the same, i.e. with the same bytecode? or is program id derived from the bytecode somehow?

basically during testing, we want to look up the deployed program based on the program id,
eg

data, accErr := s.SolanaClient.GetAccountInfoWithOpts(ctx, <PROGRAM_ID>, &rpc.GetAccountInfoOpts{
		Commitment: config.DefaultCommitment,
	})

If we dont tell solana to deploy a program with a certain program id, then we wont be able to look it up easily during testing since it is auto generated.

If we tell solana to deploy a program with a provided program id, then we can just look it up easily during testing.

Hope this make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added more info to the solana.md , let me know if that is enough or you prefer it to be in other places too

Copy link
Contributor

@Tofel Tofel left a comment

Choose a reason for hiding this comment

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

if possible, please improve documentation (see comment), otherwise 👍

By using `--upgradeable-program` , we can auto deploy programs detected in the mounted path `/programs`, this reduces the need for consumer of this library to have to deploy the programs themselves, especially with go sdk where deploying a program is not straightforward and involves a decent amount of code, the alternative is to ssh into the docker container and run `solana deploy ...` but this involves an extra step.

Inspired from https://github.com/smartcontractkit/chainlink-ccip/blob/609f7b0c9734b3cfc1d1a1aea0fd1ddf4c90bd0c/chains/solana/contracts/tests/testutils/anchor.go#L72-L72

JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1458
@cl-sonarqube-production
Copy link

@graham-chainlink graham-chainlink merged commit fb70961 into main Dec 30, 2024
53 of 57 checks passed
@graham-chainlink graham-chainlink deleted the ggoh/DPA-1458/solana-program branch December 30, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants