diff --git a/.github/AGENTS.md b/.github/AGENTS.md index 2ee2e4aaa91..02b68a96faf 100644 --- a/.github/AGENTS.md +++ b/.github/AGENTS.md @@ -1,18 +1,18 @@ - GitHub Actions in the Chainlink Go monorepo. - - +## Rules + - Prefer runs-on runners when ubuntu-latest is insufficient. -- Minimize YAML and shell in workflows. +- Minimize YAML and shell in workflows. Utilize the [Go CI CLI](../tools/ci/) for any bash requiring more than basic commands. - Resolve smartcontractkit/.github from a local clone. Ask the user for the path if you cannot find it. - - -- runs-on: https://runs-on.com/docs/ - +## New Features + +- Can [reference local actions without checkout step](https://github.blog/changelog/2026-07-30-reference-same-repository-actions-with-self-repository-syntax/) with `uses: $/path/to/action` + +## Docs & Tools - -- https://github.com/kalverra/octometrics — per-workflow debugging -- https://github.com/kalverra/octometrics-action — runner resource monitoring - +- [runs-on](https://runs-on.com/docs/): Docs for our runs-on runners +- [octometrics](https://github.com/kalverra/octometrics): Debugging and analyzing workflows +- [octometrics-action](https://github.com/kalverra/octometrics-action): Runner resource monitoring +- [Go CI CLI](../tools/ci/): Custom logic for /chainlink workflows diff --git a/.github/workflows/ccip-system-tests.yaml b/.github/workflows/ccip-system-tests.yaml index bfa905942b9..ea1cfa350a0 100644 --- a/.github/workflows/ccip-system-tests.yaml +++ b/.github/workflows/ccip-system-tests.yaml @@ -56,6 +56,13 @@ on: description: "When true, restricts the matrix to tests flagged mixed_version=true (used by the release rollout job)." + run_mixed_version_tests: + required: false + type: boolean + default: false + description: + "Whether to run the mixed-version tests. Only used for manual + workflow_dispatch runs; these tests are skipped on automatic runs." workflow_call: inputs: chainlink_image_repository_path: @@ -107,6 +114,13 @@ on: description: "When true, restricts the matrix to tests flagged mixed_version=true (used by the release rollout job)." + run_mixed_version_tests: + required: false + type: boolean + default: false + description: + "Whether to run the mixed-version tests. Only used for manual + workflow_dispatch runs; these tests are skipped on automatic runs." jobs: define-test-matrix: @@ -122,40 +136,14 @@ jobs: id: spot uses: $/.github/actions/setup-runner-spot - # TODO(DX-5101): replace this inline jq matrix step with `ci matrix ccip` - name: Define test matrix id: define-matrix shell: bash env: - RUN_ID: ${{ github.run_id }} - RUN_ATTEMPT: ${{ github.run_attempt }} - SPOT_FLAG: ${{ steps.spot.outputs.spot_flag }} - run: | - TESTS_JSON='[ - {"test_name":"Test_CCIPGasPriceUpdatesWriteFrequency","timeout":"15m","selected_network":"SIMULATED_1,SIMULATED_2"}, - {"test_name":"TestRMN_GlobalCurseTwoMessagesOnTwoLanes","timeout":"15m","selected_network":"SIMULATED_1,SIMULATED_2","rmn_rageproxy_version":"master-amd6416f5d86","rmn_afn2proxy_version":"master-amd64-10b42b2"}, - {"test_name":"TestDeleteCCIPJobs-TestRevokeJobs","timeout":"15m","selected_network":"SIMULATED_1,SIMULATED_2","job_timeout":20}, - {"test_name":"Test_CCIPMixedVersionDON","timeout":"20m","selected_network":"SIMULATED_1,SIMULATED_2","mixed_version":true}, - {"test_name":"Test_CCIPRollingUpgrade","timeout":"30m","selected_network":"SIMULATED_1,SIMULATED_2","mixed_version":true} - ]' - - tests=$(echo "$TESTS_JSON" | jq -c \ - --argjson run_id "$RUN_ID" \ - --arg run_attempt "$RUN_ATTEMPT" \ - --arg spot_flag "$SPOT_FLAG" ' - to_entries | map(.value + { - test_id: .key, - runs_on: ("runs-on=\($run_id)-\(.key)-\($run_attempt)/cpu=8/ram=64/family=r6i+r7i+r8i/\($spot_flag)/image=ubuntu24-full-x64/extras=s3-cache+tmpfs") - }) - ') - - # Release rollout callers pass mixed_version_only=true to run only the - # mixed-version / rolling-upgrade tests instead of the full smoke suite. - if [[ "${{ inputs.mixed_version_only }}" == "true" ]]; then - tests=$(echo "$tests" | jq -c '[ .[] | select(.mixed_version == true) ]') - fi - - echo "matrix=$tests" | tee -a "${GITHUB_OUTPUT}" + RUNNER_SPOT_FLAG: ${{ steps.spot.outputs.spot_flag }} + RUN_MIXED_VERSION_TESTS: ${{ inputs.run_mixed_version_tests }} + MIXED_VERSION_ONLY: ${{ inputs.mixed_version_only }} + run: ci matrix ccip run-ccip-tests: name: ${{ matrix.tests.test_name }} diff --git a/.github/workflows/cre-mixed-env-tests.yaml b/.github/workflows/cre-mixed-env-tests.yaml index 56633a6f622..f78482f83df 100644 --- a/.github/workflows/cre-mixed-env-tests.yaml +++ b/.github/workflows/cre-mixed-env-tests.yaml @@ -118,39 +118,8 @@ jobs: id: define-matrix shell: bash env: - RUN_ID: ${{ github.run_id }} - RUN_ATTEMPT: ${{ github.run_attempt }} - SPOT_FLAG: ${{ steps.spot.outputs.spot_flag }} - run: | - # Tests worth running under mixed-env: the OCR3/DON2DON-heavy ones. - # The confidential relay test runs against its own topology (the - # standard mixed-env topology lacks the confidential-workflows / - # confidential-relay capabilities and ConfidentialWorkflows.Enabled). - TESTS='[ - "Test_CRE_V2_Suite_Bucket_A", - "Test_CRE_V2_Suite_Bucket_B", - "Test_CRE_V2_EVM_Read_HeavyCalls", - "Test_CRE_V2_EVM_Read_StateQueries", - "Test_CRE_V2_EVM_Read_TxArtifacts" - ]' - # Per-test topology override. Tests not listed here default to the - # standard mixed-env topology (configs/mixed-env-don.toml). - PER_TEST_CONFIGS='{ - "Test_CRE_V2_ConfidentialWorkflows_Relay": "configs/mixed-env-confidential-workflows.toml" - }' - matrix=$(jq -c -n \ - --argjson tests "$TESTS" \ - --argjson per "$PER_TEST_CONFIGS" \ - --argjson run_id "$RUN_ID" \ - --arg run_attempt "$RUN_ATTEMPT" \ - --arg spot_flag "$SPOT_FLAG" ' - $tests | to_entries | map({ - test_name: .value, - test_id: .key, - configs: ($per[.value] // "configs/mixed-env-don.toml"), - runs_on: "runs-on=\($run_id)-\(.key)-\($run_attempt)/cpu=16/ram=64/family=m7i+m8i/\($spot_flag)/image=ubuntu24-full-x64/extras=s3-cache+tmpfs" - })') - echo "matrix=$matrix" | tee -a "${GITHUB_OUTPUT}" + RUNNER_SPOT_FLAG: ${{ steps.spot.outputs.spot_flag }} + run: ci matrix mixed-env run-mixed-env-tests: name: ${{ matrix.tests.test_name }} (mixed-env) diff --git a/core/scripts/ccip/revert-reason/handler/reason_test.go b/core/scripts/ccip/revert-reason/handler/reason_test.go index 4a9363550ce..39175d0e58d 100644 --- a/core/scripts/ccip/revert-reason/handler/reason_test.go +++ b/core/scripts/ccip/revert-reason/handler/reason_test.go @@ -15,12 +15,12 @@ func Test_RevertReasonFromTx(t *testing.T) { type args struct { txHash string } - var tests []struct { + tests := []struct { name string fields fields args args expected string - } // TODO: Add test cases. + }{} // TODO: Add test cases. for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { h := &BaseHandler{ diff --git a/core/scripts/ccip/shared/helpers.go b/core/scripts/ccip/shared/helpers.go index ac48a27a1f6..76a5c9b22a7 100644 --- a/core/scripts/ccip/shared/helpers.go +++ b/core/scripts/ccip/shared/helpers.go @@ -2,27 +2,29 @@ package shared import ( "context" + "errors" "testing" "time" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" - "github.com/pkg/errors" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-common/pkg/logger" evmclient "github.com/smartcontractkit/chainlink-evm/pkg/client" ) -const RetryTiming = 5 * time.Second -const CrossChainTimeout = 5 * time.Minute -const TxInclusionTimeout = 3 * time.Minute +const ( + RetryTiming = 5 * time.Second + CrossChainTimeout = 5 * time.Minute + TxInclusionTimeout = 3 * time.Minute +) // WaitForMined wait for a tx to be included on chain. It will panic when // the tx is reverted/successful based on the shouldSucceed parameter. func WaitForMined(lggr logger.Logger, client ethereum.TransactionReader, hash common.Hash, shouldSucceed bool) error { maxIterations := TxInclusionTimeout / RetryTiming - for i := 0; i < int(maxIterations); i++ { + for range maxIterations { lggr.Info("[MINING] waiting for tx to be mined...") receipt, _ := client.TransactionReceipt(context.Background(), hash) diff --git a/core/scripts/common/avalanche.go b/core/scripts/common/avalanche.go index db0922f5c52..af0101857bc 100644 --- a/core/scripts/common/avalanche.go +++ b/core/scripts/common/avalanche.go @@ -39,7 +39,7 @@ func (b *AvaBloom) Add(d []byte) { } // add is internal version of Add, which takes a scratch buffer for reuse (needs to be at least 6 bytes) -func (b *AvaBloom) add(d []byte, buf []byte) { +func (b *AvaBloom) add(d, buf []byte) { i1, v1, i2, v2, i3, v3 := bloomValues(d, buf) b[i1] |= v1 b[i2] |= v2 @@ -49,17 +49,17 @@ func (b *AvaBloom) add(d []byte, buf []byte) { // Big converts b to a big integer. // Note: Converting a bloom filter to a big.Int and then calling GetBytes // does not return the same bytes, since big.Int will trim leading zeroes -func (b AvaBloom) Big() *big.Int { +func (b *AvaBloom) Big() *big.Int { return new(big.Int).SetBytes(b[:]) } // Bytes returns the backing byte slice of the bloom -func (b AvaBloom) Bytes() []byte { +func (b *AvaBloom) Bytes() []byte { return b[:] } // Test checks if the given topic is present in the bloom filter -func (b AvaBloom) Test(topic []byte) bool { +func (b *AvaBloom) Test(topic []byte) bool { i1, v1, i2, v2, i3, v3 := bloomValues(topic, make([]byte, 6)) return v1 == v1&b[i1] && v2 == v2&b[i2] && @@ -67,7 +67,7 @@ func (b AvaBloom) Test(topic []byte) bool { } // MarshalText encodes b as a hex string with 0x prefix. -func (b AvaBloom) MarshalText() ([]byte, error) { +func (b *AvaBloom) MarshalText() ([]byte, error) { return hexutil.Bytes(b[:]).MarshalText() } @@ -77,10 +77,10 @@ func (b *AvaBloom) UnmarshalText(input []byte) error { } // bloomValues returns the bytes (index-value pairs) to set for the given data -func bloomValues(data []byte, hashbuf []byte) (uint, byte, uint, byte, uint, byte) { +func bloomValues(data, hashbuf []byte) (uint, byte, uint, byte, uint, byte) { sha := crypto.NewKeccakState() sha.Write(data) - sha.Read(hashbuf) //nolint:errcheck + sha.Read(hashbuf) //nolint:errcheck // keccak state read does not error // The actual bits to flip v1 := byte(1 << (hashbuf[1] & 0x7)) v2 := byte(1 << (hashbuf[3] & 0x7)) @@ -284,13 +284,15 @@ func (h *AvaHeader) UnmarshalJSON(input []byte) error { } return nil } + func (h *AvaHeader) Hash() common.Hash { return rlpHash(h) } + func rlpHash(x any) (h common.Hash) { sha := crypto.NewKeccakState() sha.Reset() - rlp.Encode(sha, x) //nolint:errcheck - sha.Read(h[:]) //nolint:errcheck + rlp.Encode(sha, x) //nolint:errcheck // rlp encode to hash buffer does not fail + sha.Read(h[:]) //nolint:errcheck // keccak state read does not error return h } diff --git a/core/scripts/common/helpers.go b/core/scripts/common/helpers.go index 18a72cb8262..12ff67ecddd 100644 --- a/core/scripts/common/helpers.go +++ b/core/scripts/common/helpers.go @@ -2,7 +2,6 @@ package common import ( "context" - "crypto/ecdsa" "crypto/tls" "encoding/hex" "flag" @@ -88,20 +87,9 @@ func SetupEnv(overrideNonce bool) Environment { PanicErr(err) // Owner key. Make sure it has eth - b, err := hex.DecodeString(accountKey) + privateKey, err := crypto.HexToECDSA(accountKey) PanicErr(err) - d := new(big.Int).SetBytes(b) - - pkX, pkY := crypto.S256().ScalarBaseMult(d.Bytes()) - privateKey := ecdsa.PrivateKey{ - PublicKey: ecdsa.PublicKey{ - Curve: crypto.S256(), - X: pkX, - Y: pkY, - }, - D: d, - } - owner, err := bind.NewKeyedTransactorWithChainID(&privateKey, big.NewInt(chainID)) + owner, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(chainID)) PanicErr(err) // Explicitly set gas price to ensure non-eip 1559 gp, err := ec.SuggestGasPrice(context.Background()) @@ -121,10 +109,10 @@ func SetupEnv(overrideNonce bool) Environment { block, err := ec.BlockNumber(context.Background()) PanicErr(err) - nonce, err := ec.NonceAt(context.Background(), owner.From, big.NewInt(int64(block))) + nonce, err := ec.NonceAt(context.Background(), owner.From, new(big.Int).SetUint64(block)) PanicErr(err) - owner.Nonce = big.NewInt(int64(nonce)) + owner.Nonce = new(big.Int).SetUint64(nonce) } owner.GasPrice = gp.Mul(gp, big.NewInt(2)) fmt.Println("Modified Gas Price that will be set:", owner.GasPrice, "wei") @@ -306,7 +294,7 @@ func ConfirmCodeAt(ctx context.Context, client *ethclient.Client, addr common.Ad // of *big.Int objects. func ParseBigIntSlice(arg string) (ret []*big.Int) { parts := strings.Split(arg, ",") - ret = []*big.Int{} + ret = make([]*big.Int, 0, len(parts)) for _, part := range parts { ret = append(ret, decimal.RequireFromString(part).BigInt()) } @@ -329,7 +317,7 @@ func ParseIntSlice(arg string) (ret []int) { // of common.Address objects. func ParseAddressSlice(arg string) (ret []common.Address) { parts := strings.Split(arg, ",") - ret = []common.Address{} + ret = make([]common.Address, 0, len(parts)) for _, part := range parts { ret = append(ret, common.HexToAddress(part)) } @@ -340,7 +328,7 @@ func ParseAddressSlice(arg string) (ret []common.Address) { // common.Hash objects. func ParseHashSlice(arg string) (ret []common.Hash) { parts := strings.Split(arg, ",") - ret = []common.Hash{} + ret = make([]common.Hash, 0, len(parts)) for _, part := range parts { ret = append(ret, common.HexToHash(part)) } @@ -365,7 +353,7 @@ func FundNode(e Environment, address string, fundingAmount *big.Int) { block, err := e.Ec.BlockNumber(context.Background()) PanicErr(err) - nonce, err := e.Ec.NonceAt(context.Background(), e.Owner.From, big.NewInt(int64(block))) + nonce, err := e.Ec.NonceAt(context.Background(), e.Owner.From, new(big.Int).SetUint64(block)) PanicErr(err) // Special case for Arbitrum since gas estimation there is different. @@ -556,19 +544,21 @@ func IsPolygonEdgeNetwork(chainID int64) bool { } func CalculateLatestBlockHeader(env Environment, blockNumberInput int) (err error) { - blockNumber := uint64(blockNumberInput) + var blockNumber uint64 if blockNumberInput == -1 { blockNumber, err = env.Ec.BlockNumber(context.Background()) if err != nil { return fmt.Errorf("failed to fetch latest block: %w", err) } + } else { + blockNumber = uint64(blockNumberInput) //nolint:gosec // block number fits in uint64 } // GetRLPHeaders method increments the blockNum sent by 1 and then fetches // block headers for the child block. - blockNumber = blockNumber - 1 + blockNumber-- - blockNumberBigInts := []*big.Int{big.NewInt(int64(blockNumber))} + blockNumberBigInts := []*big.Int{new(big.Int).SetUint64(blockNumber)} headers, hashes, err := GetRlpHeaders(env, blockNumberBigInts, true) if err != nil { fmt.Println(err) diff --git a/core/scripts/common/vrf/setup-envs/main.go b/core/scripts/common/vrf/setup-envs/main.go index 7193d69f84d..400ff7510c7 100644 --- a/core/scripts/common/vrf/setup-envs/main.go +++ b/core/scripts/common/vrf/setup-envs/main.go @@ -227,11 +227,11 @@ func main() { switch *vrfVersion { case "v2": feeConfigV2 := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ - FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), - FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), - FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), - FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), - FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), + FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), //nolint:gosec // fee tier fits in uint32 ReqsForTier2: big.NewInt(constants.ReqsForTier2), ReqsForTier3: big.NewInt(constants.ReqsForTier3), ReqsForTier4: big.NewInt(constants.ReqsForTier4), @@ -282,10 +282,10 @@ func main() { StalenessSeconds: *stalenessSeconds, GasAfterPayment: *gasAfterPayment, FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, - FulfillmentFlatFeeNativePPM: uint32(*flatFeeNativePPM), - FulfillmentFlatFeeLinkDiscountPPM: uint32(*flatFeeLinkDiscountPPM), - NativePremiumPercentage: uint8(*nativePremiumPercentage), - LinkPremiumPercentage: uint8(*linkPremiumPercentage), + FulfillmentFlatFeeNativePPM: uint32(*flatFeeNativePPM), //nolint:gosec // fee fits in uint32 + FulfillmentFlatFeeLinkDiscountPPM: uint32(*flatFeeLinkDiscountPPM), //nolint:gosec // fee fits in uint32 + NativePremiumPercentage: uint8(*nativePremiumPercentage), //nolint:gosec // premium fits in uint8 + LinkPremiumPercentage: uint8(*linkPremiumPercentage), //nolint:gosec // premium fits in uint8 } coordinatorJobSpecConfig := model.CoordinatorJobSpecConfig{ @@ -315,8 +315,8 @@ func main() { bhsJobSpecConfig, *simulationBlock, *coordinatorType, - uint8(*optimismL1GasFeeCalculationMode), - uint8(*optimismL1GasFeeCoefficient), + uint8(*optimismL1GasFeeCalculationMode), //nolint:gosec // mode fits in uint8 + uint8(*optimismL1GasFeeCoefficient), //nolint:gosec // coefficient fits in uint8 ) } @@ -401,7 +401,7 @@ func getVRFKeys(client *clcmd.Shell, app *cli.App, output *bytes.Buffer) []prese } func createJob(jobSpec string, client *clcmd.Shell, app *cli.App, output *bytes.Buffer) { - if err := os.WriteFile("job-spec.toml", []byte(jobSpec), 0666); err != nil { //nolint:gosec + if err := os.WriteFile("job-spec.toml", []byte(jobSpec), 0600); err != nil { helpers.PanicErr(err) } job := presenters.JobResource{} @@ -415,7 +415,7 @@ func createJob(jobSpec string, client *clcmd.Shell, app *cli.App, output *bytes. } func exportVRFKey(client *clcmd.Shell, app *cli.App, vrfKey presenters.VRFKeyResource, output *bytes.Buffer) { - if err := os.WriteFile("vrf-key-password.txt", []byte("twochains"), 0666); err != nil { //nolint:gosec + if err := os.WriteFile("vrf-key-password.txt", []byte("twochains"), 0600); err != nil { helpers.PanicErr(err) } flagSet := flag.NewFlagSet("blah", flag.ExitOnError) @@ -429,7 +429,7 @@ func exportVRFKey(client *clcmd.Shell, app *cli.App, vrfKey presenters.VRFKeyRes } func importVRFKey(client *clcmd.Shell, app *cli.App, output *bytes.Buffer) { - if err := os.WriteFile("vrf-key-password.txt", []byte("twochains"), 0666); err != nil { //nolint:gosec + if err := os.WriteFile("vrf-key-password.txt", []byte("twochains"), 0600); err != nil { helpers.PanicErr(err) } flagSet := flag.NewFlagSet("blah", flag.ExitOnError) @@ -456,7 +456,7 @@ func getAllJobIDs(client *clcmd.Shell, app *cli.App, output *bytes.Buffer) []str helpers.PanicErr(err) jobs := clcmd.JobPresenters{} helpers.PanicErr(json.Unmarshal(output.Bytes(), &jobs)) - var jobIDs []string + jobIDs := make([]string, 0, len(jobs)) for _, job := range jobs { jobIDs = append(jobIDs, job.ID) } @@ -476,7 +476,7 @@ func printETHKeyData(ethKeys []presenters.ETHKeyResource) { } func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []model.SendingKey { - var sendingKeys []model.SendingKey + sendingKeys := make([]model.SendingKey, 0, len(ethKeys)) for _, ethKey := range ethKeys { sendingKey := model.SendingKey{Address: ethKey.Address, BalanceEth: ethKey.EthBalance.ToInt()} sendingKeys = append(sendingKeys, sendingKey) @@ -485,7 +485,7 @@ func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []model.Send } func mapVrfKeysToStringArr(vrfKeys []presenters.VRFKeyResource) []string { - var vrfKeysString []string + vrfKeysString := make([]string, 0, len(vrfKeys)) for _, vrfKey := range vrfKeys { vrfKeysString = append(vrfKeysString, vrfKey.Uncompressed) } @@ -520,7 +520,6 @@ func connectToNode(nodeURL *string, output *bytes.Buffer, credFile string) (*clc } func createVRFKeyIfNeeded(client *clcmd.Shell, app *cli.App, output *bytes.Buffer, numVRFKeys *int, nodeURL *string) []presenters.VRFKeyResource { - var allVRFKeys []presenters.VRFKeyResource var newKeys []presenters.VRFKeyResource vrfKeys := getVRFKeys(client, app, output) @@ -548,6 +547,7 @@ func createVRFKeyIfNeeded(client *clcmd.Shell, app *cli.App, output *bytes.Buffe }(), ", ")) } fmt.Println() + allVRFKeys := make([]presenters.VRFKeyResource, 0, len(vrfKeys)+len(newKeys)) allVRFKeys = append(allVRFKeys, vrfKeys...) allVRFKeys = append(allVRFKeys, newKeys...) return allVRFKeys @@ -564,7 +564,6 @@ func createVRFKey(client *clcmd.Shell, app *cli.App, output *bytes.Buffer) prese } func createETHKeysIfNeeded(client *clcmd.Shell, app *cli.App, output *bytes.Buffer, numEthKeys *int, nodeURL *string) []presenters.ETHKeyResource { - var allETHKeysNode []presenters.ETHKeyResource var ethKeys []presenters.ETHKeyResource var newKeys []presenters.ETHKeyResource // check for ETH keys @@ -602,6 +601,7 @@ func createETHKeysIfNeeded(client *clcmd.Shell, app *cli.App, output *bytes.Buff } output.Reset() fmt.Println() + allETHKeysNode := make([]presenters.ETHKeyResource, 0, len(ethKeys)+len(newKeys)) allETHKeysNode = append(allETHKeysNode, ethKeys...) allETHKeysNode = append(allETHKeysNode, newKeys...) return allETHKeysNode diff --git a/core/scripts/common/vrf/util/util.go b/core/scripts/common/vrf/util/util.go index 751aa013201..640a23f2397 100644 --- a/core/scripts/common/vrf/util/util.go +++ b/core/scripts/common/vrf/util/util.go @@ -5,7 +5,7 @@ import ( ) func MapToSendingKeyArr(nodeSendingKeys []string) []model.SendingKey { - var sendingKeys []model.SendingKey + sendingKeys := make([]model.SendingKey, 0, len(nodeSendingKeys)) for _, key := range nodeSendingKeys { sendingKeys = append(sendingKeys, model.SendingKey{Address: key}) @@ -14,7 +14,7 @@ func MapToSendingKeyArr(nodeSendingKeys []string) []model.SendingKey { } func MapToAddressArr(sendingKeys []model.SendingKey) []string { - var sendingKeysString []string + sendingKeysString := make([]string, 0, len(sendingKeys)) for _, sendingKey := range sendingKeys { sendingKeysString = append(sendingKeysString, sendingKey.Address) } diff --git a/core/scripts/cre/environment/environment/environment.go b/core/scripts/cre/environment/environment/environment.go index 83e2037982a..bc843fac1b1 100644 --- a/core/scripts/cre/environment/environment/environment.go +++ b/core/scripts/cre/environment/environment/environment.go @@ -23,7 +23,6 @@ import ( mobyclient "github.com/moby/moby/client" "github.com/pkg/errors" "github.com/rs/zerolog" - "github.com/spf13/cobra" "github.com/smartcontractkit/chainlink-testing-framework/framework" @@ -31,6 +30,7 @@ import ( chipingressset "github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/chip_ingress_set" "github.com/smartcontractkit/chainlink-testing-framework/framework/tracking" + "github.com/smartcontractkit/chainlink/core/scripts/cre/environment/topologyviz" cldlogger "github.com/smartcontractkit/chainlink/deployment/logger" "github.com/smartcontractkit/chainlink/system-tests/lib/cre" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/don/gateway" @@ -41,8 +41,6 @@ import ( feature_set "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/sets" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/flags" libformat "github.com/smartcontractkit/chainlink/system-tests/lib/format" - - "github.com/smartcontractkit/chainlink/core/scripts/cre/environment/topologyviz" ) const ( @@ -534,14 +532,18 @@ func setupDashboards(ctx context.Context, setupCfg SetupConfig) error { } // Wait for grafana at localhost:3000 to be available - var isGrafanaUp = func() bool { + isGrafanaUp := func() bool { for range 30 { time.Sleep(1 * time.Second) - req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost:3000", nil) - _, err := http.DefaultClient.Do(req) + req, reqErr := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost:3000", nil) + if reqErr != nil { + continue + } + resp, err := http.DefaultClient.Do(req) if err != nil { continue } + _ = resp.Body.Close() return true } @@ -823,7 +825,7 @@ func StartCLIEnvironment( cmdContext context.Context, relativePathToRepoRoot string, in *envconfig.Config, - capabilities []cre.InstallableCapability, // Deprecated: use Features instead + capabilities []cre.InstallableCapability, //nolint:staticcheck // use Features instead; retained for backward compatibility features cre.Features, extraJobSpecFunctions []cre.JobSpecFn, env cre.CLIEnvironmentDependencies, diff --git a/core/scripts/cre/environment/environment/localbuild.go b/core/scripts/cre/environment/environment/localbuild.go index 772879ec18c..5ef55e8c433 100644 --- a/core/scripts/cre/environment/environment/localbuild.go +++ b/core/scripts/cre/environment/environment/localbuild.go @@ -13,7 +13,6 @@ import ( "github.com/pkg/errors" "github.com/smartcontractkit/chainlink-testing-framework/framework" - envconfig "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/config" ) diff --git a/core/scripts/cre/environment/environment/setup.go b/core/scripts/cre/environment/environment/setup.go index ca8e7d24176..9769429aa8f 100644 --- a/core/scripts/cre/environment/environment/setup.go +++ b/core/scripts/cre/environment/environment/setup.go @@ -12,9 +12,6 @@ import ( "strings" "text/template" - "golang.org/x/text/cases" - "golang.org/x/text/language" - "github.com/Masterminds/semver/v3" "github.com/ethereum/go-ethereum/log" mobyclient "github.com/moby/moby/client" @@ -23,6 +20,8 @@ import ( "github.com/rs/zerolog" "github.com/spf13/cobra" "github.com/tidwall/gjson" + "golang.org/x/text/cases" + "golang.org/x/text/language" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/smartcontractkit/chainlink-testing-framework/framework/tracking" @@ -895,7 +894,7 @@ func pullImage(ctx context.Context, awsProfile string, localImage, ecrImage stri } // Get ECR login password after successful SSO login - ecrHostname := strings.Split(ecrImage, "/")[0] + ecrHostname, _, _ := strings.Cut(ecrImage, "/") ecrLoginCmd := exec.CommandContext(ctx, "aws", "ecr", "get-login-password", "--region", "us-west-2", "--profile", awsProfile) password, passErr := ecrLoginCmd.Output() if passErr != nil { @@ -972,7 +971,7 @@ func checkIfGHLIIsInstalled(ctx context.Context, minGHCLIVersion string, noPromp if brewInfoErr != nil { fmt.Fprint(os.Stderr, string(brewInfoOutput)) logger.Warn().Msgf("GH CLI wasn't installed via brew, please update it manually to at least %s", minGHCLIVersion) - return false, nil + return false, nil //nolint:nilerr // expected if gh is not managed by brew } brewUpgradeCmd := exec.CommandContext(ctx, "brew", "upgrade", "gh") @@ -980,7 +979,7 @@ func checkIfGHLIIsInstalled(ctx context.Context, minGHCLIVersion string, noPromp if brewUpdateErr != nil { fmt.Fprint(os.Stderr, string(brewUpdateOutput)) logger.Warn().Msgf("failed to upgrade GitHub CLI via Homebrew, please update it manually to at least %s", minGHCLIVersion) - return false, nil + return false, nil //nolint:nilerr // handled by fallback warning } logger.Info().Msg(" ✓ GitHub CLI upgraded to latest via Homebrew") diff --git a/core/scripts/cre/environment/environment/swap.go b/core/scripts/cre/environment/environment/swap.go index 632b1861d23..e2989bb670c 100644 --- a/core/scripts/cre/environment/environment/swap.go +++ b/core/scripts/cre/environment/environment/swap.go @@ -17,7 +17,6 @@ import ( ptypes "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/shared/ptypes" "github.com/smartcontractkit/chainlink-testing-framework/framework" ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set" - cldlogger "github.com/smartcontractkit/chainlink/deployment/logger" "github.com/smartcontractkit/chainlink/system-tests/lib/cre" crecapabilities "github.com/smartcontractkit/chainlink/system-tests/lib/cre/capabilities" diff --git a/core/scripts/cre/environment/environment/topology.go b/core/scripts/cre/environment/environment/topology.go index bb473448791..033edb43df0 100644 --- a/core/scripts/cre/environment/environment/topology.go +++ b/core/scripts/cre/environment/environment/topology.go @@ -237,7 +237,7 @@ func discoverTopologies() ([]discoveredTopology, error) { } ok, err := isTopologyConfig(path) if err != nil || !ok { - return nil + return nil //nolint:nilerr // skip invalid or non-topology files during directory walk } candidates = append(candidates, path) return nil diff --git a/core/scripts/cre/environment/environment/workflow.go b/core/scripts/cre/environment/environment/workflow.go index 045ccd911ad..db29b0a2303 100644 --- a/core/scripts/cre/environment/environment/workflow.go +++ b/core/scripts/cre/environment/environment/workflow.go @@ -17,7 +17,6 @@ import ( "github.com/smartcontractkit/chainlink-deployments-framework/deployment" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/seth" - keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" "github.com/smartcontractkit/chainlink/system-tests/lib/cre" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/contracts" @@ -580,7 +579,7 @@ func resolveWorkflowDONNodeInfo(resolver *LocalCREStateResolver, sel workflowDON port, count, nodeErr := resolver.workflowDONNodeInfoFor(donMeta) if nodeErr != nil { // Kubernetes and other providers without direct DB access fall back to a static wait. - return 0, 0, nil + return 0, 0, nil //nolint:nilerr // providers without direct DB access fall back to static wait } return port, count, nil } diff --git a/core/scripts/cre/environment/examples/examples.go b/core/scripts/cre/environment/examples/examples.go index 868bc080c36..c3f1959ff62 100644 --- a/core/scripts/cre/environment/examples/examples.go +++ b/core/scripts/cre/environment/examples/examples.go @@ -100,7 +100,7 @@ func resolveRPC(cmd *cobra.Command, defaultRPC string) (string, error) { resolvedRPC, err := resolver.RegistryRPC() if err != nil { - return defaultRPC, nil + return defaultRPC, nil //nolint:nilerr // fallback to default RPC if resolution fails } return resolvedRPC, nil diff --git a/core/scripts/cre/environment/examples/pkg/deploy/consumer.go b/core/scripts/cre/environment/examples/pkg/deploy/consumer.go index 3e9a2943503..de4f8c42864 100644 --- a/core/scripts/cre/environment/examples/pkg/deploy/consumer.go +++ b/core/scripts/cre/environment/examples/pkg/deploy/consumer.go @@ -8,13 +8,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" + chainselectors "github.com/smartcontractkit/chain-selectors" + "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/balance_reader" "github.com/smartcontractkit/chainlink-testing-framework/framework" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/seth" - - "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/balance_reader" "github.com/smartcontractkit/chainlink/core/scripts/cre/environment/examples/contracts/permissionless_feeds_consumer" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment" crecrypto "github.com/smartcontractkit/chainlink/system-tests/lib/crypto" diff --git a/core/scripts/cre/environment/examples/pkg/verify/proof_of_reserve.go b/core/scripts/cre/environment/examples/pkg/verify/proof_of_reserve.go index 96809d2a1a2..02a3943fef1 100644 --- a/core/scripts/cre/environment/examples/pkg/verify/proof_of_reserve.go +++ b/core/scripts/cre/environment/examples/pkg/verify/proof_of_reserve.go @@ -10,7 +10,6 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/seth" "github.com/smartcontractkit/chainlink/core/scripts/cre/environment/examples/contracts/permissionless_feeds_consumer" - libformat "github.com/smartcontractkit/chainlink/system-tests/lib/format" ) diff --git a/core/scripts/gateway/connector/run_connector.go b/core/scripts/gateway/connector/run_connector.go index 064d360b26c..da92b8979a3 100644 --- a/core/scripts/gateway/connector/run_connector.go +++ b/core/scripts/gateway/connector/run_connector.go @@ -74,7 +74,7 @@ func main() { return } - var cfg connector.ConnectorConfig + var cfg connector.Config err = toml.Unmarshal(rawConfig, &cfg) if err != nil { fmt.Println("error parsing config:", err) diff --git a/core/scripts/vrfv2/genvrfnum/main.go b/core/scripts/vrfv2/genvrfnum/main.go index e8265449f9d..d0d2fedb978 100644 --- a/core/scripts/vrfv2/genvrfnum/main.go +++ b/core/scripts/vrfv2/genvrfnum/main.go @@ -53,7 +53,7 @@ func main() { blockNum := cmd.Uint64("blocknum", 10, "block number the request is in") cbGasLimit := cmd.Uint("cb-gas-limit", 100_000, "callback gas limit") numWords := cmd.Uint("num-words", 1, "num words") - numWorkers := cmd.Uint64("num-workers", uint64(runtime.NumCPU()), "num workers") + numWorkers := cmd.Uint64("num-workers", uint64(runtime.NumCPU()), "num workers") //nolint:gosec // NumCPU is positive helpers.ParseArgs(cmd, os.Args[2:], "pw", "sender", "blockhash") @@ -83,7 +83,7 @@ func main() { ) { numIters := 0 for nonce := nonceRange[0]; nonce <= nonceRange[1]; nonce++ { - var record []string + record := make([]string, 0, 16) // construct preseed using typical preseed data preSeed := preseed(keyHash, sender, *subID, nonce) @@ -98,8 +98,8 @@ func main() { BlockHash: blockhash, BlockNum: *blockNum, SubID: *subID, - CallbackGasLimit: uint32(*cbGasLimit), - NumWords: uint32(*numWords), + CallbackGasLimit: uint32(*cbGasLimit), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(*numWords), //nolint:gosec // num words fits in uint32 Sender: sender, } finalSeed := proof.FinalSeedV2(preseedData) @@ -144,7 +144,7 @@ func main() { } } - ranges := nonceRanges(1, uint64(*numCount), *numWorkers) + ranges := nonceRanges(1, uint64(*numCount), *numWorkers) //nolint:gosec // numCount is positive fmt.Println("nonce ranges:", ranges, "generating proofs...") @@ -192,7 +192,7 @@ func main() { } } - for i := 0; i < *numWorkers; i++ { + for range *numWorkers { go verify(proofsChan) } diff --git a/core/scripts/vrfv2/testnet/main.go b/core/scripts/vrfv2/testnet/main.go index 8e60aa8b75c..c80d4c595f2 100644 --- a/core/scripts/vrfv2/testnet/main.go +++ b/core/scripts/vrfv2/testnet/main.go @@ -21,6 +21,7 @@ import ( "github.com/shopspring/decimal" commonkeystore "github.com/smartcontractkit/chainlink-common/keystore" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_vrf_coordinator_v2" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/blockhash_store" @@ -39,7 +40,6 @@ import ( evmutils "github.com/smartcontractkit/chainlink-evm/pkg/utils" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/v2scripts" - "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/blockhashstore" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/vrf/proof" @@ -196,7 +196,7 @@ func main() { helpers.PanicErr(err) db := sqlx.MustOpen("postgres", *dbURL) - lggr, _ := logger.NewLogger() + lggr, _ := logger.New() keyStore := keystore.New(db, commonkeystore.DefaultScryptParams, lggr.Infof) err = keyStore.Unlock(ctx, *keystorePassword) helpers.PanicErr(err) @@ -216,8 +216,8 @@ func main() { BlockHash: bhSlice[i], BlockNum: blockNumSlice[i].Uint64(), SubID: subIDSlice[i].Uint64(), - CallbackGasLimit: uint32(cbLimitsSlice[i].Uint64()), - NumWords: uint32(numWordsSlice[i].Uint64()), + CallbackGasLimit: uint32(cbLimitsSlice[i].Uint64()), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(numWordsSlice[i].Uint64()), //nolint:gosec // num words fits in uint32 Sender: senderSlice[i], } fmt.Printf("preseed data iteration %d: %+v\n", i, preSeedData) @@ -287,7 +287,7 @@ func main() { helpers.PanicErr(err) db := sqlx.MustOpen("postgres", *dbURL) - lggr, _ := logger.NewLogger() + lggr, _ := logger.New() keyStore := keystore.New(db, commonkeystore.DefaultScryptParams, lggr.Infof) err = keyStore.Unlock(ctx, *keystorePassword) helpers.PanicErr(err) @@ -304,8 +304,8 @@ func main() { BlockHash: common.HexToHash(*blockHash), BlockNum: *blockNum, SubID: *subID, - CallbackGasLimit: uint32(*cbGasLimit), - NumWords: uint32(*numWords), + CallbackGasLimit: uint32(*cbGasLimit), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(*numWords), //nolint:gosec // num words fits in uint32 Sender: common.HexToAddress(*sender), } fmt.Printf("preseed data: %+v\n", preSeedData) @@ -398,10 +398,10 @@ func main() { } if *startBlock == -1 { - closestBlock, err2 := v2scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) + closestBlock, err2 := v2scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) //nolint:gosec // block number fits in uint64 // found a block with blockhash stored that's more recent that end block if err2 == nil { - *startBlock = int64(closestBlock) + *startBlock = int64(closestBlock) //nolint:gosec // block number fits in int64 } else { fmt.Println("encountered error while looking for closest block:", err2) tx, err2 := bhs.StoreEarliest(e.Owner) @@ -409,7 +409,7 @@ func main() { receipt := helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "Store Earliest") // storeEarliest will store receipt block number minus 256 which is the earliest block // the blockhash() instruction will work on. - *startBlock = receipt.BlockNumber.Int64() - 256 + *startBlock = int64(receipt.BlockNumber.Uint64() - 256) //nolint:gosec // block number fits in int64 } } @@ -510,17 +510,17 @@ func main() { v2scripts.SetCoordinatorConfig( e, *coordinator, - uint16(*minConfs), - uint32(*maxGasLimit), - uint32(*stalenessSeconds), - uint32(*gasAfterPayment), + uint16(*minConfs), //nolint:gosec // min confs fits in uint16 + uint32(*maxGasLimit), //nolint:gosec // max gas limit fits in uint32 + uint32(*stalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(*gasAfterPayment), //nolint:gosec // gas after payment fits in uint32 decimal.RequireFromString(*fallbackWeiPerUnitLink).BigInt(), vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ - FulfillmentFlatFeeLinkPPMTier1: uint32(*flatFeeTier1), - FulfillmentFlatFeeLinkPPMTier2: uint32(*flatFeeTier2), - FulfillmentFlatFeeLinkPPMTier3: uint32(*flatFeeTier3), - FulfillmentFlatFeeLinkPPMTier4: uint32(*flatFeeTier4), - FulfillmentFlatFeeLinkPPMTier5: uint32(*flatFeeTier5), + FulfillmentFlatFeeLinkPPMTier1: uint32(*flatFeeTier1), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier2: uint32(*flatFeeTier2), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier3: uint32(*flatFeeTier3), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier4: uint32(*flatFeeTier4), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier5: uint32(*flatFeeTier5), //nolint:gosec // fee tier fits in uint32 ReqsForTier2: big.NewInt(*reqsForTier2), ReqsForTier3: big.NewInt(*reqsForTier3), ReqsForTier4: big.NewInt(*reqsForTier4), @@ -569,7 +569,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*address), e.Ec) helpers.PanicErr(err) fmt.Println("sub-id", *subID, "address", *address, coordinator.Address()) - s, err := coordinator.GetSubscription(nil, uint64(*subID)) + s, err := coordinator.GetSubscription(nil, uint64(*subID)) //nolint:gosec // subID fits in uint64 helpers.PanicErr(err) fmt.Printf("Subscription %+v\n", s) case "consumer-deploy": @@ -786,7 +786,7 @@ func main() { e.Ec, ) helpers.PanicErr(err) - tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint32(*cbGasLimit), uint16(*requestConfirmations), uint32(*numWords), keyHashBytes) + tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint32(*cbGasLimit), uint16(*requestConfirmations), uint32(*numWords), keyHashBytes) //nolint:gosec // flags fit in target types helpers.PanicErr(err) fmt.Println("TX", helpers.ExplorerLink(e.ChainID, tx.Hash())) r, err := bind.WaitMined(context.Background(), e.Ec, tx) @@ -820,9 +820,9 @@ func main() { ) helpers.PanicErr(err) var txes []*types.Transaction - for i := 0; i < int(*runs); i++ { - tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint16(*requestConfirmations), - keyHashBytes, uint16(*requests)) + for i := range *runs { + tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint16(*requestConfirmations), //nolint:gosec // request confirmations fits in uint16 + keyHashBytes, uint16(*requests)) //nolint:gosec // requests fits in uint16 helpers.PanicErr(err) fmt.Printf("TX %d: %s\n", i+1, helpers.ExplorerLink(e.ChainID, tx.Hash())) txes = append(txes, tx) @@ -865,14 +865,14 @@ func main() { ) helpers.PanicErr(err) var txes []*types.Transaction - for i := 0; i < int(*runs); i++ { + for i := range *runs { requestRandTX, errRequestRandomWords := consumer.RequestRandomWords( e.Owner, - uint16(*requestConfirmations), + uint16(*requestConfirmations), //nolint:gosec // request confirmations fits in uint16 keyHashBytes, - uint32(*cbGasLimit), - uint32(*numWords), - uint16(*requests), + uint32(*cbGasLimit), //nolint:gosec // gas limit fits in uint32 + uint32(*numWords), //nolint:gosec // num words fits in uint32 + uint16(*requests), //nolint:gosec // requests fits in uint16 decimal.RequireFromString(*subFundingAmountJuels).BigInt(), ) helpers.PanicErr(errRequestRandomWords) @@ -894,7 +894,7 @@ func main() { panic("Actual Coordinator Owner and provided Coordinator Owner Addresses does not match") } - var subId uint64 + var subID uint64 var wg sync.WaitGroup wg.Add(1) @@ -905,8 +905,8 @@ func main() { helpers.PanicErr(errw) defer subCreatedSubscription.Unsubscribe() subscriptionCreatedEvent := <-subCreatedChan - subId = subscriptionCreatedEvent.SubId - fmt.Println("VRF Owner Test Consumer's Sub ID:", subId) + subID = subscriptionCreatedEvent.SubId + fmt.Println("VRF Owner Test Consumer's Sub ID:", subID) defer wg.Done() }() @@ -921,8 +921,8 @@ func main() { receipt = helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("load test %d", i+1)) } blockNumber := receipt.BlockNumber.Uint64() - fmt.Println("subId", subId) - subFundedIterator, err := coordinator.FilterSubscriptionFunded(&bind.FilterOpts{End: &blockNumber}, []uint64{subId}) + fmt.Println("subId", subID) + subFundedIterator, err := coordinator.FilterSubscriptionFunded(&bind.FilterOpts{End: &blockNumber}, []uint64{subID}) helpers.PanicErr(err) if !subFundedIterator.Next() { @@ -967,15 +967,15 @@ func main() { ) helpers.PanicErr(err) var txes []*types.Transaction - for i := 0; i < int(*runs); i++ { + for i := range *runs { tx, err := consumer.RequestRandomWords( e.Owner, *subID, - uint16(*requestConfirmations), + uint16(*requestConfirmations), //nolint:gosec // request confirmations fits in uint16 keyHashBytes, - uint32(*cbGasLimit), - uint32(*numWords), - uint16(*requests), + uint32(*cbGasLimit), //nolint:gosec // gas limit fits in uint32 + uint32(*numWords), //nolint:gosec // num words fits in uint32 + uint16(*requests), //nolint:gosec // requests fits in uint16 ) helpers.PanicErr(err) fmt.Printf("TX %d: %s\n", i+1, helpers.ExplorerLink(e.ChainID, tx.Hash())) @@ -1030,7 +1030,7 @@ func main() { helpers.ParseArgs(trans, os.Args[2:], "coordinator-address", "sub-id", "to") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - tx, err := coordinator.RequestSubscriptionOwnerTransfer(e.Owner, uint64(*subID), common.HexToAddress(*to)) + tx, err := coordinator.RequestSubscriptionOwnerTransfer(e.Owner, uint64(*subID), common.HexToAddress(*to)) //nolint:gosec // subID fits in uint64 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) case "eoa-accept-sub": @@ -1040,7 +1040,7 @@ func main() { helpers.ParseArgs(accept, os.Args[2:], "coordinator-address", "sub-id") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - tx, err := coordinator.AcceptSubscriptionOwnerTransfer(e.Owner, uint64(*subID)) + tx, err := coordinator.AcceptSubscriptionOwnerTransfer(e.Owner, uint64(*subID)) //nolint:gosec // subID fits in uint64 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) case "eoa-cancel-sub": @@ -1050,7 +1050,7 @@ func main() { helpers.ParseArgs(cancel, os.Args[2:], "coordinator-address", "sub-id") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - tx, err := coordinator.CancelSubscription(e.Owner, uint64(*subID), e.Owner.From) + tx, err := coordinator.CancelSubscription(e.Owner, uint64(*subID), e.Owner.From) //nolint:gosec // subID fits in uint64 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) case "eoa-fund-sub": @@ -1067,7 +1067,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - v2scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) + v2scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) //nolint:gosec // subID fits in uint64 case "eoa-read": cmd := flag.NewFlagSet("eoa-read", flag.ExitOnError) consumerAddress := cmd.String("consumer", "", "consumer address") @@ -1088,7 +1088,7 @@ func main() { helpers.ParseArgs(cancel, os.Args[2:], "coordinator-address", "sub-id") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - tx, err := coordinator.OwnerCancelSubscription(e.Owner, uint64(*subID)) + tx, err := coordinator.OwnerCancelSubscription(e.Owner, uint64(*subID)) //nolint:gosec // subID fits in uint64 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) case "sub-balance": @@ -1302,7 +1302,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "size") wrapper, err := vrfv2_wrapper.NewVRFV2Wrapper(common.HexToAddress(*wrapperAddress), e.Ec) helpers.PanicErr(err) - tx, err := wrapper.SetFulfillmentTxSize(e.Owner, uint32(*size)) + tx, err := wrapper.SetFulfillmentTxSize(e.Owner, uint32(*size)) //nolint:gosec // size fits in uint32 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "set fulfillment tx size") case "wrapper-consumer-deploy": @@ -1327,7 +1327,7 @@ func main() { ) helpers.PanicErr(err) - tx, err := consumer.MakeRequest(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) + tx, err := consumer.MakeRequest(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) //nolint:gosec // flags fit in target types helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) case "wrapper-consumer-request-status": diff --git a/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go index a14a7c906eb..6c89565b749 100644 --- a/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go +++ b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go @@ -12,21 +12,19 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + evmtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/shopspring/decimal" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" - - evmtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/smartcontractkit/chainlink-common/keystore/corekeys/vrfkey/secp256k1" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/link_token_interface" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_owner" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" ) type CoordinatorConfigV2 struct { @@ -101,11 +99,11 @@ func DeployUniverseViaCLI(e helpers.Environment) { subscriptionBalanceJuels := decimal.RequireFromString(*subscriptionBalanceJuelsString).BigInt() feeConfig := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ - FulfillmentFlatFeeLinkPPMTier1: uint32(*flatFeeTier1), - FulfillmentFlatFeeLinkPPMTier2: uint32(*flatFeeTier2), - FulfillmentFlatFeeLinkPPMTier3: uint32(*flatFeeTier3), - FulfillmentFlatFeeLinkPPMTier4: uint32(*flatFeeTier4), - FulfillmentFlatFeeLinkPPMTier5: uint32(*flatFeeTier5), + FulfillmentFlatFeeLinkPPMTier1: uint32(*flatFeeTier1), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier2: uint32(*flatFeeTier2), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier3: uint32(*flatFeeTier3), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier4: uint32(*flatFeeTier4), //nolint:gosec // fee tier fits in uint32 + FulfillmentFlatFeeLinkPPMTier5: uint32(*flatFeeTier5), //nolint:gosec // fee tier fits in uint32 ReqsForTier2: big.NewInt(*reqsForTier2), ReqsForTier3: big.NewInt(*reqsForTier3), ReqsForTier4: big.NewInt(*reqsForTier4), @@ -214,13 +212,12 @@ func VRFV2DeployUniverse( // Generate compressed public key and key hash pubBytes, err := hex.DecodeString(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey) helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) + _, err = crypto.UnmarshalPubkey(pubBytes) helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) + pkBytes := make([]byte, 33) + copy(pkBytes[:32], pubBytes[1:33]) + if pubBytes[64]&1 != 0 { + pkBytes[32] = 1 } var newPK secp256k1.PublicKey copy(newPK[:], pkBytes) @@ -283,10 +280,10 @@ func VRFV2DeployUniverse( SetCoordinatorConfig( e, *coordinator, - uint16(coordinatorConfig.MinConfs), - uint32(coordinatorConfig.MaxGasLimit), - uint32(coordinatorConfig.StalenessSeconds), - uint32(coordinatorConfig.GasAfterPayment), + uint16(coordinatorConfig.MinConfs), //nolint:gosec // min confs fits in uint16 + uint32(coordinatorConfig.MaxGasLimit), //nolint:gosec // max gas limit fits in uint32 + uint32(coordinatorConfig.StalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(coordinatorConfig.GasAfterPayment), //nolint:gosec // gas after payment fits in uint32 coordinatorConfig.FallbackWeiPerUnitLink, coordinatorConfig.FeeConfig, ) @@ -335,8 +332,9 @@ func VRFV2DeployUniverse( // VRF Owner vrfOwner, err := vrf_owner.NewVRFOwner(vrfOwnerAddress, e.Ec) helpers.PanicErr(err) - var authorizedSendersSlice []common.Address - for _, s := range nodesMap[model.VRFPrimaryNodeName].SendingKeys { + sendingKeys := nodesMap[model.VRFPrimaryNodeName].SendingKeys + authorizedSendersSlice := make([]common.Address, 0, len(sendingKeys)) + for _, s := range sendingKeys { authorizedSendersSlice = append(authorizedSendersSlice, common.HexToAddress(s.Address)) } fmt.Printf("\nSetting authorised senders for VRF Owner: %v, Authorised senders %v\n", vrfOwnerAddress.String(), authorizedSendersSlice) diff --git a/core/scripts/vrfv2/testnet/v2scripts/util.go b/core/scripts/vrfv2/testnet/v2scripts/util.go index 0553597972d..5af5a1acfd8 100644 --- a/core/scripts/vrfv2/testnet/v2scripts/util.go +++ b/core/scripts/vrfv2/testnet/v2scripts/util.go @@ -11,18 +11,17 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" - "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_coordinator_test_v2" - "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_coordinator_v2" - "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_load_test_with_metrics" - "github.com/smartcontractkit/chainlink-evm/pkg/utils" - "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_vrf_coordinator_v2" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/blockhash_store" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/link_token_interface" + "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_coordinator_test_v2" + "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_external_sub_owner_example" + "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrf_load_test_with_metrics" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrfv2_wrapper" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/vrfv2_wrapper_consumer_example" + "github.com/smartcontractkit/chainlink-evm/pkg/utils" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" ) @@ -49,7 +48,8 @@ func DeployCoordinator( e.Ec, common.HexToAddress(linkAddress), common.HexToAddress(bhsAddress), - common.HexToAddress(linkEthAddress)) + common.HexToAddress(linkEthAddress), + ) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } @@ -65,7 +65,8 @@ func DeployTestCoordinator( e.Ec, common.HexToAddress(linkAddress), common.HexToAddress(bhsAddress), - common.HexToAddress(linkEthAddress)) + common.HexToAddress(linkEthAddress), + ) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } @@ -88,12 +89,13 @@ func EoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2.VRFCoord helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func EoaDeployConsumer(e helpers.Environment, coordinatorAddress string, linkAddress string) (consumerAddress common.Address) { +func EoaDeployConsumer(e helpers.Environment, coordinatorAddress, linkAddress string) (consumerAddress common.Address) { _, tx, _, err := vrf_external_sub_owner_example.DeployVRFExternalSubOwnerExample( e.Owner, e.Ec, common.HexToAddress(coordinatorAddress), - common.HexToAddress(linkAddress)) + common.HexToAddress(linkAddress), + ) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } @@ -145,7 +147,7 @@ func SetCoordinatorConfig( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func RegisterCoordinatorProvingKey(e helpers.Environment, coordinator vrf_coordinator_v2.VRFCoordinatorV2, uncompressed string, oracleAddress string) { +func RegisterCoordinatorProvingKey(e helpers.Environment, coordinator vrf_coordinator_v2.VRFCoordinatorV2, uncompressed, oracleAddress string) { pubBytes, err := hex.DecodeString(uncompressed) helpers.PanicErr(err) pk, err := crypto.UnmarshalPubkey(pubBytes) @@ -199,11 +201,12 @@ func WrapperConfigure( tx, err := wrapper.SetConfig( e.Owner, - uint32(wrapperGasOverhead), - uint32(coordinatorGasOverhead), - uint8(premiumPercentage), + uint32(wrapperGasOverhead), //nolint:gosec // wrapper overhead fits in uint32 + uint32(coordinatorGasOverhead), //nolint:gosec // coordinator overhead fits in uint32 + uint8(premiumPercentage), //nolint:gosec // premium percentage fits in uint8 common.HexToHash(keyHash), - uint8(maxNumWords)) + uint8(maxNumWords), //nolint:gosec // maxNumWords fits in uint8 + ) helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } @@ -239,7 +242,7 @@ func EoaLoadTestConsumerWithMetricsDeploy(e helpers.Environment, consumerCoordin return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func ClosestBlock(e helpers.Environment, batchBHSAddress common.Address, blockMissingBlockhash uint64, batchSize uint64) (uint64, error) { +func ClosestBlock(e helpers.Environment, batchBHSAddress common.Address, blockMissingBlockhash, batchSize uint64) (uint64, error) { batchBHS, err := batch_blockhash_store.NewBatchBlockhashStore(batchBHSAddress, e.Ec) if err != nil { return 0, err @@ -256,7 +259,7 @@ func ClosestBlock(e helpers.Environment, batchBHSAddress common.Address, blockMi } var blockRange []*big.Int for i := startBlock; i <= endBlock; i++ { - blockRange = append(blockRange, big.NewInt(int64(i))) + blockRange = append(blockRange, new(big.Int).SetUint64(i)) } fmt.Println("Searching range", startBlock, "-", endBlock, "inclusive") hashes, err := batchBHS.GetBlockhashes(nil, blockRange) diff --git a/core/scripts/vrfv2plus/testnet/main.go b/core/scripts/vrfv2plus/testnet/main.go index 071953c07b6..5fe55d69abc 100644 --- a/core/scripts/vrfv2plus/testnet/main.go +++ b/core/scripts/vrfv2plus/testnet/main.go @@ -22,9 +22,7 @@ import ( "github.com/shopspring/decimal" commonkeystore "github.com/smartcontractkit/chainlink-common/keystore" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" - "github.com/smartcontractkit/chainlink/v2/core/logger" - + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_vrf_coordinator_v2plus" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/blockhash_store" @@ -45,6 +43,7 @@ import ( evmtypes "github.com/smartcontractkit/chainlink-evm/pkg/types" evmutils "github.com/smartcontractkit/chainlink-evm/pkg/utils" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" "github.com/smartcontractkit/chainlink/v2/core/services/blockhashstore" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/vrf/extraargs" @@ -194,7 +193,7 @@ func main() { helpers.PanicErr(err) db := sqlx.MustOpen("postgres", *dbURL) - lggr, _ := logger.NewLogger() + lggr, _ := logger.New() keyStore := keystore.New(db, commonkeystore.DefaultScryptParams, lggr.Infof) err = keyStore.Unlock(ctx, *keystorePassword) helpers.PanicErr(err) @@ -204,8 +203,8 @@ func main() { fmt.Println("vrf key found:", k) - proofs := []batch_vrf_coordinator_v2plus.VRFTypesProof{} - reqCommits := []batch_vrf_coordinator_v2plus.VRFTypesRequestCommitmentV2Plus{} + proofs := make([]batch_vrf_coordinator_v2plus.VRFTypesProof, 0, len(preSeedSlice)) + reqCommits := make([]batch_vrf_coordinator_v2plus.VRFTypesRequestCommitmentV2Plus, 0, len(preSeedSlice)) for i := range preSeedSlice { ps, err := proof.BigToSeed(preSeedSlice[i]) helpers.PanicErr(err) @@ -216,8 +215,8 @@ func main() { BlockHash: bhSlice[i], BlockNum: blockNumSlice[i].Uint64(), SubID: subIDSlice[i], - CallbackGasLimit: uint32(cbLimitsSlice[i].Uint64()), - NumWords: uint32(numWordsSlice[i].Uint64()), + CallbackGasLimit: uint32(cbLimitsSlice[i].Uint64()), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(numWordsSlice[i].Uint64()), //nolint:gosec // num words fits in uint32 Sender: senderSlice[i], ExtraArgs: extraArgs, } @@ -289,7 +288,7 @@ func main() { helpers.PanicErr(err) db := sqlx.MustOpen("postgres", *dbURL) - lggr, _ := logger.NewLogger() + lggr, _ := logger.New() keyStore := keystore.New(db, commonkeystore.DefaultScryptParams, lggr.Infof) err = keyStore.Unlock(ctx, *keystorePassword) helpers.PanicErr(err) @@ -310,8 +309,8 @@ func main() { BlockHash: common.HexToHash(*blockHash), BlockNum: *blockNum, SubID: parsedSubID, - CallbackGasLimit: uint32(*cbGasLimit), - NumWords: uint32(*numWords), + CallbackGasLimit: uint32(*cbGasLimit), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(*numWords), //nolint:gosec // num words fits in uint32 Sender: common.HexToAddress(*sender), ExtraArgs: extraArgs, } @@ -493,7 +492,7 @@ func main() { // Get recent blockhash and block number anew each iteration. We do this so they do not get stale. recentBlockNumber, err := e.Ec.BlockNumber(context.Background()) helpers.PanicErr(err) - recentBlock, err := e.Ec.HeaderByNumber(context.Background(), big.NewInt(int64(recentBlockNumber))) + recentBlock, err := e.Ec.HeaderByNumber(context.Background(), new(big.Int).SetUint64(recentBlockNumber)) helpers.PanicErr(err) recentBlockhash := recentBlock.Hash() @@ -508,7 +507,7 @@ func main() { } // Execute storage tx. - tx, err := trustedBHS.StoreTrusted(e.Owner, blockNumbersSlice, blockhashes, big.NewInt(int64(recentBlockNumber)), recentBlockhash) + tx, err := trustedBHS.StoreTrusted(e.Owner, blockNumbersSlice, blockhashes, new(big.Int).SetUint64(recentBlockNumber), recentBlockhash) helpers.PanicErr(err) fmt.Println("waiting for it to mine...") helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) @@ -558,15 +557,15 @@ func main() { v2plusscripts.SetCoordinatorConfig( e, *coordinator, - uint16(*minConfs), - uint32(*maxGasLimit), - uint32(*stalenessSeconds), - uint32(*gasAfterPayment), + uint16(*minConfs), //nolint:gosec // min confs fits in uint16 + uint32(*maxGasLimit), //nolint:gosec // max gas limit fits in uint32 + uint32(*stalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(*gasAfterPayment), //nolint:gosec // gas after payment fits in uint32 decimal.RequireFromString(*fallbackWeiPerUnitLink).BigInt(), - uint32(*flatFeeEthPPM), - uint32(*flatFeeLinkDiscountPPM), - uint8(*nativePremiumPercentage), - uint8(*linkPremiumPercentage), + uint32(*flatFeeEthPPM), //nolint:gosec // flat fee fits in uint32 + uint32(*flatFeeLinkDiscountPPM), //nolint:gosec // flat fee fits in uint32 + uint8(*nativePremiumPercentage), //nolint:gosec // premium fits in uint8 + uint8(*linkPremiumPercentage), //nolint:gosec // premium fits in uint8 ) case "coordinator-get-l1-fee-calculation": cmd := flag.NewFlagSet("coordinator-get-l1-fee-calculation", flag.ExitOnError) @@ -587,7 +586,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:], "coordinator-address", "mode", "coefficient") coordinator, err := vrf_coordinator_v2_5_optimism.NewVRFCoordinatorV25Optimism(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - tx, err := coordinator.SetL1FeeCalculation(e.Owner, uint8(*mode), uint8(*coefficient)) + tx, err := coordinator.SetL1FeeCalculation(e.Owner, uint8(*mode), uint8(*coefficient)) //nolint:gosec // mode and coefficient fit in uint8 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "set L1 fee calculation mode and coefficient") case "coordinator-register-key": @@ -658,13 +657,13 @@ func main() { case "coordinator-get-commitment": coordinatorCommitment := flag.NewFlagSet("coordinator-get-commitment", flag.ExitOnError) coordinatorAddress := coordinatorCommitment.String("coordinator-address", "", "coordinator address") - requestId := coordinatorCommitment.String("request-id", "", "consumer's request ID") + requestID := coordinatorCommitment.String("request-id", "", "consumer's request ID") helpers.ParseArgs(coordinatorCommitment, os.Args[2:], "coordinator-address", "request-id") coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - res, err := coordinator.SRequestCommitments(nil, parseUInt256String(*requestId)) + res, err := coordinator.SRequestCommitments(nil, parseUInt256String(*requestID)) helpers.PanicErr(err) - fmt.Printf("Request ID: %+v - commitment: %v\n", *requestId, hexutil.Encode(res[:])) + fmt.Printf("Request ID: %+v - commitment: %v\n", *requestID, hexutil.Encode(res[:])) case "consumer-deploy": consumerDeployCmd := flag.NewFlagSet("consumer-deploy", flag.ExitOnError) consumerCoordinator := consumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -806,9 +805,9 @@ func main() { helpers.ParseArgs(createSubCmd, os.Args[2:], "coordinator-address") coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - subId, err := v2plusscripts.EoaCreateSub(e, *coordinator) + subID, err := v2plusscripts.EoaCreateSub(e, *coordinator) helpers.PanicErr(err) - fmt.Println("Created subscription ID: ", subId) + fmt.Println("Created subscription ID: ", subID) case "eoa-add-sub-consumer": addSubConsCmd := flag.NewFlagSet("eoa-add-sub-consumer", flag.ExitOnError) coordinatorAddress := addSubConsCmd.String("coordinator-address", "", "coordinator address") @@ -878,7 +877,7 @@ func main() { e.Ec, ) helpers.PanicErr(err) - tx, err := consumer.RequestRandomWords(e.Owner, parseUInt256String(*subID), uint32(*cbGasLimit), uint16(*requestConfirmations), uint32(*numWords), keyHashBytes, *nativePayment) + tx, err := consumer.RequestRandomWords(e.Owner, parseUInt256String(*subID), uint32(*cbGasLimit), uint16(*requestConfirmations), uint32(*numWords), keyHashBytes, *nativePayment) //nolint:gosec // request params fit in respective types helpers.PanicErr(err) fmt.Println("TX", helpers.ExplorerLink(e.ChainID, tx.Hash())) r, err := bind.WaitMined(context.Background(), e.Ec, tx) @@ -911,10 +910,10 @@ func main() { e.Ec, ) helpers.PanicErr(err) - var txes []*types.Transaction - for i := 0; i < int(*runs); i++ { - tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint16(*requestConfirmations), - keyHashBytes, uint16(*requests)) + txes := make([]*types.Transaction, 0, *runs) + for i := range *runs { + tx, err := consumer.RequestRandomWords(e.Owner, *subID, uint16(*requestConfirmations), //nolint:gosec // request confirmations fits in uint16 + keyHashBytes, uint16(*requests)) //nolint:gosec // requests fits in uint16 helpers.PanicErr(err) fmt.Printf("TX %d: %s\n", i+1, helpers.ExplorerLink(e.ChainID, tx.Hash())) txes = append(txes, tx) @@ -942,17 +941,17 @@ func main() { e.Ec, ) helpers.PanicErr(err) - var txes []*types.Transaction - for i := 0; i < int(*runs); i++ { + txes := make([]*types.Transaction, 0, *runs) + for i := range *runs { tx, err := consumer.RequestRandomWords( e.Owner, decimal.RequireFromString(*subID).BigInt(), - uint16(*requestConfirmations), + uint16(*requestConfirmations), //nolint:gosec // request confirmations fits in uint16 keyHashBytes, - uint32(*cbGasLimit), + uint32(*cbGasLimit), //nolint:gosec // cbGasLimit fits in uint32 *nativePaymentEnabled, - uint32(*numWords), - uint16(*requests), + uint32(*numWords), //nolint:gosec // numWords fits in uint32 + uint16(*requests), //nolint:gosec // requests fits in uint16 ) helpers.PanicErr(err) fmt.Printf("TX %d: %s\n", i+1, helpers.ExplorerLink(e.ChainID, tx.Hash())) @@ -1275,9 +1274,9 @@ func main() { *keyHash, *maxNumWords, decimal.RequireFromString(*fallbackWeiPerUnitLink).BigInt(), - uint32(*stalenessSeconds), - uint32(*fulfillmentFlatFeeNativePPM), - uint32(*fulfillmentFlatFeeLinkDiscountPPM)) + uint32(*stalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(*fulfillmentFlatFeeNativePPM), //nolint:gosec // flat fee fits in uint32 + uint32(*fulfillmentFlatFeeLinkDiscountPPM)) //nolint:gosec // flat fee fits in uint32 case "wrapper-get-config": cmd := flag.NewFlagSet("wrapper-get-config", flag.ExitOnError) wrapperAddress := cmd.String("wrapper-address", "", "wrapper address") @@ -1301,7 +1300,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "size") wrapper, err := vrfv2plus_wrapper.NewVRFV2PlusWrapper(common.HexToAddress(*wrapperAddress), e.Ec) helpers.PanicErr(err) - tx, err := wrapper.SetFulfillmentTxSize(e.Owner, uint32(*size)) + tx, err := wrapper.SetFulfillmentTxSize(e.Owner, uint32(*size)) //nolint:gosec // size fits in uint32 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "set fulfillment tx size") case "wrapper-get-l1-fee-calculation": @@ -1323,7 +1322,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "mode", "coefficient") wrapper, err := vrfv2plus_wrapper_optimism.NewVRFV2PlusWrapperOptimism(common.HexToAddress(*wrapperAddress), e.Ec) helpers.PanicErr(err) - tx, err := wrapper.SetL1FeeCalculation(e.Owner, uint8(*mode), uint8(*coefficient)) + tx, err := wrapper.SetL1FeeCalculation(e.Owner, uint8(*mode), uint8(*coefficient)) //nolint:gosec // mode and coefficient fit in uint8 helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "set L1 fee calculation mode and coefficient") case "wrapper-consumer-deploy": @@ -1351,9 +1350,9 @@ func main() { var tx *types.Transaction if *nativePayment { - tx, err = consumer.MakeRequestNative(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) + tx, err = consumer.MakeRequestNative(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) //nolint:gosec // parameters fit in target types } else { - tx, err = consumer.MakeRequest(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) + tx, err = consumer.MakeRequest(e.Owner, uint32(*cbGasLimit), uint16(*confirmations), uint32(*numWords)) //nolint:gosec // parameters fit in target types } helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) diff --git a/core/scripts/vrfv2plus/testnet/proofs.go b/core/scripts/vrfv2plus/testnet/proofs.go index ab584c95c80..09cd1dbb964 100644 --- a/core/scripts/vrfv2plus/testnet/proofs.go +++ b/core/scripts/vrfv2plus/testnet/proofs.go @@ -62,7 +62,7 @@ func generateProofForV2Plus(e helpers.Environment) { blockNum := deployCmd.Uint64("block-num", 0, "block number of VRF request") senderString := deployCmd.String("sender", "", "requestor of VRF request") secretKeyString := deployCmd.String("secret-key", "10", "secret key for VRF V2Key") - subId := deployCmd.String("sub-id", "1", "subscription Id for VRF request") + subID := deployCmd.String("sub-id", "1", "subscription ID for VRF request") callbackGasLimit := deployCmd.Uint64("gas-limit", 1_000_000, "callback gas limit for VRF request") numWords := deployCmd.Uint64("num-words", 1, "number of words for VRF request") nativePayment := deployCmd.Bool("native-payment", false, "requestor of VRF request") @@ -78,6 +78,7 @@ func generateProofForV2Plus(e helpers.Environment) { if err != nil { panic(err) } + pk := key.PublicKey pkh := pk.MustHash() fmt.Println("Compressed: ", pk.String()) @@ -86,6 +87,7 @@ func generateProofForV2Plus(e helpers.Environment) { // Parse big ints and hexes. requestKeyHash := common.HexToHash(*keyHashString) + requestPreSeed := decimal.RequireFromString(*preSeedString).BigInt() sender := common.HexToAddress(*senderString) blockHash := common.HexToHash(*blockhashString) @@ -101,9 +103,9 @@ func generateProofForV2Plus(e helpers.Environment) { helpers.PanicErr(fmt.Errorf("unable to parse preseed: %w", err)) } - parsedSubId, ok := new(big.Int).SetString(*subId, 10) + parsedSubID, ok := new(big.Int).SetString(*subID, 10) if !ok { - helpers.PanicErr(fmt.Errorf("unable to parse subID: %s %w", *subId, err)) + helpers.PanicErr(fmt.Errorf("unable to parse subID: %s %w", *subID, err)) } extraArgs, err := extraargs.EncodeV1(*nativePayment) helpers.PanicErr(err) @@ -111,9 +113,9 @@ func generateProofForV2Plus(e helpers.Environment) { PreSeed: preSeed, BlockHash: blockHash, BlockNum: *blockNum, - SubID: parsedSubId, - CallbackGasLimit: uint32(*callbackGasLimit), - NumWords: uint32(*numWords), + SubID: parsedSubID, + CallbackGasLimit: uint32(*callbackGasLimit), //nolint:gosec // callback gas limit fits in uint32 + NumWords: uint32(*numWords), //nolint:gosec // num words fits in uint32 Sender: sender, ExtraArgs: extraArgs, } diff --git a/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go index 7f77c8a1ba2..1b5634530ce 100644 --- a/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go @@ -18,11 +18,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/shopspring/decimal" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" - "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" - "github.com/smartcontractkit/chainlink-common/keystore/corekeys/vrfkey" "github.com/smartcontractkit/chainlink-common/keystore/corekeys/vrfkey/secp256k1" "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/batch_blockhash_store" @@ -34,6 +29,10 @@ import ( evmclient "github.com/smartcontractkit/chainlink-evm/pkg/client" evmtypes "github.com/smartcontractkit/chainlink-evm/pkg/types" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" "github.com/smartcontractkit/chainlink/v2/core/services/vrf/proof" ) @@ -142,15 +141,15 @@ func SmokeTestVRF(e helpers.Environment) { SetCoordinatorConfig( e, *coordinator, - uint16(*minConfs), - uint32(*maxGasLimit), - uint32(*stalenessSeconds), - uint32(*gasAfterPayment), + uint16(*minConfs), //nolint:gosec // min confs fits in uint16 + uint32(*maxGasLimit), //nolint:gosec // max gas limit fits in uint32 + uint32(*stalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(*gasAfterPayment), //nolint:gosec // gas after payment fits in uint32 fallbackWeiPerUnitLink, - uint32(*flatFeeNativePPM), - uint32(*flatFeeLinkDiscountPPM), - uint8(*nativePremiumPercentage), - uint8(*linkPremiumPercentage), + uint32(*flatFeeNativePPM), //nolint:gosec // flat fee fits in uint32 + uint32(*flatFeeLinkDiscountPPM), //nolint:gosec // flat fee fits in uint32 + uint8(*nativePremiumPercentage), //nolint:gosec // premium fits in uint8 + uint8(*linkPremiumPercentage), //nolint:gosec // premium fits in uint8 ) } @@ -165,13 +164,12 @@ func SmokeTestVRF(e helpers.Environment) { } pubBytes, err := hex.DecodeString(uncompressed) helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) + _, err = crypto.UnmarshalPubkey(pubBytes) helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) + pkBytes := make([]byte, 33) + copy(pkBytes[:32], pubBytes[1:33]) + if pubBytes[64]&1 != 0 { + pkBytes[32] = 1 } var newPK secp256k1.PublicKey copy(newPK[:], pkBytes) @@ -190,7 +188,11 @@ func SmokeTestVRF(e helpers.Environment) { panic(fmt.Sprintf("unexpected compressed public key %s, expected %s", compressedPkHex, key.PublicKey.String())) } - kh1, err := coordinator.HashOfKey(nil, [2]*big.Int{pk.X, pk.Y}) + point, err := key.PublicKey.Point() + helpers.PanicErr(err) + x, y := secp256k1.Coordinates(point) + + kh1, err := coordinator.HashOfKey(nil, [2]*big.Int{x, y}) helpers.PanicErr(err) fmt.Println("key hash from coordinator:", hexutil.Encode(kh1[:])) if !bytes.Equal(kh1[:], keyHash[:]) { @@ -198,12 +200,8 @@ func SmokeTestVRF(e helpers.Environment) { } fmt.Println("\nRegistering proving key...") - point, err := key.PublicKey.Point() - helpers.PanicErr(err) - x, y := secp256k1.Coordinates(point) fmt.Println("proving key points x:", x, ", y:", y) - fmt.Println("proving key points from unmarshal:", pk.X, pk.Y) - tx, err := coordinator.RegisterProvingKey(e.Owner, [2]*big.Int{x, y}, uint64(*gasLaneMaxGas)) + tx, err := coordinator.RegisterProvingKey(e.Owner, [2]*big.Int{x, y}, uint64(*gasLaneMaxGas)) //nolint:gosec // gas lane max gas fits in uint64 helpers.PanicErr(err) registerReceipt := helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, "register proving key on", coordinatorAddress.String()) var provingKeyRegisteredLog *vrf_coordinator_v2_5.VRFCoordinatorV25ProvingKeyRegistered @@ -603,10 +601,10 @@ func DeployUniverseViaCLI(e helpers.Environment) { StalenessSeconds: *stalenessSeconds, GasAfterPayment: *gasAfterPayment, FallbackWeiPerUnitLink: fallbackWeiPerUnitLink, - FulfillmentFlatFeeNativePPM: uint32(*flatFeeNativePPM), - FulfillmentFlatFeeLinkDiscountPPM: uint32(*flatFeeLinkDiscountPPM), - NativePremiumPercentage: uint8(*nativePremiumPercentage), - LinkPremiumPercentage: uint8(*linkPremiumPercentage), + FulfillmentFlatFeeNativePPM: uint32(*flatFeeNativePPM), //nolint:gosec // fee fits in uint32 + FulfillmentFlatFeeLinkDiscountPPM: uint32(*flatFeeLinkDiscountPPM), //nolint:gosec // fee fits in uint32 + NativePremiumPercentage: uint8(*nativePremiumPercentage), //nolint:gosec // percentage fits in uint8 + LinkPremiumPercentage: uint8(*linkPremiumPercentage), //nolint:gosec // percentage fits in uint8 } vrfKeyRegistrationConfig := model.VRFKeyRegistrationConfig{ @@ -642,8 +640,8 @@ func DeployUniverseViaCLI(e helpers.Environment) { bhsJobSpecConfig, *simulationBlock, *coordinatorType, - uint8(*optimismL1GasFeeCalculationMode), - uint8(*optimismL1GasFeeCoefficient), + uint8(*optimismL1GasFeeCalculationMode), //nolint:gosec // mode fits in uint8 + uint8(*optimismL1GasFeeCoefficient), //nolint:gosec // coefficient fits in uint8 ) vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName] @@ -680,13 +678,12 @@ func VRFV2PlusDeployUniverse(e helpers.Environment, // Generate compressed public key and key hash pubBytes, err := hex.DecodeString(vrfKeyRegistrationConfig.VRFKeyUncompressedPubKey) helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) + _, err = crypto.UnmarshalPubkey(pubBytes) helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) + pkBytes := make([]byte, 33) + copy(pkBytes[:32], pubBytes[1:33]) + if pubBytes[64]&1 != 0 { + pkBytes[32] = 1 } var newPK secp256k1.PublicKey copy(newPK[:], pkBytes) @@ -733,10 +730,10 @@ func VRFV2PlusDeployUniverse(e helpers.Environment, SetCoordinatorConfig( e, *coordinator, - uint16(coordinatorConfig.MinConfs), - uint32(coordinatorConfig.MaxGasLimit), - uint32(coordinatorConfig.StalenessSeconds), - uint32(coordinatorConfig.GasAfterPayment), + uint16(coordinatorConfig.MinConfs), //nolint:gosec // min confs fits in uint16 + uint32(coordinatorConfig.MaxGasLimit), //nolint:gosec // max gas limit fits in uint32 + uint32(coordinatorConfig.StalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(coordinatorConfig.GasAfterPayment), //nolint:gosec // gas after payment fits in uint32 coordinatorConfig.FallbackWeiPerUnitLink, coordinatorConfig.FulfillmentFlatFeeNativePPM, coordinatorConfig.FulfillmentFlatFeeLinkDiscountPPM, @@ -966,14 +963,14 @@ func DeployWrapperUniverse(e helpers.Environment) { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - var subId *big.Int + var subID *big.Int if *subscriptionID == "" { - subId, err = EoaCreateSub(e, *coordinator) + subID, err = EoaCreateSub(e, *coordinator) helpers.PanicErr(err) - fmt.Println("Created subscription ID:", subId) + fmt.Println("Created subscription ID:", subID) } else { - subId = parseSubID(*subscriptionID) - fmt.Println("Using existing subscription ID:", subId) + subID = parseSubID(*subscriptionID) + fmt.Println("Using existing subscription ID:", subID) } fmt.Println() @@ -982,7 +979,7 @@ func DeployWrapperUniverse(e helpers.Environment) { common.HexToAddress(*linkAddress), common.HexToAddress(*linkNativeFeedAddress), common.HexToAddress(*coordinatorAddress), - subId, + subID, *wrapperType, ) @@ -1001,16 +998,16 @@ func DeployWrapperUniverse(e helpers.Environment) { *keyHash, *maxNumWords, decimal.RequireFromString(*fallbackWeiPerUnitLink).BigInt(), - uint32(*stalenessSeconds), - uint32(*fulfillmentFlatFeeNativePPM), - uint32(*fulfillmentFlatFeeLinkDiscountPPM), + uint32(*stalenessSeconds), //nolint:gosec // staleness fits in uint32 + uint32(*fulfillmentFlatFeeNativePPM), //nolint:gosec // fee fits in uint32 + uint32(*fulfillmentFlatFeeLinkDiscountPPM), //nolint:gosec // fee fits in uint32 ) fmt.Println("Configured wrapper") fmt.Println() if *wrapperType == "optimism" { - WrapperSetL1FeeCalculation(e, wrapper, uint8(*optimismL1GasFeeCalculationMode), uint8(*optimismL1GasFeeCoefficient)) + WrapperSetL1FeeCalculation(e, wrapper, uint8(*optimismL1GasFeeCalculationMode), uint8(*optimismL1GasFeeCoefficient)) //nolint:gosec // parameters fit in uint8 fmt.Println("Set L1 gas fee calculation") fmt.Println() } @@ -1023,7 +1020,7 @@ func DeployWrapperUniverse(e helpers.Environment) { fmt.Println() // for v2plus we need to add wrapper as a consumer to the subscription - EoaAddConsumerToSub(e, *coordinator, subId, wrapper.String()) + EoaAddConsumerToSub(e, *coordinator, subID, wrapper.String()) fmt.Println("Added wrapper as the subscription consumer") fmt.Println() @@ -1040,9 +1037,9 @@ func DeployWrapperUniverse(e helpers.Environment) { fmt.Println("Funded wrapper consumer") fmt.Println() - EoaFundSubWithLink(e, *coordinator, *linkAddress, subAmountLink, subId) + EoaFundSubWithLink(e, *coordinator, *linkAddress, subAmountLink, subID) // e.Owner.Value is hardcoded inside this helper function, make sure to run it as the last one in the script - EoaFundSubWithNative(e, common.HexToAddress(*coordinatorAddress), subId, subAmountNative) + EoaFundSubWithNative(e, common.HexToAddress(*coordinatorAddress), subID, subAmountNative) fmt.Println("Funded wrapper subscription") fmt.Println() @@ -1051,7 +1048,7 @@ func DeployWrapperUniverse(e helpers.Environment) { fmt.Println("Wrapper address:", wrapper.String()) fmt.Println("Wrapper type:", *wrapperType) fmt.Println("Wrapper consumer address:", consumer.String()) - fmt.Println("Wrapper subscription ID:", subId) + fmt.Println("Wrapper subscription ID:", subID) fmt.Printf("Send native request example: go run . wrapper-consumer-request --consumer-address=%s --cb-gas-limit=1000000 --native-payment=true\n", consumer.String()) fmt.Printf("Send LINK request example: go run . wrapper-consumer-request --consumer-address=%s --cb-gas-limit=1000000 --native-payment=false\n", consumer.String()) } diff --git a/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go index 2b0d86c1f5c..4edd61e999c 100644 --- a/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go @@ -57,17 +57,20 @@ func DeployCoordinator( _, tx, _, err = vrf_coordinator_v2_5.DeployVRFCoordinatorV25( e.Owner, e.Ec, - common.HexToAddress(bhsAddress)) + common.HexToAddress(bhsAddress), + ) case "arbitrum": _, tx, _, err = vrf_coordinator_v2_5_arbitrum.DeployVRFCoordinatorV25Arbitrum( e.Owner, e.Ec, - common.HexToAddress(bhsAddress)) + common.HexToAddress(bhsAddress), + ) case "optimism": _, tx, _, err = vrf_coordinator_v2_5_optimism.DeployVRFCoordinatorV25Optimism( e.Owner, e.Ec, - common.HexToAddress(bhsAddress)) + common.HexToAddress(bhsAddress), + ) default: panic(fmt.Sprintf("Coordinator type not supported '%s'", coordinatorType)) } @@ -128,12 +131,14 @@ func EoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoo func EoaDeployConsumer(e helpers.Environment, coordinatorAddress string, linkAddress string) ( - consumerAddress common.Address) { + consumerAddress common.Address, +) { _, tx, _, err := vrf_v2plus_sub_owner.DeployVRFV2PlusExternalSubOwnerExample( e.Owner, e.Ec, common.HexToAddress(coordinatorAddress), - common.HexToAddress(linkAddress)) + common.HexToAddress(linkAddress), + ) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } @@ -156,7 +161,7 @@ func EoaFundSubWithLink( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("sub ID: %d", subID)) } -func EoaFundSubWithNative(e helpers.Environment, coordinatorAddress common.Address, subID *big.Int, amount *big.Int) { +func EoaFundSubWithNative(e helpers.Environment, coordinatorAddress common.Address, subID, amount *big.Int) { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorAddress, e.Ec) helpers.PanicErr(err) e.Owner.Value = amount @@ -221,7 +226,8 @@ func SetCoordinatorL1FeeCalculation( } func RegisterCoordinatorProvingKey(e helpers.Environment, - coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, uncompressed string, gasLaneMaxGas uint64) { + coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, uncompressed string, gasLaneMaxGas uint64, +) { pubBytes, err := hex.DecodeString(uncompressed) helpers.PanicErr(err) pk, err := crypto.UnmarshalPubkey(pubBytes) @@ -330,14 +336,14 @@ func WrapperConfigure( tx, err := wrapper.SetConfig( e.Owner, - uint32(wrapperGasOverhead), - uint32(coordinatorGasOverheadNative), - uint32(coordinatorGasOverheadLink), - uint16(coordinatorGasOverheadPerWord), - uint8(nativePremiumPercentage), - uint8(linkPremiumPercentage), + uint32(wrapperGasOverhead), //nolint:gosec // wrapper overhead fits in uint32 + uint32(coordinatorGasOverheadNative), //nolint:gosec // overhead fits in uint32 + uint32(coordinatorGasOverheadLink), //nolint:gosec // overhead fits in uint32 + uint16(coordinatorGasOverheadPerWord), //nolint:gosec // overhead fits in uint16 + uint8(nativePremiumPercentage), //nolint:gosec // percentage fits in uint8 + uint8(linkPremiumPercentage), //nolint:gosec // percentage fits in uint8 common.HexToHash(keyHash), - uint8(maxNumWords), + uint8(maxNumWords), //nolint:gosec // max words fits in uint8 stalenessSeconds, fallbackWeiPerUnitLink, fulfillmentFlatFeeNativePPM, diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_billing.go b/deployment/ccip/changeset/solana_v0_1_0/cs_billing.go index c6c21474e4c..e634d105d91 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_billing.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_billing.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - solBinary "github.com/gagliardetto/binary" "github.com/gagliardetto/solana-go" cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana" @@ -12,10 +11,8 @@ import ( cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - "github.com/smartcontractkit/mcms" mcmsTypes "github.com/smartcontractkit/mcms/types" - solRouter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/ccip_router" solFeeQuoter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/fee_quoter" solState "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/state" solTokenUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens" @@ -27,24 +24,6 @@ import ( solanastateview "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview/solana" ) -// use this changeset to add a billing token to solana -var _ cldf.ChangeSet[BillingTokenConfig] = AddBillingTokenChangeset - -// use this changeset to add a token transfer fee for a remote chain to solana (used for very specific cases) -var _ cldf.ChangeSet[TokenTransferFeeForRemoteChainConfig] = AddTokenTransferFeeForRemoteChain - -// use this changeset to withdraw billed funds on solana -var _ cldf.ChangeSet[WithdrawBilledFundsConfig] = WithdrawBilledFunds - -// use this changeset to update prices for token and gas price updates on solana (emergency use only) -var _ cldf.ChangeSet[UpdatePricesConfig] = UpdatePrices - -// use this changeset to set max fee juels per msg on solana (emergency use only) -var _ cldf.ChangeSet[SetMaxFeeJuelsPerMsgConfig] = SetMaxFeeJuelsPerMsg - -// use this changeset to update price updaters on solana (emergency use only) -var _ cldf.ChangeSet[ModifyPriceUpdaterConfig] = ModifyPriceUpdater - // ADD BILLING TOKEN type BillingTokenConfig struct { ChainSelector uint64 @@ -159,48 +138,6 @@ func AddBillingToken( return txns, nil } -func AddBillingTokenChangeset(e cldf.Environment, cfg BillingTokenConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - - runSafely(func() { - solFeeQuoter.SetProgramID(chainState.FeeQuoter) - }) - - txns, err := AddBillingToken(e, chain, chainState, cfg.Config, cfg.MCMS, cfg.IsUpdate, chainState.FeeQuoter, chainState.Router) - if err != nil { - return cldf.ChangesetOutput{}, err - } - - tokenPubKey := cfg.Config.Mint - tokenBillingPDA, _, _ := solState.FindFqBillingTokenConfigPDA(tokenPubKey, chainState.FeeQuoter) - if err := extendLookupTable(e, chain, chainState.OffRamp, []solana.PublicKey{tokenBillingPDA}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to extend lookup table: %w", err) - } - e.Logger.Infow("Billing token added", "chainSelector", cfg.ChainSelector, "tokenPubKey", tokenPubKey.String()) - - // create proposals for ixns - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to add billing token to Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - // ADD BILLING TOKEN FOR REMOTE CHAIN type TokenTransferFeeForRemoteChainConfig struct { ChainSelector uint64 @@ -235,483 +172,3 @@ func (cfg TokenTransferFeeForRemoteChainConfig) Validate(e cldf.Environment, sta return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.FeeQuoter: true}) } - -func AddTokenTransferFeeForRemoteChain(e cldf.Environment, cfg TokenTransferFeeForRemoteChainConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - tokenPubKey := cfg.TokenPubKey - remoteBillingPDA, _, _ := solState.FindFqPerChainPerTokenConfigPDA(cfg.RemoteChainSelector, tokenPubKey, chainState.FeeQuoter) - feeQuoterUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - runSafely(func() { - solFeeQuoter.SetProgramID(chainState.FeeQuoter) - }) - ix, err := solFeeQuoter.NewSetTokenTransferFeeConfigInstruction( - cfg.RemoteChainSelector, - tokenPubKey, - cfg.Config, - chainState.FeeQuoterConfigPDA, - remoteBillingPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - if !feeQuoterUsingMCMS { - if err := chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - } - if err := extendLookupTable(e, chain, chainState.OffRamp, []solana.PublicKey{remoteBillingPDA}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to extend lookup table: %w", err) - } - - e.Logger.Infow("Token billing set for remote chain", "chainSelector ", cfg.ChainSelector, "remoteChainSelector ", cfg.RemoteChainSelector, "tokenPubKey", tokenPubKey.String()) - - if feeQuoterUsingMCMS { - tx, err := BuildMCMSTxn(ix, chainState.FeeQuoter.String(), shared.FeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to set billing token for remote chain to Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - -// Price Update Changesets are in case of emergency as normally offramp will call this as part of normal operations -type UpdatePricesConfig struct { - ChainSelector uint64 - TokenPriceUpdates []solFeeQuoter.TokenPriceUpdate - GasPriceUpdates []solFeeQuoter.GasPriceUpdate - PriceUpdater solana.PublicKey - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg UpdatePricesConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateFeeQuoterConfig(chain); err != nil { - return err - } - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.FeeQuoter: true}); err != nil { - return err - } - if cfg.PriceUpdater.IsZero() { - return fmt.Errorf("price updater is zero for chain %d", cfg.ChainSelector) - } - var err error - for _, update := range cfg.TokenPriceUpdates { - billingConfigPDA, _, _ := solState.FindFqBillingTokenConfigPDA(update.SourceToken, chainState.FeeQuoter) - var token0ConfigAccount solFeeQuoter.BillingTokenConfigWrapper - err = chain.GetAccountDataBorshInto(e.GetContext(), billingConfigPDA, &token0ConfigAccount) - if err != nil { - return fmt.Errorf("failed to find billing token config for (mint: %s, feeQuoter: %s): %w", update.SourceToken.String(), chainState.FeeQuoter.String(), err) - } - } - for _, update := range cfg.GasPriceUpdates { - fqDestPDA, _, _ := solState.FindFqDestChainPDA(update.DestChainSelector, chainState.FeeQuoter) - var destChainConfig solFeeQuoter.DestChainConfig - err = chain.GetAccountDataBorshInto(e.GetContext(), fqDestPDA, &destChainConfig) - if err != nil { - return fmt.Errorf("failed to find dest chain config for (destSelector: %d, feeQuoter: %s): %w", update.DestChainSelector, chainState.FeeQuoter.String(), err) - } - } - - return nil -} - -func UpdatePrices(e cldf.Environment, cfg UpdatePricesConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, s); err != nil { - return cldf.ChangesetOutput{}, err - } - - chainSel := cfg.ChainSelector - chain := e.BlockChains.SolanaChains()[chainSel] - chainState := s.SolChains[chainSel] - feeQuoterID := s.SolChains[chainSel].FeeQuoter - feeQuoterUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - - // verified while loading state - fqAllowedPriceUpdaterPDA, _, _ := solState.FindFqAllowedPriceUpdaterPDA(cfg.PriceUpdater, feeQuoterID) - feeQuoterConfigPDA, _, _ := solState.FindFqConfigPDA(feeQuoterID) - - runSafely(func() { - solFeeQuoter.SetProgramID(feeQuoterID) - }) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - raw := solFeeQuoter.NewUpdatePricesInstruction( - cfg.TokenPriceUpdates, - cfg.GasPriceUpdates, - authority, - fqAllowedPriceUpdaterPDA, - feeQuoterConfigPDA, - ) - for _, update := range cfg.TokenPriceUpdates { - billingTokenConfigPDA, _, _ := solState.FindFqBillingTokenConfigPDA(update.SourceToken, feeQuoterID) - raw.Append(solana.Meta(billingTokenConfigPDA).WRITE()) - } - for _, update := range cfg.GasPriceUpdates { - fqDestPDA, _, _ := solState.FindFqDestChainPDA(update.DestChainSelector, feeQuoterID) - raw.Append(solana.Meta(fqDestPDA).WRITE()) - } - ix, err := raw.ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - - if feeQuoterUsingMCMS { - tx, err := BuildMCMSTxn(ix, s.SolChains[chainSel].FeeQuoter.String(), shared.FeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to NewUpdatePricesInstruction in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err = chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, err - } - return cldf.ChangesetOutput{}, nil -} - -type ModifyPriceUpdaterConfig struct { - ChainSelector uint64 - PriceUpdater solana.PublicKey // price updater to add or remove - PriceUpdaterAction PriceUpdaterAction // add or remove price updater - MCMS *cldfproposalutils.TimelockConfig -} - -type PriceUpdaterAction int - -const ( - AddUpdater PriceUpdaterAction = iota - RemoveUpdater -) - -func (cfg ModifyPriceUpdaterConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateFeeQuoterConfig(chain); err != nil { - return err - } - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.FeeQuoter: true}); err != nil { - return err - } - if cfg.PriceUpdater.IsZero() { - return fmt.Errorf("price updater is zero for chain %d", cfg.ChainSelector) - } - return nil -} - -func ModifyPriceUpdater(e cldf.Environment, cfg ModifyPriceUpdaterConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, s); err != nil { - return cldf.ChangesetOutput{}, err - } - - chainSel := cfg.ChainSelector - chain := e.BlockChains.SolanaChains()[chainSel] - chainState := s.SolChains[chainSel] - feeQuoterID := s.SolChains[chainSel].FeeQuoter - feeQuoterUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - - // verified while loading state - fqAllowedPriceUpdaterPDA, _, _ := solState.FindFqAllowedPriceUpdaterPDA(cfg.PriceUpdater, feeQuoterID) - feeQuoterConfigPDA, _, _ := solState.FindFqConfigPDA(feeQuoterID) - - runSafely(func() { - solFeeQuoter.SetProgramID(feeQuoterID) - }) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "", - ) - var ix solana.Instruction - if cfg.PriceUpdaterAction == AddUpdater { - ix, err = solFeeQuoter.NewAddPriceUpdaterInstruction( - cfg.PriceUpdater, - fqAllowedPriceUpdaterPDA, - feeQuoterConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - } else { - ix, err = solFeeQuoter.NewRemovePriceUpdaterInstruction( - cfg.PriceUpdater, - fqAllowedPriceUpdaterPDA, - feeQuoterConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - } - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - - if feeQuoterUsingMCMS { - tx, err := BuildMCMSTxn(ix, s.SolChains[chainSel].FeeQuoter.String(), shared.FeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to NewUpdatePricesInstruction in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err = chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, err - } - return cldf.ChangesetOutput{}, nil -} - -type WithdrawBilledFundsConfig struct { - ChainSelector uint64 - TransferAll bool // transfer all or specific amount - Amount uint64 // amount to transfer - TokenPubKey solana.PublicKey // billing token to transfer - MCMS *cldfproposalutils.TimelockConfig // timelock config for mcms -} - -func (cfg WithdrawBilledFundsConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - tokenPubKey := cfg.TokenPubKey - chainState := state.SolChains[cfg.ChainSelector] - if err := chainState.CommonValidation(e, cfg.ChainSelector, tokenPubKey); err != nil { - return err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - if err := chainState.ValidateFeeAggregatorConfig(chain); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true}) -} - -func WithdrawBilledFunds(e cldf.Environment, cfg WithdrawBilledFundsConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, s); err != nil { - return cldf.ChangesetOutput{}, err - } - - chainSel := cfg.ChainSelector - chain := e.BlockChains.SolanaChains()[chainSel] - chainState := s.SolChains[cfg.ChainSelector] - tokenPubKey := cfg.TokenPubKey - billingSignerPDA, _, _ := solState.FindFeeBillingSignerPDA(chainState.Router) - tokenProgramID, _ := chainState.TokenToTokenProgram(tokenPubKey) - tokenReceiverPDA, _, _ := solTokenUtil.FindAssociatedTokenAddress(tokenProgramID, tokenPubKey, billingSignerPDA) - feeAggregatorATA, _, _ := solTokenUtil.FindAssociatedTokenAddress(tokenProgramID, tokenPubKey, chainState.GetFeeAggregator(chain)) - routerConfigPDA, _, _ := solState.FindConfigPDA(chainState.Router) - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "", - ) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get authority for ixn: %w", err) - } - ix, err := solRouter.NewWithdrawBilledFundsInstruction( - cfg.TransferAll, - cfg.Amount, - tokenPubKey, - tokenReceiverPDA, - feeAggregatorATA, - tokenProgramID, - billingSignerPDA, - routerConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(ix, s.SolChains[chainSel].Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to WithdrawBilledFunds in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err = chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, err - } - return cldf.ChangesetOutput{}, nil -} - -type SetMaxFeeJuelsPerMsgConfig struct { - ChainSelector uint64 - MaxFeeJuelsPerMsg solBinary.Uint128 - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg SetMaxFeeJuelsPerMsgConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState, chainExists := state.SolChains[cfg.ChainSelector] - if !chainExists { - return fmt.Errorf("chain %d not found in existing state", cfg.ChainSelector) - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - - if err := chainState.ValidateFeeQuoterConfig(chain); err != nil { - return err - } - - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.FeeQuoter: true}) -} - -func SetMaxFeeJuelsPerMsg(e cldf.Environment, cfg SetMaxFeeJuelsPerMsgConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - - fqConfig, _, _ := solState.FindConfigPDA(chainState.FeeQuoter) - fqUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - - runSafely(func() { - solFeeQuoter.SetProgramID(chainState.FeeQuoter) - }) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - instruction, err := solFeeQuoter.NewSetMaxFeeJuelsPerMsgInstruction( - cfg.MaxFeeJuelsPerMsg, - fqConfig, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if fqUsingMCMS { - tx, err := BuildMCMSTxn(instruction, chainState.FeeQuoter.String(), shared.FeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to SetMaxFeeJuelsPerMsg in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm([]solana.Instruction{instruction}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_deploy_chain.go b/deployment/ccip/changeset/solana_v0_1_0/cs_deploy_chain.go index 1431bc43c73..689283e6e1f 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_deploy_chain.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_deploy_chain.go @@ -47,9 +47,6 @@ import ( // use this changeset to deploy the CCIP contracts on solana var _ cldf.ChangeSet[DeployChainContractsConfig] = DeployChainContractsChangeset -// use this changeset to extend the global lookup table in case of emergency -var _ cldf.ChangeSet[ExtendGlobalLookupTableConfig] = ExtendGlobalLookupTableChangeset - func getTypeToProgramDeployName() map[cldf.ContractType]string { return map[cldf.ContractType]string{ shared.Router: solutils.ProgCCIPRouter, @@ -1119,45 +1116,3 @@ func getSolProgramData(e cldf.Environment, chain cldf_solana.Chain, programID so } return programData, nil } - -type CloseBuffersConfig struct { - ChainSelector uint64 - Buffers []string -} - -func CloseBuffersChangeset(e cldf.Environment, cfg CloseBuffersConfig) (cldf.ChangesetOutput, error) { - for _, buffer := range cfg.Buffers { - if err := e.BlockChains.SolanaChains()[cfg.ChainSelector].CloseBuffers(e.Logger, buffer); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to close buffer: %w", err) - } - } - return cldf.ChangesetOutput{}, nil -} - -// In case of emergency, this changeset can be used to extend the global lookup table -// by default the LUT is extended by the changesets that perform other operations -type ExtendGlobalLookupTableConfig struct { - ChainSelector uint64 - LookupTableKeys []solana.PublicKey -} - -func ExtendGlobalLookupTableChangeset(e cldf.Environment, cfg ExtendGlobalLookupTableConfig) (cldf.ChangesetOutput, error) { - chain, ok := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if !ok { - return cldf.ChangesetOutput{}, fmt.Errorf("chain not found for selector %d", cfg.ChainSelector) - } - existingState, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - chainState, ok := existingState.SolChains[chain.Selector] - if !ok { - return cldf.ChangesetOutput{}, fmt.Errorf("chain state not found for selector %d", chain.Selector) - } - - if err := extendLookupTable(e, chain, chainState.OffRamp, cfg.LookupTableKeys); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to extend lookup table: %w", err) - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_e2e.go b/deployment/ccip/changeset/solana_v0_1_0/cs_e2e.go index 600eeefc1de..ddabbc89bc0 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_e2e.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_e2e.go @@ -1,10 +1,8 @@ package solana import ( - "errors" "fmt" - "github.com/gagliardetto/solana-go" proposeutils "github.com/smartcontractkit/cld-changesets/legacy/mcms/proposeutils" "github.com/smartcontractkit/mcms" @@ -13,7 +11,6 @@ import ( "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_5_1" - "github.com/smartcontractkit/chainlink/deployment/ccip/shared" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" ) @@ -141,261 +138,3 @@ func AggregateAndCleanup(e cldf.Environment, finalOutput *cldf.ChangesetOutput, } return nil } - -type E2ETokenConfig struct { - TokenPubKey solana.PublicKey - Metadata string - PoolType cldf.ContractType - // evm chain id -> evm remote config - SolanaToEVMRemoteConfigs map[uint64]EVMRemoteConfig - // solana remote config for evm pool - EVMToSolanaRemoteConfigs v1_5_1.ConfigureTokenPoolContractsConfig -} - -func (cfg E2ETokenConfig) Validate() error { - if cfg.PoolType == "" { - return errors.New("pool type is required") - } - if cfg.TokenPubKey.IsZero() { - return errors.New("token pubkey is required") - } - if cfg.Metadata == "" { - return errors.New("metadata is required") - } - return nil -} - -type E2ETokenPoolConfigv2 struct { - ChainSelector uint64 - E2ETokens []E2ETokenConfig - // this determines whether we want to set timelock as token admin or not - // this is also required if router is owned by timelock - // so you cannot really have a case where router is owned by timelock but you want to - // set deployer key as token admin - MCMS *cldfproposalutils.TimelockConfig -} - -func E2ETokenPoolv2(env cldf.Environment, cfg E2ETokenPoolConfigv2) (cldf.ChangesetOutput, error) { - // use a clone of env to avoid modifying the original env - // if you modify the original env, the in memory tests will fail - // because after the changeset is complete and the ApplyChangesets function is called, - // it will try to add addresses from the cs output which already exist in the env - e := env.Clone() - finalCSOut := &cldf.ChangesetOutput{ - AddressBook: cldf.NewMemoryAddressBook(), - } - - // token pool and lookup table - tokenPoolAndLookupTableCfg := AddTokenPoolAndLookupTableConfig{ - ChainSelector: cfg.ChainSelector, - TokenPoolConfigs: make([]TokenPoolConfig, 0), - } - - // register token admin registry - registerTokenAdminRegistryCfg := RegisterTokenAdminRegistryConfig{ - ChainSelector: cfg.ChainSelector, - MCMS: cfg.MCMS, - RegisterTokenConfigs: make([]RegisterTokenConfig, 0), - } - var tokenAdminRegistryAdmin solana.PublicKey - timelockSignerPDA, err := FetchTimelockSigner(e, cfg.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to fetch timelock signer: %w", err) - } - if cfg.MCMS != nil { - tokenAdminRegistryAdmin = timelockSignerPDA - } else { - tokenAdminRegistryAdmin = e.BlockChains.SolanaChains()[cfg.ChainSelector].DeployerKey.PublicKey() - } - - // accept admin role token admin registry - acceptAdminRoleTokenAdminRegistryCfg := AcceptAdminRoleTokenAdminRegistryConfig{ - ChainSelector: cfg.ChainSelector, - MCMS: cfg.MCMS, - AcceptAdminRoleTokenConfigs: make([]AcceptAdminRoleTokenConfig, 0), - } - - // set pool - setPoolCfg := SetPoolConfig{ - ChainSelector: cfg.ChainSelector, - SetPoolTokenConfigs: make([]SetPoolTokenConfig, 0), - WritableIndexes: []uint8{3, 4, 7}, - MCMS: cfg.MCMS, - } - - // solana to evm remote pool setup - remotePoolConfig := SetupTokenPoolForRemoteChainConfig{ - SolChainSelector: cfg.ChainSelector, - RemoteTokenPoolConfigs: make([]RemoteChainTokenPoolConfig, 0), - MCMS: cfg.MCMS, - } - - // evm to solana remote pool setup - evmToSolanaRemotePoolCfg := v1_5_1.ConfigureMultipleTokenPoolsConfig{ - MCMS: cfg.MCMS, - } - - // transfer away the pool to timelock - var transferPoolToTimelockConfig TransferCCIPToMCMSWithTimelockSolanaConfig - if cfg.MCMS != nil { - transferPoolToTimelockConfig = TransferCCIPToMCMSWithTimelockSolanaConfig{ - MCMSCfg: *cfg.MCMS, - ContractsByChain: map[uint64]CCIPContractsToTransfer{ - cfg.ChainSelector: { - BurnMintTokenPools: map[string][]solana.PublicKey{}, - LockReleaseTokenPools: map[string][]solana.PublicKey{}, - }, - }, - } - } - poolsByType := transferPoolToTimelockConfig.ContractsByChain[cfg.ChainSelector] - - var uniquePoolTypeConfigs []E2ETokenConfig - for _, tokenCfg := range cfg.E2ETokens { - if err := tokenCfg.Validate(); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to validate token config: %w, token cfg: %+v", err, tokenCfg) - } - // add token pool and lookup table - tokenPoolAndLookupTableCfg.TokenPoolConfigs = append(tokenPoolAndLookupTableCfg.TokenPoolConfigs, TokenPoolConfig{ - PoolType: tokenCfg.PoolType, - Metadata: tokenCfg.Metadata, - TokenPubKey: tokenCfg.TokenPubKey, - }) - // register token admin registry - registerTokenAdminRegistryCfg.RegisterTokenConfigs = append(registerTokenAdminRegistryCfg.RegisterTokenConfigs, RegisterTokenConfig{ - TokenPubKey: tokenCfg.TokenPubKey, - RegisterType: ViaGetCcipAdminInstruction, - TokenAdminRegistryAdmin: tokenAdminRegistryAdmin, - }) - // accept admin role token admin registry - acceptAdminRoleTokenAdminRegistryCfg.AcceptAdminRoleTokenConfigs = append(acceptAdminRoleTokenAdminRegistryCfg.AcceptAdminRoleTokenConfigs, AcceptAdminRoleTokenConfig{ - TokenPubKey: tokenCfg.TokenPubKey, - // registering in the same changeset so skip registry check - SkipRegistryCheck: true, - }) - // set pool - setPoolCfg.SetPoolTokenConfigs = append(setPoolCfg.SetPoolTokenConfigs, SetPoolTokenConfig{ - TokenPubKey: tokenCfg.TokenPubKey, - PoolType: tokenCfg.PoolType, - Metadata: tokenCfg.Metadata, - // registering in the same changeset so skip registry check - SkipRegistryCheck: true, - }) - // setup evm remote pool on solana - if len(tokenCfg.SolanaToEVMRemoteConfigs) > 0 { - remotePoolConfig.RemoteTokenPoolConfigs = append(remotePoolConfig.RemoteTokenPoolConfigs, RemoteChainTokenPoolConfig{ - SolTokenPubKey: tokenCfg.TokenPubKey, - SolPoolType: tokenCfg.PoolType, - Metadata: tokenCfg.Metadata, - EVMRemoteConfigs: tokenCfg.SolanaToEVMRemoteConfigs, - }) - } - // setup solana remote pool on evm - if len(tokenCfg.EVMToSolanaRemoteConfigs.PoolUpdates) > 0 { - evmToSolanaRemotePoolCfg.Tokens = append(evmToSolanaRemotePoolCfg.Tokens, &tokenCfg.EVMToSolanaRemoteConfigs) - } - // transfer pool to timelock - if cfg.MCMS != nil { - if tokenCfg.PoolType == shared.BurnMintTokenPool { - poolsByType.BurnMintTokenPools[tokenCfg.Metadata] = append( - poolsByType.BurnMintTokenPools[tokenCfg.Metadata], - tokenCfg.TokenPubKey, - ) - } else { // lock and release pool - poolsByType.LockReleaseTokenPools[tokenCfg.Metadata] = append( - poolsByType.LockReleaseTokenPools[tokenCfg.Metadata], - tokenCfg.TokenPubKey, - ) - } - } - isUniquePoolType := true - for _, uniqueCfg := range uniquePoolTypeConfigs { - if uniqueCfg.PoolType == tokenCfg.PoolType { - isUniquePoolType = false - } - } - if isUniquePoolType { - uniquePoolTypeConfigs = append(uniquePoolTypeConfigs, tokenCfg) - } - } - output, err := AddTokenPoolAndLookupTable(e, tokenPoolAndLookupTableCfg) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to add token pool and lookup table: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running AddTokenPoolAndLookupTable: %w", err) - } - output, err = SetupTokenPoolForRemoteChain(e, remotePoolConfig) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to setup token pool for remote chain: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running SetupTokenPoolForRemoteChain: %w", err) - } - output, err = RegisterTokenAdminRegistry(e, registerTokenAdminRegistryCfg) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to register token admin registry: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running RegisterTokenAdminRegistry: %w", err) - } - output, err = AcceptAdminRoleTokenAdminRegistry(e, acceptAdminRoleTokenAdminRegistryCfg) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to accept admin role: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running AcceptAdminRoleTokenAdminRegistry: %w", err) - } - output, err = SetPool(e, setPoolCfg) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to set pool: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running SetPool: %w", err) - } - output, err = v1_5_1.ConfigureMultiplePoolLogic(e, evmToSolanaRemotePoolCfg) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to configure token pool contracts: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running ConfigureTokenPoolContractsChangeset: %w", err) - } - // and finally lets transfer away the pool to timelock - if cfg.MCMS != nil { - output, err = TransferCCIPToMCMSWithTimelockSolana(e, transferPoolToTimelockConfig) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to transfer ccip to mcms with timelock: %w", err) - } - if err = changeset.MergeChangesetOutput(e, finalCSOut, output); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to merge changeset output after running TransferCCIPToMCMSWithTimelockSolana: %w", err) - } - } - - if len(finalCSOut.MCMSTimelockProposals) > 1 { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - proposal, err := proposeutils.AggregateProposalsV2( - e, proposeutils.MCMSStates{ - MCMSEVMState: state.EVMMCMSStateByChain(), - MCMSSolanaState: state.SolanaMCMSStateByChain(e), - }, - finalCSOut.MCMSTimelockProposals, "E2ETokenPoolv2 changeset", cfg.MCMS, - ) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to aggregate proposals: %w", err) - } - if proposal != nil { - finalCSOut.MCMSTimelockProposals = []mcms.TimelockProposal{*proposal} - } - } - - // Preserve the datastore accumulated by MergeChangesetOutput: it carries the - // sub-changesets' semantic qualifiers, metadata, and deletions. Every merged sub-changeset - // that produces an address writes it natively (AddTokenPoolAndLookupTable records the - // lookup tables under their full (mint, pool type, metadata) qualifier; the registry, - // remote-chain and ownership changesets deploy nothing). Rebuilding from the merged - // address book could only mint address-derived qualifiers, so nothing is re-derived. - return *finalCSOut, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_idl.go b/deployment/ccip/changeset/solana_v0_1_0/cs_idl.go deleted file mode 100644 index 722407e6af4..00000000000 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_idl.go +++ /dev/null @@ -1,649 +0,0 @@ -package solana - -import ( - "encoding/binary" - "encoding/json" - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/gagliardetto/solana-go" - "github.com/pelletier/go-toml" - chainsel "github.com/smartcontractkit/chain-selectors" - solstate "github.com/smartcontractkit/cld-changesets/legacy/pkg/family/solana" - "github.com/smartcontractkit/mcms" - mcmsTypes "github.com/smartcontractkit/mcms/types" - - cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana" - cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - cldfproposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils" - - "github.com/smartcontractkit/chainlink/deployment/ccip/shared" - "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" - "github.com/smartcontractkit/chainlink/deployment/common/types" - "github.com/smartcontractkit/chainlink/deployment/utils/solutils" -) - -// use this changeset to upload the IDL for a program -var _ cldf.ChangeSet[IDLConfig] = UploadIDL - -// use this changeset to set the authority for the IDL of a program (timelock) -var _ cldf.ChangeSet[IDLConfig] = SetAuthorityIDL - -// use this changeset to upgrade the IDL of a program via timelock -var _ cldf.ChangeSet[IDLConfig] = UpgradeIDL - -const IdlIxTag uint64 = 0x0a69e9a778bcf440 - -// IDL -type IDLConfig struct { - ChainSelector uint64 - GitCommitSha string // this will be used to download the correct artifacts (idls) -> best if same as what was used to deploy the programs - Router bool // whether to upload the IDL for the router - FeeQuoter bool // whether to upload the IDL for the fee quoter - OffRamp bool // whether to upload the IDL for the off ramp - RMNRemote bool // whether to upload the IDL for the rmn remote - AccessController bool // whether to upload the IDL for the access controller - MCM bool // whether to upload the IDL for the mcm - Timelock bool // whether to upload the IDL for the timelock - BurnMintTokenPoolMetadata []string // whether to upload the IDL for the token pool (keyed my client identifier (metadata)) - LockReleaseTokenPoolMetadata []string // metadata for the lock release token pool (keyed my client identifier (metadata)) - MCMS *cldfproposalutils.TimelockConfig // timelock config for mcms -} - -// parse anchor version from running anchor --version -func parseAnchorVersion(output string) (string, error) { - const prefix = "anchor-cli " - if after, ok := strings.CutPrefix(output, prefix); ok { - return strings.TrimSpace(after), nil - } - return "", fmt.Errorf("unexpected version output: %q", output) -} - -// create Anchor.toml file to simulate anchor workspace -func writeAnchorToml(e cldf.Environment, filename, anchorVersion, cluster, wallet string) error { - e.Logger.Debugw("Writing Anchor.toml", "filename", filename, "anchorVersion", anchorVersion, "cluster", cluster, "wallet", wallet) - config := map[string]any{ - "toolchain": map[string]string{ - "anchor_version": anchorVersion, - }, - "provider": map[string]string{ - "cluster": cluster, - "wallet": wallet, - }, - } - e.Logger.Debugw("Anchor.toml config", "config", config) - - tree, err := toml.TreeFromMap(config) - if err != nil { - return fmt.Errorf("failed to build TOML tree: %w", err) - } - - file, err := os.Create(filename) - if err != nil { - return fmt.Errorf("failed to create TOML file: %w", err) - } - defer file.Close() - - if _, err := tree.WriteTo(file); err != nil { - return fmt.Errorf("failed to write TOML to file: %w", err) - } - - return nil -} - -// resolve artifacts based on sha and write anchor.toml file to simulate anchor workspace -func repoSetup(e cldf.Environment, chain cldf_solana.Chain, gitCommitSha string) error { - e.Logger.Debug("Downloading Solana CCIP program artifacts...") - err := solutils.DownloadChainlinkCCIPProgramArtifacts(e.GetContext(), chain.ProgramsPath, gitCommitSha, e.Logger) - if err != nil { - return fmt.Errorf("error downloading solana ccip program artifacts: %w", err) - } - - // get anchor version - output, err := runCommand("anchor", []string{"--version"}, ".") - if err != nil { - return errors.New("anchor-cli not installed in path") - } - e.Logger.Debugw("Anchor version command output", "output", output) - anchorVersion, err := parseAnchorVersion(output) - if err != nil { - return fmt.Errorf("error parsing anchor version: %w", err) - } - // create Anchor.toml - // this creates anchor workspace with cluster and wallet configured - if err := writeAnchorToml(e, filepath.Join(chain.ProgramsPath, "Anchor.toml"), anchorVersion, chain.URL, chain.KeypairPath); err != nil { - return fmt.Errorf("error writing Anchor.toml: %w", err) - } - - return nil -} - -// update IDL with program ID -func updateIDL(e cldf.Environment, idlFile string, programID string) error { - e.Logger.Debug("Reading IDL") - idlBytes, err := os.ReadFile(idlFile) - if err != nil { - return fmt.Errorf("failed to read IDL: %w", err) - } - e.Logger.Debug("Parsing IDL") - var idl map[string]any - if err := json.Unmarshal(idlBytes, &idl); err != nil { - return fmt.Errorf("failed to parse legacy IDL: %w", err) - } - e.Logger.Debugw("Updating IDL with programID", "programID", programID) - idl["metadata"] = map[string]any{ - "address": programID, - } - // Marshal updated IDL back to JSON - e.Logger.Debug("Marshalling updated IDL") - updatedIDLBytes, err := json.MarshalIndent(idl, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal updated IDL: %w", err) - } - e.Logger.Debug("Writing updated IDL") - // Write updated IDL back to file - if err := os.WriteFile(idlFile, updatedIDLBytes, 0600); err != nil { - return fmt.Errorf("failed to write updated IDL: %w", err) - } - return nil -} - -// get IDL file and update with program ID -func getIDL(e cldf.Environment, programsPath, programID string, programName string) (string, error) { - idlFile := filepath.Join(programsPath, programName+".json") - if _, err := os.Stat(idlFile); err != nil { - return "", fmt.Errorf("idl file not found: %w", err) - } - e.Logger.Debug("Updating IDL") - err := updateIDL(e, idlFile, programID) - if err != nil { - return "", fmt.Errorf("error updating IDL: %w", err) - } - return idlFile, nil -} - -// initialize IDL for a program -func idlInit(e cldf.Environment, programsPath, programID, programName string) error { - idlFile, err := getIDL(e, programsPath, programID, programName) - if err != nil { - return fmt.Errorf("error getting IDL: %w", err) - } - e.Logger.Infow("Uploading IDL", "programName", programName) - args := []string{"idl", "init", "--filepath", idlFile, programID} - e.Logger.Info(args) - output, err := runCommand("anchor", args, programsPath) - e.Logger.Debugw("IDL init output", "output", output) - if err != nil { - e.Logger.Debugw("IDL init error", "error", err) - return fmt.Errorf("error uploading idl: %w", err) - } - e.Logger.Infow("IDL uploaded", "programName", programName) - return nil -} - -// set IDL authority for a program -func setIdlAuthority(e cldf.Environment, newAuthority, programsPath, programID, programName, bufferAccount string) error { - e.Logger.Infow("Setting IDL authority", "programName", programName, "newAuthority", newAuthority) - args := []string{"idl", "set-authority", "-n", newAuthority, "-p", programID} - if bufferAccount != "" { - e.Logger.Infow("Setting IDL authority for buffer", "bufferAccount", bufferAccount) - args = append(args, bufferAccount) - } - e.Logger.Info(args) - _, err := runCommand("anchor", args, programsPath) - if err != nil { - return fmt.Errorf("error setting idl authority: %w", err) - } - return nil -} - -// get IDL address for a program -func getIDLAddress(e cldf.Environment, programID solana.PublicKey) (solana.PublicKey, error) { - base, _, _ := solana.FindProgramAddress([][]byte{}, programID) - idlAddress, _ := solana.CreateWithSeed(base, "anchor:idl", programID) - e.Logger.Infof("IDL Address: %s", idlAddress.String()) - return idlAddress, nil -} - -// parse IDL buffer from `anchor idl write-buffer` output -func parseIdlBuffer(output string) (string, error) { - const prefix = "Idl buffer created: " - for line := range strings.SplitSeq(output, "\n") { - if after, ok := strings.CutPrefix(line, prefix); ok { - return strings.TrimSpace(after), nil - } - } - return "", errors.New("failed to find IDL buffer in output") -} - -// write IDL buffer for a program -func writeBuffer(e cldf.Environment, programsPath, programID, programName string) (solana.PublicKey, error) { - idlFile, err := getIDL(e, programsPath, programID, programName) - if err != nil { - return solana.PublicKey{}, fmt.Errorf("error getting IDL: %w", err) - } - e.Logger.Infow("Writing IDL buffer", "programID", programID) - args := []string{"idl", "write-buffer", "--filepath", idlFile, programID} - e.Logger.Info(args) - output, err := runCommand("anchor", args, programsPath) - if err != nil { - return solana.PublicKey{}, fmt.Errorf("error writing IDL buffer: %w", err) - } - e.Logger.Infow("Parsing IDL buffer", "programID", programID) - buffer, err := parseIdlBuffer(output) - if err != nil { - return solana.PublicKey{}, fmt.Errorf("error parsing IDL buffer: %w", err) - } - bufferAddress, err := solana.PublicKeyFromBase58(buffer) - if err != nil { - return solana.PublicKey{}, fmt.Errorf("error parsing IDL buffer: %w", err) - } - return bufferAddress, nil -} - -// generate set buffer ix using solana-go sdk -func setBufferIx(e cldf.Environment, programID, buffer, authority solana.PublicKey) (solana.GenericInstruction, error) { - idlAddress, err := getIDLAddress(e, programID) - if err != nil { - return solana.GenericInstruction{}, fmt.Errorf("error getting idl address for %s: %w", programID.String(), err) - } - data := binary.LittleEndian.AppendUint64([]byte{}, IdlIxTag) // 4-byte Extend instruction identifier - data = append(data, byte(3)) - - instruction := solana.NewInstruction( - programID, - solana.AccountMetaSlice{ - solana.NewAccountMeta(buffer, true, false), - solana.NewAccountMeta(idlAddress, true, false), - solana.NewAccountMeta(authority, false, true), - }, - data, - ) - return *instruction, nil -} - -// generate upgrade IDL ix for a program via timelock -func upgradeIDLIx(e cldf.Environment, programsPath, programID, programName string, c IDLConfig) (*mcmsTypes.Transaction, error) { - timelockSignerPDA, err := FetchTimelockSigner(e, c.ChainSelector) - if err != nil { - return nil, fmt.Errorf("error loading timelockSignerPDA: %w", err) - } - buffer, err := writeBuffer(e, programsPath, programID, programName) - if err != nil { - return nil, fmt.Errorf("error writing buffer: %w", err) - } - authority := e.BlockChains.SolanaChains()[c.ChainSelector].DeployerKey.PublicKey() - if c.MCMS != nil { - authority = timelockSignerPDA - err = setIdlAuthority(e, timelockSignerPDA.String(), programsPath, programID, programName, buffer.String()) - if err != nil { - return nil, fmt.Errorf("error setting buffer authority: %w", err) - } - } - instruction, err := setBufferIx(e, solana.MustPublicKeyFromBase58(programID), buffer, authority) - if err != nil { - return nil, fmt.Errorf("error generating set buffer ix: %w", err) - } - if c.MCMS != nil { - upgradeTx, err := BuildMCMSTxn(&instruction, programID, cldf.ContractType(programName)) - if err != nil { - return nil, fmt.Errorf("failed to create upgrade transaction: %w", err) - } - return upgradeTx, nil - } - if err := e.BlockChains.SolanaChains()[c.ChainSelector].Confirm([]solana.Instruction{&instruction}); err != nil { - return nil, fmt.Errorf("failed to confirm instructions: %w", err) - } - return nil, nil -} - -func (c IDLConfig) Validate(e cldf.Environment) error { - if err := cldf.IsValidChainSelector(c.ChainSelector); err != nil { - return fmt.Errorf("invalid chain selector: %d - %w", c.ChainSelector, err) - } - family, _ := chainsel.GetSelectorFamily(c.ChainSelector) - if family != chainsel.FamilySolana { - return fmt.Errorf("chain %d is not a solana chain", c.ChainSelector) - } - existingState, err := stateview.LoadOnchainState(e) - if err != nil { - return fmt.Errorf("failed to load existing onchain state: %w", err) - } - if _, exists := existingState.SupportedChains()[c.ChainSelector]; !exists { - return fmt.Errorf("chain %d not supported", c.ChainSelector) - } - chainState := existingState.SolChains[c.ChainSelector] - chain := e.BlockChains.SolanaChains()[c.ChainSelector] - if c.Router && chainState.Router.IsZero() { - return fmt.Errorf("router not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - if c.FeeQuoter && chainState.FeeQuoter.IsZero() { - return fmt.Errorf("feeQuoter not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - if c.OffRamp && chainState.OffRamp.IsZero() { - return fmt.Errorf("offRamp not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - if c.RMNRemote && chainState.RMNRemote.IsZero() { - return fmt.Errorf("rmnRemote not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - for _, bnmMetadata := range c.BurnMintTokenPoolMetadata { - bnmTokenPool := chainState.GetActiveTokenPool(shared.BurnMintTokenPool, bnmMetadata) - if bnmTokenPool.IsZero() { - return fmt.Errorf("burnMintTokenPool not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - } - for _, lrMetadata := range c.LockReleaseTokenPoolMetadata { - lrTokenPool := chainState.GetActiveTokenPool(shared.LockReleaseTokenPool, lrMetadata) - if lrTokenPool.IsZero() { - return fmt.Errorf("lockReleaseTokenPool not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - } - addresses, err := e.ExistingAddresses.AddressesForChain(c.ChainSelector) - if err != nil { - return fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(e.BlockChains.SolanaChains()[c.ChainSelector], addresses) - if err != nil { - return fmt.Errorf("failed to load MCMS with timelock chain state: %w", err) - } - if c.MCM && mcmState.McmProgram.IsZero() { - return fmt.Errorf("mcm program not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - if c.Timelock && mcmState.TimelockProgram.IsZero() { - return fmt.Errorf("timelock program not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - if c.AccessController && mcmState.AccessControllerProgram.IsZero() { - return fmt.Errorf("access controller program not deployed for chain %d, cannot upload idl", c.ChainSelector) - } - - return repoSetup(e, chain, c.GitCommitSha) -} - -// changeset to upload idl for a program -func UploadIDL(e cldf.Environment, c IDLConfig) (cldf.ChangesetOutput, error) { - if err := c.Validate(e); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error validating idl config: %w", err) - } - chain := e.BlockChains.SolanaChains()[c.ChainSelector] - state, _ := stateview.LoadOnchainState(e) - chainState := state.SolChains[c.ChainSelector] - - // start uploading - if c.Router { - err := idlInit(e, chain.ProgramsPath, chainState.Router.String(), solutils.ProgCCIPRouter) - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.FeeQuoter { - err := idlInit(e, chain.ProgramsPath, chainState.FeeQuoter.String(), solutils.ProgFeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - if c.OffRamp { - err := idlInit(e, chain.ProgramsPath, chainState.OffRamp.String(), solutils.ProgCCIPOfframp) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - if c.RMNRemote { - err := idlInit(e, chain.ProgramsPath, chainState.RMNRemote.String(), solutils.ProgRMNRemote) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - for _, bnmMetadata := range c.BurnMintTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.BurnMintTokenPool, bnmMetadata) - err := idlInit(e, chain.ProgramsPath, tokenPool.String(), solutils.ProgBurnMintTokenPool) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - for _, lrMetadata := range c.LockReleaseTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.LockReleaseTokenPool, lrMetadata) - err := idlInit(e, chain.ProgramsPath, tokenPool.String(), solutils.ProgLockReleaseTokenPool) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - addresses, err := e.ExistingAddresses.AddressesForChain(c.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(e.BlockChains.SolanaChains()[c.ChainSelector], addresses) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load MCMS with timelock chain state: %w", err) - } - if c.MCM { - err := idlInit(e, chain.ProgramsPath, mcmState.McmProgram.String(), solutils.ProgMCM) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - if c.Timelock { - err := idlInit(e, chain.ProgramsPath, mcmState.TimelockProgram.String(), solutils.ProgTimelock) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - if c.AccessController { - err := idlInit(e, chain.ProgramsPath, mcmState.AccessControllerProgram.String(), solutils.ProgAccessController) - if err != nil { - return cldf.ChangesetOutput{}, nil - } - } - - return cldf.ChangesetOutput{}, nil -} - -// changeset to set idl authority for a program to timelock -func SetAuthorityIDL(e cldf.Environment, c IDLConfig) (cldf.ChangesetOutput, error) { - if err := c.Validate(e); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error validating idl config: %w", err) - } - state, _ := stateview.LoadOnchainState(e) - chainState := state.SolChains[c.ChainSelector] - chain := e.BlockChains.SolanaChains()[c.ChainSelector] - - timelockSignerPDA, err := FetchTimelockSigner(e, c.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error loading timelockSignerPDA: %w", err) - } - - // set idl authority - if c.Router { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, chainState.Router.String(), solutils.ProgCCIPRouter, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.FeeQuoter { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, chainState.FeeQuoter.String(), solutils.ProgFeeQuoter, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.OffRamp { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, chainState.OffRamp.String(), solutils.ProgCCIPOfframp, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.RMNRemote { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, chainState.RMNRemote.String(), solutils.ProgRMNRemote, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - for _, bnmMetadata := range c.BurnMintTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.BurnMintTokenPool, bnmMetadata) - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, tokenPool.String(), solutils.ProgBurnMintTokenPool, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - for _, lrMetadata := range c.LockReleaseTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.LockReleaseTokenPool, lrMetadata) - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, tokenPool.String(), solutils.ProgLockReleaseTokenPool, "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - - addresses, err := e.ExistingAddresses.AddressesForChain(chain.Selector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(chain, addresses) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load MCMS with timelock chain state: %w", err) - } - - if c.AccessController { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, mcmState.AccessControllerProgram.String(), types.AccessControllerProgram.String(), "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.Timelock { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, mcmState.TimelockProgram.String(), types.RBACTimelockProgram.String(), "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - if c.MCM { - err = setIdlAuthority(e, timelockSignerPDA.String(), chain.ProgramsPath, mcmState.McmProgram.String(), types.ManyChainMultisigProgram.String(), "") - if err != nil { - return cldf.ChangesetOutput{}, err - } - } - - return cldf.ChangesetOutput{}, nil -} - -// changeset to upgrade idl for a program via timelock -// write buffer using anchor cli -// set buffer authority to timelock using anchor cli -// generate set buffer ix using solana-go sdk -// build mcms txn to upgrade idl -func UpgradeIDL(e cldf.Environment, c IDLConfig) (cldf.ChangesetOutput, error) { - if err := c.Validate(e); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error validating idl config: %w", err) - } - chain := e.BlockChains.SolanaChains()[c.ChainSelector] - state, _ := stateview.LoadOnchainState(e) - chainState := state.SolChains[c.ChainSelector] - - mcmsTxs := make([]mcmsTypes.Transaction, 0) - if c.Router { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, chainState.Router.String(), solutils.ProgCCIPRouter, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - if c.FeeQuoter { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, chainState.FeeQuoter.String(), solutils.ProgFeeQuoter, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - if c.OffRamp { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, chainState.OffRamp.String(), solutils.ProgCCIPOfframp, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - if c.RMNRemote { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, chainState.RMNRemote.String(), solutils.ProgRMNRemote, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - for _, bnmMetadata := range c.BurnMintTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.BurnMintTokenPool, bnmMetadata) - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, tokenPool.String(), solutils.ProgBurnMintTokenPool, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - for _, lrMetadata := range c.LockReleaseTokenPoolMetadata { - tokenPool := chainState.GetActiveTokenPool(shared.LockReleaseTokenPool, lrMetadata) - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, tokenPool.String(), solutils.ProgLockReleaseTokenPool, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - - addresses, err := e.ExistingAddresses.AddressesForChain(chain.Selector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(chain, addresses) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load MCMS with timelock chain state: %w", err) - } - - if c.AccessController { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, mcmState.AccessControllerProgram.String(), solutils.ProgAccessController, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - if c.Timelock { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, mcmState.TimelockProgram.String(), solutils.ProgTimelock, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - if c.MCM { - upgradeTx, err := upgradeIDLIx(e, chain.ProgramsPath, mcmState.McmProgram.String(), solutils.ProgMCM, c) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error generating upgrade tx: %w", err) - } - if upgradeTx != nil { - mcmsTxs = append(mcmsTxs, *upgradeTx) - } - } - - if len(mcmsTxs) > 0 { - proposal, err := BuildProposalsForTxns( - e, c.ChainSelector, "proposal to upgrade CCIP contracts", c.MCMS.MinDelay, mcmsTxs) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_ops.go b/deployment/ccip/changeset/solana_v0_1_0/cs_ops.go index 5f288cf9952..0cca5fda06a 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_ops.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_ops.go @@ -1,27 +1,16 @@ package solana import ( - "context" - "errors" "fmt" "github.com/Masterminds/semver/v3" "github.com/gagliardetto/solana-go" - solstate "github.com/smartcontractkit/cld-changesets/legacy/pkg/family/solana" cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana" "github.com/smartcontractkit/chainlink-deployments-framework/datastore" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - cldfproposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils" - "github.com/smartcontractkit/mcms" - mcmsTypes "github.com/smartcontractkit/mcms/types" - - solOffRamp "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/ccip_offramp" - solRouter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/ccip_router" - solFeeQuoter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/fee_quoter" solTestReceiver "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_0/test_ccip_receiver" - solState "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/state" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/shared" @@ -29,246 +18,9 @@ import ( solanastateview "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview/solana" ) -// use these changesets to set the default code version -var _ cldf.ChangeSet[SetDefaultCodeVersionConfig] = SetDefaultCodeVersion - -// use these changesets to update the SVM chain selector -var _ cldf.ChangeSet[UpdateSvmChainSelectorConfig] = UpdateSvmChainSelector - -// use these changesets to update the enable manual execution after -var _ cldf.ChangeSet[UpdateEnableManualExecutionAfterConfig] = UpdateEnableManualExecutionAfter - -// use these changesets to configure the CCIP version -var _ cldf.ChangeSet[ConfigureCCIPVersionConfig] = ConfigureCCIPVersion - -// use these changesets to remove the offramp -var _ cldf.ChangeSet[RemoveOffRampConfig] = RemoveOffRamp - -// use this to set the fee aggregator -var _ cldf.ChangeSet[SetFeeAggregatorConfig] = SetFeeAggregator - -// use this to update the offramp reference addresseses -var _ cldf.ChangeSet[OffRampRefAddressesConfig] = UpdateOffRampRefAddresses - -// use this to set the upgrade authority of a contract -var _ cldf.ChangeSet[SetUpgradeAuthorityConfig] = SetUpgradeAuthorityChangeset - // use this to deploy a receiver for test var _ cldf.ChangeSet[DeployForTestConfig] = DeployReceiverForTest -// The user is not required to provide all the addresses, only the ones they want to update -type OffRampRefAddressesConfig struct { - ChainSelector uint64 - Router solana.PublicKey - FeeQuoter solana.PublicKey - AddressLookupTable solana.PublicKey - RMNRemote solana.PublicKey - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg OffRampRefAddressesConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState, chainExists := state.SolChains[chain.Selector] - if !chainExists { - return fmt.Errorf("chain %s not found in existing state, deploy the link token first", chain.String()) - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.OffRamp: true}) -} - -func UpdateOffRampRefAddresses( - e cldf.Environment, - config OffRampRefAddressesConfig, -) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainStateSolana(e) - if err != nil { - e.Logger.Errorw("Failed to load existing onchain state", "err", err) - return cldf.ChangesetOutput{}, err - } - if err := config.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[config.ChainSelector] - - chainState, chainExists := state.SolChains[chain.Selector] - if !chainExists { - return cldf.ChangesetOutput{}, fmt.Errorf("chain %s not found in existing state, deploy the link token first", chain.String()) - } - if chainState.OffRamp.IsZero() { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get offramp address for chain %s", chain.String()) - } - - var referenceAddressesAccount solOffRamp.ReferenceAddresses - offRampReferenceAddressesPDA, _, _ := solState.FindOfframpReferenceAddressesPDA(chainState.OffRamp) - if err = chain.GetAccountDataBorshInto(e.GetContext(), offRampReferenceAddressesPDA, &referenceAddressesAccount); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get offramp reference addresses: %w", err) - } - routerToSet := referenceAddressesAccount.Router - if !config.Router.IsZero() { - e.Logger.Infof("setting router on offramp to %s", config.Router.String()) - routerToSet = config.Router - } - feeQuoterToSet := referenceAddressesAccount.FeeQuoter - if !config.FeeQuoter.IsZero() { - e.Logger.Infof("setting fee quoter on offramp to %s", config.FeeQuoter.String()) - feeQuoterToSet = config.FeeQuoter - } - addressLookupTableToSet := referenceAddressesAccount.OfframpLookupTable - if !config.AddressLookupTable.IsZero() { - e.Logger.Infof("setting address lookup table on offramp to %s", config.AddressLookupTable.String()) - addressLookupTableToSet = config.AddressLookupTable - } - rmnRemoteToSet := referenceAddressesAccount.RmnRemote - if !config.RMNRemote.IsZero() { - e.Logger.Infof("setting rmn remote on offramp to %s", config.RMNRemote.String()) - rmnRemoteToSet = config.RMNRemote - } - - offRampUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "", - ) - runSafely(func() { - solOffRamp.SetProgramID(chainState.OffRamp) - }) - ix, err := solOffRamp.NewUpdateReferenceAddressesInstruction( - routerToSet, - feeQuoterToSet, - addressLookupTableToSet, - rmnRemoteToSet, - chainState.OffRampConfigPDA, - offRampReferenceAddressesPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if offRampUsingMCMS { - tx, err := BuildMCMSTxn(ix, chainState.OffRamp.String(), shared.OffRamp) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, config.ChainSelector, "proposal to UpdateOffRampRefAddresses in Solana", config.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - return cldf.ChangesetOutput{}, nil -} - -type SetUpgradeAuthorityConfig struct { - ChainSelector uint64 - NewUpgradeAuthority solana.PublicKey - SetAfterInitialDeploy bool // set all of the programs after the initial deploy - SetOffRamp bool // offramp not upgraded in place, so may need to set separately - SetMCMSPrograms bool // these all deploy at once so just set them all - TransferKeys []solana.PublicKey // any keys not covered by the above e.g. partner programs - MCMS *cldfproposalutils.TimelockConfig // if set, assumes current upgrade authority is the timelock -} - -func SetUpgradeAuthorityChangeset( - e cldf.Environment, - config SetUpgradeAuthorityConfig, -) (cldf.ChangesetOutput, error) { - chain := e.BlockChains.SolanaChains()[config.ChainSelector] - state, err := stateview.LoadOnchainStateSolana(e) - if err != nil { - e.Logger.Errorw("Failed to load existing onchain state", "err", err) - return cldf.ChangesetOutput{}, err - } - chainState, chainExists := state.SolChains[chain.Selector] - if !chainExists { - return cldf.ChangesetOutput{}, fmt.Errorf("chain %s not found in existing state, deploy the link token first", chain.String()) - } - programs := make([]solana.PublicKey, 0) - if config.SetAfterInitialDeploy { - programs = append(programs, chainState.Router, chainState.FeeQuoter, chainState.RMNRemote, chainState.BurnMintTokenPools[shared.CLLMetadata], chainState.LockReleaseTokenPools[shared.CLLMetadata]) - } - if config.SetOffRamp { - programs = append(programs, chainState.OffRamp) - } - if config.SetMCMSPrograms { - addresses, err := e.ExistingAddresses.AddressesForChain(config.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(chain, addresses) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - programs = append(programs, mcmState.AccessControllerProgram, mcmState.TimelockProgram, mcmState.McmProgram) - } - for _, transfer := range config.TransferKeys { - if transfer.IsZero() { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get program address for chain %s", chain.String()) - } - programs = append(programs, transfer) - } - // We do two loops here just to catch any errors before we get partway through the process - for _, program := range programs { - if program.IsZero() { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get program address for chain %s", chain.String()) - } - } - currentAuthority := chain.DeployerKey.PublicKey() - if config.MCMS != nil { - timelockSignerPDA, err := FetchTimelockSigner(e, chain.Selector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get timelock signer: %w", err) - } - currentAuthority = timelockSignerPDA - } - e.Logger.Infow("Setting upgrade authority", "newUpgradeAuthority", config.NewUpgradeAuthority.String()) - mcmsTxns := make([]mcmsTypes.Transaction, 0) - for _, programID := range programs { - ixn := setUpgradeAuthority(&e, &chain, programID, currentAuthority, config.NewUpgradeAuthority, false) - if config.MCMS == nil { - if err := chain.Confirm([]solana.Instruction{ixn}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - } else { - tx, err := BuildMCMSTxn( - ixn, - solana.BPFLoaderUpgradeableProgramID.String(), - cldf.ContractType(solana.BPFLoaderUpgradeableProgramID.String())) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - mcmsTxns = append(mcmsTxns, *tx) - } - } - if len(mcmsTxns) > 0 { - proposal, err := BuildProposalsForTxns( - e, config.ChainSelector, "proposal to SetUpgradeAuthority in Solana", config.MCMS.MinDelay, mcmsTxns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - return cldf.ChangesetOutput{}, nil -} - // setUpgradeAuthority creates a transaction to set the upgrade authority for a program func setUpgradeAuthority( e *cldf.Environment, @@ -303,108 +55,6 @@ func setUpgradeAuthority( return instruction } -type SetFeeAggregatorConfig struct { - ChainSelector uint64 - FeeAggregator string - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg SetFeeAggregatorConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState, chainExists := state.SolChains[cfg.ChainSelector] - if !chainExists { - return fmt.Errorf("chain %d not found in existing state", cfg.ChainSelector) - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true}); err != nil { - return err - } - - // Validate fee aggregator address is valid - if _, err := solana.PublicKeyFromBase58(cfg.FeeAggregator); err != nil { - return fmt.Errorf("invalid fee aggregator address: %w", err) - } - - if solana.MustPublicKeyFromBase58(cfg.FeeAggregator).IsZero() { - return errors.New("fee aggregator address cannot be zero") - } - - if chainState.GetFeeAggregator(chain).Equals(solana.MustPublicKeyFromBase58(cfg.FeeAggregator)) { - return fmt.Errorf("fee aggregator %s is already set on chain %d", cfg.FeeAggregator, cfg.ChainSelector) - } - - return nil -} - -func SetFeeAggregator(e cldf.Environment, cfg SetFeeAggregatorConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - - feeAggregatorPubKey := solana.MustPublicKeyFromBase58(cfg.FeeAggregator) - routerConfigPDA, _, _ := solState.FindConfigPDA(chainState.Router) - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "", - ) - instruction, err := solRouter.NewUpdateFeeAggregatorInstruction( - feeAggregatorPubKey, - routerConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(instruction, chainState.Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to SetFeeAggregator in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm([]solana.Instruction{instruction}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - e.Logger.Infow("Set new fee aggregator", "chain", chain.String(), "fee_aggregator", feeAggregatorPubKey.String()) - - return cldf.ChangesetOutput{}, nil -} - type DeployForTestConfig struct { ChainSelector uint64 BuildConfig *BuildSolanaConfig @@ -500,580 +150,3 @@ func DeployReceiverForTest(e cldf.Environment, cfg DeployForTestConfig) (cldf.Ch DataStore: ds, }, nil } - -type SetDefaultCodeVersionConfig struct { - ChainSelector uint64 - VersionEnum uint8 - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg SetDefaultCodeVersionConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - if err := chainState.ValidateOffRampConfig(chain); err != nil { - return err - } - if err := chainState.ValidateFeeQuoterConfig(chain); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.FeeQuoter: true, shared.OffRamp: true, shared.Router: true}) -} - -func SetDefaultCodeVersion(e cldf.Environment, cfg SetDefaultCodeVersionConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infow("Setting default code version", "chain_selector", cfg.ChainSelector, "new_code_version", cfg.VersionEnum) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - offRampUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - feeQuoterUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - txns := make([]mcmsTypes.Transaction, 0) - ixns := make([]solana.Instruction, 0) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - ixn, err := solRouter.NewSetDefaultCodeVersionInstruction( - solRouter.CodeVersion(cfg.VersionEnum), - chainState.RouterConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(ixn, chainState.Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn) - } - - authority = GetAuthorityForIxn( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - runSafely(func() { - solOffRamp.SetProgramID(chainState.OffRamp) - }) - ixn2, err := solOffRamp.NewSetDefaultCodeVersionInstruction( - solOffRamp.CodeVersion(cfg.VersionEnum), - chainState.OffRampConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if offRampUsingMCMS { - tx, err := BuildMCMSTxn(ixn2, chainState.OffRamp.String(), shared.OffRamp) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn2) - } - - authority = GetAuthorityForIxn( - &e, - chain, - chainState, - shared.FeeQuoter, - solana.PublicKey{}, - "") - runSafely(func() { - solFeeQuoter.SetProgramID(chainState.FeeQuoter) - }) - ixn3, err := solFeeQuoter.NewSetDefaultCodeVersionInstruction( - solFeeQuoter.CodeVersion(cfg.VersionEnum), - chainState.FeeQuoterConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if feeQuoterUsingMCMS { - tx, err := BuildMCMSTxn(ixn3, chainState.FeeQuoter.String(), shared.FeeQuoter) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn3) - } - - if len(ixns) > 0 { - if err = chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, err - } - } - - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to SetDefaultCodeVersion in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - -type UpdateSvmChainSelectorConfig struct { - OldChainSelector uint64 - NewChainSelector uint64 - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg UpdateSvmChainSelectorConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.OldChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.OldChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - if err := chainState.ValidateOffRampConfig(chain); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true, shared.OffRamp: true}) -} - -func UpdateSvmChainSelector(e cldf.Environment, cfg UpdateSvmChainSelectorConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infow("Updating SVM chain selector", "old_chain_selector", cfg.OldChainSelector, "new_chain_selector", cfg.NewChainSelector) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - - chain := e.BlockChains.SolanaChains()[cfg.OldChainSelector] - chainState := state.SolChains[cfg.OldChainSelector] - routerConfigPDA, _, _ := solState.FindConfigPDA(chainState.Router) - - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - offRampUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - txns := make([]mcmsTypes.Transaction, 0) - ixns := make([]solana.Instruction, 0) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - ixn, err := solRouter.NewUpdateSvmChainSelectorInstruction( - cfg.NewChainSelector, - routerConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(ixn, chainState.Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn) - } - - authority = GetAuthorityForIxn( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - runSafely(func() { - solOffRamp.SetProgramID(chainState.OffRamp) - }) - ixn2, err := solOffRamp.NewUpdateSvmChainSelectorInstruction( - cfg.NewChainSelector, - chainState.OffRampConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if offRampUsingMCMS { - tx, err := BuildMCMSTxn(ixn2, chainState.OffRamp.String(), shared.OffRamp) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn2) - } - - if len(ixns) > 0 { - if err = chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, err - } - } - - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.OldChainSelector, "proposal to UpdateSvmChainSelector in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - -type UpdateEnableManualExecutionAfterConfig struct { - ChainSelector uint64 - EnableManualExecution int64 - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg UpdateEnableManualExecutionAfterConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateOffRampConfig(chain); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.OffRamp: true}) -} - -func UpdateEnableManualExecutionAfter(e cldf.Environment, cfg UpdateEnableManualExecutionAfterConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infow("Updating enable manual execution after", "chain_selector", cfg.ChainSelector, "enable_manual_execution_after", cfg.EnableManualExecution) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - offRampUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - txns := make([]mcmsTypes.Transaction, 0) - ixns := make([]solana.Instruction, 0) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.OffRamp, - solana.PublicKey{}, - "") - runSafely(func() { - solOffRamp.SetProgramID(chainState.OffRamp) - }) - ixn2, err := solOffRamp.NewUpdateEnableManualExecutionAfterInstruction( - cfg.EnableManualExecution, - chainState.OffRampConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if offRampUsingMCMS { - tx, err := BuildMCMSTxn(ixn2, chainState.OffRamp.String(), shared.OffRamp) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn2) - } - - if len(ixns) > 0 { - if err = chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, err - } - } - - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to UpdateEnableManualExecutionAfter in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - -type CCIPVersionOp int - -const ( - Bump CCIPVersionOp = iota - Rollback -) - -type ConfigureCCIPVersionConfig struct { - ChainSelector uint64 - DestChainSelector uint64 - Operation CCIPVersionOp - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg ConfigureCCIPVersionConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - routerDestChainPDA, err := solState.FindDestChainStatePDA(cfg.DestChainSelector, chainState.Router) - if err != nil { - return fmt.Errorf("failed to find dest chain state pda for remote chain %d: %w", cfg.DestChainSelector, err) - } - var destChainStateAccount solRouter.DestChain - err = chain.GetAccountDataBorshInto(context.Background(), routerDestChainPDA, &destChainStateAccount) - if err != nil { - return fmt.Errorf("remote %d is not configured on solana chain %d", cfg.DestChainSelector, cfg.ChainSelector) - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true}) -} - -func ConfigureCCIPVersion(e cldf.Environment, cfg ConfigureCCIPVersionConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - destChainStatePDA, _ := solState.FindDestChainStatePDA(cfg.DestChainSelector, chainState.Router) - - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - txns := make([]mcmsTypes.Transaction, 0) - ixns := make([]solana.Instruction, 0) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - var ixn solana.Instruction - switch cfg.Operation { - case Bump: - ixn, err = solRouter.NewBumpCcipVersionForDestChainInstruction( - cfg.DestChainSelector, - destChainStatePDA, - chainState.RouterConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - case Rollback: - ixn, err = solRouter.NewRollbackCcipVersionForDestChainInstruction( - cfg.DestChainSelector, - destChainStatePDA, - chainState.RouterConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(ixn, chainState.Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn) - } - - if len(ixns) > 0 { - if err = chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, err - } - } - - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to ConfigureCCIPVersion in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - -type RemoveOffRampConfig struct { - ChainSelector uint64 - OffRamp solana.PublicKey - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg RemoveOffRampConfig) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - chainState := state.SolChains[cfg.ChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true}) -} - -func RemoveOffRamp(e cldf.Environment, cfg RemoveOffRampConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - chainState := state.SolChains[cfg.ChainSelector] - routerUsingMCMS := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - txns := make([]mcmsTypes.Transaction, 0) - ixns := make([]solana.Instruction, 0) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - shared.Router, - solana.PublicKey{}, - "") - runSafely(func() { - solRouter.SetProgramID(chainState.Router) - }) - ixn, err := solRouter.NewRemoveOfframpInstruction( - cfg.ChainSelector, - cfg.OffRamp, - chainState.OffRamp, - chainState.RouterConfigPDA, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build instruction: %w", err) - } - - if routerUsingMCMS { - tx, err := BuildMCMSTxn(ixn, chainState.Router.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - txns = append(txns, *tx) - } else { - ixns = append(ixns, ixn) - } - - if len(ixns) > 0 { - if err = chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, err - } - } - - if len(txns) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to RemoveOffRamp in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_solana_token.go b/deployment/ccip/changeset/solana_v0_1_0/cs_solana_token.go index 64994643e17..67e2df91fdd 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_solana_token.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_solana_token.go @@ -2,7 +2,6 @@ package solana import ( "context" - "errors" "fmt" "github.com/gagliardetto/solana-go" @@ -17,8 +16,6 @@ import ( "github.com/smartcontractkit/chainlink/deployment/ccip/shared" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" - solToken "github.com/gagliardetto/solana-go/programs/token" - solCommonUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common" solTokenUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens" ) @@ -32,12 +29,6 @@ var _ cldf.ChangeSet[MintSolanaTokenConfig] = MintSolanaToken // use this changeset to create ATAs for a token var _ cldf.ChangeSet[CreateSolanaTokenATAConfig] = CreateSolanaTokenATA -// use this changeset to set the authority of a token -var _ cldf.ChangeSet[SetTokenAuthorityConfig] = SetTokenAuthority - -// use this changeset to upload or update token metadata -var _ cldf.ChangeSet[UploadTokenMetadataConfig] = UploadTokenMetadata - func getMintIxs(e cldf.Environment, chain cldf_solana.Chain, tokenprogramID, mint solana.PublicKey, amountToAddress map[string]uint64) error { for toAddress, amount := range amountToAddress { e.Logger.Infof("Minting %d to %s", amount, toAddress) @@ -262,172 +253,3 @@ func CreateSolanaTokenATA(e cldf.Environment, cfg CreateSolanaTokenATAConfig) (c return cldf.ChangesetOutput{}, nil } - -type TokenAuthorityConfig struct { - AuthorityType solToken.AuthorityType - TokenPubkey solana.PublicKey - NewAuthority solana.PublicKey -} - -type SetTokenAuthorityConfig struct { - ChainSelector uint64 - TokenAuthorityConfigs []TokenAuthorityConfig -} - -func SetTokenAuthority(e cldf.Environment, cfg SetTokenAuthorityConfig) (cldf.ChangesetOutput, error) { - if cfg.ChainSelector == 0 { - return cldf.ChangesetOutput{}, errors.New("chain selector is required") - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - state, err := stateview.LoadOnchainStateSolana(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - chainState, ok := state.SolChains[cfg.ChainSelector] - if !ok { - return cldf.ChangesetOutput{}, fmt.Errorf("chain %d not found in environment", cfg.ChainSelector) - } - - for _, tokenAuthorityConfig := range cfg.TokenAuthorityConfigs { - tokenprogramID, err := chainState.TokenToTokenProgram(tokenAuthorityConfig.TokenPubkey) - if err != nil { - return cldf.ChangesetOutput{}, err - } - - ix, err := solToken.NewSetAuthorityInstruction( - tokenAuthorityConfig.AuthorityType, - tokenAuthorityConfig.NewAuthority, - tokenAuthorityConfig.TokenPubkey, - chain.DeployerKey.PublicKey(), - solana.PublicKeySlice{}, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, err - } - tokenIx := &solTokenUtil.TokenInstruction{Instruction: ix, Program: tokenprogramID} - - // confirm instructions - if err = chain.Confirm([]solana.Instruction{tokenIx}); err != nil { - e.Logger.Errorw("Failed to confirm instructions for SetTokenAuthority", "chain", chain.String(), "err", err) - return cldf.ChangesetOutput{}, err - } - e.Logger.Infow("Set token authority on", "chain", cfg.ChainSelector, "for token", tokenAuthorityConfig.TokenPubkey.String(), "newAuthority", tokenAuthorityConfig.NewAuthority.String(), "authorityType", tokenAuthorityConfig.AuthorityType) - } - - return cldf.ChangesetOutput{}, nil -} - -type TokenMetadata struct { - TokenPubkey solana.PublicKey - // https://metaboss.dev/create.html#metadata - // only to be provided on initial upload, it takes in name, symbol, uri - // after initial upload, those fields can be updated using the update inputs - // put the json in ccip/env/input dir in CLD - MetadataJSONPath string - UpdateAuthority solana.PublicKey // used to set update authority of the token metadata PDA after initial upload - // https://metaboss.dev/update.html#update-name - UpdateName string // used to update the name of the token metadata PDA after initial upload - // https://metaboss.dev/update.html#update-symbol - UpdateSymbol string // used to update the symbol of the token metadata PDA after initial upload - // https://metaboss.dev/update.html#update-uri - UpdateURI string // used to update the uri of the token metadata PDA after initial upload -} - -type UploadTokenMetadataConfig struct { - ChainSelector uint64 - TokenMetadata []TokenMetadata -} - -func UploadTokenMetadata(e cldf.Environment, cfg UploadTokenMetadataConfig) (cldf.ChangesetOutput, error) { - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - out1, err1 := runCommand("solana", []string{"config", "set", "--url", chain.URL}, chain.ProgramsPath) - e.Logger.Infow("solana config set url output", "output", out1) - if err1 != nil { - e.Logger.Errorw("solana config set url error", "error", err1) - return cldf.ChangesetOutput{}, fmt.Errorf("error setting solana url: %w", err1) - } - out2, err2 := runCommand("solana", []string{"config", "set", "--keypair", chain.KeypairPath}, chain.ProgramsPath) - e.Logger.Infow("solana config set keypair output", "output", out2) - if err2 != nil { - e.Logger.Errorw("solana config set keypair error", "error", err2) - return cldf.ChangesetOutput{}, fmt.Errorf("error setting solana keypair: %w", err2) - } - for _, metadata := range cfg.TokenMetadata { - if metadata.TokenPubkey.IsZero() { - e.Logger.Errorw("Token pubkey is zero", "tokenPubkey", metadata.TokenPubkey.String()) - return cldf.ChangesetOutput{}, errors.New("token pubkey is zero") - } - - // initial upload - if metadata.MetadataJSONPath != "" { - e.Logger.Infow("Uploading token metadata", "tokenPubkey", metadata.TokenPubkey.String()) - args := []string{"create", "metadata", "--mint", metadata.TokenPubkey.String(), "--metadata", metadata.MetadataJSONPath} - e.Logger.Info(args) - output, err := runCommand("metaboss", args, chain.ProgramsPath) - e.Logger.Debugw("metaboss output", "output", output) - if err != nil { - e.Logger.Debugw("metaboss create error", "error", err) - return cldf.ChangesetOutput{}, fmt.Errorf("error uploading token metadata: %w", err) - } - e.Logger.Infow("Token metadata uploaded", "tokenPubkey", metadata.TokenPubkey.String()) - } - - // update authority after initial upload - if !metadata.UpdateAuthority.IsZero() { - e.Logger.Infow("Updating token metadata authority", "tokenPubkey", metadata.TokenPubkey.String()) - args := []string{"set", "update-authority", "--account", metadata.TokenPubkey.String(), "--new-update-authority", metadata.UpdateAuthority.String()} - e.Logger.Info(args) - output, err := runCommand("metaboss", args, chain.ProgramsPath) - e.Logger.Debugw("metaboss output", "output", output) - if err != nil { - e.Logger.Debugw("metaboss set error", "error", err) - return cldf.ChangesetOutput{}, fmt.Errorf("error uploading token metadata: %w", err) - } - e.Logger.Infow("Token metadata update authority set", "tokenPubkey", metadata.TokenPubkey.String(), "updateAuthority", metadata.UpdateAuthority.String()) - } - - // update name - if metadata.MetadataJSONPath == "" && metadata.UpdateName != "" { - e.Logger.Infow("Updating token metadata name", "tokenPubkey", metadata.TokenPubkey.String()) - args := []string{"update", "name", "--account", metadata.TokenPubkey.String(), "--new-name", metadata.UpdateName} - e.Logger.Info(args) - output, err := runCommand("metaboss", args, chain.ProgramsPath) - e.Logger.Debugw("metaboss output", "output", output) - if err != nil { - e.Logger.Debugw("metaboss update name error", "error", err) - return cldf.ChangesetOutput{}, fmt.Errorf("error uploading token metadata: %w", err) - } - e.Logger.Infow("Token metadata name set", "tokenPubkey", metadata.TokenPubkey.String(), "name", metadata.UpdateName) - } - - // update symbol - if metadata.MetadataJSONPath == "" && metadata.UpdateSymbol != "" { - e.Logger.Infow("Updating token metadata symbol", "tokenPubkey", metadata.TokenPubkey.String()) - args := []string{"update", "symbol", "--account", metadata.TokenPubkey.String(), "--new-symbol", metadata.UpdateSymbol} - e.Logger.Info(args) - output, err := runCommand("metaboss", args, chain.ProgramsPath) - e.Logger.Debugw("metaboss output", "output", output) - if err != nil { - e.Logger.Debugw("metaboss update symbol error", "error", err) - return cldf.ChangesetOutput{}, fmt.Errorf("error uploading token metadata: %w", err) - } - e.Logger.Infow("Token metadata symbol set", "tokenPubkey", metadata.TokenPubkey.String(), "symbol", metadata.UpdateSymbol) - } - - // update uri - if metadata.MetadataJSONPath == "" && metadata.UpdateURI != "" { - e.Logger.Infow("Updating token metadata uri", "tokenPubkey", metadata.TokenPubkey.String()) - args := []string{"update", "uri", "--account", metadata.TokenPubkey.String(), "--new-uri", metadata.UpdateURI} - e.Logger.Info(args) - output, err := runCommand("metaboss", args, chain.ProgramsPath) - e.Logger.Debugw("metaboss output", "output", output) - if err != nil { - e.Logger.Debugw("metaboss update uri error", "error", err) - return cldf.ChangesetOutput{}, fmt.Errorf("error uploading token metadata: %w", err) - } - e.Logger.Infow("Token metadata uri set", "tokenPubkey", metadata.TokenPubkey.String(), "uri", metadata.UpdateURI) - } - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_token_admin_registry.go b/deployment/ccip/changeset/solana_v0_1_0/cs_token_admin_registry.go index 3054449c11f..5d7dff2ced4 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_token_admin_registry.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_token_admin_registry.go @@ -24,7 +24,6 @@ import ( // use these changesets to register a token admin registry, transfer the admin role, and accept the admin role var _ cldf.ChangeSet[RegisterTokenAdminRegistryConfig] = RegisterTokenAdminRegistry -var _ cldf.ChangeSet[TransferAdminRoleTokenAdminRegistryConfig] = TransferAdminRoleTokenAdminRegistry var _ cldf.ChangeSet[AcceptAdminRoleTokenAdminRegistryConfig] = AcceptAdminRoleTokenAdminRegistry // use this changeset to set pool on token admin registry @@ -235,154 +234,6 @@ func RegisterTokenAdminRegistry(e cldf.Environment, cfg RegisterTokenAdminRegist return cldf.ChangesetOutput{}, nil } -type TrasnferTokenAdminConfig struct { - TokenPubKey solana.PublicKey - NewRegistryAdminPublicKey solana.PublicKey -} - -// TRANSFER AND ACCEPT TOKEN ADMIN REGISTRY -type TransferAdminRoleTokenAdminRegistryConfig struct { - ChainSelector uint64 - TransferTokenAdminConfigs []TrasnferTokenAdminConfig - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg TransferAdminRoleTokenAdminRegistryConfig) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - if err := chainState.ValidateRouterConfig(chain); err != nil { - return err - } - routerProgramAddress, _, _ := chainState.GetRouterInfo() - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, solana.PublicKey{}, "", map[cldf.ContractType]bool{shared.Router: true}); err != nil { - return err - } - - deployerKey := chain.DeployerKey.PublicKey() - timelockSignerPDA, err := FetchTimelockSigner(e, cfg.ChainSelector) - if err != nil { - return fmt.Errorf("failed to fetch timelock signer: %w", err) - } - - for _, transferTokenAdminConfig := range cfg.TransferTokenAdminConfigs { - tokenPubKey := transferTokenAdminConfig.TokenPubKey - if err := chainState.CommonValidation(e, cfg.ChainSelector, tokenPubKey); err != nil { - return err - } - newRegistryAdminPubKey := transferTokenAdminConfig.NewRegistryAdminPublicKey - tokenAdminRegistryPDA, _, err := solState.FindTokenAdminRegistryPDA(tokenPubKey, routerProgramAddress) - if err != nil { - return fmt.Errorf("failed to find token admin registry pda (mint: %s, router: %s): %w", tokenPubKey.String(), routerProgramAddress.String(), err) - } - var tokenAdminRegistryAccount solCommon.TokenAdminRegistry - if err := chain.GetAccountDataBorshInto(context.Background(), tokenAdminRegistryPDA, &tokenAdminRegistryAccount); err != nil { - return fmt.Errorf("token admin registry not found for (mint: %s, router: %s), cannot transfer admin role", tokenPubKey.String(), routerProgramAddress.String()) - } - currentAdmin := tokenAdminRegistryAccount.Administrator - // if current admin is not the deployer key or timelock signer, we cannot transfer the admin role - if !currentAdmin.Equals(deployerKey) && !currentAdmin.Equals(timelockSignerPDA) { - return fmt.Errorf("current registry admin public key (%s) is not the deployer key (%s) or timelock signer (%s) for token %s, hence this changeset cannot sign for the transfer", - currentAdmin.String(), - deployerKey.String(), - timelockSignerPDA.String(), - tokenPubKey.String(), - ) - } - if currentAdmin.Equals(timelockSignerPDA) && cfg.MCMS == nil { - return fmt.Errorf("current registry admin public key (%s) is the timelock signer (%s) for token %s, but no mcms config is provided, hence this changeset cannot sign for the transfer", - currentAdmin.String(), - timelockSignerPDA.String(), - tokenPubKey.String(), - ) - } - if currentAdmin.Equals(newRegistryAdminPubKey) { - return fmt.Errorf("new registry admin public key (%s) cannot be the same as current registry admin public key (%s) for token %s", - newRegistryAdminPubKey.String(), - currentAdmin.String(), - tokenPubKey.String(), - ) - } - } - - return nil -} - -func TransferAdminRoleTokenAdminRegistry(e cldf.Environment, cfg TransferAdminRoleTokenAdminRegistryConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infow("TransferAdminRoleTokenAdminRegistry", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - chainState, ok := state.SolChains[cfg.ChainSelector] - if !ok { - return cldf.ChangesetOutput{}, fmt.Errorf("chain %d not found in environment", cfg.ChainSelector) - } - if err := cfg.Validate(e, chainState); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - routerProgramAddress, routerConfigPDA, _ := chainState.GetRouterInfo() - runSafely(func() { - solRouter.SetProgramID(routerProgramAddress) - }) - - timelockSignerPDA, err := FetchTimelockSigner(e, cfg.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to fetch timelock signer: %w", err) - } - - mcmsTxs := []mcmsTypes.Transaction{} - - for _, transferTokenAdminConfig := range cfg.TransferTokenAdminConfigs { - tokenPubKey := transferTokenAdminConfig.TokenPubKey - tokenAdminRegistryPDA, _, _ := solState.FindTokenAdminRegistryPDA(tokenPubKey, routerProgramAddress) - newRegistryAdminPubKey := transferTokenAdminConfig.NewRegistryAdminPublicKey - - var tokenAdminRegistryAccount solCommon.TokenAdminRegistry - if err := chain.GetAccountDataBorshInto(context.Background(), tokenAdminRegistryPDA, &tokenAdminRegistryAccount); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get token admin registry account: %w", err) - } - currentAdmin := tokenAdminRegistryAccount.Administrator - - instruction, err := solRouter.NewTransferAdminRoleTokenAdminRegistryInstruction( - newRegistryAdminPubKey, - routerConfigPDA, - tokenAdminRegistryPDA, - tokenPubKey, - currentAdmin, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - // when transferring admin role away from timelock, we will need to build mcms transaction - if currentAdmin.Equals(timelockSignerPDA) { - tx, err := BuildMCMSTxn(instruction, routerProgramAddress.String(), shared.Router) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - mcmsTxs = append(mcmsTxs, *tx) - } else { // already confirmed that admin is either deployer key or timelock signer - instructions := []solana.Instruction{instruction} - if err := chain.Confirm(instructions); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - } - } - - // when transferring admin role away from timelock, we will need to build mcms transaction - if len(mcmsTxs) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to TransferAdminRoleTokenAdminRegistry in Solana", cfg.MCMS.MinDelay, mcmsTxs) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} - // ACCEPT TOKEN ADMIN REGISTRY type AcceptAdminRoleTokenConfig struct { diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_token_pool.go b/deployment/ccip/changeset/solana_v0_1_0/cs_token_pool.go index c05ec99d7ec..acc4d855ee4 100644 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_token_pool.go +++ b/deployment/ccip/changeset/solana_v0_1_0/cs_token_pool.go @@ -42,18 +42,6 @@ var _ cldf.ChangeSet[AddTokenPoolAndLookupTableConfig] = AddTokenPoolAndLookupTa // use this changeset to setup a token pool for a remote chain var _ cldf.ChangeSet[SetupTokenPoolForRemoteChainConfig] = SetupTokenPoolForRemoteChain -// lock / release ops on LnR token pool -var _ cldf.ChangeSet[LockReleaseLiquidityOpsConfig] = LockReleaseLiquidityOps - -// configure token pool allow list -var _ cldf.ChangeSet[ConfigureTokenPoolAllowListConfig] = ConfigureTokenPoolAllowList - -// remove from token pool allow list -var _ cldf.ChangeSet[RemoveFromAllowListConfig] = RemoveFromTokenPoolAllowList - -// token pool ops -var _ cldf.ChangeSet[TokenPoolOpsCfg] = TokenPoolOps - // append mcms txns generated from solanainstructions func appendTxs(instructions []solana.Instruction, tokenPool solana.PublicKey, poolType cldf.ContractType, txns *[]mcmsTypes.Transaction) error { for _, ixn := range instructions { @@ -112,39 +100,6 @@ type AddTokenPoolAndLookupTableConfig struct { ForceDatastoreOverwrite bool } -type TokenPoolConfigWithMCM struct { - ChainSelector uint64 - PoolType cldf.ContractType - TokenPubKey solana.PublicKey - Metadata string - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg TokenPoolConfigWithMCM) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - if err := chainState.CommonValidation(e, cfg.ChainSelector, cfg.TokenPubKey); err != nil { - return err - } - - return chainState.ValidatePoolDeployment(&e, cfg.PoolType, cfg.ChainSelector, cfg.TokenPubKey, false, cfg.Metadata) -} - -type NewMintTokenPoolConfig struct { - ChainSelector uint64 - PoolType cldf.ContractType - TokenPubKey solana.PublicKey - Metadata string - MCMS *cldfproposalutils.TimelockConfig - NewMintAuthority solana.PublicKey // new mint authority to set for the token pool -} - -func (cfg NewMintTokenPoolConfig) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - if err := chainState.CommonValidation(e, cfg.ChainSelector, cfg.TokenPubKey); err != nil { - return err - } - - return chainState.ValidatePoolDeployment(&e, cfg.PoolType, cfg.ChainSelector, cfg.TokenPubKey, false, cfg.Metadata) -} - // PlannedRefs returns all lookup-table refs produced by this aggregate changeset. Keeping the // complete key set at the aggregate boundary prevents a later child validation from discovering a // duplicate after an earlier token-pool transaction has already been confirmed. @@ -1109,614 +1064,3 @@ func AddTokenPoolLookupTable(e cldf.Environment, cfg TokenPoolLookupTableConfig) DataStore: ds, }, nil } - -// CONFIGURE TOKEN POOL ALLOW LIST -type ConfigureTokenPoolAllowListConfig struct { - SolChainSelector uint64 - // a pool pda is uniquely identified by (solTokenPubKey, poolType, metadata) - SolTokenPubKey string - PoolType cldf.ContractType - Metadata string // tag to identify which client/cll token pool executable to use - // input only the ones you want to add, onchain throws error when we pass already configured accounts - Accounts []solana.PublicKey - Enabled bool // enable or disable the allow list - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg ConfigureTokenPoolAllowListConfig) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - - if cfg.PoolType == "" { - return errors.New("pool type must be defined") - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - if err := chainState.CommonValidation(e, cfg.SolChainSelector, tokenPubKey); err != nil { - return err - } - if err := chainState.ValidatePoolDeployment(&e, cfg.PoolType, cfg.SolChainSelector, tokenPubKey, true, cfg.Metadata); err != nil { - return err - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, tokenPubKey, cfg.Metadata, map[cldf.ContractType]bool{}) -} - -func ConfigureTokenPoolAllowList(e cldf.Environment, cfg ConfigureTokenPoolAllowListConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infof("Configuring token pool allowlist for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - chainState := state.SolChains[cfg.SolChainSelector] - if err := cfg.Validate(e, chainState); err != nil { - return cldf.ChangesetOutput{}, err - } - - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - - var ix solana.Instruction - tokenPool := chainState.GetActiveTokenPool(cfg.PoolType, cfg.Metadata) - tokenPoolUsingMcms := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - poolConfigPDA, _ := solTokenUtil.TokenPoolConfigAddress(tokenPubKey, tokenPool) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - switch cfg.PoolType { - case shared.BurnMintTokenPool: - runSafely(func() { - solBurnMintTokenPool.SetProgramID(tokenPool) - }) - ix, err = solBurnMintTokenPool.NewConfigureAllowListInstruction( - cfg.Accounts, - cfg.Enabled, - poolConfigPDA, - tokenPubKey, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - case shared.LockReleaseTokenPool: - runSafely(func() { - solLockReleaseTokenPool.SetProgramID(tokenPool) - }) - ix, err = solLockReleaseTokenPool.NewConfigureAllowListInstruction( - cfg.Accounts, - cfg.Enabled, - poolConfigPDA, - tokenPubKey, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - default: - return cldf.ChangesetOutput{}, fmt.Errorf("invalid pool type: %s", cfg.PoolType) - } - if tokenPoolUsingMcms { - tx, err := BuildMCMSTxn(ix, tokenPool.String(), cfg.PoolType) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.SolChainSelector, "proposal to ConfigureTokenPoolAllowList in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - e.Logger.Infow("Configured token pool allowlist", "token_pubkey", tokenPubKey.String()) - return cldf.ChangesetOutput{}, nil -} - -// REMOVE FROM TOKEN POOL ALLOW LIST -type RemoveFromAllowListConfig struct { - SolChainSelector uint64 - // a pool pda is uniquely identified by (solTokenPubKey, poolType, metadata) - SolTokenPubKey string - PoolType cldf.ContractType - Metadata string // tag to identify which client/cll token pool executable to use - Accounts []solana.PublicKey // accounts to remove from allow list - MCMS *cldfproposalutils.TimelockConfig -} - -func (cfg RemoveFromAllowListConfig) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - if err := chainState.CommonValidation(e, cfg.SolChainSelector, tokenPubKey); err != nil { - return err - } - if cfg.PoolType == "" { - return errors.New("pool type must be defined") - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, tokenPubKey, cfg.Metadata, map[cldf.ContractType]bool{}); err != nil { - return err - } - return chainState.ValidatePoolDeployment(&e, cfg.PoolType, cfg.SolChainSelector, tokenPubKey, true, cfg.Metadata) -} - -func RemoveFromTokenPoolAllowList(e cldf.Environment, cfg RemoveFromAllowListConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infof("Removing from token pool allowlist for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - chainState := state.SolChains[cfg.SolChainSelector] - if err := cfg.Validate(e, chainState); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - tokenPool := chainState.GetActiveTokenPool(cfg.PoolType, cfg.Metadata) - - var ix solana.Instruction - tokenPoolUsingMcms := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - poolConfigPDA, _ := solTokenUtil.TokenPoolConfigAddress(tokenPubKey, tokenPool) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - switch cfg.PoolType { - case shared.BurnMintTokenPool: - runSafely(func() { - solBurnMintTokenPool.SetProgramID(tokenPool) - }) - ix, err = solBurnMintTokenPool.NewRemoveFromAllowListInstruction( - cfg.Accounts, - poolConfigPDA, - tokenPubKey, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - case shared.LockReleaseTokenPool: - runSafely(func() { - solLockReleaseTokenPool.SetProgramID(tokenPool) - }) - ix, err = solLockReleaseTokenPool.NewRemoveFromAllowListInstruction( - cfg.Accounts, - poolConfigPDA, - tokenPubKey, - authority, - solana.SystemProgramID, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - default: - return cldf.ChangesetOutput{}, fmt.Errorf("invalid pool type: %s", cfg.PoolType) - } - if tokenPoolUsingMcms { - tx, err := BuildMCMSTxn(ix, tokenPool.String(), cfg.PoolType) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.SolChainSelector, "proposal to RemoveFromTokenPoolAllowList in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm([]solana.Instruction{ix}); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - e.Logger.Infow("Configured token pool allowlist", "token_pubkey", tokenPubKey.String()) - return cldf.ChangesetOutput{}, nil -} - -// LOCK/UNLOCK LIQUIDITY -type LockReleaseLiquidityOpsConfig struct { - SolChainSelector uint64 - // a pool pda is uniquely identified by (solTokenPubKey, poolType, metadata) - // poolType is only LockAndRelease_PoolType for this migration - SolTokenPubKey string - SetCfg *SetLiquidityConfig - LiquidityCfg *LiquidityConfig - RebalancerCfg *RebalancerConfig - MCMS *cldfproposalutils.TimelockConfig - Metadata string -} - -type SetLiquidityConfig struct { - Enabled bool -} -type LiquidityOperation int - -const ( - Provide LiquidityOperation = iota - Withdraw -) - -type LiquidityConfig struct { - Amount int - RemoteTokenAccount solana.PublicKey - Type LiquidityOperation -} - -type RebalancerConfig struct { - Rebalancer solana.PublicKey -} - -func (cfg LockReleaseLiquidityOpsConfig) Validate(e cldf.Environment, chainState solanastateview.CCIPChainState) error { - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - if err := chainState.CommonValidation(e, cfg.SolChainSelector, tokenPubKey); err != nil { - return err - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - if err := ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, tokenPubKey, cfg.Metadata, map[cldf.ContractType]bool{}); err != nil { - return err - } - return chainState.ValidatePoolDeployment(&e, shared.LockReleaseTokenPool, cfg.SolChainSelector, tokenPubKey, true, cfg.Metadata) -} - -func LockReleaseLiquidityOps(e cldf.Environment, cfg LockReleaseLiquidityOpsConfig) (cldf.ChangesetOutput, error) { - e.Logger.Infof("Locking/Unlocking liquidity for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - chainState := state.SolChains[cfg.SolChainSelector] - if err := cfg.Validate(e, chainState); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - poolType := shared.LockReleaseTokenPool - tokenPool := chainState.GetActiveTokenPool(poolType, cfg.Metadata) - runSafely(func() { - solLockReleaseTokenPool.SetProgramID(tokenPool) - }) - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - poolConfigPDA, _ := solTokenUtil.TokenPoolConfigAddress(tokenPubKey, tokenPool) - tokenPoolUsingMcms := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - poolType, - tokenPubKey, - cfg.Metadata, - ) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - poolType, - tokenPubKey, - cfg.Metadata, - ) - ixns := make([]solana.Instruction, 0) - if cfg.SetCfg != nil { - ix, err := solLockReleaseTokenPool.NewSetCanAcceptLiquidityInstruction( - cfg.SetCfg.Enabled, - poolConfigPDA, - tokenPubKey, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - if cfg.LiquidityCfg != nil { - tokenProgram, _ := chainState.TokenToTokenProgram(tokenPubKey) - poolSigner, _ := solTokenUtil.TokenPoolSignerAddress(tokenPubKey, tokenPool) - poolConfigAccount := solLockReleaseTokenPool.State{} - _ = chain.GetAccountDataBorshInto(context.Background(), poolConfigPDA, &poolConfigAccount) - if cfg.LiquidityCfg.Amount <= 0 { - return cldf.ChangesetOutput{}, fmt.Errorf("invalid amount: %d", cfg.LiquidityCfg.Amount) - } - tokenAmount := uint64(cfg.LiquidityCfg.Amount) // #nosec G115 - we check the amount above - switch cfg.LiquidityCfg.Type { - case Provide: - outDec, outVal, err := solTokenUtil.TokenBalance( - e.GetContext(), - chain.Client, - cfg.LiquidityCfg.RemoteTokenAccount, - cldf_solana.SolDefaultCommitment) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get token balance: %w", err) - } - if outVal < cfg.LiquidityCfg.Amount { - return cldf.ChangesetOutput{}, fmt.Errorf("insufficient token balance: %d < %d", outVal, cfg.LiquidityCfg.Amount) - } - ix1, err := solTokenUtil.TokenApproveChecked( - tokenAmount, - outDec, - tokenProgram, - cfg.LiquidityCfg.RemoteTokenAccount, - tokenPubKey, - poolSigner, - chain.DeployerKey.PublicKey(), - solana.PublicKeySlice{}, - ) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to TokenApproveChecked: %w", err) - } - if err = chain.Confirm([]solana.Instruction{ix1}); err != nil { - e.Logger.Errorw("Failed to confirm instructions for TokenApproveChecked", "chain", chain.String(), "err", err) - return cldf.ChangesetOutput{}, err - } - ix, err := solLockReleaseTokenPool.NewProvideLiquidityInstruction( - tokenAmount, - poolConfigPDA, - tokenProgram, - tokenPubKey, - poolSigner, - poolConfigAccount.Config.PoolTokenAccount, - cfg.LiquidityCfg.RemoteTokenAccount, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - case Withdraw: - ix, err := solLockReleaseTokenPool.NewWithdrawLiquidityInstruction( - tokenAmount, - poolConfigPDA, - tokenProgram, - tokenPubKey, - poolSigner, - poolConfigAccount.Config.PoolTokenAccount, - cfg.LiquidityCfg.RemoteTokenAccount, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - } - if cfg.RebalancerCfg != nil { - ix, err := solLockReleaseTokenPool.NewSetRebalancerInstruction( - cfg.RebalancerCfg.Rebalancer, - poolConfigPDA, - tokenPubKey, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - - if tokenPoolUsingMcms { - txns := make([]mcmsTypes.Transaction, 0) - err := appendTxs(ixns, tokenPool, poolType, &txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate mcms txn: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.SolChainSelector, "proposal to RemoveFromTokenPoolAllowList in Solana", cfg.MCMS.MinDelay, txns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - err = chain.Confirm(ixns) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - return cldf.ChangesetOutput{}, nil -} - -// TOKEN POOL OPS -type TokenPoolOpsCfg struct { - SolChainSelector uint64 - // a pool pda is uniquely identified by (solTokenPubKey, poolType, metadata) - SolTokenPubKey string - PoolType cldf.ContractType - Metadata string // tag to identify which client/cll token pool executable to use - DeleteChainCfg *DeleteChainCfg // remove remote pool config corresponding to the set (solTokenPubKey, poolType, metadata, remoteChainSelector) - SetRouterCfg *SetRouterCfg // set router address on token pool config pda - MCMS *cldfproposalutils.TimelockConfig -} - -type DeleteChainCfg struct { - RemoteChainSelector uint64 -} - -type SetRouterCfg struct { - Router solana.PublicKey -} - -func (cfg TokenPoolOpsCfg) Validate(e cldf.Environment, state stateview.CCIPOnChainState) error { - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - if cfg.PoolType == "" { - return errors.New("pool type must be defined") - } - chainState := state.SolChains[cfg.SolChainSelector] - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - if err := chainState.CommonValidation(e, cfg.SolChainSelector, tokenPubKey); err != nil { - return err - } - if err := chainState.ValidatePoolDeployment(&e, cfg.PoolType, cfg.SolChainSelector, tokenPubKey, true, cfg.Metadata); err != nil { - return err - } - if cfg.DeleteChainCfg != nil { - var remoteChainConfigAccount any - - tokenPool := chainState.GetActiveTokenPool(cfg.PoolType, cfg.Metadata) - switch cfg.PoolType { - case shared.BurnMintTokenPool: - remoteChainConfigAccount = solBurnMintTokenPool.ChainConfig{} - case shared.LockReleaseTokenPool: - remoteChainConfigAccount = solLockReleaseTokenPool.ChainConfig{} - default: - return fmt.Errorf("invalid pool type: %s", cfg.PoolType) - } - // check if this remote chain is already configured for this token - remoteChainConfigPDA, _, err := solTokenUtil.TokenPoolChainConfigPDA(cfg.DeleteChainCfg.RemoteChainSelector, tokenPubKey, tokenPool) - if err != nil { - return fmt.Errorf("failed to get token pool remote chain config pda (remoteSelector: %d, mint: %s, pool: %s): %w", cfg.DeleteChainCfg.RemoteChainSelector, tokenPubKey.String(), tokenPool.String(), err) - } - err = chain.GetAccountDataBorshInto(context.Background(), remoteChainConfigPDA, &remoteChainConfigAccount) - if err != nil { - return fmt.Errorf("remote chain config not found for (remoteSelector: %d, mint: %s, pool: %s, type: %s): %w", cfg.DeleteChainCfg.RemoteChainSelector, tokenPubKey.String(), tokenPool.String(), cfg.PoolType, err) - } - } - if cfg.SetRouterCfg != nil { - if cfg.SetRouterCfg.Router.IsZero() { - return fmt.Errorf("invalid router address: %s", cfg.SetRouterCfg.Router.String()) - } - } - return ValidateMCMSConfigSolana(e, cfg.MCMS, chain, chainState, tokenPubKey, cfg.Metadata, map[cldf.ContractType]bool{}) -} - -// remove remote pool config corresponding to the set (solTokenPubKey, poolType, metadata, remoteChainSelector) -// set router address on token pool config pda -func TokenPoolOps(e cldf.Environment, cfg TokenPoolOpsCfg) (cldf.ChangesetOutput, error) { - e.Logger.Infof("Setting pool config for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) - if err != nil { - return cldf.ChangesetOutput{}, err - } - if err := cfg.Validate(e, state); err != nil { - return cldf.ChangesetOutput{}, err - } - chain := e.BlockChains.SolanaChains()[cfg.SolChainSelector] - tokenPubKey := solana.MustPublicKeyFromBase58(cfg.SolTokenPubKey) - chainState := state.SolChains[cfg.SolChainSelector] - var ix solana.Instruction - ixns := make([]solana.Instruction, 0) - tokenPool := chainState.GetActiveTokenPool(cfg.PoolType, cfg.Metadata) - tokenPoolUsingMcms := solanastateview.IsSolanaProgramOwnedByTimelock( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - - poolConfigPDA, _ := solTokenUtil.TokenPoolConfigAddress(tokenPubKey, tokenPool) - remoteChainConfigPDA, _, _ := solTokenUtil.TokenPoolChainConfigPDA(cfg.DeleteChainCfg.RemoteChainSelector, tokenPubKey, tokenPool) - authority := GetAuthorityForIxn( - &e, - chain, - chainState, - cfg.PoolType, - tokenPubKey, - cfg.Metadata, - ) - switch cfg.PoolType { - case shared.BurnMintTokenPool: - runSafely(func() { - solBurnMintTokenPool.SetProgramID(tokenPool) - }) - if cfg.DeleteChainCfg != nil { - ix, err = solBurnMintTokenPool.NewDeleteChainConfigInstruction( - cfg.DeleteChainCfg.RemoteChainSelector, - tokenPubKey, - poolConfigPDA, - remoteChainConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - if cfg.SetRouterCfg != nil { - ix, err = solBurnMintTokenPool.NewSetRouterInstruction( - cfg.SetRouterCfg.Router, - poolConfigPDA, - tokenPubKey, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - case shared.LockReleaseTokenPool: - runSafely(func() { - solLockReleaseTokenPool.SetProgramID(tokenPool) - }) - if cfg.DeleteChainCfg != nil { - ix, err = solLockReleaseTokenPool.NewDeleteChainConfigInstruction( - cfg.DeleteChainCfg.RemoteChainSelector, - tokenPubKey, - poolConfigPDA, - remoteChainConfigPDA, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - if cfg.SetRouterCfg != nil { - ix, err = solLockReleaseTokenPool.NewSetRouterInstruction( - cfg.SetRouterCfg.Router, - poolConfigPDA, - tokenPubKey, - authority, - ).ValidateAndBuild() - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate instructions: %w", err) - } - ixns = append(ixns, ix) - } - default: - return cldf.ChangesetOutput{}, fmt.Errorf("invalid pool type: %s", cfg.PoolType) - } - if tokenPoolUsingMcms { - tx, err := BuildMCMSTxn(ix, tokenPool.String(), cfg.PoolType) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to create transaction: %w", err) - } - proposal, err := BuildProposalsForTxns( - e, cfg.SolChainSelector, "proposal to ConfigureTokenPoolAllowList in Solana", cfg.MCMS.MinDelay, []mcmsTypes.Transaction{*tx}) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - if err := chain.Confirm(ixns); err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to confirm instructions: %w", err) - } - e.Logger.Infow("Configured token pool allowlist", "token_pubkey", tokenPubKey.String()) - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_0/cs_verify_contracts.go b/deployment/ccip/changeset/solana_v0_1_0/cs_verify_contracts.go deleted file mode 100644 index 0948df4c49b..00000000000 --- a/deployment/ccip/changeset/solana_v0_1_0/cs_verify_contracts.go +++ /dev/null @@ -1,414 +0,0 @@ -package solana - -import ( - "encoding/json" - "errors" - "fmt" - "strings" - - "github.com/gagliardetto/solana-go" - "github.com/mr-tron/base58" - solstate "github.com/smartcontractkit/cld-changesets/legacy/pkg/family/solana" - pdasol "github.com/smartcontractkit/cld-changesets/pkg/family/solana" - - "github.com/smartcontractkit/mcms" - mcmsTypes "github.com/smartcontractkit/mcms/types" - - cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana" - cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - cldfproposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils" - - "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" - "github.com/smartcontractkit/chainlink/deployment/utils/solutils" -) - -const ( - SolanaVerifyProgramID = "verifycLy8mB96wd9wqq3WDXQwM4oU6r42Th37Db9fC" -) - -// https://solana.com/developers/guides/advanced/verified-builds -type VerifyBuildConfig struct { - GitCommitSha string - ChainSelector uint64 - VerifyFeeQuoter bool - VerifyRouter bool - VerifyOffRamp bool - VerifyRMNRemote bool - BurnMintTokenPoolMetadata []string - LockReleaseTokenPoolMetadata []string - VerifyAccessController bool - VerifyMCM bool - VerifyTimelock bool - // if program is owned by deployer key - // set to true -> verification and remote job submission will be done in the same call to this changeset - // if program is owned by timelock signer - // set to false in the first call to this changeset - // get the proposal -> signed -> executed on chain - // once thats done, call this changeset again, set to true and it will submit the remote job - RemoteVerification bool - // set to the same as upgrade authority of the program - // timelock signer or deployer key - UpgradeAuthority solana.PublicKey - MCMS *cldfproposalutils.TimelockConfig -} - -func runSolanaVerifyMCMS(e cldf.Environment, - cfg VerifyBuildConfig, - chain cldf_solana.Chain, - programID, libraryName, mountPath string, - timelockSignerPDA solana.PublicKey, - mcmsTxs *[]mcmsTypes.Transaction, -) error { - // enter here only if mcms tx has been signed and submitted to the chain - // https://solana.com/developers/guides/advanced/verified-builds#7-submit-remote-verification-job - if cfg.RemoteVerification { - cmdArgs := []string{ - "remote", - "submit-job", - "--url", chain.URL, - "--uploader", timelockSignerPDA.String(), - "--program-id", programID, - } - output, err := runCommand("solana-verify", cmdArgs, chain.ProgramsPath) - e.Logger.Infow("remote submit-job output", "output", output) - if err != nil { - return fmt.Errorf("solana program verification failed: %s %w", output, err) - } - // only need to submit job this time as we are assuming here that the mcms tx has been signed and submitted to the chain - return nil - } - - // run cli command - cmdArgs := []string{ - "export-pda-tx", - "--url", chain.URL, - "--program-id", programID, - "--library-name", libraryName, - strings.TrimSuffix(repoURL, ".git"), - "--commit-hash", cfg.GitCommitSha, - "--mount-path", mountPath, - "--uploader", timelockSignerPDA.String(), - } - e.Logger.Infow("export-pda-tx cmdArgs", "cmdArgs", cmdArgs) - output, err := runCommand("solana-verify", cmdArgs, ".") - e.Logger.Infow("export-pda-tx output", "output", output) - if err != nil { - return fmt.Errorf("solana program verification failed: %s %w", output, err) - } - - // get ix from output - resolvedIxn, err := getIxnFromEncodedTx(e, output, timelockSignerPDA) - if err != nil { - return fmt.Errorf("failed to get ixn from encoded tx: %w", err) - } - if resolvedIxn == nil { - return errors.New("failed to get ixn from encoded tx") - } - - // build mcms tx from ix - upgradeTx, err := BuildMCMSTxn(resolvedIxn, resolvedIxn.ProgID.String(), cldf.ContractType(libraryName)) - if err != nil { - return fmt.Errorf("failed to build upgrade transaction: %w", err) - } - if upgradeTx != nil { - e.Logger.Infow("upgradeTx", "tx", upgradeTx) - *mcmsTxs = append(*mcmsTxs, *upgradeTx) - } - return nil -} - -func runSolanaVerifyWithoutMCMS(e cldf.Environment, - cfg VerifyBuildConfig, - chain cldf_solana.Chain, - programID, libraryName, mountPath string, - timelockSignerPDA solana.PublicKey, -) error { - // if timelock signer does not exist - // or user has set the upgrade authority to the deployer key - // then we need to run the cli command - cmdArgs := []string{ - "verify-from-repo", - "--url", chain.URL, - "--program-id", programID, - "--library-name", libraryName, - strings.TrimSuffix(repoURL, ".git"), - "--commit-hash", cfg.GitCommitSha, - "--mount-path", mountPath, - "--skip-prompt", - } - - output, err := runCommand("solana-verify", cmdArgs, ".") - e.Logger.Infow("verify-from-repo output", "output", output) - if err != nil { - return fmt.Errorf("solana program verification failed: %s %w", output, err) - } - if cfg.RemoteVerification { - cmdArgs = []string{ - "remote", - "submit-job", - "--url", chain.URL, - "--uploader", chain.DeployerKey.PublicKey().String(), - "--program-id", programID, - } - output, err := runCommand("solana-verify", cmdArgs, chain.ProgramsPath) - e.Logger.Infow("remote submit-job output", "output", output) - if err != nil { - return fmt.Errorf("solana program verification failed: %s %w", output, err) - } - } - return nil -} - -func runSolanaVerify(e cldf.Environment, - cfg VerifyBuildConfig, - chain cldf_solana.Chain, - programID, libraryName, mountPath string, - timelockSignerPDA solana.PublicKey, - mcmsTxs *[]mcmsTypes.Transaction, -) error { - params := map[string]string{ - "Keypair Path": chain.KeypairPath, - "Network URL": chain.URL, - "Program ID": programID, - "Lib Name": libraryName, - "Commit Hash": cfg.GitCommitSha, - "Mount Path": mountPath, - } - log, err := json.MarshalIndent(params, "", "") - if err != nil { - return err - } - e.Logger.Infow("solana verify params", "params", string(log)) - - // if timelock signer exists - // and user has set the upgrade authority to the timelock signer - // then we need to create mcms txs - if !timelockSignerPDA.IsZero() && cfg.UpgradeAuthority == timelockSignerPDA { - return runSolanaVerifyMCMS(e, cfg, chain, programID, libraryName, mountPath, timelockSignerPDA, mcmsTxs) - } - return runSolanaVerifyWithoutMCMS(e, cfg, chain, programID, libraryName, mountPath, timelockSignerPDA) -} - -// each tx contains 2 things -// 1. message (which contains a list of instructions) -// 2. signatures -// we will extract out the relevant instruction from the message by decoding the different layers -func getIxnFromEncodedTx(e cldf.Environment, output string, timelockSignerPDA solana.PublicKey) (*solana.GenericInstruction, error) { - // get the base58-encoded transaction from the output - // this is based on the current tx output format - // if solana-verify cli changes the output format, this will break - lines := strings.Split(output, "\n") - var base58EncodedTx string - for i := len(lines) - 1; i >= 0; i-- { - if strings.TrimSpace(lines[i]) != "" { - base58EncodedTx = strings.TrimSpace(lines[i]) - break - } - } - if base58EncodedTx == "" { - return nil, errors.New("failed to extract base58-encoded transaction") - } - e.Logger.Infow("base58-encoded transaction", "tx", base58EncodedTx) - - // create a transaction object from the base58EncodedTx - tx, err := solana.TransactionFromBase58(base58EncodedTx) - if err != nil { - return nil, fmt.Errorf("failed to create transaction from bytes: %w", err) - } - - // we will now find the instruction within the tx that is being executed on the verify program - - // list of all accounts in the tx - txAccountList := tx.Message.AccountKeys - for _, inst := range tx.Message.Instructions { - // this should not happen unless solana-verify cli has a bug - if int(inst.ProgramIDIndex) >= len(txAccountList) { - return nil, fmt.Errorf("program ID index out of range: %d", inst.ProgramIDIndex) - } - // the programID on which this instruction is being executed - programID := txAccountList[inst.ProgramIDIndex] - // if its the verify program, resolve the instruction - // this is the ix we need to get signed by mcms - if programID.String() == SolanaVerifyProgramID { - resolved, err := resolveVerifyInstruction(e, timelockSignerPDA, tx.Message, inst) - if err != nil { - return nil, fmt.Errorf("failed to resolve the verify instruction: %w", err) - } - return resolved, nil - } - } - return nil, errors.New("failed to find verify instruction") -} - -// this function takes in an ix which is part of a tx -// and creates an independent ixn object -// which will then be used to create an independent mcms tx -// it uses the tx.Message to do so -func resolveVerifyInstruction( - e cldf.Environment, - timelockSignerPDA solana.PublicKey, - msg solana.Message, - verifyIxn solana.CompiledInstruction, -) (*solana.GenericInstruction, error) { - // the programID on which this instruction is being executed - // this must be the verify program - programID := msg.AccountKeys[verifyIxn.ProgramIDIndex] - // the data of the instruction that we want to run on the verify programs - data, err := base58.Decode(verifyIxn.Data.String()) - if err != nil { - return nil, fmt.Errorf("failed to decode instruction data: %w", err) - } - - // the accounts that are being used in the instruction - // we need to get the pubkeys of these accounts from the tx.Message - // and then create an AccountMeta object for each account - // this is the list of accounts that will be used to create the verify ix - accounts := make(solana.AccountMetaSlice, len(verifyIxn.Accounts)) - for i, idx := range verifyIxn.Accounts { - if int(idx) >= len(msg.AccountKeys) { - return nil, fmt.Errorf("account index out of range: %d", idx) - } - accountPubKey := msg.AccountKeys[idx] - isSigner := msg.IsSigner(accountPubKey) - isWritable, err := msg.IsWritable(accountPubKey) - if err != nil { - return nil, fmt.Errorf("failed to check if account is writable: %w", err) - } - accounts[i] = &solana.AccountMeta{ - PublicKey: accountPubKey, - IsSigner: isSigner, - IsWritable: isWritable, - } - } - - return &solana.GenericInstruction{ - ProgID: programID, - AccountValues: accounts, - DataBytes: data, - }, nil -} - -func setConfig(e cldf.Environment, chain cldf_solana.Chain) error { - cmdArgs := []string{ - "config", - "set", - "--keypair", chain.KeypairPath, - } - output, err := runCommand("solana", cmdArgs, ".") - e.Logger.Infow("solana config set output", "output", output) - if err != nil { - return fmt.Errorf("failed to set keypair during program verification: %s %w", output, err) - } - cmdArgs = []string{ - "config", - "set", - "--url", chain.URL, - } - output, err = runCommand("solana", cmdArgs, ".") - e.Logger.Infow("solana config set output", "output", output) - if err != nil { - return fmt.Errorf("failed to set url during program verification: %s %w", output, err) - } - return nil -} - -func VerifyBuild(e cldf.Environment, cfg VerifyBuildConfig) (cldf.ChangesetOutput, error) { - chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - state, _ := stateview.LoadOnchainState(e) - chainState := state.SolChains[cfg.ChainSelector] - - addresses, err := e.ExistingAddresses.AddressesForChain(cfg.ChainSelector) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to get existing addresses: %w", err) - } - mcmState, err := solstate.MaybeLoadMCMSWithTimelockChainState(chain, addresses) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) - } - var timelockSignerPDA solana.PublicKey - if mcmState != nil { - timelockSignerPDA = pdasol.GetTimelockSignerPDA(mcmState.TimelockProgram, mcmState.TimelockSeed) - } - - verifications := []struct { - name string - programID string - programLib string - enabled bool - }{ - {"Fee Quoter", chainState.FeeQuoter.String(), solutils.ProgFeeQuoter, cfg.VerifyFeeQuoter}, - {"Router", chainState.Router.String(), solutils.ProgCCIPRouter, cfg.VerifyRouter}, - {"OffRamp", chainState.OffRamp.String(), solutils.ProgCCIPOfframp, cfg.VerifyOffRamp}, - {"RMN Remote", chainState.RMNRemote.String(), solutils.ProgRMNRemote, cfg.VerifyRMNRemote}, - {"Access Controller", mcmState.AccessControllerProgram.String(), solutils.ProgAccessController, cfg.VerifyAccessController}, - {"MCM", mcmState.McmProgram.String(), solutils.ProgMCM, cfg.VerifyMCM}, - {"Timelock", mcmState.TimelockProgram.String(), solutils.ProgTimelock, cfg.VerifyTimelock}, - } - for _, bnmMetadata := range cfg.BurnMintTokenPoolMetadata { - verifications = append(verifications, struct { - name string - programID string - programLib string - enabled bool - }{ - name: "Burn Mint Token Pool", - programID: chainState.BurnMintTokenPools[bnmMetadata].String(), - programLib: solutils.ProgBurnMintTokenPool, - enabled: true, - }) - } - - for _, lnrMetadata := range cfg.LockReleaseTokenPoolMetadata { - verifications = append(verifications, struct { - name string - programID string - programLib string - enabled bool - }{ - name: "Lock Release Token Pool", - programID: chainState.LockReleaseTokenPools[lnrMetadata].String(), - programLib: solutils.ProgLockReleaseTokenPool, - enabled: true, - }) - } - - err = setConfig(e, chain) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to set config: %w", err) - } - - mcmsTxs := make([]mcmsTypes.Transaction, 0) - for _, v := range verifications { - if !v.enabled { - continue - } - - e.Logger.Debugw("Verifying program", "name", v.name, "programID", v.programID, "programLib", v.programLib) - err := runSolanaVerify( - e, - cfg, - chain, - v.programID, - v.programLib, - anchorDir, - timelockSignerPDA, - &mcmsTxs, - ) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("error verifying %s: %w", v.name, err) - } - } - if len(mcmsTxs) > 0 { - proposal, err := BuildProposalsForTxns( - e, cfg.ChainSelector, "proposal to verify CCIP contracts", cfg.MCMS.MinDelay, mcmsTxs) - if err != nil { - return cldf.ChangesetOutput{}, fmt.Errorf("failed to build proposal: %w", err) - } - - return cldf.ChangesetOutput{ - MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, - }, nil - } - - return cldf.ChangesetOutput{}, nil -} diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_billing.go b/deployment/ccip/changeset/solana_v0_1_1/cs_billing.go index 213a6ca7050..de25ca7d61c 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_billing.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_billing.go @@ -164,7 +164,7 @@ func AddBillingToken( } func AddBillingTokenChangeset(e cldf.Environment, cfg BillingTokenConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -241,7 +241,7 @@ func (cfg TokenTransferFeeForRemoteChainConfig) Validate(e cldf.Environment, sta } func AddTokenTransferFeeForRemoteChain(e cldf.Environment, cfg TokenTransferFeeForRemoteChainConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -363,7 +363,7 @@ func (cfg UpdatePricesConfig) Validate(e cldf.Environment, state stateview.CCIPO } func UpdatePrices(e cldf.Environment, cfg UpdatePricesConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) + s, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -468,7 +468,7 @@ func (cfg ModifyPriceUpdaterConfig) Validate(e cldf.Environment, state stateview } func ModifyPriceUpdater(e cldf.Environment, cfg ModifyPriceUpdaterConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) + s, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -571,7 +571,7 @@ func (cfg WithdrawBilledFundsConfig) Validate(e cldf.Environment, state statevie } func WithdrawBilledFunds(e cldf.Environment, cfg WithdrawBilledFundsConfig) (cldf.ChangesetOutput, error) { - s, err := stateview.LoadOnchainState(e) + s, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -667,7 +667,7 @@ func (cfg SetMaxFeeJuelsPerMsgConfig) Validate(e cldf.Environment, state statevi } func SetMaxFeeJuelsPerMsg(e cldf.Environment, cfg SetMaxFeeJuelsPerMsgConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_deploy_chain.go b/deployment/ccip/changeset/solana_v0_1_1/cs_deploy_chain.go index 77ba1a862b8..f6a499279a3 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_deploy_chain.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_deploy_chain.go @@ -1348,7 +1348,7 @@ func ExtendGlobalLookupTableChangeset(e cldf.Environment, cfg ExtendGlobalLookup if !ok { return cldf.ChangesetOutput{}, fmt.Errorf("chain not found for selector %d", cfg.ChainSelector) } - existingState, err := stateview.LoadOnchainState(e) + existingState, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_ops.go b/deployment/ccip/changeset/solana_v0_1_1/cs_ops.go index 4794797f06e..742570b407c 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_ops.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_ops.go @@ -338,7 +338,7 @@ func (cfg SetFeeAggregatorConfig) Validate(e cldf.Environment, state stateview.C } func SetFeeAggregator(e cldf.Environment, cfg SetFeeAggregatorConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -420,7 +420,7 @@ func (cfg DeployForTestConfig) Validate(e cldf.Environment, state stateview.CCIP } func DeployReceiverForTest(e cldf.Environment, cfg DeployForTestConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -512,7 +512,7 @@ func (cfg SetLinkTokenConfig) Validate(e cldf.Environment, state stateview.CCIPO } func SetLinkToken(e cldf.Environment, cfg SetLinkTokenConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -578,7 +578,7 @@ func (cfg SetDefaultCodeVersionConfig) Validate(e cldf.Environment, state statev func SetDefaultCodeVersion(e cldf.Environment, cfg SetDefaultCodeVersionConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Setting default code version", "chain_selector", cfg.ChainSelector, "new_code_version", cfg.VersionEnum) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } @@ -738,7 +738,7 @@ func (cfg UpdateSvmChainSelectorConfig) Validate(e cldf.Environment, state state func UpdateSvmChainSelector(e cldf.Environment, cfg UpdateSvmChainSelectorConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Updating SVM chain selector", "old_chain_selector", cfg.OldChainSelector, "new_chain_selector", cfg.NewChainSelector) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } @@ -862,7 +862,7 @@ func (cfg UpdateEnableManualExecutionAfterConfig) Validate(e cldf.Environment, s func UpdateEnableManualExecutionAfter(e cldf.Environment, cfg UpdateEnableManualExecutionAfterConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Updating enable manual execution after", "chain_selector", cfg.ChainSelector, "enable_manual_execution_after", cfg.EnableManualExecution) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } @@ -962,7 +962,7 @@ func (cfg ConfigureCCIPVersionConfig) Validate(e cldf.Environment, state statevi } func ConfigureCCIPVersion(e cldf.Environment, cfg ConfigureCCIPVersionConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } @@ -1064,7 +1064,7 @@ func (cfg RemoveOffRampConfig) Validate(e cldf.Environment, state stateview.CCIP } func RemoveOffRamp(e cldf.Environment, cfg RemoveOffRampConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, fmt.Errorf("failed to load onchain state: %w", err) } diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_solana_token.go b/deployment/ccip/changeset/solana_v0_1_1/cs_solana_token.go index ae796cfcc81..99f78d84ca1 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_solana_token.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_solana_token.go @@ -223,7 +223,7 @@ type MintSolanaTokenConfig struct { func (cfg MintSolanaTokenConfig) Validate(e cldf.Environment) error { chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] tokenAddress := solana.MustPublicKeyFromBase58(cfg.TokenPubkey) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return err } @@ -256,7 +256,7 @@ func MintSolanaToken(e cldf.Environment, cfg MintSolanaTokenConfig) (cldf.Change } // get chain chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - state, _ := stateview.LoadOnchainState(e) + state, _ := stateview.LoadOnchainStateSolana(e) chainState := state.SolChains[cfg.ChainSelector] // get addresses tokenAddress := solana.MustPublicKeyFromBase58(cfg.TokenPubkey) @@ -282,7 +282,7 @@ type CreateSolanaTokenATAConfig struct { func CreateSolanaTokenATA(e cldf.Environment, cfg CreateSolanaTokenATAConfig) (cldf.ChangesetOutput, error) { chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - state, _ := stateview.LoadOnchainState(e) + state, _ := stateview.LoadOnchainStateSolana(e) chainState := state.SolChains[cfg.ChainSelector] tokenprogramID, err := chainState.TokenToTokenProgram(cfg.TokenPubkey) diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_token_admin_registry.go b/deployment/ccip/changeset/solana_v0_1_1/cs_token_admin_registry.go index ea50a6788bc..18da6af8d5e 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_token_admin_registry.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_token_admin_registry.go @@ -109,7 +109,7 @@ func (cfg RegisterTokenAdminRegistryConfig) Validate(e cldf.Environment, chainSt // you can register using the token mint authority which can be the deployer key only func RegisterTokenAdminRegistry(e cldf.Environment, cfg RegisterTokenAdminRegistryConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("RegisterTokenAdminRegistry", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -329,7 +329,7 @@ func (cfg TransferAdminRoleTokenAdminRegistryConfig) Validate(e cldf.Environment func TransferAdminRoleTokenAdminRegistry(e cldf.Environment, cfg TransferAdminRoleTokenAdminRegistryConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("TransferAdminRoleTokenAdminRegistry", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -466,7 +466,7 @@ func (cfg AcceptAdminRoleTokenAdminRegistryConfig) Validate(e cldf.Environment, func AcceptAdminRoleTokenAdminRegistry(e cldf.Environment, cfg AcceptAdminRoleTokenAdminRegistryConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("AcceptAdminRoleTokenAdminRegistry", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -566,7 +566,7 @@ func (cfg UpgradeTokenAdminRegistryConfig) Validate(e cldf.Environment, chainSta func UpgradeTokenAdminRegistry(e cldf.Environment, cfg UpgradeTokenAdminRegistryConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("UpgradeTokenAdminRegistry", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -679,7 +679,7 @@ func (cfg SetPoolConfig) Validate(e cldf.Environment, chainState solanastateview // this sets the writable indexes of the token pool lookup table func SetPool(e cldf.Environment, cfg SetPoolConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Setting pool config", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -814,7 +814,7 @@ func (cfg RemovePoolConfig) Validate(e cldf.Environment, chainState solanastatev // RemovePool sets the token pool lookup table to the zero address, effectively removing the pool association. func RemovePool(e cldf.Environment, cfg RemovePoolConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Removing pool config", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -910,7 +910,7 @@ func (cfg SetTokenPoolSupportAutoDerivationConfig) Validate(e cldf.Environment, func SetTokenPoolSupportAutoDerivation(e cldf.Environment, cfg SetTokenPoolSupportAutoDerivationConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Setting auto derivation in token admin registry for token", "autoDerivation", cfg.SupportsAutoDerivation, "tokenPubkey", cfg.TokenPubKey.String()) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go b/deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go index 434e3a7ddbf..0057d85fc5a 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_token_pool.go @@ -235,7 +235,7 @@ func (cfg AddTokenPoolAndLookupTableConfig) Validate(e cldf.Environment, chainSt } func AddTokenPoolAndLookupTable(e cldf.Environment, cfg AddTokenPoolAndLookupTableConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -625,7 +625,7 @@ func getOnChainEVMPoolConfig(e cldf.Environment, state stateview.CCIPOnChainStat func InitGlobalConfigTokenPoolProgram(e cldf.Environment, cfg TokenPoolConfigWithMCM) (cldf.ChangesetOutput, error) { e.Logger.Infow("Setting up token pool global config", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -747,7 +747,7 @@ func DisableSelfServedInTokenPoolProgram(e cldf.Environment, cfg TokenPoolConfig } func modifySelfServedConfig(e cldf.Environment, cfg TokenPoolConfigWithMCM, enabled bool) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -890,7 +890,7 @@ func (cfg CreateTokenMultisigConfig) Validate(e cldf.Environment, chainState sol func CreateTokenMultisig(e cldf.Environment, cfg CreateTokenMultisigConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Create Token Multisig with", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -951,7 +951,12 @@ func recordTokenMultisig( return fmt.Errorf("failed to save new token multisig to address book: %w", err) } - datastoreTV := cldf.NewTypeAndVersion("TOKEN_MULTISIG", deployment.Version1_6_0) + // PascalCase, matching every other Solana contract type in the datastore. 374 of the + // 380 existing Solana rows already use it; SCREAMING_SNAKE was the outlier here and in + // the 2.0 writer, and two spellings for one concept means a lookup by type resolves + // only half the population. The address-book identity above keeps its own legacy + // spelling -- that store is being retired, and changing it would rewrite history. + datastoreTV := cldf.NewTypeAndVersion("TokenMultisig", deployment.Version1_6_0) datastoreTV.AddLabel(mint.String()) return shared.RecordAddress(nil, ds, chainSelector, address, datastoreTV, qualifier) } @@ -1024,7 +1029,7 @@ func (cfg TransferMintAuthorityToSignerPDAConfig) Validate(e cldf.Environment, c func TransferMintAuthorityToSignerPDA(e cldf.Environment, cfg TransferMintAuthorityToSignerPDAConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Transfer mint authority to signer PDA", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -1121,7 +1126,7 @@ func TransferMintAuthorityToSignerPDA(e cldf.Environment, cfg TransferMintAuthor func ModifyMintAuthority(e cldf.Environment, cfg NewMintTokenPoolConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Use multisig as mint authority", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2019,7 +2024,7 @@ func (cfg TokenPoolLookupTableConfig) Validate(e cldf.Environment, chainState so // AddTokenPoolAndLookupTable should be called instead func AddTokenPoolLookupTable(e cldf.Environment, cfg TokenPoolLookupTableConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Adding token pool lookup table", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2170,7 +2175,7 @@ func (cfg ConfigureTokenPoolAllowListConfig) Validate(e cldf.Environment, chainS func ConfigureTokenPoolAllowList(e cldf.Environment, cfg ConfigureTokenPoolAllowListConfig) (cldf.ChangesetOutput, error) { e.Logger.Infof("Configuring token pool allowlist for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2302,7 +2307,7 @@ func (cfg RemoveFromAllowListConfig) Validate(e cldf.Environment, chainState sol func RemoveFromTokenPoolAllowList(e cldf.Environment, cfg RemoveFromAllowListConfig) (cldf.ChangesetOutput, error) { e.Logger.Infof("Removing from token pool allowlist for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2449,7 +2454,7 @@ func (cfg LockReleaseLiquidityOpsConfig) Validate(e cldf.Environment, chainState func LockReleaseLiquidityOps(e cldf.Environment, cfg LockReleaseLiquidityOpsConfig) (cldf.ChangesetOutput, error) { e.Logger.Infof("Locking/Unlocking liquidity for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2668,7 +2673,7 @@ func (cfg TokenPoolOpsCfg) Validate(e cldf.Environment, state stateview.CCIPOnCh // set router address on token pool config pda func TokenPoolOps(e cldf.Environment, cfg TokenPoolOpsCfg) (cldf.ChangesetOutput, error) { e.Logger.Infof("Setting pool config for token %s", cfg.SolTokenPubKey) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2827,7 +2832,7 @@ func TokenPoolOps(e cldf.Environment, cfg TokenPoolOpsCfg) (cldf.ChangesetOutput func InitializeStateVersion(e cldf.Environment, cfg TokenPoolConfigWithMCM) (cldf.ChangesetOutput, error) { e.Logger.Infow("Init state version for old tp", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -2952,7 +2957,7 @@ func (cfg SyncDomainConfig) Validate(e cldf.Environment, chainState solanastatev // SyncDomain adds or removes CCTP domain configs from the Solana CCTP token pool func SyncDomain(e cldf.Environment, cfg SyncDomainConfig) (cldf.ChangesetOutput, error) { e.Logger.Infow("Syncing USDC domains", "cfg", cfg) - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -3137,7 +3142,7 @@ func ExtendTokenPoolLookupTable(e cldf.Environment, cfg ExtendTokenPoolLookupTab return cldf.ChangesetOutput{}, nil } - chainState, err := stateview.LoadOnchainState(e) + chainState, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } @@ -3243,7 +3248,7 @@ func (cfg SetRateLimitAdminConfig) Validate(e cldf.Environment, chainState solan } func SetRateLimitAdmin(e cldf.Environment, cfg SetRateLimitAdminConfig) (cldf.ChangesetOutput, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return cldf.ChangesetOutput{}, err } diff --git a/deployment/ccip/changeset/solana_v0_1_1/cs_verify_contracts.go b/deployment/ccip/changeset/solana_v0_1_1/cs_verify_contracts.go index 68639aed436..d954c2bae09 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/cs_verify_contracts.go +++ b/deployment/ccip/changeset/solana_v0_1_1/cs_verify_contracts.go @@ -315,7 +315,7 @@ func setConfig(e cldf.Environment, chain cldf_solana.Chain) error { func VerifyBuild(e cldf.Environment, cfg VerifyBuildConfig) (cldf.ChangesetOutput, error) { chain := e.BlockChains.SolanaChains()[cfg.ChainSelector] - state, _ := stateview.LoadOnchainState(e) + state, _ := stateview.LoadOnchainStateSolana(e) chainState := state.SolChains[cfg.ChainSelector] addresses, err := e.ExistingAddresses.AddressesForChain(cfg.ChainSelector) diff --git a/deployment/ccip/changeset/solana_v0_1_1/self_serve.go b/deployment/ccip/changeset/solana_v0_1_1/self_serve.go index fae1bd1bf3f..0d60afe499e 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/self_serve.go +++ b/deployment/ccip/changeset/solana_v0_1_1/self_serve.go @@ -329,7 +329,7 @@ type routerSolanaState struct { } func loadRouterSolanaState(e cldf.Environment, cfg OnboardTokenPoolsForSelfServeConfig) (globalState, routerSolanaState, error) { - state, err := stateview.LoadOnchainState(e) + state, err := stateview.LoadOnchainStateSolana(e) if err != nil { return globalState{}, routerSolanaState{}, err } diff --git a/deployment/ccip/changeset/solana_v0_1_1/token_symbol_test.go b/deployment/ccip/changeset/solana_v0_1_1/token_symbol_test.go index 1483410b4ca..362d78e43f3 100644 --- a/deployment/ccip/changeset/solana_v0_1_1/token_symbol_test.go +++ b/deployment/ccip/changeset/solana_v0_1_1/token_symbol_test.go @@ -52,7 +52,7 @@ func TestRecordTokenMultisig(t *testing.T) { refs, err := ds.Addresses().Fetch() require.NoError(t, err) require.Len(t, refs, 1) - require.Equal(t, datastore.ContractType("TOKEN_MULTISIG"), refs[0].Type) + require.Equal(t, datastore.ContractType("TokenMultisig"), refs[0].Type) require.Equal(t, deployment.Version1_6_0, *refs[0].Version) require.Equal(t, "TEST_TOKEN", refs[0].Qualifier) require.Equal(t, datastore.NewLabelSet(mint.String()), refs[0].Labels) diff --git a/integration-tests/smoke/ccip/ccip_solana_sui_token_transfer_test.go b/integration-tests/smoke/ccip/ccip_solana_sui_token_transfer_test.go index f0159b35bc9..9e0bfff8846 100644 --- a/integration-tests/smoke/ccip/ccip_solana_sui_token_transfer_test.go +++ b/integration-tests/smoke/ccip/ccip_solana_sui_token_transfer_test.go @@ -81,7 +81,7 @@ func prepareSolana2SuiTokenTransferTest(t *testing.T) solana2SuiTokenFixtures { rpcClient := solChains[sourceChain].Client ctx := testcontext.Get(t) - wSOL := solana.SolMint + wSOL := solana.WrappedSol ixAtaUser, deployerWSOL, err := soltokens.CreateAssociatedTokenAccount(solana.TokenProgramID, wSOL, deployer.PublicKey(), deployer.PublicKey()) require.NoError(t, err) diff --git a/plugins/plugins.public.yaml b/plugins/plugins.public.yaml index 653cacbcc43..97e68ec611f 100644 --- a/plugins/plugins.public.yaml +++ b/plugins/plugins.public.yaml @@ -84,7 +84,7 @@ plugins: capability-evm: - moduleURI: "github.com/smartcontractkit/capabilities/chain_capabilities/evm" - gitRef: "4d4c4ec65942cf2732b8bc0594278cd05165aec2" + gitRef: "89fb223ac4be910d320ebc5f36e34ad58483057f" installPath: "." capability-solana: @@ -99,7 +99,7 @@ plugins: capability-stellar: - moduleURI: "github.com/smartcontractkit/capabilities/chain_capabilities/stellar" - gitRef: "37945e9e0fa41f14eaac47ad457cd6270b0ef0bf" + gitRef: "5eeef034d90b0f4644cd1ad79b410174d042b162" installPath: "." confidential-http: diff --git a/system-tests/tests/smoke/cre/stellar/stellarwrite/main.go b/system-tests/tests/smoke/cre/stellar/stellarwrite/main.go index ce708331a6a..f3fbdb55461 100644 --- a/system-tests/tests/smoke/cre/stellar/stellarwrite/main.go +++ b/system-tests/tests/smoke/cre/stellar/stellarwrite/main.go @@ -113,7 +113,15 @@ func onStellarWriteTrigger(cfg config.Config, runtime sdk.Runtime, payload *cron }).Await() if err != nil { if cfg.ExpectFailure { - return nil, fmt.Errorf("expected failed tx status in WriteReport reply, got call error instead: %w", err) + // The capability rejects undeliverable writes before submitting (pre-submit + // simulation gate): the receiver reports it cannot accept the report, so no tx + // is sent and WriteReport returns a call error instead of a failed-tx reply. + // That rejection is the expected failure for these negative receivers. + runtime.Logger().Info( + fmt.Sprintf("Stellar write failure observed as expected error=%v", err), + "workflow", cfg.WorkflowName, + ) + return nil, nil } runtime.Logger().Info(fmt.Sprintf("Stellar write failed: WriteReport error: %v", err), "workflow", cfg.WorkflowName, "chainSelector", cfg.ChainSelector) return nil, err diff --git a/tools/ci/README.md b/tools/ci/README.md index a6dd46a54ac..c5ec1ec6048 100644 --- a/tools/ci/README.md +++ b/tools/ci/README.md @@ -12,6 +12,10 @@ | `ci ccip resolve-baseline` | Resolve the CCIP release baseline image tag for mixed-version/rollout tests | `.github/scripts/resolve-ccip-release-baseline.sh` | | `ci changeset check-tags` | Validate semver in changeset frontmatter and check release tags | `.github/scripts/check-changeset-tags.sh` | | `ci tools matrix` | Generate test target matrix for tools directory | Inline matrix scripts | +| `ci matrix system` | Discover Go system tests and generate matrix for CRE smoke / regression | Inline `grep` + `jq` matrix scripts | +| `ci matrix in-memory` | Parse in-memory test configuration and generate matrix | Inline `jq` matrix scripts | +| `ci matrix ccip` | Generate CCIP system test matrix | Inline `jq` matrix scripts | +| `ci matrix mixed-env` | Generate CRE mixed-environment test matrix | Inline `jq` matrix scripts | ## Usage diff --git a/tools/ci/cmd/matrix.go b/tools/ci/cmd/matrix.go new file mode 100644 index 00000000000..52e8f7cc6d6 --- /dev/null +++ b/tools/ci/cmd/matrix.go @@ -0,0 +1,299 @@ +package cmd + +import ( + "encoding/json" + "fmt" + "strconv" + + "github.com/spf13/cobra" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/ghaction" + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func newMatrixCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "matrix", + Short: "Commands for generating dynamic GitHub Actions test matrices", + } + + cmd.AddCommand(newMatrixSystemCmd()) + cmd.AddCommand(newMatrixInMemoryCmd()) + cmd.AddCommand(newMatrixCCIPCmd()) + cmd.AddCommand(newMatrixMixedEnvCmd()) + + return cmd +} + +func resolveMatrixCommon(act *ghaction.Action, runID, runAttempt, spotFlag *string) { + ctx, err := act.Context() + if err != nil { + ctx = nil + } + + if *runID == "" { + *runID = act.GetInput("run_id") + } + if *runID == "" { + *runID = act.Getenv("GITHUB_RUN_ID") + } + if *runID == "" && ctx != nil && ctx.RunID != 0 { + *runID = strconv.FormatInt(ctx.RunID, 10) + } + + if *runAttempt == "" { + *runAttempt = act.GetInput("run_attempt") + } + if *runAttempt == "" { + *runAttempt = act.Getenv("GITHUB_RUN_ATTEMPT") + } + if *runAttempt == "" && ctx != nil && ctx.RunAttempt != 0 { + *runAttempt = strconv.FormatInt(ctx.RunAttempt, 10) + } + + if *spotFlag == "" { + *spotFlag = act.GetInput("spot_flag") + } + if *spotFlag == "" { + *spotFlag = act.Getenv("RUNNER_SPOT_FLAG") + } +} + +func outputMatrix(cmd *cobra.Command, act *ghaction.Action, res any, jsonOutput bool) error { + jsonData, err := json.Marshal(res) + if err != nil { + return fmt.Errorf("failed to marshal matrix to JSON: %w", err) + } + + if act.Getenv("GITHUB_OUTPUT") != "" { + if err := act.SetOutput("matrix", string(jsonData)); err != nil { + return fmt.Errorf("failed to set GitHub Action output: %w", err) + } + } + + if jsonOutput || act.Getenv("GITHUB_OUTPUT") == "" { + enc := json.NewEncoder(cmd.OutOrStdout()) + if jsonOutput { + enc.SetIndent("", " ") + } + return enc.Encode(res) + } + + return nil +} + +func newMatrixSystemCmd() *cobra.Command { + var ( + suite string + dir string + runID string + runAttempt string + spotFlag string + jsonOutput bool + ) + + cmd := &cobra.Command{ + Use: "system", + Short: "Generate test matrix for Go system tests (CRE smoke or regression)", + RunE: func(cmd *cobra.Command, args []string) error { + act := ghaction.NewAction(cmd.OutOrStdout()) + resolveMatrixCommon(act, &runID, &runAttempt, &spotFlag) + + if suite == "" { + suite = act.GetInput("suite") + } + if suite == "" { + suite = "cre-smoke" + } + + if dir == "" { + dir = act.GetInput("dir") + } + + var ( + res any + err error + ) + + switch suite { + case "cre-smoke": + if dir == "" { + dir = "system-tests/tests/smoke/cre" + } + res, err = matrix.BuildCRESmokeMatrix(cmd.Context(), matrix.CRESmokeOptions{ + Dir: dir, + RunID: runID, + RunAttempt: runAttempt, + SpotFlag: spotFlag, + }) + case "cre-regression": + if dir == "" { + dir = "system-tests/tests/regression/cre" + } + res, err = matrix.BuildCRERegressionMatrix(cmd.Context(), matrix.CRERegressionOptions{ + Dir: dir, + RunID: runID, + RunAttempt: runAttempt, + SpotFlag: spotFlag, + }) + default: + return fmt.Errorf("unknown system test suite: %q (expected 'cre-smoke' or 'cre-regression')", suite) + } + + if err != nil { + return err + } + + return outputMatrix(cmd, act, res, jsonOutput) + }, + } + + cmd.Flags().StringVar(&suite, "suite", "", "System test suite name ('cre-smoke', 'cre-regression')") + cmd.Flags().StringVar(&dir, "dir", "", "Directory containing Go system test files") + cmd.Flags().StringVar(&runID, "run-id", "", "GitHub run ID (env: GITHUB_RUN_ID)") + cmd.Flags().StringVar(&runAttempt, "run-attempt", "", "GitHub run attempt (env: GITHUB_RUN_ATTEMPT)") + cmd.Flags().StringVar(&spotFlag, "spot-flag", "", "RunsOn spot flag (e.g. 'spot=co', 'spot=false')") + cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output formatted JSON to stdout") + + return cmd +} + +func newMatrixInMemoryCmd() *cobra.Command { + var ( + file string + runID string + runAttempt string + spotFlag string + jsonOutput bool + ) + + cmd := &cobra.Command{ + Use: "in-memory", + Short: "Generate test matrix for in-memory integration tests", + RunE: func(cmd *cobra.Command, args []string) error { + act := ghaction.NewAction(cmd.OutOrStdout()) + resolveMatrixCommon(act, &runID, &runAttempt, &spotFlag) + + if file == "" { + file = act.GetInput("file") + } + if file == "" { + file = ".github/in-memory-tests.json" + } + + res, err := matrix.BuildInMemoryMatrix(cmd.Context(), matrix.InMemoryOptions{ + ConfigFile: file, + RunID: runID, + RunAttempt: runAttempt, + SpotFlag: spotFlag, + }) + if err != nil { + return err + } + + return outputMatrix(cmd, act, res, jsonOutput) + }, + } + + cmd.Flags().StringVar(&file, "file", "", "Path to in-memory tests configuration JSON") + cmd.Flags().StringVar(&runID, "run-id", "", "GitHub run ID (env: GITHUB_RUN_ID)") + cmd.Flags().StringVar(&runAttempt, "run-attempt", "", "GitHub run attempt (env: GITHUB_RUN_ATTEMPT)") + cmd.Flags().StringVar(&spotFlag, "spot-flag", "", "RunsOn spot flag (e.g. 'spot=co', 'spot=false')") + cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output formatted JSON to stdout") + + return cmd +} + +func newMatrixCCIPCmd() *cobra.Command { + var ( + runID string + runAttempt string + spotFlag string + mixedVersionOnly bool + runMixedVersionTests bool + jsonOutput bool + ) + + cmd := &cobra.Command{ + Use: "ccip", + Short: "Generate test matrix for CCIP system tests", + RunE: func(cmd *cobra.Command, args []string) error { + act := ghaction.NewAction(cmd.OutOrStdout()) + resolveMatrixCommon(act, &runID, &runAttempt, &spotFlag) + + if !mixedVersionOnly { + if v := act.GetInput("mixed_version_only"); v == "true" || v == "1" { + mixedVersionOnly = true + } else if v := act.Getenv("MIXED_VERSION_ONLY"); v == "true" || v == "1" { + mixedVersionOnly = true + } + } + + if !runMixedVersionTests { + if v := act.GetInput("run_mixed_version_tests"); v == "true" || v == "1" { + runMixedVersionTests = true + } else if v := act.Getenv("RUN_MIXED_VERSION_TESTS"); v == "true" || v == "1" { + runMixedVersionTests = true + } + } + + res, err := matrix.BuildCCIPSystemMatrix(cmd.Context(), matrix.CCIPSystemOptions{ + RunID: runID, + RunAttempt: runAttempt, + SpotFlag: spotFlag, + MixedVersionOnly: mixedVersionOnly, + RunMixedVersionTests: runMixedVersionTests, + }) + if err != nil { + return err + } + + return outputMatrix(cmd, act, res, jsonOutput) + }, + } + + cmd.Flags().StringVar(&runID, "run-id", "", "GitHub run ID (env: GITHUB_RUN_ID)") + cmd.Flags().StringVar(&runAttempt, "run-attempt", "", "GitHub run attempt (env: GITHUB_RUN_ATTEMPT)") + cmd.Flags().StringVar(&spotFlag, "spot-flag", "", "RunsOn spot flag (e.g. 'spot=co', 'spot=false')") + cmd.Flags().BoolVar(&mixedVersionOnly, "mixed-version-only", false, "Restrict matrix to mixed-version tests (release rollout) (env: MIXED_VERSION_ONLY)") + cmd.Flags().BoolVar(&runMixedVersionTests, "run-mixed-version-tests", false, "Include mixed-version tests in test matrix (env: RUN_MIXED_VERSION_TESTS)") + cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output formatted JSON to stdout") + + return cmd +} + +func newMatrixMixedEnvCmd() *cobra.Command { + var ( + runID string + runAttempt string + spotFlag string + jsonOutput bool + ) + + cmd := &cobra.Command{ + Use: "mixed-env", + Short: "Generate test matrix for CRE mixed-environment system tests", + RunE: func(cmd *cobra.Command, args []string) error { + act := ghaction.NewAction(cmd.OutOrStdout()) + resolveMatrixCommon(act, &runID, &runAttempt, &spotFlag) + + res, err := matrix.BuildCREMixedEnvMatrix(cmd.Context(), matrix.CREMixedEnvOptions{ + RunID: runID, + RunAttempt: runAttempt, + SpotFlag: spotFlag, + }) + if err != nil { + return err + } + + return outputMatrix(cmd, act, res, jsonOutput) + }, + } + + cmd.Flags().StringVar(&runID, "run-id", "", "GitHub run ID (env: GITHUB_RUN_ID)") + cmd.Flags().StringVar(&runAttempt, "run-attempt", "", "GitHub run attempt (env: GITHUB_RUN_ATTEMPT)") + cmd.Flags().StringVar(&spotFlag, "spot-flag", "", "RunsOn spot flag (e.g. 'spot=co', 'spot=false')") + cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output formatted JSON to stdout") + + return cmd +} diff --git a/tools/ci/cmd/matrix_test.go b/tools/ci/cmd/matrix_test.go new file mode 100644 index 00000000000..eb7b984948f --- /dev/null +++ b/tools/ci/cmd/matrix_test.go @@ -0,0 +1,233 @@ +package cmd_test + +import ( + "bytes" + "context" + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/cmd" + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func TestMatrixSystem_CLI(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "smoke_test.go") + content := `package smoke_test + +import "testing" + +func Test_CRE_V2_Demo(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "system", + "--suite", "cre-smoke", + "--dir", tmpDir, + "--run-id", "123", + "--run-attempt", "1", + "--spot-flag", "spot=co", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CRESmokeEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 1) + assert.Equal(t, "Test_CRE_V2_Demo", res[0].TestName) + assert.Equal(t, "workflow-gateway-capabilities", res[0].Topology) + assert.Equal(t, "runs-on=123-0-1/cpu=16/ram=64/family=m7i+m8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) +} + +func TestMatrixInMemory_CLI(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + configFile := filepath.Join(tmpDir, "in-memory-tests.json") + content := `[ + {"name":"sample_test.go","test":"TestSample","timeout":"10m","parallel":1,"plugins":false,"runs_on":"","free_disk":false,"aptos":"","sui":""} +]` + require.NoError(t, os.WriteFile(configFile, []byte(content), 0o600)) + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "in-memory", + "--file", configFile, + "--run-id", "456", + "--run-attempt", "1", + "--spot-flag", "spot=pco", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.InMemoryEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 1) + assert.Equal(t, "sample_test.go", res[0].Name) + assert.Equal(t, 15, res[0].JobTimeout) + assert.Equal(t, "ubuntu-latest", res[0].RunsOn) +} + +func TestMatrixCCIP_CLI_DefaultQuarantine(t *testing.T) { + t.Parallel() + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "ccip", + "--run-id", "789", + "--run-attempt", "2", + "--spot-flag", "spot=co", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CCIPSystemEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 3) + assert.Equal(t, "Test_CCIPGasPriceUpdatesWriteFrequency", res[0].TestName) + assert.Equal(t, "TestRMN_GlobalCurseTwoMessagesOnTwoLanes", res[1].TestName) + assert.Equal(t, "TestDeleteCCIPJobs-TestRevokeJobs", res[2].TestName) +} + +func TestMatrixCCIP_CLI_RunMixedVersionTests(t *testing.T) { + t.Parallel() + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "ccip", + "--run-mixed-version-tests", + "--run-id", "789", + "--run-attempt", "2", + "--spot-flag", "spot=co", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CCIPSystemEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 5) + assert.Equal(t, "Test_CCIPGasPriceUpdatesWriteFrequency", res[0].TestName) + assert.Equal(t, "TestRMN_GlobalCurseTwoMessagesOnTwoLanes", res[1].TestName) + assert.Equal(t, "TestDeleteCCIPJobs-TestRevokeJobs", res[2].TestName) + assert.Equal(t, "Test_CCIPMixedVersionDON", res[3].TestName) + assert.True(t, res[3].MixedVersion) + assert.Equal(t, "Test_CCIPRollingUpgrade", res[4].TestName) + assert.True(t, res[4].MixedVersion) +} + +func TestMatrixCCIP_CLI_MixedVersionOnly(t *testing.T) { + t.Parallel() + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "ccip", + "--mixed-version-only", + "--run-id", "789", + "--run-attempt", "2", + "--spot-flag", "spot=co", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CCIPSystemEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 2) + assert.Equal(t, "Test_CCIPMixedVersionDON", res[0].TestName) + assert.Equal(t, "Test_CCIPRollingUpgrade", res[1].TestName) +} + +func TestMatrixCCIP_CLI_EnvResolution(t *testing.T) { + t.Setenv("GITHUB_RUN_ID", "555") + t.Setenv("GITHUB_RUN_ATTEMPT", "1") + t.Setenv("RUNNER_SPOT_FLAG", "spot=co") + t.Setenv("RUN_MIXED_VERSION_TESTS", "true") + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "ccip", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CCIPSystemEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 5) + assert.Equal(t, "runs-on=555-0-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) +} + +func TestMatrixMixedEnv_CLI(t *testing.T) { + t.Parallel() + + rootCmd := cmd.NewRootCmd() + var out bytes.Buffer + rootCmd.SetOut(&out) + rootCmd.SetErr(&out) + rootCmd.SetArgs([]string{ + "matrix", "mixed-env", + "--run-id", "321", + "--run-attempt", "1", + "--spot-flag", "spot=pco", + "--json", + }) + + err := rootCmd.ExecuteContext(context.Background()) + require.NoError(t, err) + + var res []matrix.CREMixedEnvEntry + err = json.Unmarshal(out.Bytes(), &res) + require.NoError(t, err) + require.Len(t, res, 5) + assert.Equal(t, "Test_CRE_V2_Suite_Bucket_A", res[0].TestName) + assert.Equal(t, 0, res[0].TestID) + assert.Equal(t, "configs/mixed-env-don.toml", res[0].Configs) + assert.Equal(t, "runs-on=321-0-1/cpu=16/ram=64/family=m7i+m8i/spot=pco/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) + assert.Equal(t, "Test_CRE_V2_EVM_Read_TxArtifacts", res[4].TestName) + assert.Equal(t, 4, res[4].TestID) + assert.Equal(t, "configs/mixed-env-don.toml", res[4].Configs) + assert.Equal(t, "runs-on=321-4-1/cpu=16/ram=64/family=m7i+m8i/spot=pco/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[4].RunsOn) +} diff --git a/tools/ci/cmd/root.go b/tools/ci/cmd/root.go index 1d7c11645a6..65b542d07f2 100644 --- a/tools/ci/cmd/root.go +++ b/tools/ci/cmd/root.go @@ -25,6 +25,7 @@ func NewRootCmd() *cobra.Command { rootCmd.AddCommand(newChangesetCmd()) rootCmd.AddCommand(newCCIPCmd()) rootCmd.AddCommand(newRunnerCmd()) + rootCmd.AddCommand(newMatrixCmd()) return rootCmd } diff --git a/tools/ci/internal/matrix/ccip.go b/tools/ci/internal/matrix/ccip.go new file mode 100644 index 00000000000..a180f0fa842 --- /dev/null +++ b/tools/ci/internal/matrix/ccip.go @@ -0,0 +1,108 @@ +package matrix + +import ( + "context" + "fmt" +) + +// CCIPSystemOptions contains parameters for generating CCIP system test matrix. +type CCIPSystemOptions struct { + RunID string + RunAttempt string + SpotFlag string + MixedVersionOnly bool + RunMixedVersionTests bool +} + +// CCIPSystemEntry is a single test entry in the CCIP system matrix. +type CCIPSystemEntry struct { + TestName string `json:"test_name"` + Timeout string `json:"timeout,omitempty"` + JobTimeout int `json:"job_timeout,omitempty"` + SelectedNetwork string `json:"selected_network,omitempty"` + RMNRageProxyVersion string `json:"rmn_rageproxy_version,omitempty"` + RMNAFN2ProxyVersion string `json:"rmn_afn2proxy_version,omitempty"` + MixedVersion bool `json:"mixed_version,omitempty"` + TestID int `json:"test_id"` + RunsOn string `json:"runs_on"` +} + +// BuildCCIPSystemMatrix generates the matrix for CCIP system tests. +func BuildCCIPSystemMatrix(ctx context.Context, opts CCIPSystemOptions) ([]CCIPSystemEntry, error) { + params, err := resolveRunsOnParams(opts.RunID, opts.RunAttempt, opts.SpotFlag) + if err != nil { + return nil, err + } + + definitions := []struct { + TestName string + Timeout string + JobTimeout int + SelectedNetwork string + RMNRageProxyVersion string + RMNAFN2ProxyVersion string + MixedVersion bool + }{ + { + TestName: "Test_CCIPGasPriceUpdatesWriteFrequency", + Timeout: "15m", + SelectedNetwork: "SIMULATED_1,SIMULATED_2", + }, + { + TestName: "TestRMN_GlobalCurseTwoMessagesOnTwoLanes", + Timeout: "15m", + SelectedNetwork: "SIMULATED_1,SIMULATED_2", + RMNRageProxyVersion: "master-amd6416f5d86", + RMNAFN2ProxyVersion: "master-amd64-10b42b2", + }, + { + TestName: "TestDeleteCCIPJobs-TestRevokeJobs", + Timeout: "15m", + JobTimeout: 20, + SelectedNetwork: "SIMULATED_1,SIMULATED_2", + }, + { + TestName: "Test_CCIPMixedVersionDON", + Timeout: "20m", + SelectedNetwork: "SIMULATED_1,SIMULATED_2", + MixedVersion: true, + }, + { + TestName: "Test_CCIPRollingUpgrade", + Timeout: "30m", + SelectedNetwork: "SIMULATED_1,SIMULATED_2", + MixedVersion: true, + }, + } + + entries := make([]CCIPSystemEntry, len(definitions)) + for i, def := range definitions { + runsOn := fmt.Sprintf("runs-on=%s-%d-%s/cpu=8/ram=64/family=r6i+r7i+r8i/%s/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", + params.RunID, i, params.RunAttempt, params.SpotFlag) + + entries[i] = CCIPSystemEntry{ + TestName: def.TestName, + Timeout: def.Timeout, + JobTimeout: def.JobTimeout, + SelectedNetwork: def.SelectedNetwork, + RMNRageProxyVersion: def.RMNRageProxyVersion, + RMNAFN2ProxyVersion: def.RMNAFN2ProxyVersion, + MixedVersion: def.MixedVersion, + TestID: i, + RunsOn: runsOn, + } + } + + var filtered []CCIPSystemEntry + for _, e := range entries { + if opts.MixedVersionOnly { + if e.MixedVersion { + filtered = append(filtered, e) + } + } else if opts.RunMixedVersionTests || !e.MixedVersion { + filtered = append(filtered, e) + } + } + + return filtered, nil +} diff --git a/tools/ci/internal/matrix/ccip_test.go b/tools/ci/internal/matrix/ccip_test.go new file mode 100644 index 00000000000..2e3b9271ff1 --- /dev/null +++ b/tools/ci/internal/matrix/ccip_test.go @@ -0,0 +1,136 @@ +package matrix_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func TestBuildCCIPSystemMatrix_DefaultQuarantine(t *testing.T) { + t.Parallel() + + res, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunID: "112233", + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.NoError(t, err) + require.Len(t, res, 3) + + assert.Equal(t, "Test_CCIPGasPriceUpdatesWriteFrequency", res[0].TestName) + assert.Equal(t, 0, res[0].TestID) + assert.Equal(t, "15m", res[0].Timeout) + assert.Equal(t, "SIMULATED_1,SIMULATED_2", res[0].SelectedNetwork) + assert.False(t, res[0].MixedVersion) + assert.Equal(t, "runs-on=112233-0-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) + + assert.Equal(t, "TestRMN_GlobalCurseTwoMessagesOnTwoLanes", res[1].TestName) + assert.Equal(t, 1, res[1].TestID) + assert.Equal(t, "master-amd6416f5d86", res[1].RMNRageProxyVersion) + assert.Equal(t, "master-amd64-10b42b2", res[1].RMNAFN2ProxyVersion) + assert.False(t, res[1].MixedVersion) + assert.Equal(t, "runs-on=112233-1-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[1].RunsOn) + + assert.Equal(t, "TestDeleteCCIPJobs-TestRevokeJobs", res[2].TestName) + assert.Equal(t, 2, res[2].TestID) + assert.Equal(t, 20, res[2].JobTimeout) + assert.False(t, res[2].MixedVersion) + assert.Equal(t, "runs-on=112233-2-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[2].RunsOn) +} + +func TestBuildCCIPSystemMatrix_RunMixedVersionTests(t *testing.T) { + t.Parallel() + + res, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunID: "112233", + RunAttempt: "1", + SpotFlag: "spot=co", + RunMixedVersionTests: true, + }) + require.NoError(t, err) + require.Len(t, res, 5) + + assert.Equal(t, "Test_CCIPGasPriceUpdatesWriteFrequency", res[0].TestName) + assert.Equal(t, "TestRMN_GlobalCurseTwoMessagesOnTwoLanes", res[1].TestName) + assert.Equal(t, "TestDeleteCCIPJobs-TestRevokeJobs", res[2].TestName) + + assert.Equal(t, "Test_CCIPMixedVersionDON", res[3].TestName) + assert.Equal(t, 3, res[3].TestID) + assert.Equal(t, "20m", res[3].Timeout) + assert.Equal(t, "SIMULATED_1,SIMULATED_2", res[3].SelectedNetwork) + assert.True(t, res[3].MixedVersion) + assert.Equal(t, "runs-on=112233-3-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[3].RunsOn) + + assert.Equal(t, "Test_CCIPRollingUpgrade", res[4].TestName) + assert.Equal(t, 4, res[4].TestID) + assert.Equal(t, "30m", res[4].Timeout) + assert.Equal(t, "SIMULATED_1,SIMULATED_2", res[4].SelectedNetwork) + assert.True(t, res[4].MixedVersion) + assert.Equal(t, "runs-on=112233-4-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[4].RunsOn) +} + +func TestBuildCCIPSystemMatrix_MissingRunID(t *testing.T) { + t.Parallel() + + _, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "run ID is required") +} + +func TestBuildCCIPSystemMatrix_Defaults(t *testing.T) { + t.Parallel() + + res, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunID: "112233", + }) + require.NoError(t, err) + require.Len(t, res, 3) + + assert.Equal(t, "runs-on=112233-0-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) +} + +func TestBuildCCIPSystemMatrix_MixedVersionOnly(t *testing.T) { + t.Parallel() + + res, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunID: "112233", + RunAttempt: "1", + SpotFlag: "spot=co", + MixedVersionOnly: true, + }) + require.NoError(t, err) + require.Len(t, res, 2) + + assert.Equal(t, "Test_CCIPMixedVersionDON", res[0].TestName) + assert.Equal(t, 3, res[0].TestID) + assert.Equal(t, "runs-on=112233-3-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) + + assert.Equal(t, "Test_CCIPRollingUpgrade", res[1].TestName) + assert.Equal(t, 4, res[1].TestID) + assert.Equal(t, "runs-on=112233-4-1/cpu=8/ram=64/family=r6i+r7i+r8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[1].RunsOn) +} + +func TestBuildCCIPSystemMatrix_MixedVersionOnly_Precedence(t *testing.T) { + t.Parallel() + + // Release rollout callers set MixedVersionOnly=true without RunMixedVersionTests; + // it must still return mixed-version tests (preventing PR #23790 bash bug). + res, err := matrix.BuildCCIPSystemMatrix(context.Background(), matrix.CCIPSystemOptions{ + RunID: "112233", + RunAttempt: "1", + SpotFlag: "spot=co", + MixedVersionOnly: true, + RunMixedVersionTests: false, + }) + require.NoError(t, err) + require.Len(t, res, 2) + assert.Equal(t, "Test_CCIPMixedVersionDON", res[0].TestName) + assert.Equal(t, "Test_CCIPRollingUpgrade", res[1].TestName) +} diff --git a/tools/ci/internal/matrix/discover.go b/tools/ci/internal/matrix/discover.go new file mode 100644 index 00000000000..161fe7d3e50 --- /dev/null +++ b/tools/ci/internal/matrix/discover.go @@ -0,0 +1,81 @@ +package matrix + +import ( + "fmt" + "go/ast" + "go/parser" + "go/token" + "os" + "path/filepath" + "regexp" + "sort" + "strings" +) + +// DiscoverOptions specifies filtering options when discovering test names. +type DiscoverOptions struct { + IgnoredPatterns []string +} + +// DiscoverGoTestNames scans a directory for Go test and example function names. +func DiscoverGoTestNames(dir string, opts DiscoverOptions) ([]string, error) { + var ignoredRegexes []*regexp.Regexp + for _, pattern := range opts.IgnoredPatterns { + re, err := regexp.Compile(pattern) + if err != nil { + return nil, fmt.Errorf("invalid ignore regex %q: %w", pattern, err) + } + ignoredRegexes = append(ignoredRegexes, re) + } + + entries, err := os.ReadDir(dir) + if err != nil { + return nil, fmt.Errorf("failed to read test directory %s: %w", dir, err) + } + + fset := token.NewFileSet() + testNames := make(map[string]struct{}) + + for _, entry := range entries { + if entry.IsDir() || !strings.HasSuffix(entry.Name(), "_test.go") { + continue + } + + filePath := filepath.Join(dir, entry.Name()) + node, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments) + if err != nil { + return nil, fmt.Errorf("failed to parse file %s: %w", filePath, err) + } + + for _, decl := range node.Decls { + fn, ok := decl.(*ast.FuncDecl) + if !ok || fn.Recv != nil { + continue + } + + name := fn.Name.Name + if !strings.HasPrefix(name, "Test") && !strings.HasPrefix(name, "Example") { + continue + } + + ignored := false + for _, re := range ignoredRegexes { + if re.MatchString(name) { + ignored = true + break + } + } + if !ignored { + testNames[name] = struct{}{} + } + } + } + + var result []string + for name := range testNames { + result = append(result, name) + } + sort.Strings(result) + + return result, nil +} diff --git a/tools/ci/internal/matrix/inmemory.go b/tools/ci/internal/matrix/inmemory.go new file mode 100644 index 00000000000..5acebe36252 --- /dev/null +++ b/tools/ci/internal/matrix/inmemory.go @@ -0,0 +1,106 @@ +package matrix + +import ( + "context" + "encoding/json" + "fmt" + "os" + "regexp" + "strconv" + "strings" +) + +var sanitizeRegex = regexp.MustCompile(`[^A-Za-z0-9._-]`) + +// SanitizeTestID sanitizes test name to be a legal artifact name. +func SanitizeTestID(name string) string { + return sanitizeRegex.ReplaceAllString(name, "_") +} + +// InMemoryOptions contains parameters for generating in-memory test matrix. +type InMemoryOptions struct { + ConfigFile string + RunID string + RunAttempt string + SpotFlag string +} + +// RawInMemoryEntry matches structure in .github/in-memory-tests.json. +type RawInMemoryEntry struct { + Name string `json:"name"` + Test string `json:"test"` + Timeout string `json:"timeout"` + Parallel int `json:"parallel"` + Plugins bool `json:"plugins"` + RunsOn string `json:"runs_on"` + FreeDisk bool `json:"free_disk"` + Aptos string `json:"aptos"` + Sui string `json:"sui"` +} + +// InMemoryEntry is the resolved test matrix entry. +type InMemoryEntry struct { + Name string `json:"name"` + Test string `json:"test"` + Timeout string `json:"timeout"` + JobTimeout int `json:"job_timeout"` + Parallel int `json:"parallel"` + Plugins bool `json:"plugins"` + RunsOn string `json:"runs_on"` + TestID string `json:"test_id"` + FreeDisk bool `json:"free_disk"` + Aptos string `json:"aptos"` + Sui string `json:"sui"` +} + +// BuildInMemoryMatrix parses in-memory test configuration and builds matrix. +func BuildInMemoryMatrix(ctx context.Context, opts InMemoryOptions) ([]InMemoryEntry, error) { + params, err := resolveRunsOnParams(opts.RunID, opts.RunAttempt, opts.SpotFlag) + if err != nil { + return nil, err + } + + data, err := os.ReadFile(opts.ConfigFile) + if err != nil { + return nil, fmt.Errorf("failed to read in-memory test config file %s: %w", opts.ConfigFile, err) + } + + var rawEntries []RawInMemoryEntry + if err = json.Unmarshal(data, &rawEntries); err != nil { + return nil, fmt.Errorf("failed to parse JSON from %s: %w", opts.ConfigFile, err) + } + + entries := make([]InMemoryEntry, len(rawEntries)) + for i, raw := range rawEntries { + timeoutMinutes := 15 + trimmed := strings.TrimSuffix(raw.Timeout, "m") + if val, err := strconv.Atoi(trimmed); err == nil { + timeoutMinutes = val + } + jobTimeout := timeoutMinutes + 5 + + var runsOn string + if raw.RunsOn == "" { + runsOn = "ubuntu-latest" + } else { + runsOn = fmt.Sprintf("runs-on=%s-%d-%s/%s/family=m7i+m8i/%s/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", + params.RunID, i, params.RunAttempt, raw.RunsOn, params.SpotFlag) + } + + entries[i] = InMemoryEntry{ + Name: raw.Name, + Test: raw.Test, + Timeout: raw.Timeout, + JobTimeout: jobTimeout, + Parallel: raw.Parallel, + Plugins: raw.Plugins, + RunsOn: runsOn, + TestID: SanitizeTestID(raw.Name), + FreeDisk: raw.FreeDisk, + Aptos: raw.Aptos, + Sui: raw.Sui, + } + } + + return entries, nil +} diff --git a/tools/ci/internal/matrix/inmemory_test.go b/tools/ci/internal/matrix/inmemory_test.go new file mode 100644 index 00000000000..c6ca8981da6 --- /dev/null +++ b/tools/ci/internal/matrix/inmemory_test.go @@ -0,0 +1,77 @@ +package matrix_test + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func TestBuildInMemoryMatrix(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + configFile := filepath.Join(tmpDir, "in-memory-tests.json") + content := `[ + {"name":"ccip_fees_test.go","test":"^(Test_CCIPFees)$","timeout":"20m","parallel":4,"plugins":false,"runs_on":"cpu=8/ram=32","free_disk":false,"aptos":"","sui":""}, + {"name":"Test_CCIPMessaging_Solana2EVM","test":"Test_CCIPMessaging_Solana2EVM","timeout":"18m","parallel":4,"plugins":true,"runs_on":"","free_disk":false,"aptos":"","sui":""} +]` + require.NoError(t, os.WriteFile(configFile, []byte(content), 0o600)) + + res, err := matrix.BuildInMemoryMatrix(context.Background(), matrix.InMemoryOptions{ + ConfigFile: configFile, + RunID: "999888", + RunAttempt: "3", + SpotFlag: "spot=pco", + }) + require.NoError(t, err) + require.Len(t, res, 2) + + // Entry 0: custom runs_on + first := res[0] + assert.Equal(t, "ccip_fees_test.go", first.Name) + assert.Equal(t, "ccip_fees_test.go", first.TestID) // sanitized name + assert.Equal(t, 25, first.JobTimeout) // 20m + 5 = 25 + assert.Equal(t, "runs-on=999888-0-3/cpu=8/ram=32/family=m7i+m8i/spot=pco/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", first.RunsOn) + assert.Equal(t, 4, first.Parallel) + assert.False(t, first.Plugins) + + // Entry 1: empty runs_on -> ubuntu-latest + second := res[1] + assert.Equal(t, "Test_CCIPMessaging_Solana2EVM", second.Name) + assert.Equal(t, "Test_CCIPMessaging_Solana2EVM", second.TestID) + assert.Equal(t, 23, second.JobTimeout) // 18m + 5 = 23 + assert.Equal(t, "ubuntu-latest", second.RunsOn) + assert.True(t, second.Plugins) +} + +func TestBuildInMemoryMatrix_MissingRunID(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + configFile := filepath.Join(tmpDir, "in-memory-tests.json") + content := `[ + {"name":"ccip_fees_test.go","test":"^(Test_CCIPFees)$","timeout":"20m","parallel":4,"plugins":false,"runs_on":"cpu=8/ram=32","free_disk":false,"aptos":"","sui":""} +]` + require.NoError(t, os.WriteFile(configFile, []byte(content), 0o600)) + + _, err := matrix.BuildInMemoryMatrix(context.Background(), matrix.InMemoryOptions{ + ConfigFile: configFile, + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "run ID is required") +} + +func TestSanitizeTestID(t *testing.T) { + t.Parallel() + + assert.Equal(t, "ccip_fees_test.go", matrix.SanitizeTestID("ccip_fees_test.go")) + assert.Equal(t, "Test_Foo_Bar_Baz.123-v1", matrix.SanitizeTestID("Test/Foo Bar:Baz.123-v1")) +} diff --git a/tools/ci/internal/matrix/mixedenv.go b/tools/ci/internal/matrix/mixedenv.go new file mode 100644 index 00000000000..c92daa5d747 --- /dev/null +++ b/tools/ci/internal/matrix/mixedenv.go @@ -0,0 +1,61 @@ +package matrix + +import ( + "context" + "fmt" +) + +// CREMixedEnvOptions contains parameters for generating CRE mixed-env test matrix. +type CREMixedEnvOptions struct { + RunID string + RunAttempt string + SpotFlag string +} + +// CREMixedEnvEntry is a single test entry in the CRE mixed-env matrix. +type CREMixedEnvEntry struct { + TestName string `json:"test_name"` + Configs string `json:"configs"` + TestID int `json:"test_id"` + RunsOn string `json:"runs_on"` +} + +var defaultCREMixedEnvTests = []string{ + "Test_CRE_V2_Suite_Bucket_A", + "Test_CRE_V2_Suite_Bucket_B", + "Test_CRE_V2_EVM_Read_HeavyCalls", + "Test_CRE_V2_EVM_Read_StateQueries", + "Test_CRE_V2_EVM_Read_TxArtifacts", +} + +var defaultCREMixedEnvConfigs = map[string]string{ + "Test_CRE_V2_ConfidentialWorkflows_Relay": "configs/mixed-env-confidential-workflows.toml", +} + +// BuildCREMixedEnvMatrix generates the matrix for CRE mixed-env tests. +func BuildCREMixedEnvMatrix(ctx context.Context, opts CREMixedEnvOptions) ([]CREMixedEnvEntry, error) { + params, err := resolveRunsOnParams(opts.RunID, opts.RunAttempt, opts.SpotFlag) + if err != nil { + return nil, err + } + + entries := make([]CREMixedEnvEntry, len(defaultCREMixedEnvTests)) + for i, name := range defaultCREMixedEnvTests { + configs, ok := defaultCREMixedEnvConfigs[name] + if !ok { + configs = "configs/mixed-env-don.toml" + } + + runsOn := fmt.Sprintf("runs-on=%s-%d-%s/cpu=16/ram=64/family=m7i+m8i/%s/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", + params.RunID, i, params.RunAttempt, params.SpotFlag) + + entries[i] = CREMixedEnvEntry{ + TestName: name, + Configs: configs, + TestID: i, + RunsOn: runsOn, + } + } + + return entries, nil +} diff --git a/tools/ci/internal/matrix/mixedenv_test.go b/tools/ci/internal/matrix/mixedenv_test.go new file mode 100644 index 00000000000..aa51bf83a00 --- /dev/null +++ b/tools/ci/internal/matrix/mixedenv_test.go @@ -0,0 +1,46 @@ +package matrix_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func TestBuildCREMixedEnvMatrix(t *testing.T) { + t.Parallel() + + res, err := matrix.BuildCREMixedEnvMatrix(context.Background(), matrix.CREMixedEnvOptions{ + RunID: "445566", + RunAttempt: "1", + SpotFlag: "spot=pco", + }) + require.NoError(t, err) + require.Len(t, res, 5) + + // Bucket A with default configs + assert.Equal(t, "Test_CRE_V2_Suite_Bucket_A", res[0].TestName) + assert.Equal(t, 0, res[0].TestID) + assert.Equal(t, "configs/mixed-env-don.toml", res[0].Configs) + assert.Equal(t, "runs-on=445566-0-1/cpu=16/ram=64/family=m7i+m8i/spot=pco/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) + + // TxArtifacts with default configs + assert.Equal(t, "Test_CRE_V2_EVM_Read_TxArtifacts", res[4].TestName) + assert.Equal(t, 4, res[4].TestID) + assert.Equal(t, "configs/mixed-env-don.toml", res[4].Configs) + assert.Equal(t, "runs-on=445566-4-1/cpu=16/ram=64/family=m7i+m8i/spot=pco/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[4].RunsOn) +} + +func TestBuildCREMixedEnvMatrix_MissingRunID(t *testing.T) { + t.Parallel() + + _, err := matrix.BuildCREMixedEnvMatrix(context.Background(), matrix.CREMixedEnvOptions{ + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "run ID is required") +} diff --git a/tools/ci/internal/matrix/runson.go b/tools/ci/internal/matrix/runson.go new file mode 100644 index 00000000000..eb85a0cd553 --- /dev/null +++ b/tools/ci/internal/matrix/runson.go @@ -0,0 +1,26 @@ +package matrix + +import "errors" + +// runsOnParams holds resolved parameters used to construct runs-on labels. +type runsOnParams struct { + RunID string + RunAttempt string + SpotFlag string +} + +// resolveRunsOnParams validates common runs-on label parameters and applies +// defaults for run attempt and spot flag. Run ID has no default because empty +// run IDs produce invalid runner labels. +func resolveRunsOnParams(runID, runAttempt, spotFlag string) (runsOnParams, error) { + if runID == "" { + return runsOnParams{}, errors.New("run ID is required to generate runs-on labels (provide --run-id, action input run_id, or GITHUB_RUN_ID)") + } + if runAttempt == "" { + runAttempt = "1" + } + if spotFlag == "" { + spotFlag = "spot=co" + } + return runsOnParams{RunID: runID, RunAttempt: runAttempt, SpotFlag: spotFlag}, nil +} diff --git a/tools/ci/internal/matrix/system.go b/tools/ci/internal/matrix/system.go new file mode 100644 index 00000000000..e1f15a0f668 --- /dev/null +++ b/tools/ci/internal/matrix/system.go @@ -0,0 +1,182 @@ +package matrix + +import ( + "context" + "fmt" +) + +// CRES smoke & regression topology structure. +type TopologyConfig struct { + Topology string `json:"topology,omitempty"` + Configs string `json:"configs"` +} + +// CRES smoke options. +type CRESmokeOptions struct { + Dir string + RunID string + RunAttempt string + SpotFlag string +} + +// CRES smoke matrix entry. +type CRESmokeEntry struct { + TestName string `json:"test_name"` + Topology string `json:"topology"` + Configs string `json:"configs"` + TestID int `json:"test_id"` + RunsOn string `json:"runs_on"` +} + +// CRERegression options. +type CRERegressionOptions struct { + Dir string + RunID string + RunAttempt string + SpotFlag string +} + +// CRERegression matrix entry. +type CRERegressionEntry struct { + TestName string `json:"test_name"` + TestID int `json:"test_id"` + Configs string `json:"configs"` + RunsOn string `json:"runs_on"` +} + +var defaultCRESmokePerTestTopologies = map[string][]TopologyConfig{ + "Test_CRE_V2_Suite_Bucket_B": { + {Topology: "workflow-gateway-capabilities", Configs: "configs/workflow-gateway-capabilities-don.toml"}, + {Topology: "workflow-gateway-capabilities-vault-stall-purge", Configs: "configs/workflow-gateway-capabilities-don-vault-stall-purge.toml"}, + }, + "Test_CRE_V2_Aptos_Suite": { + {Topology: "workflow-gateway-aptos", Configs: "configs/workflow-gateway-don-aptos.toml"}, + }, + "Test_CRE_V2_Stellar_Suite": { + {Topology: "workflow-gateway-stellar", Configs: "configs/workflow-gateway-don-stellar.toml"}, + }, + "Test_CRE_V2_Solana_Write": { + {Topology: "workflow", Configs: "configs/workflow-don-solana.toml"}, + }, + "Test_CRE_V2_Solana_LogTrigger": { + {Topology: "workflow", Configs: "configs/workflow-don-solana.toml"}, + }, + "Test_CRE_V2_Solana_Read_Accounts": { + {Topology: "workflow", Configs: "configs/workflow-don-solana.toml"}, + }, + "Test_CRE_V2_Solana_Read_Block": { + {Topology: "workflow", Configs: "configs/workflow-don-solana.toml"}, + }, + "Test_CRE_V2_Solana_Read_Tx": { + {Topology: "workflow", Configs: "configs/workflow-don-solana.toml"}, + }, + "Test_CRE_V2_Sharding": { + {Topology: "workflow-gateway-sharded", Configs: "configs/workflow-gateway-sharded-don.toml"}, + }, + "Test_CRE_V2_ShardingWithHttpTrigger": { + {Topology: "workflow-gateway-sharded", Configs: "configs/workflow-gateway-sharded-don.toml"}, + }, + "Test_CRE_V2_ShardManualAssignment": { + {Topology: "workflow-gateway-sharded-manual", Configs: "configs/workflow-gateway-sharded-manual.toml"}, + }, + "Test_CRE_V2_ShardedCapabilitiesManualEVMLogTrigger": { + {Topology: "workflow-sharded-capabilities", Configs: "configs/workflow-sharded-capabilities-don.toml"}, + }, + "Test_CRE_V2_ShardRingOCROverrides": { + {Topology: "workflow-gateway-sharded-ringocr-overrides", Configs: "configs/workflow-gateway-sharded-ringocr-overrides.toml"}, + }, + "Test_CRE_V2_FailoverManualSwap": { + {Topology: "workflow-gateway-failover", Configs: "configs/workflow-gateway-failover-don.toml"}, + }, + "Test_CRE_V2_Module_Cache": { + {Topology: "workflow-gateway-cache-test", Configs: "configs/workflow-gateway-don-cache-test.toml"}, + }, + "Test_CRE_V2_HTTP_Action_Multi_Gateway": { + {Topology: "workflow-gateway-capabilities-multi-gateway", Configs: "configs/workflow-gateway-capabilities-multi-gateway-don.toml"}, + }, + "Test_CRE_V2_ConfidentialWorkflows_Relay": { + {Topology: "workflow-gateway-capabilities-confidential-workflows", Configs: "configs/workflow-gateway-capabilities-don-confidential-workflows.toml"}, + }, +} + +var defaultCRERegressionPerTestConfigs = map[string]string{ + "Test_CRE_V2_Stellar_Regression": "configs/workflow-gateway-don-stellar.toml", + "Test_CRE_V2_Solana_Regression": "configs/workflow-don-solana.toml", +} + +// BuildCRESmokeMatrix discovers tests in dir and constructs CRE smoke test matrix. +func BuildCRESmokeMatrix(ctx context.Context, opts CRESmokeOptions) ([]CRESmokeEntry, error) { + testNames, err := DiscoverGoTestNames(opts.Dir, DiscoverOptions{ + IgnoredPatterns: []string{"^Test_Upgrade", "^TestMain$"}, + }) + if err != nil { + return nil, fmt.Errorf("failed discovering tests in %s: %w", opts.Dir, err) + } + + params, err := resolveRunsOnParams(opts.RunID, opts.RunAttempt, opts.SpotFlag) + if err != nil { + return nil, err + } + + entries := make([]CRESmokeEntry, 0, len(testNames)) + testID := 0 + + for _, name := range testNames { + topologies, hasOverride := defaultCRESmokePerTestTopologies[name] + if !hasOverride { + topologies = []TopologyConfig{ + {Topology: "workflow-gateway-capabilities", Configs: "configs/workflow-gateway-capabilities-don.toml"}, + } + } + + for _, top := range topologies { + runsOn := fmt.Sprintf("runs-on=%s-%d-%s/cpu=16/ram=64/family=m7i+m8i/%s/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", + params.RunID, testID, params.RunAttempt, params.SpotFlag) + entries = append(entries, CRESmokeEntry{ + TestName: name, + Topology: top.Topology, + Configs: top.Configs, + TestID: testID, + RunsOn: runsOn, + }) + testID++ + } + } + + return entries, nil +} + +// BuildCRERegressionMatrix discovers tests in dir and constructs CRE regression test matrix. +func BuildCRERegressionMatrix(ctx context.Context, opts CRERegressionOptions) ([]CRERegressionEntry, error) { + testNames, err := DiscoverGoTestNames(opts.Dir, DiscoverOptions{ + IgnoredPatterns: []string{"^TestMain$"}, + }) + if err != nil { + return nil, fmt.Errorf("failed discovering tests in %s: %w", opts.Dir, err) + } + + params, err := resolveRunsOnParams(opts.RunID, opts.RunAttempt, opts.SpotFlag) + if err != nil { + return nil, err + } + + entries := make([]CRERegressionEntry, 0, len(testNames)) + for i, name := range testNames { + configs, ok := defaultCRERegressionPerTestConfigs[name] + if !ok { + configs = "configs/workflow-gateway-capabilities-don.toml" + } + + runsOn := fmt.Sprintf("runs-on=%s-%d-%s/cpu=16/ram=64/family=m7i+m8i/%s/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", + params.RunID, i, params.RunAttempt, params.SpotFlag) + + entries = append(entries, CRERegressionEntry{ + TestName: name, + TestID: i, + Configs: configs, + RunsOn: runsOn, + }) + } + + return entries, nil +} diff --git a/tools/ci/internal/matrix/system_test.go b/tools/ci/internal/matrix/system_test.go new file mode 100644 index 00000000000..c1e9a84697d --- /dev/null +++ b/tools/ci/internal/matrix/system_test.go @@ -0,0 +1,281 @@ +package matrix_test + +import ( + "context" + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink/v2/tools/ci/internal/matrix" +) + +func TestDiscoverGoTestNames(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "sample_test.go") + content := `package sample_test + +import "testing" + +func TestMain(m *testing.M) {} +func Test_Smoke_HappyPath(t *testing.T) {} +func Test_Upgrade_Something(t *testing.T) {} +func Example_Something() {} +func Test_Smoke_ComplexFlow(t *testing.T) {} +func helperFunction() {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + names, err := matrix.DiscoverGoTestNames(tmpDir, matrix.DiscoverOptions{ + IgnoredPatterns: []string{"TestMain", "Test_Upgrade.*"}, + }) + require.NoError(t, err) + + assert.Equal(t, []string{"Example_Something", "Test_Smoke_ComplexFlow", "Test_Smoke_HappyPath"}, names) +} + +func TestBuildCRESmokeMatrix(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "smoke_test.go") + content := `package smoke_test + +import "testing" + +func Test_CRE_V2_Basic(t *testing.T) {} +func Test_CRE_V2_Sharding(t *testing.T) {} +func Test_CRE_V2_Suite_Bucket_B(t *testing.T) {} +func Test_CRE_V2_Solana_Write(t *testing.T) {} +func Test_CRE_V2_Solana_Read_Tx(t *testing.T) {} +func Test_CRE_V2_Stellar_Suite(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + res, err := matrix.BuildCRESmokeMatrix(context.Background(), matrix.CRESmokeOptions{ + Dir: tmpDir, + RunID: "123456", + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.NoError(t, err) + require.Len(t, res, 7) + + // Test_CRE_V2_Basic has default topology + basic := res[0] + assert.Equal(t, "Test_CRE_V2_Basic", basic.TestName) + assert.Equal(t, 0, basic.TestID) + assert.Equal(t, "workflow-gateway-capabilities", basic.Topology) + assert.Equal(t, "configs/workflow-gateway-capabilities-don.toml", basic.Configs) + assert.Equal(t, "runs-on=123456-0-1/cpu=16/ram=64/family=m7i+m8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", basic.RunsOn) + + // Test_CRE_V2_Sharding has per-test override + sharding := res[1] + assert.Equal(t, "Test_CRE_V2_Sharding", sharding.TestName) + assert.Equal(t, 1, sharding.TestID) + assert.Equal(t, "workflow-gateway-sharded", sharding.Topology) + assert.Equal(t, "configs/workflow-gateway-sharded-don.toml", sharding.Configs) + assert.Equal(t, "runs-on=123456-1-1/cpu=16/ram=64/family=m7i+m8i/spot=co/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", sharding.RunsOn) + + // Solana tests use the workflow topology with solana configs + solanaReadTx := res[2] + assert.Equal(t, "Test_CRE_V2_Solana_Read_Tx", solanaReadTx.TestName) + assert.Equal(t, 2, solanaReadTx.TestID) + assert.Equal(t, "workflow", solanaReadTx.Topology) + assert.Equal(t, "configs/workflow-don-solana.toml", solanaReadTx.Configs) + + solanaWrite := res[3] + assert.Equal(t, "Test_CRE_V2_Solana_Write", solanaWrite.TestName) + assert.Equal(t, 3, solanaWrite.TestID) + assert.Equal(t, "workflow", solanaWrite.Topology) + assert.Equal(t, "configs/workflow-don-solana.toml", solanaWrite.Configs) + + // Test_CRE_V2_Stellar_Suite has per-test override + stellar := res[4] + assert.Equal(t, "Test_CRE_V2_Stellar_Suite", stellar.TestName) + assert.Equal(t, 4, stellar.TestID) + assert.Equal(t, "workflow-gateway-stellar", stellar.Topology) + assert.Equal(t, "configs/workflow-gateway-don-stellar.toml", stellar.Configs) + + // Test_CRE_V2_Suite_Bucket_B has two topology entries + bucketB := res[5] + assert.Equal(t, "Test_CRE_V2_Suite_Bucket_B", bucketB.TestName) + assert.Equal(t, 5, bucketB.TestID) + assert.Equal(t, "workflow-gateway-capabilities", bucketB.Topology) + assert.Equal(t, "configs/workflow-gateway-capabilities-don.toml", bucketB.Configs) + + bucketBVault := res[6] + assert.Equal(t, "Test_CRE_V2_Suite_Bucket_B", bucketBVault.TestName) + assert.Equal(t, 6, bucketBVault.TestID) + assert.Equal(t, "workflow-gateway-capabilities-vault-stall-purge", bucketBVault.Topology) + assert.Equal(t, "configs/workflow-gateway-capabilities-don-vault-stall-purge.toml", bucketBVault.Configs) +} + +func TestBuildCRESmokeMatrix_MissingRunID(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "smoke_test.go") + content := `package smoke_test + +import "testing" + +func Test_CRE_V2_Basic(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + _, err := matrix.BuildCRESmokeMatrix(context.Background(), matrix.CRESmokeOptions{ + Dir: tmpDir, + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "run ID is required") +} + +func TestBuildCRERegressionMatrix(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "regression_test.go") + content := `package regression_test + +import "testing" + +func Test_CRE_V2_Standard_Regression(t *testing.T) {} +func Test_CRE_V2_Stellar_Regression(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + res, err := matrix.BuildCRERegressionMatrix(context.Background(), matrix.CRERegressionOptions{ + Dir: tmpDir, + RunID: "789012", + RunAttempt: "2", + SpotFlag: "spot=false", + }) + require.NoError(t, err) + require.Len(t, res, 2) + + assert.Equal(t, "Test_CRE_V2_Standard_Regression", res[0].TestName) + assert.Equal(t, 0, res[0].TestID) + assert.Equal(t, "configs/workflow-gateway-capabilities-don.toml", res[0].Configs) + assert.Equal(t, "runs-on=789012-0-2/cpu=16/ram=64/family=m7i+m8i/spot=false/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[0].RunsOn) + + assert.Equal(t, "Test_CRE_V2_Stellar_Regression", res[1].TestName) + assert.Equal(t, 1, res[1].TestID) + assert.Equal(t, "configs/workflow-gateway-don-stellar.toml", res[1].Configs) + assert.Equal(t, "runs-on=789012-1-2/cpu=16/ram=64/family=m7i+m8i/spot=false/image=ubuntu24-full-x64/extras=s3-cache+tmpfs", res[1].RunsOn) +} + +func TestBuildCRERegressionMatrix_MissingRunID(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "regression_test.go") + content := `package regression_test + +import "testing" + +func Test_CRE_V2_Standard_Regression(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + _, err := matrix.BuildCRERegressionMatrix(context.Background(), matrix.CRERegressionOptions{ + Dir: tmpDir, + RunAttempt: "1", + SpotFlag: "spot=co", + }) + require.Error(t, err) + assert.Contains(t, err.Error(), "run ID is required") +} + +func TestBuildCRESmokeMatrix_EmptyDir(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + res, err := matrix.BuildCRESmokeMatrix(context.Background(), matrix.CRESmokeOptions{ + Dir: tmpDir, + RunID: "123", + }) + require.NoError(t, err) + require.NotNil(t, res) + + data, err := json.Marshal(res) + require.NoError(t, err) + assert.Equal(t, "[]", string(data)) +} + +func TestBuildCRERegressionMatrix_EmptyDir(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + res, err := matrix.BuildCRERegressionMatrix(context.Background(), matrix.CRERegressionOptions{ + Dir: tmpDir, + RunID: "123", + }) + require.NoError(t, err) + require.NotNil(t, res) + + data, err := json.Marshal(res) + require.NoError(t, err) + assert.Equal(t, "[]", string(data)) +} + +func TestBuildCRESmokeMatrix_AdditionalOverrides(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "smoke_test.go") + content := `package smoke_test + +import "testing" + +func Test_CRE_V2_FailoverManualSwap(t *testing.T) {} +func Test_CRE_V2_ShardedCapabilitiesManualEVMLogTrigger(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + res, err := matrix.BuildCRESmokeMatrix(context.Background(), matrix.CRESmokeOptions{ + Dir: tmpDir, + RunID: "123456", + }) + require.NoError(t, err) + require.Len(t, res, 2) + + assert.Equal(t, "Test_CRE_V2_FailoverManualSwap", res[0].TestName) + assert.Equal(t, "workflow-gateway-failover", res[0].Topology) + assert.Equal(t, "configs/workflow-gateway-failover-don.toml", res[0].Configs) + + assert.Equal(t, "Test_CRE_V2_ShardedCapabilitiesManualEVMLogTrigger", res[1].TestName) + assert.Equal(t, "workflow-sharded-capabilities", res[1].Topology) + assert.Equal(t, "configs/workflow-sharded-capabilities-don.toml", res[1].Configs) +} + +func TestBuildCRERegressionMatrix_AdditionalOverrides(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + testFile := filepath.Join(tmpDir, "regression_test.go") + content := `package regression_test + +import "testing" + +func Test_CRE_V2_Solana_Regression(t *testing.T) {} +` + require.NoError(t, os.WriteFile(testFile, []byte(content), 0o600)) + + res, err := matrix.BuildCRERegressionMatrix(context.Background(), matrix.CRERegressionOptions{ + Dir: tmpDir, + RunID: "789012", + }) + require.NoError(t, err) + require.Len(t, res, 1) + + assert.Equal(t, "Test_CRE_V2_Solana_Regression", res[0].TestName) + assert.Equal(t, "configs/workflow-don-solana.toml", res[0].Configs) +}