Skip to content

Commit 0127e7b

Browse files
authored
Polish tooling ops (#617)
* Update DefaultOpFinalizationTimeout to 30s * Transfer ownership adapter default to loaded Timelock addr * Fix comments * Transfer ownership - default current owner to deployer address if not provided * More transfer ownership fixes * PR feedback
1 parent 054376f commit 0127e7b

2 files changed

Lines changed: 53 additions & 19 deletions

File tree

deployment/ccip/1_6_0/sequences/transfer_ownership.go

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,24 @@ func (a *TonTransferOwnershipAdapter) SequenceTransferOwnershipViaMCMS() *cldfop
6868
return sequences.OnChainOutput{}, fmt.Errorf("TON chain with selector %d not found in environment", in.ChainSelector)
6969
}
7070

71-
proposedOwner, err := address.ParseAddr(in.ProposedOwner)
72-
if err != nil {
73-
return sequences.OnChainOutput{}, fmt.Errorf("failed to parse proposed owner address: %w", err)
74-
}
75-
7671
dp, err := dep.NewDependencyProvider(
7772
dep.Provide(chain),
7873
)
7974
if err != nil {
8075
return sequences.OnChainOutput{}, fmt.Errorf("failed to create dependency provider: %w", err)
8176
}
8277

83-
deployerAddr := chain.Wallet.WalletAddress()
78+
proposedOwner, err := a.getProposedOwner(in)
79+
if err != nil {
80+
return sequences.OnChainOutput{}, fmt.Errorf("failed to get proposed owner: %w", err)
81+
}
82+
8483
_inputMCMS := opsmcms.NewSendOrPlanInput(types.ChainSelector(in.ChainSelector))
8584

86-
currentOwner, err := address.ParseAddr(in.CurrentOwner)
85+
deployerAddr := chain.Wallet.WalletAddress()
86+
currentOwner, err := a.getCurrentOwner(in, deployerAddr)
8787
if err != nil {
88-
return sequences.OnChainOutput{}, fmt.Errorf("failed to parse current owner address: %w", err)
88+
return sequences.OnChainOutput{}, fmt.Errorf("failed to get current owner: %w", err)
8989
}
9090

9191
for _, contractRef := range in.ContractRef {
@@ -166,18 +166,18 @@ func (a *TonTransferOwnershipAdapter) SequenceAcceptOwnership() *cldfops.Sequenc
166166
return sequences.OnChainOutput{}, fmt.Errorf("TON chain with selector %d not found in environment", in.ChainSelector)
167167
}
168168

169-
proposedOwner, err := address.ParseAddr(in.ProposedOwner)
170-
if err != nil {
171-
return sequences.OnChainOutput{}, fmt.Errorf("failed to parse proposed owner address: %w", err)
172-
}
173-
174169
dp, err := dep.NewDependencyProvider(
175170
dep.Provide(chain),
176171
)
177172
if err != nil {
178173
return sequences.OnChainOutput{}, fmt.Errorf("failed to create dependency provider: %w", err)
179174
}
180175

176+
proposedOwner, err := a.getProposedOwner(in)
177+
if err != nil {
178+
return sequences.OnChainOutput{}, fmt.Errorf("failed to get proposed owner: %w", err)
179+
}
180+
181181
sender := chain.Wallet.WalletAddress()
182182
_inputMCMS := opsmcms.NewSendOrPlanInput(types.ChainSelector(in.ChainSelector))
183183

