Skip to content

Commit d137b22

Browse files
committed
Changes from local testing
1 parent 29a99a9 commit d137b22

File tree

5 files changed

+105
-38
lines changed

5 files changed

+105
-38
lines changed

deployment/ccip/changeset/ccip-attestation-solana/cs_deploy_signer_registry_solana.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ type DeployBaseSignerRegistryContractConfig struct {
4343

4444
type InitalizeBaseSignerRegistryContractConfig struct {
4545
ChainSelector uint64
46-
Owner solana.PublicKey
4746
}
4847

4948
func DeployBaseSignerRegistryContractChangeset(e cldf.Environment, c DeployBaseSignerRegistryContractConfig) (cldf.ChangesetOutput, error) {

deployment/ccip/changeset/ccip-attestation-solana/cs_idl.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,21 @@ func BaseUploadIDLChangeset(e cldf.Environment, c BaseIDLConfig) (cldf.Changeset
9191
return cldf.ChangesetOutput{}, fmt.Errorf("error setting up repo: %w", err)
9292
}
9393

94-
err := cs_solana.IdlInit(e, chain.ProgramsPath, signer_registry.ProgramID.String(), deployment.BaseSignerRegistryProgramName)
94+
idlFile := filepath.Join(chain.ProgramsPath, deployment.BaseSignerRegistryProgramName+".json")
95+
if _, err := os.Stat(idlFile); err != nil {
96+
return cldf.ChangesetOutput{}, fmt.Errorf("idl file not found: %w", err)
97+
}
98+
99+
e.Logger.Infow("Uploading IDL", "programName", deployment.BaseSignerRegistryProgramName)
100+
args := []string{"idl", "init", "--filepath", idlFile, signer_registry.ProgramID.String()}
101+
e.Logger.Info(args)
102+
output, err := cs_solana.RunCommand("anchor", args, chain.ProgramsPath)
103+
e.Logger.Debugw("IDL init output", "output", output)
95104
if err != nil {
96-
return cldf.ChangesetOutput{}, err
105+
e.Logger.Debugw("IDL init error", "error", err)
106+
return cldf.ChangesetOutput{}, fmt.Errorf("error uploading idl: %w", err)
97107
}
108+
e.Logger.Infow("IDL uploaded", "programName", deployment.BaseSignerRegistryProgramName)
98109
return cldf.ChangesetOutput{}, nil
99110
}
100111

deployment/ccip/changeset/ccip-attestation-solana/cs_ops_solana.go

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/gagliardetto/solana-go"
9+
"github.com/gagliardetto/solana-go/rpc"
910
"github.com/smartcontractkit/mcms"
1011
mcmsTypes "github.com/smartcontractkit/mcms/types"
1112

@@ -106,7 +107,7 @@ type SetUpgradeAuthorityConfig struct {
106107
}
107108

108109
func RotateBaseSignerNopsChangeset(e cldf.Environment, c RotateBaseSignerNopsConfig) (cldf.ChangesetOutput, error) {
109-
e.Logger.Infow("Rotating Base signer nops", "chain_selector", c.ChainSelector, "removing", c.NopKeysToAdd, "adding", c.NopKeysToAdd)
110+
e.Logger.Infow("Rotating Base signer nops", "chain_selector", c.ChainSelector, "removing", c.NopKeysToRemove, "adding", c.NopKeysToAdd)
110111
chain := e.BlockChains.SolanaChains()[c.ChainSelector]
111112
err := c.Validate(e)
112113
if err != nil {
@@ -175,25 +176,25 @@ func (c RotateBaseSignerNopsConfig) Validate(e cldf.Environment) error {
175176
keysToRemoveParsed[i] = parsed
176177
}
177178

178-
var signersAccount signer_registry.Signers
179-
signersPda, _, _ := solana.FindProgramAddress([][]byte{[]byte("signers")}, signer_registry.ProgramID)
180-
181179
chain := e.BlockChains.SolanaChains()[c.ChainSelector]
182-
if err := chain.GetAccountDataBorshInto(e.GetContext(), signersPda, &signersAccount); err != nil {
183-
return fmt.Errorf("failed to get signers: %w", err)
184-
}
180+
if len(c.NopKeysToRemove) > 0 {
181+
signersPda, _, _ := solana.FindProgramAddress([][]byte{[]byte("signers")}, signer_registry.ProgramID)
185182

186-
// Check that all NopKeysToRemove exist in signersAccount
187-
for i, keyBytes := range keysToRemoveParsed {
188-
if !keyExistsInSigners(keyBytes, signersAccount.Signers) {
189-
return fmt.Errorf("NopKeysToRemove[%d] (%s) does not exist in current signers", i, c.NopKeysToRemove[i])
183+
data, err := GetAccountData(e, &chain, signersPda)
184+
if err != nil {
185+
return fmt.Errorf("failed to get signers: %w", err)
190186
}
191-
}
192187

193-
// Check that none of NopKeysToAdd already exist in signersAccount
194-
for i, keyBytes := range keysToAddParsed {
195-
if keyExistsInSigners(keyBytes, signersAccount.Signers) {
196-
return fmt.Errorf("NopKeysToAdd[%d] (%s) already exists in current signers", i, c.NopKeysToAdd[i])
188+
signersAccount, err := signer_registry.ParseAccount_Signers(data)
189+
190+
if err != nil {
191+
return fmt.Errorf("failed to get signers: %w", err)
192+
}
193+
// Check that all NopKeysToRemove exist in signersAccount
194+
for i, keyBytes := range keysToRemoveParsed {
195+
if !keyExistsInSigners(keyBytes, signersAccount.Signers) {
196+
return fmt.Errorf("NopKeysToRemove[%d] (%s) does not exist in current signers", i, c.NopKeysToRemove[i])
197+
}
197198
}
198199
}
199200

@@ -206,14 +207,6 @@ func (c RotateBaseSignerNopsConfig) Validate(e cldf.Environment) error {
206207
}
207208
}
208209

209-
// Check that the final number of signers doesn't exceed 20
210-
currentSignerCount := len(signersAccount.Signers)
211-
finalSignerCount := currentSignerCount - len(keysToRemoveParsed) + len(keysToAddParsed)
212-
if finalSignerCount > 20 {
213-
return fmt.Errorf("final signer count would be %d, which exceeds the maximum of 20 (current: %d, removing: %d, adding: %d)",
214-
finalSignerCount, currentSignerCount, len(keysToRemoveParsed), len(keysToAddParsed))
215-
}
216-
217210
return solanastateview.ValidateOwnershipSolana(&e, chain, c.MCMS != nil, signer_registry.ProgramID, shared.SVMSignerRegistry, solana.PublicKey{})
218211
}
219212

@@ -282,13 +275,15 @@ func (c AddGreenKeysConfig) Validate(e cldf.Environment) error {
282275
}
283276

284277
// Get current signers account
285-
var signersAccount signer_registry.Signers
286278
signersPda, _, _ := solana.FindProgramAddress([][]byte{[]byte("signers")}, signer_registry.ProgramID)
287279

288-
if err := chain.GetAccountDataBorshInto(e.GetContext(), signersPda, &signersAccount); err != nil {
280+
data, err := GetAccountData(e, &chain, signersPda)
281+
if err != nil {
289282
return fmt.Errorf("failed to get signers: %w", err)
290283
}
291284

285+
signersAccount, err := signer_registry.ParseAccount_Signers(data)
286+
292287
// Check that all blue keys exist in signersAccount (either as EvmAddress or NewEvmAddress)
293288
for i, blueKey := range blueKeysParsed {
294289
if !keyExistsInSigners(blueKey, signersAccount.Signers) {
@@ -371,13 +366,15 @@ func (c PromoteKeysConfig) Validate(e cldf.Environment) error {
371366
}
372367

373368
// Get current signers account
374-
var signersAccount signer_registry.Signers
375369
signersPda, _, _ := solana.FindProgramAddress([][]byte{[]byte("signers")}, signer_registry.ProgramID)
376370

377-
if err := chain.GetAccountDataBorshInto(e.GetContext(), signersPda, &signersAccount); err != nil {
371+
data, err := GetAccountData(e, &chain, signersPda)
372+
if err != nil {
378373
return fmt.Errorf("failed to get signers: %w", err)
379374
}
380375

376+
signersAccount, err := signer_registry.ParseAccount_Signers(data)
377+
381378
// Check that each key exists and has an active blue/green pair
382379
for i, keyBytes := range keysParsed {
383380
signer := findSignerWithKey(keyBytes, signersAccount.Signers)
@@ -488,3 +485,23 @@ func findSignerWithKey(key [20]uint8, signers []signer_registry.Signer) *signer_
488485
}
489486
return nil
490487
}
488+
489+
func GetAccountData(
490+
e cldf.Environment,
491+
chain *cldf_solana.Chain,
492+
account solana.PublicKey,
493+
494+
) ([]byte, error) {
495+
resp, err := chain.Client.GetAccountInfoWithOpts(
496+
e.GetContext(),
497+
account,
498+
&rpc.GetAccountInfoOpts{
499+
Commitment: rpc.CommitmentFinalized,
500+
DataSlice: nil,
501+
},
502+
)
503+
if err != nil {
504+
return nil, err
505+
}
506+
return resp.Value.Data.GetBinary(), nil
507+
}

deployment/ccip/shared/bindings/signer_registry_solana/instructions.go

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deployment/ccip/shared/stateview/solana/state.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/Masterminds/semver/v3"
1010
"github.com/gagliardetto/solana-go"
11+
"github.com/gagliardetto/solana-go/rpc"
1112
"github.com/rs/zerolog/log"
1213

1314
cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana"
@@ -637,14 +638,17 @@ func ValidateOwnershipSolana(
637638
return fmt.Errorf("failed to validate ownership for cctp_token_pool: %w", err)
638639
}
639640
case shared.SVMSignerRegistry:
640-
programData := signer_registry.Config{}
641641
configPda, _, _ := solana.FindProgramAddress([][]byte{[]byte("config")}, signer_registry.ProgramID)
642-
err = chain.GetAccountDataBorshInto(e.GetContext(), configPda, &programData)
642+
data, err := GetAccountData(*e, &chain, configPda)
643643
if err != nil {
644-
return nil
644+
return fmt.Errorf("failed to get config: %w", err)
645645
}
646-
if err := commonchangeset.ValidateOwnershipSolanaCommon(mcms, chain.DeployerKey.PublicKey(), timelockSignerPDA, programData.Owner); err != nil {
647-
return fmt.Errorf("failed to validate ownership for signer_registry: %w", err)
646+
647+
configAccount, err := signer_registry.ParseAccount_Config(data)
648+
fmt.Printf("%+v\n", configAccount)
649+
650+
if err := commonchangeset.ValidateOwnershipSolanaCommon(mcms, chain.DeployerKey.PublicKey(), timelockSignerPDA, configAccount.Owner); err != nil {
651+
return fmt.Errorf("failed to validate ownership for signer_registry at account %s: %w", configPda, err)
648652
}
649653
default:
650654
return fmt.Errorf("unsupported contract type: %s", contractType)
@@ -755,3 +759,23 @@ func FindReceiverTargetAccount(receiverID solana.PublicKey) solana.PublicKey {
755759
receiverTargetAccount, _, _ := solana.FindProgramAddress([][]byte{[]byte("counter")}, receiverID)
756760
return receiverTargetAccount
757761
}
762+
763+
func GetAccountData(
764+
e cldf.Environment,
765+
chain *cldf_solana.Chain,
766+
account solana.PublicKey,
767+
768+
) ([]byte, error) {
769+
resp, err := chain.Client.GetAccountInfoWithOpts(
770+
e.GetContext(),
771+
account,
772+
&rpc.GetAccountInfoOpts{
773+
Commitment: rpc.CommitmentFinalized,
774+
DataSlice: nil,
775+
},
776+
)
777+
if err != nil {
778+
return nil, err
779+
}
780+
return resp.Value.Data.GetBinary(), nil
781+
}

0 commit comments

Comments
 (0)