Skip to content

Commit

Permalink
inject call proxies in execution methods
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilchainani committed Dec 8, 2024
1 parent 4d007c3 commit 101b9fd
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 31 deletions.
6 changes: 5 additions & 1 deletion deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) {
source: state.Chains[source].Timelock,
dest: state.Chains[dest].Timelock,
}
callProxies := map[uint64]*gethwrappers.CallProxy{
source: state.Chains[source].CallProxy,
dest: state.Chains[dest].CallProxy,
}

// at this point we have the initial deploys done, now we need to transfer ownership
// to the timelock contract
state, err = LoadOnchainState(e.Env)
require.NoError(t, err)

// compose the transfer ownership and accept ownership changesets
_, err = commonchangeset.ApplyChangesets(t, e.Env, timelocks, []commonchangeset.ChangesetApplication{
_, err = commonchangeset.ApplyChangesets(t, e.Env, timelocks, callProxies, []commonchangeset.ChangesetApplication{
// note this doesn't have proposals.
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Expand Down
12 changes: 8 additions & 4 deletions deployment/ccip/changeset/cs_active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ func TestActiveCandidate(t *testing.T) {
for _, chain := range allChains {
timelocks[chain] = state.Chains[chain].Timelock
}
_, err = commonchangeset.ApplyChangesets(t, e, timelocks, []commonchangeset.ChangesetApplication{
callProxies := make(map[uint64]*gethwrappers.CallProxy)
for _, chain := range allChains {
callProxies[chain] = state.Chains[chain].CallProxy
}
_, err = commonchangeset.ApplyChangesets(t, e, timelocks, callProxies, []commonchangeset.ChangesetApplication{
// note this doesn't have proposals.
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Expand Down Expand Up @@ -177,7 +181,7 @@ func TestActiveCandidate(t *testing.T) {
}}, "set new candidates on commit plugin", 0)
require.NoError(t, err)
setCommitCandidateSigned := commonchangeset.SignProposal(t, e, setCommitCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, state.Chains[tenv.HomeChainSel].CallProxy, tenv.HomeChainSel)

// create the op for the commit plugin as well
setExecCandidateOp, err := setCandidateOnExistingDon(
Expand All @@ -195,7 +199,7 @@ func TestActiveCandidate(t *testing.T) {
}}, "set new candidates on commit and exec plugins", 0)
require.NoError(t, err)
setExecCandidateSigned := commonchangeset.SignProposal(t, e, setExecCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, state.Chains[tenv.HomeChainSel].CallProxy, tenv.HomeChainSel)

// check setup was successful by confirming number of nodes from cap reg
donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
Expand All @@ -222,7 +226,7 @@ func TestActiveCandidate(t *testing.T) {
}}, "promote candidates and revoke actives", 0)
require.NoError(t, err)
promoteSigned := commonchangeset.SignProposal(t, e, promoteProposal)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.Chains[tenv.HomeChainSel].Timelock, state.Chains[tenv.HomeChainSel].CallProxy, tenv.HomeChainSel)
// [NEW ACTIVE, NO CANDIDATE] done promoting

// [NEW ACTIVE, NO CANDIDATE] check onchain state
Expand Down
11 changes: 9 additions & 2 deletions deployment/ccip/changeset/cs_add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestAddChainInbound(t *testing.T) {
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockMinDelay: big.NewInt(0),
}
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Config: initialDeploy,
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestAddChainInbound(t *testing.T) {
require.NoError(t, err)

// Deploy contracts to new chain
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Config: []uint64{newChain},
Expand Down Expand Up @@ -149,6 +149,10 @@ func TestAddChainInbound(t *testing.T) {
initialDeploy[0]: state.Chains[initialDeploy[0]].Timelock,
initialDeploy[1]: state.Chains[initialDeploy[1]].Timelock,
initialDeploy[2]: state.Chains[initialDeploy[2]].Timelock,
}, map[uint64]*gethwrappers.CallProxy{
initialDeploy[0]: state.Chains[initialDeploy[0]].CallProxy,
initialDeploy[1]: state.Chains[initialDeploy[1]].CallProxy,
initialDeploy[2]: state.Chains[initialDeploy[2]].CallProxy,
}, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock),
Expand Down Expand Up @@ -181,6 +185,9 @@ func TestAddChainInbound(t *testing.T) {
_, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*gethwrappers.RBACTimelock{
e.HomeChainSel: state.Chains[e.HomeChainSel].Timelock,
newChain: state.Chains[newChain].Timelock,
}, map[uint64]*gethwrappers.CallProxy{
e.HomeChainSel: state.Chains[e.HomeChainSel].CallProxy,
newChain: state.Chains[newChain].CallProxy,
}, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(AddDonAndSetCandidateChangeset),
Expand Down
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/cs_deploy_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestDeployChainContractsChangeset(t *testing.T) {
TimelockMinDelay: big.NewInt(0),
}
}
e, err = commonchangeset.ApplyChangesets(t, e, nil, []commonchangeset.ChangesetApplication{
e, err = commonchangeset.ApplyChangesets(t, e, nil, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(DeployHomeChain),
Config: DeployHomeChainConfig{
Expand Down
8 changes: 5 additions & 3 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
}
// Need to deploy prerequisites first so that we can form the USDC config
// no proposals to be made, timelock can be passed as nil here
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(commonchangeset.DeployLinkToken),
Config: allChains,
Expand Down Expand Up @@ -366,13 +366,15 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
// Build the per chain config.
chainConfigs := make(map[uint64]CCIPOCRParams)
timelocksPerChain := make(map[uint64]*gethwrappers.RBACTimelock)
callProxiesPerChain := make(map[uint64]*gethwrappers.CallProxy)
for _, chain := range allChains {
timelocksPerChain[chain] = state.Chains[chain].Timelock
callProxiesPerChain[chain] = state.Chains[chain].CallProxy
tokenInfo := tokenConfig.GetTokenInfo(e.Env.Logger, state.Chains[chain].LinkToken, state.Chains[chain].Weth9)
chainConfigs[chain] = DefaultOCRParams(e.FeedChainSel, tokenInfo, tokenDataProviders)
}
// Deploy second set of changesets to deploy and configure the CCIP contracts.
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, timelocksPerChain, []commonchangeset.ChangesetApplication{
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, timelocksPerChain, callProxiesPerChain, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(ConfigureNewChains),
Config: NewChainsConfig{
Expand Down Expand Up @@ -822,7 +824,7 @@ func ProcessChangeset(t *testing.T, e deployment.Environment, c deployment.Chang

signed := commonchangeset.SignProposal(t, e, &prop)
for _, sel := range chains.ToSlice() {
commonchangeset.ExecuteProposal(t, e, signed, state.Chains[sel].Timelock, sel)
commonchangeset.ExecuteProposal(t, e, signed, state.Chains[sel].Timelock, state.Chains[sel].CallProxy, sel)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/common/changeset/deploy_link_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestDeployLinkToken(t *testing.T) {
Chains: 1,
})
chain1 := e.AllChainSelectors()[0]
e, err := changeset.ApplyChangesets(t, e, nil, []changeset.ChangesetApplication{
e, err := changeset.ApplyChangesets(t, e, nil, nil, []changeset.ChangesetApplication{
{
Changeset: changeset.WrapChangeSet(changeset.DeployLinkToken),
Config: []uint64{chain1},
Expand Down
2 changes: 2 additions & 0 deletions deployment/common/changeset/internal/mcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type MCMSWithTimelockDeploy struct {
Bypasser *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Proposer *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Timelock *deployment.ContractDeploy[*owner_helpers.RBACTimelock]
CallProxy *deployment.ContractDeploy[*owner_helpers.CallProxy]
}

func DeployMCMSWithTimelockContractsBatch(
Expand Down Expand Up @@ -164,5 +165,6 @@ func DeployMCMSWithTimelockContracts(
Bypasser: bypasser,
Proposer: proposer,
Timelock: timelock,
CallProxy: callProxy,
}, nil
}
5 changes: 3 additions & 2 deletions deployment/common/changeset/mcms_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func SignProposal(t *testing.T, env deployment.Environment, proposal *timelock.M
}

func ExecuteProposal(t *testing.T, env deployment.Environment, executor *mcms.Executor,
timelock *owner_helpers.RBACTimelock, sel uint64) {
timelock *owner_helpers.RBACTimelock, callProxy *owner_helpers.CallProxy, sel uint64) {
t.Log("Executing proposal on chain", sel)
// Set the root.
tx, err2 := executor.SetRootOnChain(env.Chains[sel].Client, env.Chains[sel].DeployerKey, mcms.ChainIdentifier(sel))
Expand Down Expand Up @@ -104,7 +104,8 @@ func ExecuteProposal(t *testing.T, env deployment.Environment, executor *mcms.Ex
Value: it.Event.Value,
})
}
tx, err := timelock.ExecuteBatch(
timelockExecutorProxy, err := owner_helpers.NewRBACTimelock(callProxy.Address(), env.Chains[sel].Client)
tx, err := timelockExecutorProxy.ExecuteBatch(
env.Chains[sel].DeployerKey, calls, pred, salt)
require.NoError(t, err)
_, err = env.Chains[sel].Confirm(tx)
Expand Down
18 changes: 17 additions & 1 deletion deployment/common/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MCMSWithTimelockState struct {
BypasserMcm *owner_helpers.ManyChainMultiSig
ProposerMcm *owner_helpers.ManyChainMultiSig
Timelock *owner_helpers.RBACTimelock
CallProxy *owner_helpers.CallProxy
}

// Validate checks that all fields are non-nil, ensuring it's ready
Expand All @@ -40,6 +41,9 @@ func (state MCMSWithTimelockState) Validate() error {
if state.BypasserMcm == nil {
return errors.New("bypasser not found")
}
if state.CallProxy == nil {
return errors.New("call proxy not found")
}
return nil
}

Expand All @@ -51,6 +55,10 @@ func (state MCMSWithTimelockState) GenerateMCMSWithTimelockView() (v1_0.MCMSWith
if err != nil {
return v1_0.MCMSWithTimelockView{}, nil
}
callProxyView, err := v1_0.GenerateCallProxyView(*state.CallProxy)
if err != nil {
return v1_0.MCMSWithTimelockView{}, nil
}
bypasserView, err := v1_0.GenerateMCMSView(*state.BypasserMcm)
if err != nil {
return v1_0.MCMSWithTimelockView{}, nil
Expand All @@ -68,6 +76,7 @@ func (state MCMSWithTimelockState) GenerateMCMSWithTimelockView() (v1_0.MCMSWith
Bypasser: bypasserView,
Proposer: proposerView,
Canceller: cancellerView,
CallProxy: callProxyView,
}, nil
}

Expand All @@ -82,14 +91,15 @@ func MaybeLoadMCMSWithTimelockState(chain deployment.Chain, addresses map[string
state := MCMSWithTimelockState{}
// We expect one of each contract on the chain.
timelock := deployment.NewTypeAndVersion(types.RBACTimelock, deployment.Version1_0_0)
callProxy := deployment.NewTypeAndVersion(types.CallProxy, deployment.Version1_0_0)
proposer := deployment.NewTypeAndVersion(types.ProposerManyChainMultisig, deployment.Version1_0_0)
canceller := deployment.NewTypeAndVersion(types.CancellerManyChainMultisig, deployment.Version1_0_0)
bypasser := deployment.NewTypeAndVersion(types.BypasserManyChainMultisig, deployment.Version1_0_0)

// Ensure we either have the bundle or not.
_, err := deployment.AddressesContainBundle(addresses,
map[deployment.TypeAndVersion]struct{}{
timelock: {}, proposer: {}, canceller: {}, bypasser: {},
timelock: {}, proposer: {}, canceller: {}, bypasser: {}, callProxy: {},
})
if err != nil {
return nil, fmt.Errorf("unable to check MCMS contracts on chain %s error: %w", chain.Name(), err)
Expand All @@ -103,6 +113,12 @@ func MaybeLoadMCMSWithTimelockState(chain deployment.Chain, addresses map[string
return nil, err
}
state.Timelock = tl
case callProxy:
cp, err := owner_helpers.NewCallProxy(common.HexToAddress(address), chain.Client)
if err != nil {
return nil, err
}
state.CallProxy = cp
case proposer:
mcms, err := owner_helpers.NewManyChainMultiSig(common.HexToAddress(address), chain.Client)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions deployment/common/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WrapChangeSet[C any](fn deployment.ChangeSet[C]) func(e deployment.Environm
}

// ApplyChangesets applies the changeset applications to the environment and returns the updated environment.
func ApplyChangesets(t *testing.T, e deployment.Environment, timelocksPerChain map[uint64]*gethwrappers.RBACTimelock, changesetApplications []ChangesetApplication) (deployment.Environment, error) {
func ApplyChangesets(t *testing.T, e deployment.Environment, timelocksPerChain map[uint64]*gethwrappers.RBACTimelock, callProxiesPerChain map[uint64]*gethwrappers.CallProxy, changesetApplications []ChangesetApplication) (deployment.Environment, error) {
currentEnv := e
for i, csa := range changesetApplications {
out, err := csa.Changeset(currentEnv, csa.Config)
Expand Down Expand Up @@ -79,7 +79,12 @@ func ApplyChangesets(t *testing.T, e deployment.Environment, timelocksPerChain m
if !ok || timelock == nil {
return deployment.Environment{}, fmt.Errorf("timelock not found for chain %d", sel)
}
ExecuteProposal(t, e, signed, timelock, sel)

callProxy, ok := callProxiesPerChain[sel]
if !ok || callProxy == nil {
return deployment.Environment{}, fmt.Errorf("call proxy not found for chain %d", sel)
}
ExecuteProposal(t, e, signed, timelock, callProxy, sel)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestTransferToMCMSWithTimelock(t *testing.T) {
Nodes: 1,
})
chain1 := e.AllChainSelectors()[0]
e, err := ApplyChangesets(t, e, nil, []ChangesetApplication{
e, err := ApplyChangesets(t, e, nil, nil, []ChangesetApplication{
{
Changeset: WrapChangeSet(DeployLinkToken),
Config: []uint64{chain1},
Expand All @@ -47,6 +47,8 @@ func TestTransferToMCMSWithTimelock(t *testing.T) {
require.NoError(t, err)
e, err = ApplyChangesets(t, e, map[uint64]*owner_helpers.RBACTimelock{
chain1: state.Timelock,
}, map[uint64]*owner_helpers.CallProxy{
chain1: state.CallProxy,
}, []ChangesetApplication{
{
Changeset: WrapChangeSet(TransferToMCMSWithTimelock),
Expand Down
26 changes: 22 additions & 4 deletions deployment/common/view/v1_0/mcms.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,24 @@ func GenerateTimelockView(tl owner_helpers.RBACTimelock) (TimelockView, error) {
}, nil
}

type CallProxyView struct {
types.ContractMetaData
}

func GenerateCallProxyView(cp owner_helpers.CallProxy) (CallProxyView, error) {
return CallProxyView{
ContractMetaData: types.ContractMetaData{
Address: cp.Address(),
},
}, nil
}

type MCMSWithTimelockView struct {
Bypasser MCMSView `json:"bypasser"`
Canceller MCMSView `json:"canceller"`
Proposer MCMSView `json:"proposer"`
Timelock TimelockView `json:"timelock"`
Bypasser MCMSView `json:"bypasser"`
Canceller MCMSView `json:"canceller"`
Proposer MCMSView `json:"proposer"`
Timelock TimelockView `json:"timelock"`
CallProxy CallProxyView `json:"callProxy"`
}

func GenerateMCMSWithTimelockView(
Expand All @@ -124,6 +137,10 @@ func GenerateMCMSWithTimelockView(
if err != nil {
return MCMSWithTimelockView{}, nil
}
callProxyView, err := GenerateCallProxyView(owner_helpers.CallProxy{})
if err != nil {
return MCMSWithTimelockView{}, nil
}
bypasserView, err := GenerateMCMSView(bypasser)
if err != nil {
return MCMSWithTimelockView{}, nil
Expand All @@ -142,5 +159,6 @@ func GenerateMCMSWithTimelockView(
Bypasser: bypasserView,
Proposer: proposerView,
Canceller: cancellerView,
CallProxy: callProxyView,
}, nil
}
4 changes: 3 additions & 1 deletion deployment/keystone/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAcceptAllOwnership(t *testing.T) {
}
env := memory.NewMemoryEnvironment(t, lggr, zapcore.DebugLevel, cfg)
registrySel := env.AllChainSelectors()[0]
env, err := commonchangeset.ApplyChangesets(t, env, nil, []commonchangeset.ChangesetApplication{
env, err := commonchangeset.ApplyChangesets(t, env, nil, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.DeployCapabilityRegistry),
Config: registrySel,
Expand Down Expand Up @@ -58,6 +58,8 @@ func TestAcceptAllOwnership(t *testing.T) {

_, err = commonchangeset.ApplyChangesets(t, env, map[uint64]*owner_helpers.RBACTimelock{
registrySel: timelock.Timelock,
}, map[uint64]*owner_helpers.CallProxy{
registrySel: timelock.CallProxy,
}, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.AcceptAllOwnershipsProposal),
Expand Down
5 changes: 4 additions & 1 deletion deployment/keystone/changeset/deploy_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ func TestConfigureForwarders(t *testing.T) {
require.Nil(t, csOut.AddressBook)

timelocks := make(map[uint64]*gethwrappers.RBACTimelock)
callProxies := make(map[uint64]*gethwrappers.CallProxy)
for selector, contractSet := range te.ContractSets() {
require.NotNil(t, contractSet.Timelock)
timelocks[selector] = contractSet.Timelock
require.NotNil(t, contractSet.CallProxy)
callProxies[selector] = contractSet.CallProxy
}
_, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, []commonchangeset.ChangesetApplication{
_, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, callProxies, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.ConfigureForwardContracts),
Config: cfg,
Expand Down
5 changes: 4 additions & 1 deletion deployment/keystone/changeset/deploy_ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ func TestConfigureOCR3(t *testing.T) {
var timelocks = map[uint64]*gethwrappers.RBACTimelock{
te.RegistrySelector: contractSetsResp.ContractSets[te.RegistrySelector].Timelock,
}
var callProxies = map[uint64]*gethwrappers.CallProxy{
te.RegistrySelector: contractSetsResp.ContractSets[te.RegistrySelector].CallProxy,
}
// now apply the changeset such that the proposal is signed and execed
w2 := &bytes.Buffer{}
cfg.WriteGeneratedConfig = w2
_, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, []commonchangeset.ChangesetApplication{
_, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, callProxies, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(changeset.ConfigureOCR3Contract),
Config: cfg,
Expand Down
Loading

0 comments on commit 101b9fd

Please sign in to comment.