Skip to content

Commit

Permalink
refactor(mcms): handle nil scenario
Browse files Browse the repository at this point in the history
Some scenarios will throw nil pointer exception without using the ok pattern check. We should handle those properly.
  • Loading branch information
graham-chainlink committed Dec 17, 2024
1 parent 85c8b96 commit ba1a8cd
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions deployment/common/changeset/transfer_to_mcms_with_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,46 @@ type RenounceTimelockDeployerConfig struct {
ChainSel uint64
}

func (cfg RenounceTimelockDeployerConfig) Validate() error {
if err := deployment.IsValidChainSelector(cfg.ChainSel); err != nil {
return fmt.Errorf("invalid chain selector: %w", err)
}
return nil
}

// RenounceTimelockDeployer revokes the deployer key from administering the contract.
func RenounceTimelockDeployer(e deployment.Environment, cfg RenounceTimelockDeployerConfig) (deployment.ChangesetOutput, error) {
if err := cfg.Validate(); err != nil {
return deployment.ChangesetOutput{}, err
}

contracts, err := MaybeLoadMCMSWithTimelockState(e, []uint64{cfg.ChainSel})
if err != nil {
return deployment.ChangesetOutput{}, err
}
tl := contracts[cfg.ChainSel].Timelock
contract, ok := contracts[cfg.ChainSel]
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("mcms contracts not found on chain %d", cfg.ChainSel)
}
tl := contract.Timelock
if tl == nil {
return deployment.ChangesetOutput{}, fmt.Errorf("timelock not found on chain %d", cfg.ChainSel)
}
admin, err := tl.ADMINROLE(&bind.CallOpts{})
admin, err := tl.ADMINROLE(&bind.CallOpts{Context: e.GetContext()})
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get admin role: %w", err)
}
tx, err := tl.RenounceRole(e.Chains[cfg.ChainSel].DeployerKey, admin, e.Chains[cfg.ChainSel].DeployerKey.From)

chain, ok := e.Chains[cfg.ChainSel]
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("chain %d not found", cfg.ChainSel)
}

tx, err := tl.RenounceRole(chain.DeployerKey, admin, chain.DeployerKey.From)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to revoke deployer key: %w", err)
}
if _, err := deployment.ConfirmIfNoError(e.Chains[cfg.ChainSel], tx, err); err != nil {
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("revoked deployer key from owning contract %s", tl.Address().Hex())
Expand Down

0 comments on commit ba1a8cd

Please sign in to comment.