Skip to content

Commit 890afa5

Browse files
committed
Merge branch 'develop' into cron-flux-runlog-env
2 parents a121a5b + 38b23ab commit 890afa5

File tree

6 files changed

+253
-5
lines changed

6 files changed

+253
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package config
2+
3+
import "github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
4+
5+
type UpgradeAptosChainConfig struct {
6+
ChainSelector uint64
7+
UpgradeCCIP bool
8+
UpgradeOffRamp bool
9+
UpgradeOnRamp bool
10+
UpgradeRouter bool
11+
MCMS *proposalutils.TimelockConfig
12+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package aptos
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/aptos-labs/aptos-go-sdk"
8+
"github.com/smartcontractkit/mcms"
9+
"github.com/smartcontractkit/mcms/types"
10+
11+
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/operations"
13+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/config"
14+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/dependency"
15+
seq "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/sequence"
16+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/utils"
17+
"github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview"
18+
)
19+
20+
var _ cldf.ChangeSetV2[config.UpgradeAptosChainConfig] = UpgradeAptosChain{}
21+
22+
// UpgradeAptosChain upgrades Aptos chain packages and modules
23+
type UpgradeAptosChain struct{}
24+
25+
func (cs UpgradeAptosChain) VerifyPreconditions(env cldf.Environment, cfg config.UpgradeAptosChainConfig) error {
26+
var errs []error
27+
if !cfg.UpgradeCCIP && !cfg.UpgradeOffRamp && !cfg.UpgradeOnRamp && !cfg.UpgradeRouter {
28+
errs = append(errs, errors.New("no upgrades selected"))
29+
}
30+
state, err := stateview.LoadOnchainState(env)
31+
if err != nil {
32+
errs = append(errs, fmt.Errorf("failed to load Aptos onchain state: %w", err))
33+
}
34+
// Validate supported chain
35+
supportedChains := state.SupportedChains()
36+
if _, ok := supportedChains[cfg.ChainSelector]; !ok {
37+
errs = append(errs, fmt.Errorf("unsupported chain: %d", cfg.ChainSelector))
38+
}
39+
// Validate MCMS config
40+
if cfg.MCMS == nil {
41+
errs = append(errs, errors.New("MCMS config is required for UpgradeAptosChain changeset"))
42+
}
43+
// Check CCIP Package
44+
ccipAddress := state.AptosChains[cfg.ChainSelector].CCIPAddress
45+
client := env.BlockChains.AptosChains()[cfg.ChainSelector].Client
46+
if ccipAddress == (aptos.AccountAddress{}) {
47+
errs = append(errs, fmt.Errorf("package CCIP is not deployed on Aptos chain %d", cfg.ChainSelector))
48+
}
49+
// Check OnRamp module
50+
hasOnramp, err := utils.IsModuleDeployed(client, ccipAddress, "onramp")
51+
if err != nil || !hasOnramp {
52+
errs = append(errs, fmt.Errorf("onRamp module is not deployed on Aptos chain %d: %w", cfg.ChainSelector, err))
53+
}
54+
// Check OffRamp module
55+
hasOfframp, err := utils.IsModuleDeployed(client, ccipAddress, "offramp")
56+
if err != nil || !hasOfframp {
57+
errs = append(errs, fmt.Errorf("offRamp module is not deployed on Aptos chain %d: %w", cfg.ChainSelector, err))
58+
}
59+
// Check Router module
60+
hasRouter, err := utils.IsModuleDeployed(client, ccipAddress, "router")
61+
if err != nil || !hasRouter {
62+
errs = append(errs, fmt.Errorf("router module is not deployed on Aptos chain %d: %w", cfg.ChainSelector, err))
63+
}
64+
65+
return errors.Join(errs...)
66+
}
67+
68+
func (cs UpgradeAptosChain) Apply(env cldf.Environment, cfg config.UpgradeAptosChainConfig) (cldf.ChangesetOutput, error) {
69+
timeLockProposals := []mcms.TimelockProposal{}
70+
mcmsOperations := []types.BatchOperation{}
71+
seqReports := make([]operations.Report[any, any], 0)
72+
73+
state, err := stateview.LoadOnchainState(env)
74+
if err != nil {
75+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to load Aptos onchain state: %w", err)
76+
}
77+
78+
deps := dependency.AptosDeps{
79+
AptosChain: env.BlockChains.AptosChains()[cfg.ChainSelector],
80+
CCIPOnChainState: state,
81+
}
82+
83+
// Execute the sequence
84+
upgradeSeqReport, err := operations.ExecuteSequence(env.OperationsBundle, seq.UpgradeCCIPSequence, deps, cfg)
85+
if err != nil {
86+
return cldf.ChangesetOutput{}, err
87+
}
88+
seqReports = append(seqReports, upgradeSeqReport.ExecutionReports...)
89+
mcmsOperations = append(mcmsOperations, upgradeSeqReport.Output...)
90+
91+
// Generate MCMS proposals
92+
proposal, err := utils.GenerateProposal(
93+
env,
94+
state.AptosChains[cfg.ChainSelector].MCMSAddress,
95+
cfg.ChainSelector,
96+
mcmsOperations,
97+
"Upgrade chain contracts on Aptos chain",
98+
*cfg.MCMS,
99+
)
100+
if err != nil {
101+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to generate MCMS proposal for Aptos chain %d: %w", cfg.ChainSelector, err)
102+
}
103+
timeLockProposals = append(timeLockProposals, *proposal)
104+
105+
return cldf.ChangesetOutput{
106+
MCMSTimelockProposals: timeLockProposals,
107+
Reports: seqReports,
108+
}, nil
109+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package aptos_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
chain_selectors "github.com/smartcontractkit/chain-selectors"
8+
mcmstypes "github.com/smartcontractkit/mcms/types"
9+
"github.com/stretchr/testify/require"
10+
11+
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
12+
aptoscs "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos"
13+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/config"
14+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
15+
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
16+
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
17+
)
18+
19+
func TestUpgradeAptosChain_Apply(t *testing.T) {
20+
t.Skip("skipping - no need to run these tests in CI")
21+
t.Parallel()
22+
// Setup environment with contracts deployed
23+
deployedEnvironment, _ := testhelpers.NewMemoryEnvironment(
24+
t,
25+
testhelpers.WithAptosChains(1),
26+
)
27+
env := deployedEnvironment.Env
28+
29+
chainSelector := env.BlockChains.ListChainSelectors(cldf_chain.WithFamily(chain_selectors.FamilyAptos))[0]
30+
31+
cfg := config.UpgradeAptosChainConfig{
32+
ChainSelector: chainSelector,
33+
MCMS: &proposalutils.TimelockConfig{
34+
MinDelay: time.Second,
35+
MCMSAction: mcmstypes.TimelockActionSchedule,
36+
OverrideRoot: false,
37+
},
38+
UpgradeCCIP: true,
39+
UpgradeOffRamp: true,
40+
UpgradeOnRamp: true,
41+
UpgradeRouter: true,
42+
}
43+
44+
// Apply the changeset
45+
env, out, err := commonchangeset.ApplyChangesets(t, env, []commonchangeset.ConfiguredChangeSet{
46+
commonchangeset.Configure(aptoscs.UpgradeAptosChain{}, cfg),
47+
})
48+
49+
proposals := out[0].MCMSTimelockProposals
50+
require.Len(t, proposals, 1)
51+
require.Len(t, proposals[0].Operations, 7)
52+
require.NoError(t, err)
53+
}

