Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCMS owner rollback to deployer key #15672

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 := MaybeLoadMCMSWithTimelockState(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
}
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)
}
Loading