From abb5a0103bb41251b8452884fdb697ec87364696 Mon Sep 17 00:00:00 2001 From: yashnevatia Date: Wed, 8 Jan 2025 22:52:29 +0000 Subject: [PATCH] linting --- deployment/ccip/changeset/cs_deploy_chain.go | 40 ++++++++++--------- .../ccip/changeset/cs_deploy_chain_test.go | 6 ++- deployment/ccip/changeset/solana_state.go | 32 +++++++-------- deployment/solana_chain.go | 3 +- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index 2915830982d..7cd2f8be75e 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -10,12 +10,14 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/gagliardetto/solana-go" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" - "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router" "golang.org/x/sync/errgroup" + "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router" + solBinary "github.com/gagliardetto/binary" solRpc "github.com/gagliardetto/solana-go/rpc" chainsel "github.com/smartcontractkit/chain-selectors" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" @@ -125,7 +127,6 @@ func deployChainContractsForChains( ab deployment.AddressBook, homeChainSel uint64, chainsToDeploy []uint64) error { - existingEVMState, err := LoadOnchainState(e) if err != nil { e.Logger.Errorw("Failed to load existing onchain state", "err") @@ -450,7 +451,7 @@ func deployChainContractsEVM( return nil } -func solRouterProgramData(e deployment.Environment, chain deployment.SolChain, CcipRouterProgram solana.PublicKey) (struct { +func solRouterProgramData(e deployment.Environment, chain deployment.SolChain, ccipRouterProgram solana.PublicKey) (struct { DataType uint32 Address solana.PublicKey }, error) { @@ -458,16 +459,16 @@ func solRouterProgramData(e deployment.Environment, chain deployment.SolChain, C DataType uint32 Address solana.PublicKey } - data, err := chain.Client.GetAccountInfoWithOpts(e.GetContext(), CcipRouterProgram, &solRpc.GetAccountInfoOpts{ + data, err := chain.Client.GetAccountInfoWithOpts(e.GetContext(), ccipRouterProgram, &solRpc.GetAccountInfoOpts{ Commitment: solRpc.CommitmentConfirmed, }) if err != nil { - return programData, fmt.Errorf("failed to deploy program: %v", err) + return programData, fmt.Errorf("failed to deploy program: %w", err) } err = solBinary.UnmarshalBorsh(&programData, data.Bytes()) if err != nil { - return programData, fmt.Errorf("failed to unmarshal program data: %v", err) + return programData, fmt.Errorf("failed to unmarshal program data: %w", err) } return programData, nil } @@ -493,19 +494,19 @@ func deployChainContractsSolana( // deploy and initialize router programID, err := chain.DeployProgram(e.Logger, "ccip_router") if err != nil { - return fmt.Errorf("failed to deploy program: %v", err) + return fmt.Errorf("failed to deploy program: %w", err) } tv := deployment.NewTypeAndVersion("SolCcipRouter", deployment.Version1_0_0) e.Logger.Infow("Deployed contract", "Contract", tv.String(), "addr", programID, "chain", chain.String()) - CcipRouterProgram := solana.MustPublicKeyFromBase58(programID) - programData, err := solRouterProgramData(e, chain, CcipRouterProgram) + ccipRouterProgram := solana.MustPublicKeyFromBase58(programID) + programData, err := solRouterProgramData(e, chain, ccipRouterProgram) if err != nil { - return fmt.Errorf("failed to get solana router program data: %v", err) + return fmt.Errorf("failed to get solana router program data: %w", err) } - ccip_router.SetProgramID(CcipRouterProgram) + ccip_router.SetProgramID(ccipRouterProgram) defaultGasLimit := solBinary.Uint128{Lo: 3000, Hi: 0, Endianness: nil} @@ -515,30 +516,31 @@ func deployChainContractsSolana( true, // allow out of order execution EnableExecutionAfter, // period to wait before allowing manual execution solana.PublicKey{}, - GetRouterConfigPDA(CcipRouterProgram), - GetRouterStatePDA(CcipRouterProgram), + GetRouterConfigPDA(ccipRouterProgram), + GetRouterStatePDA(ccipRouterProgram), chain.DeployerKey.PublicKey(), solana.SystemProgramID, - CcipRouterProgram, + ccipRouterProgram, programData.Address, - GetExternalExecutionConfigPDA(CcipRouterProgram), - GetExternalTokenPoolsSignerPDA(CcipRouterProgram), + GetExternalExecutionConfigPDA(ccipRouterProgram), + GetExternalTokenPoolsSignerPDA(ccipRouterProgram), ).ValidateAndBuild() if err != nil { - return fmt.Errorf("failed to build instruction: %v", err) + return fmt.Errorf("failed to build instruction: %w", err) } err = chain.Confirm([]solana.Instruction{instruction}) if err != nil { - return fmt.Errorf("failed to confirm instructions: %v", err) + return fmt.Errorf("failed to confirm instructions: %w", err) } err = ab.Save(chain.Selector, programID, tv) if err != nil { - return fmt.Errorf("failed to save address: %v", err) + return fmt.Errorf("failed to save address: %w", err) } //TODO: deploy token pool contract + //TODO: log errors } return nil } diff --git a/deployment/ccip/changeset/cs_deploy_chain_test.go b/deployment/ccip/changeset/cs_deploy_chain_test.go index 147ebdc04f4..5ed2f6fdc3a 100644 --- a/deployment/ccip/changeset/cs_deploy_chain_test.go +++ b/deployment/ccip/changeset/cs_deploy_chain_test.go @@ -11,6 +11,7 @@ import ( "go.uber.org/zap/zapcore" "github.com/gagliardetto/solana-go" + "github.com/smartcontractkit/chainlink/deployment" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" @@ -31,7 +32,9 @@ func TestDeployChainContractsChangeset(t *testing.T) { evmSelectors := e.AllChainSelectors() homeChainSel := evmSelectors[0] solChainSelectors := e.AllChainSelectorsSolana() - selectors := append(evmSelectors, solChainSelectors...) + selectors := make([]uint64, 0, len(evmSelectors)+len(solChainSelectors)) + selectors = append(selectors, evmSelectors...) + selectors = append(selectors, solChainSelectors...) nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) p2pIds := nodes.NonBootstraps().PeerIDs() @@ -160,7 +163,6 @@ func TestSolanaKeygen(t *testing.T) { return } - pk, err := solana.PrivateKeyFromSolanaKeygenFile(outputFilePath) require.NoError(t, err) require.Equal(t, pk.String(), privateKey.String()) diff --git a/deployment/ccip/changeset/solana_state.go b/deployment/ccip/changeset/solana_state.go index cd38de97c94..69aee5d481a 100644 --- a/deployment/ccip/changeset/solana_state.go +++ b/deployment/ccip/changeset/solana_state.go @@ -63,85 +63,85 @@ func LoadChainStateSolana(chain deployment.SolChain, addresses map[string]deploy } // GetRouterConfigPDA returns the PDA for the "config" account. -func GetRouterConfigPDA(CcipRouterProgram solana.PublicKey) solana.PublicKey { +func GetRouterConfigPDA(ccipRouterProgramId solana.PublicKey) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{[]byte("config")}, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetRouterStatePDA returns the PDA for the "state" account. -func GetRouterStatePDA(CcipRouterProgram solana.PublicKey) solana.PublicKey { +func GetRouterStatePDA(ccipRouterProgramId solana.PublicKey) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{[]byte("state")}, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetExternalExecutionConfigPDA returns the PDA for the "external_execution_config" account. -func GetExternalExecutionConfigPDA(CcipRouterProgram solana.PublicKey) solana.PublicKey { +func GetExternalExecutionConfigPDA(ccipRouterProgramId solana.PublicKey) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{[]byte("external_execution_config")}, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetExternalTokenPoolsSignerPDA returns the PDA for the "external_token_pools_signer" account. -func GetExternalTokenPoolsSignerPDA(CcipRouterProgram solana.PublicKey) solana.PublicKey { +func GetExternalTokenPoolsSignerPDA(ccipRouterProgramId solana.PublicKey) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{[]byte("external_token_pools_signer")}, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetSolanaSourceChainStatePDA returns the PDA for the "source_chain_state" account for Solana. -func GetSolanaSourceChainStatePDA(CcipRouterProgram solana.PublicKey, SolanaChainSelector uint64) solana.PublicKey { +func GetSolanaSourceChainStatePDA(ccipRouterProgramId solana.PublicKey, SolanaChainSelector uint64) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{ []byte("source_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, SolanaChainSelector), }, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetSolanaDestChainStatePDA returns the PDA for the "dest_chain_state" account for Solana. -func GetSolanaDestChainStatePDA(CcipRouterProgram solana.PublicKey, SolanaChainSelector uint64) solana.PublicKey { +func GetSolanaDestChainStatePDA(ccipRouterProgramId solana.PublicKey, SolanaChainSelector uint64) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{ []byte("dest_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, SolanaChainSelector), }, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetEvmSourceChainStatePDA returns the PDA for the "source_chain_state" account for EVM. -func GetEvmSourceChainStatePDA(CcipRouterProgram solana.PublicKey, EvmChainSelector uint64) solana.PublicKey { +func GetEvmSourceChainStatePDA(ccipRouterProgramId solana.PublicKey, EvmChainSelector uint64) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{ []byte("source_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, EvmChainSelector), }, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } // GetEvmDestChainStatePDA returns the PDA for the "dest_chain_state" account for EVM. -func GetEvmDestChainStatePDA(CcipRouterProgram solana.PublicKey, EvmChainSelector uint64) solana.PublicKey { +func GetEvmDestChainStatePDA(ccipRouterProgramId solana.PublicKey, EvmChainSelector uint64) solana.PublicKey { pda, _, _ := solana.FindProgramAddress( [][]byte{ []byte("dest_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, EvmChainSelector), }, - CcipRouterProgram, + ccipRouterProgramId, ) return pda } diff --git a/deployment/solana_chain.go b/deployment/solana_chain.go index b89ae7a92cb..0f14e9e8920 100644 --- a/deployment/solana_chain.go +++ b/deployment/solana_chain.go @@ -9,6 +9,7 @@ import ( "github.com/gagliardetto/solana-go" solRpc "github.com/gagliardetto/solana-go/rpc" + "github.com/pkg/errors" solCommomUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -92,7 +93,7 @@ func parseProgramID(output string) (string, error) { const prefix = "Program Id: " startIdx := bytes.Index([]byte(output), []byte(prefix)) if startIdx == -1 { - return "", fmt.Errorf("failed to find program ID in output") + return "", errors.New("failed to find program ID in output") } startIdx += len(prefix) endIdx := bytes.Index([]byte(output[startIdx:]), []byte("\n"))