Skip to content

Commit

Permalink
MCMS owner rollback to deployer key (#15672)
Browse files Browse the repository at this point in the history
* Rollback test

* Fix merge conflicts
  • Loading branch information
connorwstein authored Dec 13, 2024
1 parent 98f222d commit 4e84600
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
62 changes: 62 additions & 0 deletions deployment/common/changeset/transfer_to_mcms_with_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,65 @@ func TransferToMCMSWithTimelock(

return deployment.ChangesetOutput{Proposals: []timelock.MCMSWithTimelockProposal{*proposal}}, nil
}

var _ deployment.ChangeSet[TransferToDeployerConfig] = TransferToDeployer

type TransferToDeployerConfig struct {
ContractAddress common.Address
ChainSel uint64
}

// TransferToDeployer relies on the deployer key
// still being a timelock admin and transfers the ownership of a contract
// back to the deployer key. It's effectively the rollback function of transferring
// to the timelock.
func TransferToDeployer(e deployment.Environment, cfg TransferToDeployerConfig) (deployment.ChangesetOutput, error) {
_, ownable, err := LoadOwnableContract(cfg.ContractAddress, e.Chains[cfg.ChainSel].Client)
if err != nil {
return deployment.ChangesetOutput{}, err
}
tx, err := ownable.TransferOwnership(deployment.SimTransactOpts(), e.Chains[cfg.ChainSel].DeployerKey.From)
if err != nil {
return deployment.ChangesetOutput{}, err
}
addrs, err := e.ExistingAddresses.AddressesForChain(cfg.ChainSel)
if err != nil {
return deployment.ChangesetOutput{}, err
}
tls, err := MaybeLoadMCMSWithTimelockChainState(e.Chains[cfg.ChainSel], addrs)
if err != nil {
return deployment.ChangesetOutput{}, err
}
calls := []owner_helpers.RBACTimelockCall{
{
Target: ownable.Address(),
Data: tx.Data(),
Value: big.NewInt(0),
},
}
tx, err = tls.Timelock.ScheduleBatch(e.Chains[cfg.ChainSel].DeployerKey, calls, [32]byte{}, [32]byte{}, big.NewInt(0))
if _, err = deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("scheduled transfer ownership batch with tx %s", tx.Hash().Hex())
timelockExecutorProxy, err := owner_helpers.NewRBACTimelock(tls.CallProxy.Address(), e.Chains[cfg.ChainSel].Client)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("error creating timelock executor proxy: %w", err)
}
tx, err = timelockExecutorProxy.ExecuteBatch(
e.Chains[cfg.ChainSel].DeployerKey, calls, [32]byte{}, [32]byte{})
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("error executing batch: %w", err)
}
if _, err = deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("executed transfer ownership to deployer key with tx %s", tx.Hash().Hex())

tx, err = ownable.AcceptOwnership(e.Chains[cfg.ChainSel].DeployerKey)
if _, err = deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("deployer key accepted ownership tx %s", tx.Hash().Hex())
return deployment.ChangesetOutput{}, nil
}
16 changes: 16 additions & 0 deletions deployment/common/changeset/transfer_to_mcms_with_timelock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ func TestTransferToMCMSWithTimelock(t *testing.T) {
o, err := link.LinkToken.Owner(nil)
require.NoError(t, err)
require.Equal(t, state.Timelock.Address(), o)

// Try a rollback to the deployer.
e, err = ApplyChangesets(t, e, nil, []ChangesetApplication{
{
Changeset: WrapChangeSet(TransferToDeployer),
Config: TransferToDeployerConfig{
ContractAddress: link.LinkToken.Address(),
ChainSel: chain1,
},
},
})
require.NoError(t, err)

o, err = link.LinkToken.Owner(nil)
require.NoError(t, err)
require.Equal(t, e.Chains[chain1].DeployerKey.From, o)
}

0 comments on commit 4e84600

Please sign in to comment.