deployment/ccip/changeset/aptos/operation/ccip.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var CCIPOperations = []*operations.Operation[any, any, any]{
2828
// OP: DeployCCIPOp deploys the CCIP package on Aptos chain
2929
type DeployCCIPInput struct {
3030
MCMSAddress aptos.AccountAddress
31-
IsUpdate bool
31+
IsUpgrade bool
3232
}
3333

3434
type DeployCCIPOutput struct {
@@ -46,8 +46,8 @@ var DeployCCIPOp = operations.NewOperation(
4646
func deployCCIP(b operations.Bundle, deps dependency.AptosDeps, in DeployCCIPInput) (DeployCCIPOutput, error) {
4747
onChainState := deps.CCIPOnChainState.AptosChains[deps.AptosChain.Selector]
4848
// Validate there's no package deployed XOR is update
49-
if (onChainState.CCIPAddress == (aptos.AccountAddress{})) == (in.IsUpdate) {
50-
if in.IsUpdate {
49+
if (onChainState.CCIPAddress == (aptos.AccountAddress{})) == (in.IsUpgrade) {
50+
if in.IsUpgrade {
5151
b.Logger.Infow("Trying to update a non-deployed package", "addr", onChainState.CCIPAddress.StringLong())
5252
return DeployCCIPOutput{}, fmt.Errorf("CCIP package not deployed on Aptos chain %d", deps.AptosChain.Selector)
5353
}
@@ -61,7 +61,7 @@ func deployCCIP(b operations.Bundle, deps dependency.AptosDeps, in DeployCCIPInp
6161
if err != nil {
6262
return DeployCCIPOutput{}, fmt.Errorf("failed to compile and create deploy operations: %w", err)
6363
}
64-
if in.IsUpdate {
64+
if in.IsUpgrade {
6565
return DeployCCIPOutput{
6666
MCMSOperations: operations,
6767
}, nil

deployment/ccip/changeset/aptos/sequence/deploy_ccip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func deployCCIPSequence(b operations.Bundle, deps dependency.AptosDeps, in Deplo
4949
// Generate batch operations to deploy CCIP package
5050
deployCCIPInput := operation.DeployCCIPInput{
5151
MCMSAddress: in.MCMSAddress,
52-
IsUpdate: false,
52+
IsUpgrade: false,
5353
}
5454
deployCCIPReport, err := operations.ExecuteOperation(b, operation.DeployCCIPOp, deps, deployCCIPInput)
5555
if err != nil {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package sequence
2+
3+
import (
4+
mcmstypes "github.com/smartcontractkit/mcms/types"
5+
6+
"github.com/smartcontractkit/chainlink-deployments-framework/operations"
7+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/config"
8+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/dependency"
9+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/operation"
10+
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/utils"
11+
)
12+
13+
var UpgradeCCIPSequence = operations.NewSequence(
14+
"upgrade-aptos-ccip-sequence",
15+
operation.Version1_0_0,
16+
"Upgrade Aptos CCIP contracts",
17+
upgradeCCIPSequence,
18+
)
19+
20+
func upgradeCCIPSequence(b operations.Bundle, deps dependency.AptosDeps, in config.UpgradeAptosChainConfig) ([]mcmstypes.BatchOperation, error) {
21+
var mcmsOperations []mcmstypes.BatchOperation
22+
mcmsAddress := deps.CCIPOnChainState.AptosChains[deps.AptosChain.Selector].MCMSAddress
23+
// Cleanup staging area
24+
cleanupReport, err := operations.ExecuteOperation(b, operation.CleanupStagingAreaOp, deps, mcmsAddress)
25+
if err != nil {
26+
return nil, err
27+
}
28+
if len(cleanupReport.Output.Transactions) > 0 {
29+
mcmsOperations = append(mcmsOperations, cleanupReport.Output)
30+
}
31+
32+
if in.UpgradeCCIP {
33+
deployCCIPInput := operation.DeployCCIPInput{
34+
MCMSAddress: mcmsAddress,
35+
IsUpgrade: in.UpgradeCCIP,
36+
}
37+
deployCCIPReport, err := operations.ExecuteOperation(b, operation.DeployCCIPOp, deps, deployCCIPInput)
38+
if err != nil {
39+
return nil, err
40+
}
41+
mcmsOperations = append(mcmsOperations, utils.ToBatchOperations(deployCCIPReport.Output.MCMSOperations)...)
42+
}
43+
44+
deployModulesInput := operation.DeployModulesInput{
45+
MCMSAddress: mcmsAddress,
46+
CCIPAddress: deps.CCIPOnChainState.AptosChains[deps.AptosChain.Selector].CCIPAddress,
47+
}
48+
49+
if in.UpgradeOnRamp {
50+
deployOnRampReport, err := operations.ExecuteOperation(b, operation.DeployOnRampOp, deps, deployModulesInput)
51+
if err != nil {
52+
return nil, err
53+
}
54+
mcmsOperations = append(mcmsOperations, utils.ToBatchOperations(deployOnRampReport.Output)...)
55+
}
56+
57+
if in.UpgradeOffRamp {
58+
deployOffRampReport, err := operations.ExecuteOperation(b, operation.DeployOffRampOp, deps, deployModulesInput)
59+
if err != nil {
60+
return nil, err
61+
}
62+
mcmsOperations = append(mcmsOperations, utils.ToBatchOperations(deployOffRampReport.Output)...)
63+
}
64+
65+
if in.UpgradeRouter {
66+
deployRouterReport, err := operations.ExecuteOperation(b, operation.DeployRouterOp, deps, deployModulesInput)
67+
if err != nil {
68+
return nil, err
69+
}
70+
mcmsOperations = append(mcmsOperations, utils.ToBatchOperations(deployRouterReport.Output)...)
71+
}
72+
73+
return mcmsOperations, nil
74+
}

0 commit comments

Comments
 (0)