Skip to content

Commit

Permalink
Ccip-4506 log improvements in deployment code (#15535)
Browse files Browse the repository at this point in the history
* improve logging in deployment code to denote human readable chain name

* fix

* fix test

* more logs and review comments

* review comment

* change to String to include chain selector

* revert

* more fixes

* revert
  • Loading branch information
AnieeG authored Dec 6, 2024
1 parent c9496ef commit f8a221f
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 171 deletions.
1 change: 1 addition & 0 deletions deployment/ccip/changeset/cs_add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func TestAddChainInbound(t *testing.T) {

// verify if the configs are updated
require.NoError(t, ValidateCCIPHomeConfigSetUp(
e.Env.Logger,
state.Chains[e.HomeChainSel].CapabilityRegistry,
state.Chains[e.HomeChainSel].CCIPHome,
newChain,
Expand Down
69 changes: 31 additions & 38 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,31 @@ func deployChainContracts(
}
chainState, chainExists := state.Chains[chain.Selector]
if !chainExists {
return fmt.Errorf("chain %d not found in existing state, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("chain %s not found in existing state, deploy the prerequisites first", chain.String())
}
if chainState.Weth9 == nil {
return fmt.Errorf("weth9 not found for chain %d, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("weth9 not found for chain %s, deploy the prerequisites first", chain.String())
}
if chainState.Timelock == nil {
return fmt.Errorf("timelock not found for chain %d, deploy the mcms contracts first", chain.Selector)
return fmt.Errorf("timelock not found for chain %s, deploy the mcms contracts first", chain.String())
}
weth9Contract := chainState.Weth9
if chainState.LinkToken == nil {
return fmt.Errorf("link token not found for chain %d, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("link token not found for chain %s, deploy the prerequisites first", chain.String())
}
linkTokenContract := chainState.LinkToken
if chainState.TokenAdminRegistry == nil {
return fmt.Errorf("token admin registry not found for chain %d, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("token admin registry not found for chain %s, deploy the prerequisites first", chain.String())
}
tokenAdminReg := chainState.TokenAdminRegistry
if chainState.RegistryModule == nil {
return fmt.Errorf("registry module not found for chain %d, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("registry module not found for chain %s, deploy the prerequisites first", chain.String())
}
if chainState.Router == nil {
return fmt.Errorf("router not found for chain %d, deploy the prerequisites first", chain.Selector)
return fmt.Errorf("router not found for chain %s, deploy the prerequisites first", chain.String())
}
if chainState.Receiver == nil {
ccipReceiver, err := deployment.DeployContract(e.Logger, chain, ab,
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
receiverAddr, tx, receiver, err2 := maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver(
chain.DeployerKey,
Expand All @@ -221,9 +221,8 @@ func deployChainContracts(
e.Logger.Errorw("Failed to deploy receiver", "err", err)
return err
}
e.Logger.Infow("deployed receiver", "addr", ccipReceiver.Address)
} else {
e.Logger.Infow("receiver already deployed", "addr", chainState.Receiver.Address)
e.Logger.Infow("receiver already deployed", "addr", chainState.Receiver.Address, "chain", chain.String())
}
rmnRemoteContract := chainState.RMNRemote
if chainState.RMNRemote == nil {
Expand All @@ -242,20 +241,19 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy RMNRemote", "err", err)
e.Logger.Errorw("Failed to deploy RMNRemote", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("deployed RMNRemote", "addr", rmnRemote.Address)
rmnRemoteContract = rmnRemote.Contract
} else {
e.Logger.Infow("rmn remote already deployed", "addr", chainState.RMNRemote.Address)
e.Logger.Infow("rmn remote already deployed", "chain", chain.String(), "addr", chainState.RMNRemote.Address)
}
activeDigest, err := rmnHome.GetActiveDigest(&bind.CallOpts{})
if err != nil {
e.Logger.Errorw("Failed to get active digest", "err", err)
e.Logger.Errorw("Failed to get active digest", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("setting active home digest to rmn remote", "digest", activeDigest)
e.Logger.Infow("setting active home digest to rmn remote", "chain", chain.String(), "digest", activeDigest)

tx, err := rmnRemoteContract.SetConfig(chain.DeployerKey, rmn_remote.RMNRemoteConfig{
RmnHomeContractConfigDigest: activeDigest,
Expand All @@ -265,7 +263,7 @@ func deployChainContracts(
F: 0, // TODO: update when we have signers
})
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
e.Logger.Errorw("Failed to confirm RMNRemote config", "err", err)
e.Logger.Errorw("Failed to confirm RMNRemote config", "chain", chain.String(), "err", err)
return err
}

Expand All @@ -286,16 +284,15 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy RMNProxyNew", "err", err)
e.Logger.Errorw("Failed to deploy RMNProxyNew", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("deployed new RMNProxyNew", "addr", rmnProxy.Address)
rmnProxyContract = rmnProxy.Contract
} else {
e.Logger.Infow("rmn proxy already deployed", "addr", chainState.RMNProxyNew.Address)
e.Logger.Infow("rmn proxy already deployed", "chain", chain.String(), "addr", chainState.RMNProxyNew.Address)
}
if chainState.TestRouter == nil {
testRouterContract, err := deployment.DeployContract(e.Logger, chain, ab,
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*router.Router] {
routerAddr, tx2, routerC, err2 := router.DeployRouter(
chain.DeployerKey,
Expand All @@ -308,12 +305,11 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy test router", "err", err)
e.Logger.Errorw("Failed to deploy test router", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("deployed test router", "addr", testRouterContract.Address)
} else {
e.Logger.Infow("test router already deployed", "addr", chainState.TestRouter.Address)
e.Logger.Infow("test router already deployed", "chain", chain.String(), "addr", chainState.TestRouter.Address)
}

nmContract := chainState.NonceManager
Expand All @@ -330,13 +326,12 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy nonce manager", "err", err)
e.Logger.Errorw("Failed to deploy nonce manager", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("Deployed nonce manager", "addr", nonceManager.Address)
nmContract = nonceManager.Contract
} else {
e.Logger.Infow("nonce manager already deployed", "addr", chainState.NonceManager.Address)
e.Logger.Infow("nonce manager already deployed", "chain", chain.String(), "addr", chainState.NonceManager.Address)
}
feeQuoterContract := chainState.FeeQuoter
if chainState.FeeQuoter == nil {
Expand Down Expand Up @@ -371,13 +366,12 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy fee quoter", "err", err)
e.Logger.Errorw("Failed to deploy fee quoter", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("Deployed fee quoter", "addr", feeQuoter.Address)
feeQuoterContract = feeQuoter.Contract
} else {
e.Logger.Infow("fee quoter already deployed", "addr", chainState.FeeQuoter.Address)
e.Logger.Infow("fee quoter already deployed", "chain", chain.String(), "addr", chainState.FeeQuoter.Address)
}
onRampContract := chainState.OnRamp
if onRampContract == nil {
Expand All @@ -403,13 +397,12 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy onramp", "err", err)
e.Logger.Errorw("Failed to deploy onramp", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("Deployed onramp", "addr", onRamp.Address)
onRampContract = onRamp.Contract
} else {
e.Logger.Infow("onramp already deployed", "addr", chainState.OnRamp.Address)
e.Logger.Infow("onramp already deployed", "chain", chain.String(), "addr", chainState.OnRamp.Address)
}
offRampContract := chainState.OffRamp
if offRampContract == nil {
Expand All @@ -436,13 +429,12 @@ func deployChainContracts(
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy offramp", "err", err)
e.Logger.Errorw("Failed to deploy offramp", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("Deployed offramp", "addr", offRamp.Address)
offRampContract = offRamp.Contract
} else {
e.Logger.Infow("offramp already deployed", "addr", chainState.OffRamp.Address)
e.Logger.Infow("offramp already deployed", "chain", chain.String(), "addr", chainState.OffRamp.Address)
}
// Basic wiring is always needed.
tx, err = feeQuoterContract.ApplyAuthorizedCallerUpdates(chain.DeployerKey, fee_quoter.AuthorizedCallersAuthorizedCallerArgs{
Expand All @@ -451,16 +443,17 @@ func deployChainContracts(
AddedCallers: []common.Address{offRampContract.Address(), chain.DeployerKey.From},
})
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
e.Logger.Errorw("Failed to confirm fee quoter authorized caller update", "err", err)
e.Logger.Errorw("Failed to confirm fee quoter authorized caller update", "chain", chain.String(), "err", err)
return err
}

e.Logger.Infow("Added fee quoter authorized callers", "chain", chain.String(), "callers", []common.Address{offRampContract.Address(), chain.DeployerKey.From})
tx, err = nmContract.ApplyAuthorizedCallerUpdates(chain.DeployerKey, nonce_manager.AuthorizedCallersAuthorizedCallerArgs{
AddedCallers: []common.Address{offRampContract.Address(), onRampContract.Address()},
})
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
e.Logger.Errorw("Failed to update nonce manager with ramps", "err", err)
e.Logger.Errorw("Failed to update nonce manager with ramps", "chain", chain.String(), "err", err)
return err
}
e.Logger.Infow("Added nonce manager authorized callers", "chain", chain.String(), "callers", []common.Address{offRampContract.Address(), onRampContract.Address()})
return nil
}
25 changes: 12 additions & 13 deletions deployment/ccip/changeset/cs_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"golang.org/x/exp/maps"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home"
Expand Down Expand Up @@ -111,7 +112,7 @@ func deployCapReg(
}
})
if err != nil {
lggr.Errorw("Failed to deploy capreg", "err", err)
lggr.Errorw("Failed to deploy capreg", "chain", chain.String(), "err", err)
return nil, err
}
return capReg, nil
Expand Down Expand Up @@ -152,10 +153,9 @@ func deployHomeChain(
}
})
if err != nil {
lggr.Errorw("Failed to deploy CCIPHome", "err", err)
lggr.Errorw("Failed to deploy CCIPHome", "chain", chain.String(), "err", err)
return nil, err
}
lggr.Infow("deployed CCIPHome", "addr", ccipHome.Address)

rmnHome, err := deployment.DeployContract(
lggr, chain, ab,
Expand All @@ -170,10 +170,9 @@ func deployHomeChain(
},
)
if err != nil {
lggr.Errorw("Failed to deploy RMNHome", "err", err)
lggr.Errorw("Failed to deploy RMNHome", "chain", chain.String(), "err", err)
return nil, err
}
lggr.Infow("deployed RMNHome", "addr", rmnHome.Address)

// considering the RMNHome is recently deployed, there is no digest to overwrite
tx, err := rmnHome.Contract.SetCandidate(chain.DeployerKey, rmnHomeStatic, rmnHomeDynamic, [32]byte{})
Expand All @@ -184,19 +183,19 @@ func deployHomeChain(

rmnCandidateDigest, err := rmnHome.Contract.GetCandidateDigest(nil)
if err != nil {
lggr.Errorw("Failed to get RMNHome candidate digest", "err", err)
lggr.Errorw("Failed to get RMNHome candidate digest", "chain", chain.String(), "err", err)
return nil, err
}

tx, err = rmnHome.Contract.PromoteCandidateAndRevokeActive(chain.DeployerKey, rmnCandidateDigest, [32]byte{})
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
lggr.Errorw("Failed to promote candidate and revoke active on RMNHome", "err", err)
lggr.Errorw("Failed to promote candidate and revoke active on RMNHome", "chain", chain.String(), "err", err)
return nil, err
}

rmnActiveDigest, err := rmnHome.Contract.GetActiveDigest(nil)
if err != nil {
lggr.Errorw("Failed to get RMNHome active digest", "err", err)
lggr.Errorw("Failed to get RMNHome active digest", "chain", chain.String(), "err", err)
return nil, err
}
lggr.Infow("Got rmn home active digest", "digest", rmnActiveDigest)
Expand All @@ -217,22 +216,22 @@ func deployHomeChain(
},
})
if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
lggr.Errorw("Failed to add capabilities", "err", err)
lggr.Errorw("Failed to add capabilities", "chain", chain.String(), "err", err)
return nil, err
}

tx, err = capReg.Contract.AddNodeOperators(chain.DeployerKey, nodeOps)
txBlockNum, err := deployment.ConfirmIfNoError(chain, tx, err)
if err != nil {
lggr.Errorw("Failed to add node operators", "err", err)
lggr.Errorw("Failed to add node operators", "chain", chain.String(), "err", err)
return nil, err
}
addedEvent, err := capReg.Contract.FilterNodeOperatorAdded(&bind.FilterOpts{
Start: txBlockNum,
Context: context.Background(),
}, nil, nil)
if err != nil {
lggr.Errorw("Failed to filter NodeOperatorAdded event", "err", err)
lggr.Errorw("Failed to filter NodeOperatorAdded event", "chain", chain.String(), "err", err)
return capReg, err
}
// Need to fetch nodeoperators ids to be able to add nodes for corresponding node operators
Expand All @@ -246,7 +245,7 @@ func deployHomeChain(
}
}
if len(p2pIDsByNodeOpId) != len(nodeP2PIDsPerNodeOpAdmin) {
lggr.Errorw("Failed to add all node operators", "added", maps.Keys(p2pIDsByNodeOpId), "expected", maps.Keys(nodeP2PIDsPerNodeOpAdmin))
lggr.Errorw("Failed to add all node operators", "added", maps.Keys(p2pIDsByNodeOpId), "expected", maps.Keys(nodeP2PIDsPerNodeOpAdmin), "chain", chain.String())
return capReg, errors.New("failed to add all node operators")
}
// Adds initial set of nodes to CR, who all have the CCIP capability
Expand Down Expand Up @@ -317,7 +316,7 @@ func addNodes(
}
tx, err := capReg.AddNodes(chain.DeployerKey, nodeParams)
if err != nil {
lggr.Errorw("Failed to add nodes", "err", deployment.MaybeDataErr(err))
lggr.Errorw("Failed to add nodes", "chain", chain.String(), "err", deployment.MaybeDataErr(err))
return err
}
_, err = chain.Confirm(tx)
Expand Down
6 changes: 1 addition & 5 deletions deployment/ccip/changeset/cs_home_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package changeset
import (
"testing"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -43,10 +42,7 @@ func TestDeployHomeChain(t *testing.T) {
require.NotNil(t, state.Chains[homeChainSel].RMNHome)
snap, err := state.View([]uint64{homeChainSel})
require.NoError(t, err)
chainid, err := chainsel.ChainIdFromSelector(homeChainSel)
require.NoError(t, err)
chainName, err := chainsel.NameFromChainId(chainid)
require.NoError(t, err)
chainName := e.Chains[homeChainSel].Name()
_, ok := snap[chainName]
require.True(t, ok)
capRegSnap, ok := snap[chainName].CapabilityRegistry[state.Chains[homeChainSel].CapabilityRegistry.Address().String()]
Expand Down
Loading

0 comments on commit f8a221f

Please sign in to comment.