Skip to content

Commit

Permalink
Helper methods to GetAllTimeLocksForChains and GetAllProposerMCMSForC…
Browse files Browse the repository at this point in the history
…hains (#15691)

* remove deployCCIPContracts

* review comments from past PR
  • Loading branch information
AnieeG authored Dec 13, 2024
1 parent 2ec4d6c commit a5fe613
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
30 changes: 4 additions & 26 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_proxy_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)
Expand Down Expand Up @@ -177,6 +176,10 @@ func deployChainContracts(
if chainState.Router == nil {
return fmt.Errorf("router not found for chain %s, deploy the prerequisites first", chain.String())
}
rmnProxyContract := chainState.RMNProxy
if chainState.RMNProxy == nil {
return fmt.Errorf("rmn proxy not found for chain %s, deploy the prerequisites first", chain.String())
}
if chainState.Receiver == nil {
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
Expand Down Expand Up @@ -246,31 +249,6 @@ func deployChainContracts(
e.Logger.Errorw("Failed to confirm RMNRemote config", "chain", chain.String(), "err", err)
return err
}

// we deploy a new RMNProxy so that RMNRemote can be tested first before pointing it to the main Existing RMNProxy
// To differentiate between the two RMNProxies, we will deploy new one with Version1_6_0_dev
rmnProxyContract := chainState.RMNProxy
if chainState.RMNProxy == nil {
// we deploy a new rmnproxy contract to test RMNRemote
rmnProxy, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] {
rmnProxyAddr, tx, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract(
chain.DeployerKey,
chain.Client,
rmnRemoteContract.Address(),
)
return deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{
rmnProxyAddr, rmnProxy, tx, deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_6_0_dev), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy RMNProxy", "chain", chain.String(), "err", err)
return err
}
rmnProxyContract = rmnProxy.Contract
} else {
e.Logger.Infow("rmn proxy already deployed", "chain", chain.String(), "addr", chainState.RMNProxy.Address)
}
if chainState.TestRouter == nil {
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*router.Router] {
Expand Down
12 changes: 8 additions & 4 deletions deployment/ccip/changeset/cs_update_rmn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ func SetRMNRemoteOnRMNProxy(e deployment.Environment, cfg SetRMNRemoteOnRMNProxy
if err := cfg.Validate(state); err != nil {
return deployment.ChangesetOutput{}, err
}
timelocks, err := state.GetAllTimeLocksForChains(cfg.ChainSelectors)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get timelocks for chains %v: %w", cfg.ChainSelectors, err)
}
multiSigs, err := state.GetAllProposerMCMSForChains(cfg.ChainSelectors)
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to get proposer MCMS for chains %v: %w", cfg.ChainSelectors, err)
}
var timelockBatch []timelock.BatchChainOperation
multiSigs := make(map[uint64]*gethwrappers.ManyChainMultiSig)
timelocks := make(map[uint64]common.Address)
for _, sel := range cfg.ChainSelectors {
chain, exists := e.Chains[sel]
if !exists {
Expand All @@ -73,8 +79,6 @@ func SetRMNRemoteOnRMNProxy(e deployment.Environment, cfg SetRMNRemoteOnRMNProxy
ChainIdentifier: mcms.ChainIdentifier(sel),
Batch: []mcms.Operation{mcmsOps},
})
multiSigs[sel] = state.Chains[sel].ProposerMcm
timelocks[sel] = state.Chains[sel].Timelock.Address()
}
}
// If we're not using MCMS, we can just return now as we've already confirmed the transactions
Expand Down
32 changes: 32 additions & 0 deletions deployment/ccip/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package changeset
import (
"fmt"

"github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"

burn_mint_token_pool "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/burn_mint_token_pool_1_4_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/erc20"

Expand Down Expand Up @@ -257,6 +259,36 @@ type CCIPOnChainState struct {
SolChains map[uint64]SolCCIPChainState
}

func (s CCIPOnChainState) GetAllProposerMCMSForChains(chains []uint64) (map[uint64]*gethwrappers.ManyChainMultiSig, error) {
multiSigs := make(map[uint64]*gethwrappers.ManyChainMultiSig)
for _, chain := range chains {
chainState, ok := s.Chains[chain]
if !ok {
return nil, fmt.Errorf("chain %d not found", chain)
}
if chainState.ProposerMcm == nil {
return nil, fmt.Errorf("proposer mcm not found for chain %d", chain)
}
multiSigs[chain] = chainState.ProposerMcm
}
return multiSigs, nil
}

func (s CCIPOnChainState) GetAllTimeLocksForChains(chains []uint64) (map[uint64]common.Address, error) {
timelocks := make(map[uint64]common.Address)
for _, chain := range chains {
chainState, ok := s.Chains[chain]
if !ok {
return nil, fmt.Errorf("chain %d not found", chain)
}
if chainState.Timelock == nil {
return nil, fmt.Errorf("timelock not found for chain %d", chain)
}
timelocks[chain] = chainState.Timelock.Address()
}
return timelocks, nil
}

func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, error) {
m := make(map[string]view.ChainView)
for _, chainSelector := range chains {
Expand Down
2 changes: 1 addition & 1 deletion deployment/environment/memory/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func CreateKeys(t *testing.T,
}
backend := chain.Client.(*Backend).Sim
fundAddress(t, chain.DeployerKey, transmitters[evmChainID], assets.Ether(1000).ToInt(), backend)
// in sim chains the send transactions are performed with 0x0 address as the sender
// need to look more into it, but it seems like with sim chains nodes are sending txs with 0x from address
fundAddress(t, chain.DeployerKey, common.Address{}, assets.Ether(1000).ToInt(), backend)
}

Expand Down

0 comments on commit a5fe613

Please sign in to comment.