@@ -239,9 +239,9 @@ func (a *TonTransferOwnershipAdapter) SequenceAcceptOwnership() *cldfops.Sequenc
239239
// Returns false when the proposed owner is the deployer (timelock transfers via deferred execution, can't accept in same changeset).
240240
// Returns false when the proposed owner is unknown
241241
func (a *TonTransferOwnershipAdapter) ShouldAcceptOwnershipWithTransferOwnership(_ cldf.Environment, in deploy.TransferOwnershipPerChainInput) (bool, error) {
242-
proposedOwner, err := address.ParseAddr(in.ProposedOwner)
242+
proposedOwner, err := a.getProposedOwner(in)
243243
if err != nil {
244-
return false, fmt.Errorf("failed to parse proposed owner address: %w", err)
244+
return false, fmt.Errorf("failed to get proposed owner: %w", err)
245245
}
246246

247247
timelockAddr, ok := a.timelockAddrs[in.ChainSelector]
@@ -251,3 +251,37 @@ func (a *TonTransferOwnershipAdapter) ShouldAcceptOwnershipWithTransferOwnership
251251

252252
return false, nil
253253
}
254+
255+
// Default proposed owner to timelock address if not provided
256+
func (a *TonTransferOwnershipAdapter) getProposedOwner(in deploy.TransferOwnershipPerChainInput) (*address.Address, error) {
257+
if in.ProposedOwner != "" {
258+
proposedOwner, err := address.ParseAddr(in.ProposedOwner)
259+
if err != nil {
260+
return nil, fmt.Errorf("failed to parse proposed owner address: %w", err)
261+
}
262+
263+
return proposedOwner, nil
264+
}
265+
266+
timelockAddr, ok := a.timelockAddrs[in.ChainSelector]
267+
if !ok {
268+
return nil, fmt.Errorf("timelock address not initialized for chain %d", in.ChainSelector)
269+
}
270+
271+
return timelockAddr, nil
272+
}
273+
274+
func (a *TonTransferOwnershipAdapter) getCurrentOwner(in deploy.TransferOwnershipPerChainInput, defaultAddr *address.Address) (*address.Address, error) {
275+
// Default current owner to deployer address if not provided
276+
// Notice: common case where deployer is transferring to timelock
277+
if in.CurrentOwner != "" {
278+
currentOwner, err := address.ParseAddr(in.CurrentOwner)
279+
if err != nil {
280+
return nil, fmt.Errorf("failed to parse current owner address: %w", err)
281+
}
282+
283+
return currentOwner, nil
284+
}
285+
286+
return defaultAddr, nil
287+
}

deployment/pkg/ops/mcms/deploy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
const (
3636
DefaultMinDelay = 1 * 60 * 60 // 1 hour in seconds
37-
DefaultOpFinalizationTimeout = 10 // 10 seconds
37+
DefaultOpFinalizationTimeout = 30 // 30 seconds
3838

3939
// DefaultDeployValueTON is the default amount of TON coins to allocate for MCMS/Timelock contract deployment.
4040
// MCMS contracts require more storage and operational capacity, hence the higher allocation compared to CCIP contracts.
@@ -47,7 +47,7 @@ type DeployMCMSSeqInput struct {
4747
// Extra TON specific params
4848
Value *tlb.Coins `json:"value"` // value to send with deployment, optional, if not provided, defaults to 1.5 TON
4949
ContractID uint32 `json:"contractID"` // ID (storage data) to use for the deployed contracts, can be used to derive the address pre-deployment.
50-
OpFinalizationTimeout uint32 `json:"opFinalizationTimeout"` // optional, if not provided, defaults to 10 seconds
50+
OpFinalizationTimeout uint32 `json:"opFinalizationTimeout"` // optional, if not provided, defaults to 30 seconds
5151
// Extra Timelock params
5252
// Notice: in.Config.TimelockAdmin is of EVM type common.Address (20 bytes),
5353
// which is not compatible with TON address, so we have a separate field for TON address type.
@@ -129,7 +129,7 @@ func deployMCMSSequence(b cldfops.Bundle, dp *dep.DependencyProvider, in DeployM
129129
// Notice: we increment the id for each deployment to avoid address collision
130130
id := in.ContractID
131131

132-
opFinalizationTimeout := uint32(DefaultOpFinalizationTimeout) // default to 10 seconds
132+
opFinalizationTimeout := uint32(DefaultOpFinalizationTimeout) // default to 30 seconds
133133
if in.OpFinalizationTimeout != 0 {
134134
opFinalizationTimeout = in.OpFinalizationTimeout
135135
}
@@ -268,7 +268,7 @@ func deployMCMSSequence(b cldfops.Bundle, dp *dep.DependencyProvider, in DeployM
268268

269269
// disable executor role check to allow anyone to execute (TON does not have a CallProxy)
270270
ExecutorRoleCheckEnabled: in.TimelockExecutorRoleCheckEnabled,
271-
OpFinalizationTimeout: opFinalizationTimeout, // 10 seconds default, can be updated later
271+
OpFinalizationTimeout: opFinalizationTimeout, // 30 seconds default, can be updated later
272272
}
273273

274274
version := in.ContractsSemverTimelock

0 commit comments

Comments
 (0)