From 387d972d901c43d41f16201e386aaa051e251f7b Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Tue, 26 Nov 2024 01:20:43 +0400 Subject: [PATCH] make the proposal multichain --- deployment/ccip/changeset/accept_ownership.go | 62 ++++++++++++------- .../ccip/changeset/accept_ownership_test.go | 36 +++++------ deployment/common/changeset/internal/mcms.go | 2 +- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/deployment/ccip/changeset/accept_ownership.go b/deployment/ccip/changeset/accept_ownership.go index 6a9e6e20ca6..dc34d7110da 100644 --- a/deployment/ccip/changeset/accept_ownership.go +++ b/deployment/ccip/changeset/accept_ownership.go @@ -20,15 +20,15 @@ type ownershipAcceptor interface { } type AcceptOwnershipConfig struct { - State CCIPOnChainState - ChainSelector uint64 + State CCIPOnChainState + ChainSelectors []uint64 } // type assertion - comply with deployment.ChangeSet interface var _ deployment.ChangeSet[AcceptOwnershipConfig] = NewAcceptOwnershipChangeset // NewAcceptOwnershipChangeset creates a changeset that accepts ownership of all the -// chain contracts on the given chainSelector. +// ccip chain contracts deployed on the given chain selectors. // New chain contracts are: // * OnRamp // * OffRamp @@ -39,12 +39,42 @@ func NewAcceptOwnershipChangeset( e deployment.Environment, cfg AcceptOwnershipConfig, ) (deployment.ChangesetOutput, error) { - chainState, ok := cfg.State.Chains[cfg.ChainSelector] - if !ok { - return deployment.ChangesetOutput{}, fmt.Errorf("desired chain selector %d not found in onchain state", cfg.ChainSelector) + // gen one batch per chain + var batches []timelock.BatchChainOperation + for _, chainSelector := range cfg.ChainSelectors { + chainState, ok := cfg.State.Chains[chainSelector] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("chain %d not found in state", chainSelector) + } + + ops, err := genAcceptProposalBatch(chainState) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to generate accept ownership batch for chain %d: %w", + chainSelector, err) + } + + batches = append(batches, timelock.BatchChainOperation{ + ChainIdentifier: mcms.ChainIdentifier(chainSelector), + Batch: ops, + }) } - var batch timelock.BatchChainOperation + proposal, err := BuildProposalFromBatches( + cfg.State, + batches, + "Accept ownership of all CCIP chain contracts", + time.Duration(0), // minDelay + ) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w, batches: %+v", err, batches) + } + + return deployment.ChangesetOutput{ + Proposals: []timelock.MCMSWithTimelockProposal{*proposal}, + }, nil +} + +func genAcceptProposalBatch(chainState CCIPChainState) (ops []mcms.Operation, err error) { for _, contract := range []ownershipAcceptor{ chainState.OnRamp, chainState.OffRamp, @@ -54,27 +84,15 @@ func NewAcceptOwnershipChangeset( } { acceptOwnershipTx, err := contract.AcceptOwnership(deployment.SimTransactOpts()) if err != nil { - return deployment.ChangesetOutput{}, fmt.Errorf("failed to generate accept ownership calldata of %T: %w", contract, err) + return nil, fmt.Errorf("failed to generate accept ownership calldata of %T: %w", contract, err) } - batch.Batch = append(batch.Batch, mcms.Operation{ + ops = append(ops, mcms.Operation{ To: contract.Address(), Data: acceptOwnershipTx.Data(), Value: big.NewInt(0), }) } - proposal, err := BuildProposalFromBatches( - cfg.State, - []timelock.BatchChainOperation{batch}, - "Accept ownership of all CCIP chain contracts", - time.Duration(0), // minDelay - ) - if err != nil { - return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w, batch: %+v", err, batch) - } - - return deployment.ChangesetOutput{ - Proposals: []timelock.MCMSWithTimelockProposal{*proposal}, - }, nil + return ops, nil } diff --git a/deployment/ccip/changeset/accept_ownership_test.go b/deployment/ccip/changeset/accept_ownership_test.go index 0b48d9f0577..c7437b0e88c 100644 --- a/deployment/ccip/changeset/accept_ownership_test.go +++ b/deployment/ccip/changeset/accept_ownership_test.go @@ -74,42 +74,42 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) { // OnRamp tx, err := state.Chains[chain].OnRamp.TransferOwnership( - e.Env.Chains[source].DeployerKey, - state.Chains[source].Timelock.Address(), + e.Env.Chains[chain].DeployerKey, + state.Chains[chain].Timelock.Address(), ) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) + _, err = deployment.ConfirmIfNoError(e.Env.Chains[chain], tx, err) require.NoError(t, err) // OffRamp tx, err = state.Chains[chain].OffRamp.TransferOwnership( - e.Env.Chains[source].DeployerKey, - state.Chains[source].Timelock.Address(), + e.Env.Chains[chain].DeployerKey, + state.Chains[chain].Timelock.Address(), ) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) + _, err = deployment.ConfirmIfNoError(e.Env.Chains[chain], tx, err) require.NoError(t, err) // FeeQuoter tx, err = state.Chains[chain].FeeQuoter.TransferOwnership( - e.Env.Chains[source].DeployerKey, - state.Chains[source].Timelock.Address(), + e.Env.Chains[chain].DeployerKey, + state.Chains[chain].Timelock.Address(), ) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) + _, err = deployment.ConfirmIfNoError(e.Env.Chains[chain], tx, err) require.NoError(t, err) // NonceManager tx, err = state.Chains[chain].NonceManager.TransferOwnership( - e.Env.Chains[source].DeployerKey, - state.Chains[source].Timelock.Address(), + e.Env.Chains[chain].DeployerKey, + state.Chains[chain].Timelock.Address(), ) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) + _, err = deployment.ConfirmIfNoError(e.Env.Chains[chain], tx, err) require.NoError(t, err) // RMNRemote tx, err = state.Chains[chain].RMNRemote.TransferOwnership( - e.Env.Chains[source].DeployerKey, - state.Chains[source].Timelock.Address(), + e.Env.Chains[chain].DeployerKey, + state.Chains[chain].Timelock.Address(), ) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) + _, err = deployment.ConfirmIfNoError(e.Env.Chains[chain], tx, err) require.NoError(t, err) } @@ -120,11 +120,7 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) { }, []commonchangeset.ChangesetApplication{ { Changeset: commonchangeset.WrapChangeSet(NewAcceptOwnershipChangeset), - Config: AcceptOwnershipConfig{State: state, ChainSelector: source}, - }, - { - Changeset: commonchangeset.WrapChangeSet(NewAcceptOwnershipChangeset), - Config: AcceptOwnershipConfig{State: state, ChainSelector: dest}, + Config: AcceptOwnershipConfig{State: state, ChainSelectors: allChains}, }, }) require.NoError(t, err) diff --git a/deployment/common/changeset/internal/mcms.go b/deployment/common/changeset/internal/mcms.go index 1e2fb958aae..5694f83786b 100644 --- a/deployment/common/changeset/internal/mcms.go +++ b/deployment/common/changeset/internal/mcms.go @@ -95,7 +95,7 @@ func DeployMCMSWithTimelockContracts( return nil, err } - timelock, err := deployment.DeployContract[*owner_helpers.RBACTimelock](lggr, chain, ab, + timelock, err := deployment.DeployContract(lggr, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*owner_helpers.RBACTimelock] { timelock, tx2, cc, err2 := owner_helpers.DeployRBACTimelock( chain.DeployerKey,