Skip to content

Commit 7771b45

Browse files
authored
match solana setocr with EVM (#17561)
* update solana setocr * add candidate test * fix test
1 parent 455237a commit 7771b45

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

deployment/ccip/changeset/internal/deploy_home_chain.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ func BuildSetOCR3ConfigArgsSolana(
238238
donID uint32,
239239
ccipHome *ccip_home.CCIPHome,
240240
destSelector uint64,
241+
configType globals.ConfigType,
241242
) ([]MultiOCR3BaseOCRConfigArgsSolana, error) {
243+
chainCfg, err := ccipHome.GetChainConfig(nil, destSelector)
244+
if err != nil {
245+
return nil, fmt.Errorf("error getting chain config for chain selector %d it must be set before OCR3Config set up: %w", destSelector, err)
246+
}
242247
ocr3Configs := make([]MultiOCR3BaseOCRConfigArgsSolana, 0)
243248
for _, pluginType := range []types.PluginType{types.PluginTypeCCIPCommit, types.PluginTypeCCIPExec} {
244249
ocrConfig, err2 := ccipHome.GetAllConfigs(&bind.CallOpts{
@@ -248,15 +253,30 @@ func BuildSetOCR3ConfigArgsSolana(
248253
return nil, err2
249254
}
250255

251-
// we expect only an active config and no candidate config.
252-
if ocrConfig.ActiveConfig.ConfigDigest == [32]byte{} || ocrConfig.CandidateConfig.ConfigDigest != [32]byte{} {
253-
return nil, fmt.Errorf("invalid OCR3 config state, expected active config and no candidate config, donID: %d", donID)
256+
fmt.Printf("pluginType: %s, destSelector: %d, donID: %d, activeConfig digest: %x, candidateConfig digest: %x\n",
257+
pluginType.String(), destSelector, donID, ocrConfig.ActiveConfig.ConfigDigest, ocrConfig.CandidateConfig.ConfigDigest)
258+
259+
configForOCR3 := ocrConfig.ActiveConfig
260+
// we expect only an active config
261+
if configType == globals.ConfigTypeActive {
262+
if ocrConfig.ActiveConfig.ConfigDigest == [32]byte{} {
263+
return nil, fmt.Errorf("invalid OCR3 config state, expected active config, donID: %d, activeConfig: %v, candidateConfig: %v",
264+
donID, hexutil.Encode(ocrConfig.ActiveConfig.ConfigDigest[:]), hexutil.Encode(ocrConfig.CandidateConfig.ConfigDigest[:]))
265+
}
266+
} else if configType == globals.ConfigTypeCandidate {
267+
if ocrConfig.CandidateConfig.ConfigDigest == [32]byte{} {
268+
return nil, fmt.Errorf("invalid OCR3 config state, expected candidate config, donID: %d, activeConfig: %v, candidateConfig: %v",
269+
donID, hexutil.Encode(ocrConfig.ActiveConfig.ConfigDigest[:]), hexutil.Encode(ocrConfig.CandidateConfig.ConfigDigest[:]))
270+
}
271+
configForOCR3 = ocrConfig.CandidateConfig
272+
}
273+
if err := validateOCR3Config(destSelector, configForOCR3.Config, &chainCfg); err != nil {
274+
return nil, err
254275
}
255276

256-
activeConfig := ocrConfig.ActiveConfig
257277
var signerAddresses [][20]byte
258278
var transmitterAddresses []solana.PublicKey
259-
for _, node := range activeConfig.Config.Nodes {
279+
for _, node := range configForOCR3.Config.Nodes {
260280
var signer [20]uint8
261281
if len(node.SignerKey) != 20 {
262282
return nil, fmt.Errorf("node signer key not 20 bytes long, got: %d", len(node.SignerKey))
@@ -268,9 +288,9 @@ func BuildSetOCR3ConfigArgsSolana(
268288
}
269289

270290
ocr3Configs = append(ocr3Configs, MultiOCR3BaseOCRConfigArgsSolana{
271-
ConfigDigest: activeConfig.ConfigDigest,
291+
ConfigDigest: configForOCR3.ConfigDigest,
272292
OCRPluginType: uint8(pluginType),
273-
F: activeConfig.Config.FRoleDON,
293+
F: configForOCR3.Config.FRoleDON,
274294
IsSignatureVerificationEnabled: pluginType == types.PluginTypeCCIPCommit,
275295
Signers: signerAddresses,
276296
Transmitters: transmitterAddresses,

deployment/ccip/changeset/solana/cs_chain_contracts_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func TestDeployCCIPContracts(t *testing.T) {
846846
}
847847

848848
// ocr3 test
849-
func TestSetOcr3(t *testing.T) {
849+
func TestSetOcr3Active(t *testing.T) {
850850
t.Parallel()
851851
tenv, _ := testhelpers.NewMemoryEnvironment(t,
852852
testhelpers.WithNumOfNodes(16),
@@ -876,3 +876,33 @@ func TestSetOcr3(t *testing.T) {
876876
})
877877
require.NoError(t, err)
878878
}
879+
880+
func TestSetOcr3Candidate(t *testing.T) {
881+
t.Parallel()
882+
tenv, _ := testhelpers.NewMemoryEnvironment(t,
883+
testhelpers.WithSolChains(1))
884+
var err error
885+
evmSelectors := tenv.Env.AllChainSelectors()
886+
homeChainSel := evmSelectors[0]
887+
solChainSelectors := tenv.Env.AllChainSelectorsSolana()
888+
_, _ = testhelpers.TransferOwnershipSolana(t, &tenv.Env, solChainSelectors[0], true,
889+
ccipChangesetSolana.CCIPContractsToTransfer{
890+
Router: true,
891+
FeeQuoter: true,
892+
OffRamp: true,
893+
})
894+
895+
tenv.Env, _, err = commonchangeset.ApplyChangesetsV2(t, tenv.Env, []commonchangeset.ConfiguredChangeSet{
896+
commonchangeset.Configure(
897+
deployment.CreateLegacyChangeSet(ccipChangesetSolana.SetOCR3ConfigSolana),
898+
v1_6.SetOCR3OffRampConfig{
899+
HomeChainSel: homeChainSel,
900+
RemoteChainSels: solChainSelectors,
901+
CCIPHomeConfigType: globals.ConfigTypeCandidate,
902+
MCMS: &proposalutils.TimelockConfig{MinDelay: 1 * time.Second},
903+
},
904+
),
905+
})
906+
require.Error(t, err)
907+
require.Contains(t, err.Error(), "invalid OCR3 config state, expected candidate config")
908+
}

deployment/ccip/changeset/solana/cs_set_ocr3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func SetOCR3ConfigSolana(e deployment.Environment, cfg v1_6.SetOCR3OffRampConfig
7777
if err != nil {
7878
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get don id for chain %d: %w", remote, err)
7979
}
80-
args, err := internal.BuildSetOCR3ConfigArgsSolana(donID, state.Chains[cfg.HomeChainSel].CCIPHome, remote)
80+
args, err := internal.BuildSetOCR3ConfigArgsSolana(donID, state.Chains[cfg.HomeChainSel].CCIPHome, remote, cfg.CCIPHomeConfigType)
8181
if err != nil {
8282
return deployment.ChangesetOutput{}, fmt.Errorf("failed to build set ocr3 config args: %w", err)
8383
}

0 commit comments

Comments
 (0)