Skip to content

Commit

Permalink
make the proposal multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
makramkd committed Nov 25, 2024
1 parent 7a55173 commit 387d972
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
62 changes: 40 additions & 22 deletions deployment/ccip/changeset/accept_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
}
36 changes: 16 additions & 20 deletions deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deployment/common/changeset/internal/mcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 387d972

Please sign in to comment.