Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Jan 8, 2025
1 parent 040ca48 commit abb5a01
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
40 changes: 21 additions & 19 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Check failure on line 132 in deployment/ccip/changeset/cs_deploy_chain.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

odd number of arguments passed as key-value pairs for logging (loggercheck)
Expand Down Expand Up @@ -450,24 +451,24 @@ 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) {
var programData struct {
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
}
Expand All @@ -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}

Expand All @@ -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
}
6 changes: 4 additions & 2 deletions deployment/ccip/changeset/cs_deploy_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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())
Expand Down
32 changes: 16 additions & 16 deletions deployment/ccip/changeset/solana_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 66 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

var-naming: func parameter ccipRouterProgramId should be ccipRouterProgramID (revive)
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 {

Check failure on line 75 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

var-naming: func parameter ccipRouterProgramId should be ccipRouterProgramID (revive)
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 {

Check failure on line 84 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

var-naming: func parameter ccipRouterProgramId should be ccipRouterProgramID (revive)
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 {

Check failure on line 102 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

captLocal: `SolanaChainSelector' should not be capitalized (gocritic)
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 {

Check failure on line 114 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

captLocal: `SolanaChainSelector' should not be capitalized (gocritic)
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 {

Check failure on line 126 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

captLocal: `EvmChainSelector' should not be capitalized (gocritic)
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 {

Check failure on line 138 in deployment/ccip/changeset/solana_state.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

captLocal: `EvmChainSelector' should not be capitalized (gocritic)
pda, _, _ := solana.FindProgramAddress(
[][]byte{
[]byte("dest_chain_state"),
binary.LittleEndian.AppendUint64([]byte{}, EvmChainSelector),
},
CcipRouterProgram,
ccipRouterProgramId,
)
return pda
}
3 changes: 2 additions & 1 deletion deployment/solana_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -92,7 +93,7 @@ func parseProgramID(output string) (string, error) {
const prefix = "Program Id: "
startIdx := bytes.Index([]byte(output), []byte(prefix))

Check failure on line 94 in deployment/solana_chain.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

avoid allocations with strings.Index (mirror)
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"))

Check failure on line 99 in deployment/solana_chain.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

avoid allocations with strings.Index (mirror)
Expand Down

0 comments on commit abb5a01

Please sign in to comment.