From f8a221f284ce8747a943284a647905586fa3dda0 Mon Sep 17 00:00:00 2001 From: Anindita Ghosh <88458927+AnieeG@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:54:01 -0800 Subject: [PATCH] Ccip-4506 log improvements in deployment code (#15535) * 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 --- .../ccip/changeset/cs_add_chain_test.go | 1 + deployment/ccip/changeset/cs_deploy_chain.go | 69 +++++++++---------- deployment/ccip/changeset/cs_home_chain.go | 25 ++++--- .../ccip/changeset/cs_home_chain_test.go | 6 +- .../ccip/changeset/cs_initial_add_chain.go | 32 +++++++-- deployment/ccip/changeset/cs_prerequisites.go | 42 +++++------ .../changeset/internal/deploy_home_chain.go | 34 ++++++--- deployment/ccip/changeset/state.go | 34 ++++----- .../ccip/changeset/test_usdc_helpers.go | 14 ++-- .../common/changeset/deploy_link_token.go | 2 +- deployment/common/changeset/internal/mcms.go | 10 +-- deployment/common/view/nops.go | 4 +- .../common/view/types/contract_state.go | 6 +- deployment/common/view/v1_0/link_token.go | 7 +- deployment/environment.go | 20 +++++- .../environment/clo/models/models_gen.go | 10 +-- deployment/environment/devenv/chain.go | 18 ++--- deployment/environment/memory/environment.go | 15 ++-- deployment/helpers.go | 27 ++++++-- deployment/keystone/ocr3config_test.go | 8 +-- deployment/multiclient.go | 22 ++++-- 21 files changed, 235 insertions(+), 171 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index c83872c0dd7..f6e1c04c469 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -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, diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index b57c00fd796..e2762b27578 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -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, @@ -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 { @@ -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, @@ -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 } @@ -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, @@ -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 @@ -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 { @@ -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 { @@ -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 { @@ -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{ @@ -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 } diff --git a/deployment/ccip/changeset/cs_home_chain.go b/deployment/ccip/changeset/cs_home_chain.go index 0df8d87affb..750b21229aa 100644 --- a/deployment/ccip/changeset/cs_home_chain.go +++ b/deployment/ccip/changeset/cs_home_chain.go @@ -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" @@ -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 @@ -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, @@ -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{}) @@ -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) @@ -217,14 +216,14 @@ 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{ @@ -232,7 +231,7 @@ func deployHomeChain( 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 @@ -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 @@ -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) diff --git a/deployment/ccip/changeset/cs_home_chain_test.go b/deployment/ccip/changeset/cs_home_chain_test.go index 55bc7466837..a06161f7086 100644 --- a/deployment/ccip/changeset/cs_home_chain_test.go +++ b/deployment/ccip/changeset/cs_home_chain_test.go @@ -3,7 +3,6 @@ package changeset import ( "testing" - chainsel "github.com/smartcontractkit/chain-selectors" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" @@ -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()] diff --git a/deployment/ccip/changeset/cs_initial_add_chain.go b/deployment/ccip/changeset/cs_initial_add_chain.go index 0e425aef8c7..d18116b8a74 100644 --- a/deployment/ccip/changeset/cs_initial_add_chain.go +++ b/deployment/ccip/changeset/cs_initial_add_chain.go @@ -18,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/deployment/common/types" @@ -178,19 +179,20 @@ func configureChain( e.Logger.Errorw("Failed to load existing onchain state", "err") return err } + homeChain := e.Chains[c.HomeChainSel] capReg := existingState.Chains[c.HomeChainSel].CapabilityRegistry if capReg == nil { - e.Logger.Errorw("Failed to get capability registry") + e.Logger.Errorw("Failed to get capability registry", "chain", homeChain.String()) return fmt.Errorf("capability registry not found") } ccipHome := existingState.Chains[c.HomeChainSel].CCIPHome if ccipHome == nil { - e.Logger.Errorw("Failed to get ccip home", "err", err) + e.Logger.Errorw("Failed to get ccip home", "chain", homeChain.String(), "err", err) return fmt.Errorf("ccip home not found") } rmnHome := existingState.Chains[c.HomeChainSel].RMNHome if rmnHome == nil { - e.Logger.Errorw("Failed to get rmn home", "err", err) + e.Logger.Errorw("Failed to get rmn home", "chain", homeChain.String(), "err", err) return fmt.Errorf("rmn home not found") } @@ -267,7 +269,7 @@ func addChainConfig( if _, err := deployment.ConfirmIfNoError(h, tx, err); err != nil { return ccip_home.CCIPHomeChainConfigArgs{}, err } - lggr.Infow("Applied chain config updates", "chainConfig", chainConfig) + lggr.Infow("Applied chain config updates", "homeChain", h.String(), "addedChain", chainSelector, "chainConfig", chainConfig) return chainConfig, nil } @@ -301,17 +303,17 @@ func createDON( donID := latestDon.Id + 1 - err = internal.SetupCommitDON(donID, commitConfig, capReg, home, nodes, ccipHome) + err = internal.SetupCommitDON(lggr, donID, commitConfig, capReg, home, nodes, ccipHome) if err != nil { return fmt.Errorf("setup commit don: %w", err) } // TODO: bug in contract causing this to not work as expected. - err = internal.SetupExecDON(donID, execConfig, capReg, home, nodes, ccipHome) + err = internal.SetupExecDON(lggr, donID, execConfig, capReg, home, nodes, ccipHome) if err != nil { return fmt.Errorf("setup exec don: %w", err) } - return ValidateCCIPHomeConfigSetUp(capReg, ccipHome, newChainSel) + return ValidateCCIPHomeConfigSetUp(lggr, capReg, ccipHome, newChainSel) } func addDON( @@ -369,6 +371,15 @@ func addDON( if err != nil { return err } + lggr.Debugw("Fetched OCR3 Configs", + "MultiOCR3BaseOCRConfig.F", ocrConfig.ConfigInfo.F, + "MultiOCR3BaseOCRConfig.N", ocrConfig.ConfigInfo.N, + "MultiOCR3BaseOCRConfig.IsSignatureVerificationEnabled", ocrConfig.ConfigInfo.IsSignatureVerificationEnabled, + "Signers", ocrConfig.Signers, + "Transmitters", ocrConfig.Transmitters, + "configDigest", hex.EncodeToString(ocrConfig.ConfigInfo.ConfigDigest[:]), + "chain", dest.String(), + ) // TODO: assertions to be done as part of full state // resprentation validation CCIP-3047 if mapOfframpOCR3Configs[pluginType].ConfigDigest != ocrConfig.ConfigInfo.ConfigDigest { @@ -400,6 +411,7 @@ func addDON( // ValidateCCIPHomeConfigSetUp checks that the commit and exec active and candidate configs are set up correctly func ValidateCCIPHomeConfigSetUp( + lggr logger.Logger, capReg *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, chainSel uint64, @@ -420,10 +432,12 @@ func ValidateCCIPHomeConfigSetUp( if err != nil { return fmt.Errorf("get active commit digest: %w", err) } + lggr.Debugw("Fetched active commit digest", "commitActiveDigest", hex.EncodeToString(commitActiveDigest[:])) commitCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit)) if err != nil { return fmt.Errorf("get commit candidate digest: %w", err) } + lggr.Debugw("Fetched candidate commit digest", "commitCandidateDigest", hex.EncodeToString(commitCandidateDigest[:])) if commitConfigs.ActiveConfig.ConfigDigest == [32]byte{} { return fmt.Errorf( "active config digest is empty for commit, expected nonempty, donID: %d, cfg: %+v, config digest from GetActiveDigest call: %x, config digest from GetCandidateDigest call: %x", @@ -439,6 +453,10 @@ func ValidateCCIPHomeConfigSetUp( if err != nil { return fmt.Errorf("get all exec configs: %w", err) } + lggr.Debugw("Fetched exec configs", + "ActiveConfig.ConfigDigest", hex.EncodeToString(execConfigs.ActiveConfig.ConfigDigest[:]), + "CandidateConfig.ConfigDigest", hex.EncodeToString(execConfigs.CandidateConfig.ConfigDigest[:]), + ) if execConfigs.ActiveConfig.ConfigDigest == [32]byte{} { return fmt.Errorf("active config digest is empty for exec, expected nonempty, cfg: %v", execConfigs.ActiveConfig) } diff --git a/deployment/ccip/changeset/cs_prerequisites.go b/deployment/ccip/changeset/cs_prerequisites.go index e610dfaaeeb..2386d3bb784 100644 --- a/deployment/ccip/changeset/cs_prerequisites.go +++ b/deployment/ccip/changeset/cs_prerequisites.go @@ -153,10 +153,9 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - lggr.Errorw("Failed to deploy mock RMN", "err", err) + lggr.Errorw("Failed to deploy mock RMN", "chain", chain.String(), "err", err) return err } - lggr.Infow("deployed mock RMN", "addr", rmn.Address) rmnProxyContract, err := deployment.DeployContract(lggr, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] { rmnProxyAddr, tx2, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract( @@ -169,10 +168,9 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - lggr.Errorw("Failed to deploy RMNProxyNew", "err", err) + lggr.Errorw("Failed to deploy RMNProxyExisting", "chain", chain.String(), "err", err) return err } - lggr.Infow("deployed RMNProxyNew", "addr", rmnProxyContract.Address) rmnProxy = rmnProxyContract.Contract } if tokenAdminReg == nil { @@ -186,13 +184,12 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - e.Logger.Errorw("Failed to deploy token admin registry", "err", err) + e.Logger.Errorw("Failed to deploy token admin registry", "chain", chain.String(), "err", err) return err } - e.Logger.Infow("deployed tokenAdminRegistry", "addr", tokenAdminRegistry) tokenAdminReg = tokenAdminRegistry.Contract } else { - e.Logger.Infow("tokenAdminRegistry already deployed", "addr", tokenAdminReg.Address) + e.Logger.Infow("tokenAdminRegistry already deployed", "chain", chain.String(), "addr", tokenAdminReg.Address) } if registryModule == nil { customRegistryModule, err := deployment.DeployContract(e.Logger, chain, ab, @@ -206,29 +203,28 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - e.Logger.Errorw("Failed to deploy custom registry module", "err", err) + e.Logger.Errorw("Failed to deploy custom registry module", "chain", chain.String(), "err", err) return err } - e.Logger.Infow("deployed custom registry module", "addr", customRegistryModule) registryModule = customRegistryModule.Contract } else { - e.Logger.Infow("custom registry module already deployed", "addr", registryModule.Address) + e.Logger.Infow("custom registry module already deployed", "chain", chain.String(), "addr", registryModule.Address) } isRegistryAdded, err := tokenAdminReg.IsRegistryModule(nil, registryModule.Address()) if err != nil { - e.Logger.Errorw("Failed to check if registry module is added on token admin registry", "err", err) + e.Logger.Errorw("Failed to check if registry module is added on token admin registry", "chain", chain.String(), "err", err) return fmt.Errorf("failed to check if registry module is added on token admin registry: %w", err) } if !isRegistryAdded { tx, err := tokenAdminReg.AddRegistryModule(chain.DeployerKey, registryModule.Address()) if err != nil { - e.Logger.Errorw("Failed to assign registry module on token admin registry", "err", err) + e.Logger.Errorw("Failed to assign registry module on token admin registry", "chain", chain.String(), "err", err) return fmt.Errorf("failed to assign registry module on token admin registry: %w", err) } _, err = chain.Confirm(tx) if err != nil { - e.Logger.Errorw("Failed to confirm assign registry module on token admin registry", "err", err) + e.Logger.Errorw("Failed to confirm assign registry module on token admin registry", "chain", chain.String(), "err", err) return fmt.Errorf("failed to confirm assign registry module on token admin registry: %w", err) } e.Logger.Infow("assigned registry module on token admin registry") @@ -245,10 +241,9 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - lggr.Errorw("Failed to deploy weth9", "err", err) + lggr.Errorw("Failed to deploy weth9", "chain", chain.String(), "err", err) return err } - lggr.Infow("deployed weth9", "addr", weth.Address) weth9Contract = weth.Contract } else { lggr.Infow("weth9 already deployed", "addr", weth9Contract.Address) @@ -268,16 +263,16 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - e.Logger.Errorw("Failed to deploy router", "err", err) + e.Logger.Errorw("Failed to deploy router", "chain", chain.String(), "err", err) return err } - e.Logger.Infow("deployed router", "addr", routerContract.Address) + r = routerContract.Contract } else { - e.Logger.Infow("router already deployed", "addr", chainState.Router.Address) + e.Logger.Infow("router already deployed", "chain", chain.String(), "addr", chainState.Router.Address) } if deployOpts.Multicall3Enabled && mc3 == nil { - multicall3Contract, err := deployment.DeployContract(e.Logger, chain, ab, + _, err := deployment.DeployContract(e.Logger, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*multicall3.Multicall3] { multicall3Addr, tx2, multicall3Wrapper, err2 := multicall3.DeployMulticall3( chain.DeployerKey, @@ -288,12 +283,13 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } }) if err != nil { - e.Logger.Errorw("Failed to deploy ccip multicall", "err", err) + e.Logger.Errorw("Failed to deploy ccip multicall", "chain", chain.String(), "err", err) return err } - e.Logger.Infow("deployed ccip multicall", "addr", multicall3Contract.Address) } else { - e.Logger.Info("ccip multicall already deployed", "addr", mc3.Address) + if mc3 != nil { + e.Logger.Info("ccip multicall already deployed", "chain", chain.String(), "addr", mc3.Address) + } } if isUSDC { token, pool, messenger, transmitter, err1 := DeployUSDC(e.Logger, chain, ab, rmnProxy.Address(), r.Address()) @@ -301,7 +297,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address return err1 } e.Logger.Infow("Deployed USDC contracts", - "chainSelector", chain.Selector, + "chain", chain.String(), "token", token.Address(), "pool", pool.Address(), "transmitter", transmitter.Address(), diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 27052b04d07..6328c329b9a 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" @@ -173,6 +174,7 @@ func BuildSetOCR3ConfigArgs( } func SetupExecDON( + lggr logger.Logger, donID uint32, execConfig ccip_home.CCIPHomeOCR3Config, capReg *capabilities_registry.CapabilitiesRegistry, @@ -212,6 +214,7 @@ func SetupExecDON( if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { return fmt.Errorf("confirm update don w/ exec config: %w", err) } + lggr.Infow("Updated DON with exec config", "chain", home.String(), "donID", donID, "txHash", tx.Hash().Hex(), "setCandidateCall", encodedSetCandidateCall) execCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, execConfig.PluginType) if err != nil { @@ -221,7 +224,7 @@ func SetupExecDON( if execCandidateDigest == [32]byte{} { return fmt.Errorf("candidate digest is empty, expected nonempty") } - + lggr.Infow("Got exec candidate digest", "chain", home.String(), "donID", donID, "execCandidateDigest", execCandidateDigest) // promote candidate call encodedPromotionCall, err := CCIPHomeABI.Pack( "promoteCandidateAndRevokeActive", @@ -257,6 +260,7 @@ func SetupExecDON( if bn == 0 { return fmt.Errorf("UpdateDON tx not confirmed") } + lggr.Infow("Promoted exec candidate", "chain", home.String(), "donID", donID, "txHash", tx.Hash().Hex(), "promotionCall", encodedPromotionCall) // check if candidate digest is promoted pEvent, err := ccipHome.FilterConfigPromoted(&bind.FilterOpts{ Context: context.Background(), @@ -293,14 +297,20 @@ func SetupExecDON( return fmt.Errorf("get all exec configs 2nd time: %w", err) } - // print the above info - fmt.Printf("completed exec DON creation and promotion: donID: %d execCandidateDigest: %x, execActiveDigest: %x, execCandidateDigestFromGetAllConfigs: %x, execActiveDigestFromGetAllConfigs: %x\n", - donID, execCandidateDigest, execActiveDigest, execConfigs.CandidateConfig.ConfigDigest, execConfigs.ActiveConfig.ConfigDigest) + // log the above info + lggr.Infow("completed exec DON creation and promotion", + "donID", donID, + "execCandidateDigest", execCandidateDigest, + "execActiveDigest", execActiveDigest, + "execCandidateDigestFromGetAllConfigs", execConfigs.CandidateConfig.ConfigDigest, + "execActiveDigestFromGetAllConfigs", execConfigs.ActiveConfig.ConfigDigest, + ) return nil } func SetupCommitDON( + lggr logger.Logger, donID uint32, commitConfig ccip_home.CCIPHomeOCR3Config, capReg *capabilities_registry.CapabilitiesRegistry, @@ -331,7 +341,7 @@ func SetupCommitDON( if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { return fmt.Errorf("confirm add don w/ commit config: %w", err) } - + lggr.Debugw("Added DON with commit config", "chain", home.String(), "donID", donID, "txHash", tx.Hash().Hex(), "setCandidateCall", encodedSetCandidateCall) commitCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) if err != nil { return fmt.Errorf("get commit candidate digest: %w", err) @@ -340,7 +350,7 @@ func SetupCommitDON( if commitCandidateDigest == [32]byte{} { return fmt.Errorf("candidate digest is empty, expected nonempty") } - fmt.Printf("commit candidate digest after setCandidate: %x\n", commitCandidateDigest) + lggr.Debugw("Got commit candidate digest", "chain", home.String(), "donID", donID, "commitCandidateDigest", commitCandidateDigest) encodedPromotionCall, err := CCIPHomeABI.Pack( "promoteCandidateAndRevokeActive", @@ -373,6 +383,7 @@ func SetupCommitDON( if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { return fmt.Errorf("confirm update don w/ commit config: %w", err) } + lggr.Debugw("Promoted commit candidate", "chain", home.String(), "donID", donID, "txHash", tx.Hash().Hex(), "promotionCall", encodedPromotionCall) // check that candidate digest is empty. commitCandidateDigest, err = ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) @@ -399,9 +410,14 @@ func SetupCommitDON( return fmt.Errorf("get all commit configs 2nd time: %w", err) } - // print the above information - fmt.Printf("completed commit DON creation and promotion: donID: %d, commitCandidateDigest: %x, commitActiveDigest: %x, commitCandidateDigestFromGetAllConfigs: %x, commitActiveDigestFromGetAllConfigs: %x\n", - donID, commitCandidateDigest, commitActiveDigest, commitConfigs.CandidateConfig.ConfigDigest, commitConfigs.ActiveConfig.ConfigDigest) + // log the above information + lggr.Infow("completed commit DON creation and promotion", + "donID", donID, + "commitCandidateDigest", commitCandidateDigest, + "commitActiveDigest", commitActiveDigest, + "commitCandidateDigestFromGetAllConfigs", commitConfigs.CandidateConfig.ConfigDigest, + "commitActiveDigestFromGetAllConfigs", commitConfigs.ActiveConfig.ConfigDigest, + ) return nil } diff --git a/deployment/ccip/changeset/state.go b/deployment/ccip/changeset/state.go index 20763523141..0820f42d0c7 100644 --- a/deployment/ccip/changeset/state.go +++ b/deployment/ccip/changeset/state.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - chainsel "github.com/smartcontractkit/chain-selectors" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/view" @@ -134,35 +133,35 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { if c.Router != nil { routerView, err := v1_2.GenerateRouterView(c.Router) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate router view for router %s", c.Router.Address().String()) } chainView.Router[c.Router.Address().Hex()] = routerView } if c.TokenAdminRegistry != nil { taView, err := v1_5.GenerateTokenAdminRegistryView(c.TokenAdminRegistry) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate token admin registry view for token admin registry %s", c.TokenAdminRegistry.Address().String()) } chainView.TokenAdminRegistry[c.TokenAdminRegistry.Address().Hex()] = taView } if c.NonceManager != nil { nmView, err := v1_6.GenerateNonceManagerView(c.NonceManager) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate nonce manager view for nonce manager %s", c.NonceManager.Address().String()) } chainView.NonceManager[c.NonceManager.Address().Hex()] = nmView } if c.RMNRemote != nil { rmnView, err := v1_6.GenerateRMNRemoteView(c.RMNRemote) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate rmn remote view for rmn remote %s", c.RMNRemote.Address().String()) } chainView.RMN[c.RMNRemote.Address().Hex()] = rmnView } if c.FeeQuoter != nil && c.Router != nil && c.TokenAdminRegistry != nil { fqView, err := v1_6.GenerateFeeQuoterView(c.FeeQuoter, c.Router, c.TokenAdminRegistry) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate fee quoter view for fee quoter %s", c.FeeQuoter.Address().String()) } chainView.FeeQuoter[c.FeeQuoter.Address().Hex()] = fqView } @@ -174,7 +173,7 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { c.TokenAdminRegistry, ) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate on ramp view for on ramp %s", c.OnRamp.Address().String()) } chainView.OnRamp[c.OnRamp.Address().Hex()] = onRampView } @@ -185,7 +184,7 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { c.Router, ) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate off ramp view for off ramp %s", c.OffRamp.Address().String()) } chainView.OffRamp[c.OffRamp.Address().Hex()] = offRampView } @@ -193,7 +192,7 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { if c.CommitStore != nil { commitStoreView, err := v1_5.GenerateCommitStoreView(c.CommitStore) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate commit store view for commit store %s", c.CommitStore.Address().String()) } chainView.CommitStore[c.CommitStore.Address().Hex()] = commitStoreView } @@ -201,28 +200,28 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { if c.RMNProxyNew != nil { rmnProxyView, err := v1_0.GenerateRMNProxyView(c.RMNProxyNew) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate rmn proxy view for rmn proxy %s", c.RMNProxyNew.Address().String()) } chainView.RMNProxy[c.RMNProxyNew.Address().Hex()] = rmnProxyView } if c.CapabilityRegistry != nil { capRegView, err := common_v1_0.GenerateCapabilityRegistryView(c.CapabilityRegistry) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate capability registry view for capability registry %s", c.CapabilityRegistry.Address().String()) } chainView.CapabilityRegistry[c.CapabilityRegistry.Address().Hex()] = capRegView } if c.MCMSWithTimelockState.Timelock != nil { mcmsView, err := c.MCMSWithTimelockState.GenerateMCMSWithTimelockView() if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate MCMS with timelock view for MCMS with timelock %s", c.MCMSWithTimelockState.Timelock.Address().String()) } chainView.MCMSWithTimelock = mcmsView } if c.LinkToken != nil { linkTokenView, err := common_v1_0.GenerateLinkTokenView(c.LinkToken) if err != nil { - return chainView, err + return chainView, errors.Wrapf(err, "failed to generate link token view for link token %s", c.LinkToken.Address().String()) } chainView.LinkToken = linkTokenView } @@ -242,12 +241,7 @@ type CCIPOnChainState struct { func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, error) { m := make(map[string]view.ChainView) for _, chainSelector := range chains { - // TODO: Need a utility for this - chainid, err := chainsel.ChainIdFromSelector(chainSelector) - if err != nil { - return m, err - } - chainName, err := chainsel.NameFromChainId(chainid) + chainInfo, err := deployment.ChainInfo(chainSelector) if err != nil { return m, err } @@ -259,7 +253,7 @@ func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, erro if err != nil { return m, err } - m[chainName] = chainView + m[chainInfo.ChainName] = chainView } return m, nil } diff --git a/deployment/ccip/changeset/test_usdc_helpers.go b/deployment/ccip/changeset/test_usdc_helpers.go index 75994ec9356..55f1bd25a36 100644 --- a/deployment/ccip/changeset/test_usdc_helpers.go +++ b/deployment/ccip/changeset/test_usdc_helpers.go @@ -175,13 +175,13 @@ func DeployUSDC( } }) if err != nil { - lggr.Errorw("Failed to deploy USDC token", "err", err) + lggr.Errorw("Failed to deploy USDC token", "chain", chain.String(), "err", err) return nil, nil, nil, nil, err } tx, err := token.Contract.GrantMintRole(chain.DeployerKey, chain.DeployerKey.From) if err != nil { - lggr.Errorw("Failed to grant mint role", "token", token.Contract.Address(), "err", err) + lggr.Errorw("Failed to grant mint role", "chain", chain.String(), "token", token.Contract.Address(), "err", err) return nil, nil, nil, nil, err } _, err = chain.Confirm(tx) @@ -207,12 +207,10 @@ func DeployUSDC( } }) if err != nil { - lggr.Errorw("Failed to deploy mock USDC transmitter", "err", err) + lggr.Errorw("Failed to deploy mock USDC transmitter", "chain", chain.String(), "err", err) return nil, nil, nil, nil, err } - lggr.Infow("deployed mock USDC transmitter", "addr", transmitter.Address) - messenger, err := deployment.DeployContract(lggr, chain, addresses, func(chain deployment.Chain) deployment.ContractDeploy[*mock_usdc_token_messenger.MockE2EUSDCTokenMessenger] { messengerAddress, tx, messengerContract, err2 := mock_usdc_token_messenger.DeployMockE2EUSDCTokenMessenger( @@ -230,10 +228,9 @@ func DeployUSDC( } }) if err != nil { - lggr.Errorw("Failed to deploy USDC token messenger", "err", err) + lggr.Errorw("Failed to deploy USDC token messenger", "chain", chain.String(), "err", err) return nil, nil, nil, nil, err } - lggr.Infow("deployed mock USDC token messenger", "addr", messenger.Address) tokenPool, err := deployment.DeployContract(lggr, chain, addresses, func(chain deployment.Chain) deployment.ContractDeploy[*usdc_token_pool.USDCTokenPool] { @@ -255,10 +252,9 @@ func DeployUSDC( } }) if err != nil { - lggr.Errorw("Failed to deploy USDC token pool", "err", err) + lggr.Errorw("Failed to deploy USDC token pool", "chain", chain.String(), "err", err) return nil, nil, nil, nil, err } - lggr.Infow("deployed USDC token pool", "addr", tokenPool.Address) return token.Contract, tokenPool.Contract, messenger.Contract, transmitter.Contract, nil } diff --git a/deployment/common/changeset/deploy_link_token.go b/deployment/common/changeset/deploy_link_token.go index 5728e977c47..292c07c93df 100644 --- a/deployment/common/changeset/deploy_link_token.go +++ b/deployment/common/changeset/deploy_link_token.go @@ -52,7 +52,7 @@ func deployLinkTokenContract( } }) if err != nil { - lggr.Errorw("Failed to deploy link token", "err", err) + lggr.Errorw("Failed to deploy link token", "chain", chain.String(), "err", err) return linkToken, err } return linkToken, nil diff --git a/deployment/common/changeset/internal/mcms.go b/deployment/common/changeset/internal/mcms.go index 5694f83786b..281f43924f4 100644 --- a/deployment/common/changeset/internal/mcms.go +++ b/deployment/common/changeset/internal/mcms.go @@ -6,6 +6,7 @@ import ( owner_helpers "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/common/types" "github.com/smartcontractkit/chainlink/deployment/common/view/v1_0" @@ -30,7 +31,7 @@ func DeployMCMSWithConfig( } }) if err != nil { - lggr.Errorw("Failed to deploy mcm", "err", err) + lggr.Errorw("Failed to deploy mcm", "chain", chain.String(), "err", err) return mcm, err } mcmsTx, err := mcm.Contract.SetConfig(chain.DeployerKey, @@ -42,7 +43,7 @@ func DeployMCMSWithConfig( false, ) if _, err := deployment.ConfirmIfNoError(chain, mcmsTx, err); err != nil { - lggr.Errorw("Failed to confirm mcm config", "err", err) + lggr.Errorw("Failed to confirm mcm config", "chain", chain.String(), "err", err) return mcm, err } return mcm, nil @@ -115,15 +116,14 @@ func DeployMCMSWithTimelockContracts( } }) if err != nil { - lggr.Errorw("Failed to deploy timelock", "err", err) + lggr.Errorw("Failed to deploy timelock", "chain", chain.String(), "err", err) return nil, err } - lggr.Infow("deployed timelock", "addr", timelock.Address) // We grant the timelock the admin role on the MCMS contracts. tx, err := timelock.Contract.GrantRole(chain.DeployerKey, v1_0.ADMIN_ROLE.ID, timelock.Address) if _, err := deployment.ConfirmIfNoError(chain, tx, err); err != nil { - lggr.Errorw("Failed to grant timelock admin role", "err", err) + lggr.Errorw("Failed to grant timelock admin role", "chain", chain.String(), "err", err) return nil, err } // After the proposer cycle is validated, diff --git a/deployment/common/view/nops.go b/deployment/common/view/nops.go index 7d705f694d3..61e16d59145 100644 --- a/deployment/common/view/nops.go +++ b/deployment/common/view/nops.go @@ -4,7 +4,9 @@ import ( "context" "fmt" + "github.com/pkg/errors" nodev1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node" + "github.com/smartcontractkit/chainlink/deployment" ) @@ -39,7 +41,7 @@ func GenerateNopsView(nodeIds []string, oc deployment.OffchainClient) (map[strin // get node info nodeDetails, err := oc.GetNode(context.Background(), &nodev1.GetNodeRequest{Id: node.NodeID}) if err != nil { - return nv, err + return nv, errors.Wrapf(err, "failed to get node details from offchain client for node %s", node.NodeID) } if nodeDetails == nil || nodeDetails.Node == nil { return nv, fmt.Errorf("failed to get node details from offchain client for node %s", node.NodeID) diff --git a/deployment/common/view/types/contract_state.go b/deployment/common/view/types/contract_state.go index f65c510af53..9b63d1f4db0 100644 --- a/deployment/common/view/types/contract_state.go +++ b/deployment/common/view/types/contract_state.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ) @@ -14,11 +16,11 @@ type ContractMetaData struct { func NewContractMetaData(tv Meta, addr common.Address) (ContractMetaData, error) { tvStr, err := tv.TypeAndVersion(nil) if err != nil { - return ContractMetaData{}, err + return ContractMetaData{}, fmt.Errorf("failed to get type and version addr %s: %w", addr.String(), err) } owner, err := tv.Owner(nil) if err != nil { - return ContractMetaData{}, err + return ContractMetaData{}, fmt.Errorf("failed to get owner addr %s: %w", addr.String(), err) } return ContractMetaData{ TypeAndVersion: tvStr, diff --git a/deployment/common/view/v1_0/link_token.go b/deployment/common/view/v1_0/link_token.go index 38649037592..19b1b43aa02 100644 --- a/deployment/common/view/v1_0/link_token.go +++ b/deployment/common/view/v1_0/link_token.go @@ -1,6 +1,7 @@ package v1_0 import ( + "fmt" "math/big" "github.com/smartcontractkit/chainlink/deployment" @@ -18,15 +19,15 @@ type LinkTokenView struct { func GenerateLinkTokenView(lt *link_token.LinkToken) (LinkTokenView, error) { owner, err := lt.Owner(nil) if err != nil { - return LinkTokenView{}, err + return LinkTokenView{}, fmt.Errorf("view error to get link token owner addr %s: %w", lt.Address().String(), err) } decimals, err := lt.Decimals(nil) if err != nil { - return LinkTokenView{}, err + return LinkTokenView{}, fmt.Errorf("view error to get link token decimals addr %s: %w", lt.Address().String(), err) } totalSupply, err := lt.TotalSupply(nil) if err != nil { - return LinkTokenView{}, err + return LinkTokenView{}, fmt.Errorf("view error to get link token total supply addr %s: %w", lt.Address().String(), err) } return LinkTokenView{ ContractMetaData: types.ContractMetaData{ diff --git a/deployment/environment.go b/deployment/environment.go index 2de16a32cab..b4ac3a4f3f0 100644 --- a/deployment/environment.go +++ b/deployment/environment.go @@ -59,6 +59,24 @@ type Chain struct { Users []*bind.TransactOpts } +func (c Chain) String() string { + chainInfo, err := ChainInfo(c.Selector) + if err != nil { + // we should never get here, if the selector is invalid it should not be in the environment + panic(err) + } + return fmt.Sprintf("%s (%d)", chainInfo.ChainName, chainInfo.ChainSelector) +} + +func (c Chain) Name() string { + chainInfo, err := ChainInfo(c.Selector) + if err != nil { + // we should never get here, if the selector is invalid it should not be in the environment + panic(err) + } + return chainInfo.ChainName +} + // Environment represents an instance of a deployed product // including on and offchain components. It is intended to be // cross-family to enable a coherent view of a product deployed @@ -147,7 +165,7 @@ func ConfirmIfNoError(chain Chain, tx *types.Transaction, err error) (uint64, er var d rpc.DataError ok := errors.As(err, &d) if ok { - return 0, fmt.Errorf("transaction reverted: Error %s ErrorData %v", d.Error(), d.ErrorData()) + return 0, fmt.Errorf("transaction reverted on chain %s: Error %s ErrorData %v", chain.String(), d.Error(), d.ErrorData()) } return 0, err } diff --git a/deployment/environment/clo/models/models_gen.go b/deployment/environment/clo/models/models_gen.go index baea1dbcbed..8d8f57c3b56 100644 --- a/deployment/environment/clo/models/models_gen.go +++ b/deployment/environment/clo/models/models_gen.go @@ -58,7 +58,7 @@ type AddAggregatorInput struct { type AddChainInput struct { NetworkID string `json:"networkID,omitempty"` Template string `json:"template,omitempty"` - // The Display Name lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. + // The Display String lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. DisplayName *string `json:"displayName,omitempty"` } @@ -102,7 +102,7 @@ type AddLaneInput struct { ChainAid string `json:"chainAID,omitempty"` ChainBid string `json:"chainBID,omitempty"` Template string `json:"template,omitempty"` - // The Display Name lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. + // The Display String lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. DisplayName *string `json:"displayName,omitempty"` } @@ -353,7 +353,7 @@ type CCIPChain struct { FeeTokens []string `json:"feeTokens,omitempty"` WrappedNativeToken string `json:"wrappedNativeToken,omitempty"` ArchivedAt *Time `json:"archivedAt,omitempty"` - // The Display Name lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. + // The Display String lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. DisplayName *string `json:"displayName,omitempty"` DeployedTemplate map[string]interface{} `json:"deployedTemplate,omitempty"` Labels map[string]interface{} `json:"labels,omitempty"` @@ -1001,7 +1001,7 @@ type ImportAggregatorInput struct { type ImportChainInput struct { NetworkID string `json:"networkID,omitempty"` Template string `json:"template,omitempty"` - // The Display Name lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. + // The Display String lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. DisplayName *string `json:"displayName,omitempty"` } @@ -1047,7 +1047,7 @@ type ImportLaneInput struct { ChainAid string `json:"chainAID,omitempty"` ChainBid string `json:"chainBID,omitempty"` Template string `json:"template,omitempty"` - // The Display Name lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. + // The Display String lets a user differentiate multiple CCIP chains on the same network. It is not unique and used for display purposes only. DisplayName *string `json:"displayName,omitempty"` } diff --git a/deployment/environment/devenv/chain.go b/deployment/environment/devenv/chain.go index 407b898cb04..5c6c4336ed7 100644 --- a/deployment/environment/devenv/chain.go +++ b/deployment/environment/devenv/chain.go @@ -108,6 +108,10 @@ func NewChains(logger logger.Logger, configs []ChainConfig) (map[uint64]deployme if ec == nil { return nil, fmt.Errorf("failed to connect to chain %s", chainCfg.ChainName) } + chainInfo, err := deployment.ChainInfo(selector) + if err != nil { + return nil, fmt.Errorf("failed to get chain info for chain %s: %w", chainCfg.ChainName, err) + } chains[selector] = deployment.Chain{ Selector: selector, Client: ec, @@ -115,28 +119,24 @@ func NewChains(logger logger.Logger, configs []ChainConfig) (map[uint64]deployme Confirm: func(tx *types.Transaction) (uint64, error) { var blockNumber uint64 if tx == nil { - return 0, fmt.Errorf("tx was nil, nothing to confirm") + return 0, fmt.Errorf("tx was nil, nothing to confirm chain %s", chainInfo.ChainName) } ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) defer cancel() - chainId, err := ec.ChainID(ctx) - if err != nil { - return blockNumber, fmt.Errorf("failed to get chain id: %w", err) - } receipt, err := bind.WaitMined(ctx, ec, tx) if err != nil { - return blockNumber, fmt.Errorf("failed to get confirmed receipt for chain %d: %w", chainId, err) + return blockNumber, fmt.Errorf("failed to get confirmed receipt for chain %s: %w", chainInfo.ChainName, err) } if receipt == nil { - return blockNumber, fmt.Errorf("receipt was nil for tx %s", tx.Hash().Hex()) + return blockNumber, fmt.Errorf("receipt was nil for tx %s chain %s", tx.Hash().Hex(), chainInfo.ChainName) } blockNumber = receipt.BlockNumber.Uint64() if receipt.Status == 0 { errReason, err := deployment.GetErrorReasonFromTx(ec, chainCfg.DeployerKey.From, tx, receipt) if err == nil && errReason != "" { - return blockNumber, fmt.Errorf("tx %s reverted,error reason: %s", tx.Hash().Hex(), errReason) + return blockNumber, fmt.Errorf("tx %s reverted,error reason: %s chain %s", tx.Hash().Hex(), errReason, chainInfo.ChainName) } - return blockNumber, fmt.Errorf("tx %s reverted, could not decode error reason", tx.Hash().Hex()) + return blockNumber, fmt.Errorf("tx %s reverted, could not decode error reason chain %s", tx.Hash().Hex(), chainInfo.ChainName) } return blockNumber, nil }, diff --git a/deployment/environment/memory/environment.go b/deployment/environment/memory/environment.go index e8f0c265101..1693834c572 100644 --- a/deployment/environment/memory/environment.go +++ b/deployment/environment/memory/environment.go @@ -3,6 +3,7 @@ package memory import ( "context" "fmt" + "strconv" "testing" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -66,30 +67,30 @@ func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]de chains := make(map[uint64]deployment.Chain) for cid, chain := range inputs { chain := chain - sel, err := chainsel.SelectorFromChainId(cid) + chainInfo, err := chainsel.GetChainDetailsByChainIDAndFamily(strconv.FormatUint(cid, 10), chainsel.FamilyEVM) require.NoError(t, err) backend := NewBackend(chain.Backend) - chains[sel] = deployment.Chain{ - Selector: sel, + chains[chainInfo.ChainSelector] = deployment.Chain{ + Selector: chainInfo.ChainSelector, Client: backend, DeployerKey: chain.DeployerKey, Confirm: func(tx *types.Transaction) (uint64, error) { if tx == nil { - return 0, fmt.Errorf("tx was nil, nothing to confirm") + return 0, fmt.Errorf("tx was nil, nothing to confirm, chain %s", chainInfo.ChainName) } for { backend.Commit() receipt, err := backend.TransactionReceipt(context.Background(), tx.Hash()) if err != nil { - t.Log("failed to get receipt", err) + t.Log("failed to get receipt", "chain", chainInfo.ChainName, err) continue } if receipt.Status == 0 { errReason, err := deployment.GetErrorReasonFromTx(chain.Backend.Client(), chain.DeployerKey.From, tx, receipt) if err == nil && errReason != "" { - return 0, fmt.Errorf("tx %s reverted,error reason: %s", tx.Hash().Hex(), errReason) + return 0, fmt.Errorf("tx %s reverted,error reason: %s chain %s", tx.Hash().Hex(), errReason, chainInfo.ChainName) } - return 0, fmt.Errorf("tx %s reverted, could not decode error reason", tx.Hash().Hex()) + return 0, fmt.Errorf("tx %s reverted, could not decode error reason chain %s", tx.Hash().Hex(), chainInfo.ChainName) } return receipt.BlockNumber.Uint64(), nil } diff --git a/deployment/helpers.go b/deployment/helpers.go index e8d2d8c8d59..50f4c404b09 100644 --- a/deployment/helpers.go +++ b/deployment/helpers.go @@ -138,17 +138,18 @@ func DeployContract[C any]( ) (*ContractDeploy[C], error) { contractDeploy := deploy(chain) if contractDeploy.Err != nil { - lggr.Errorw("Failed to deploy contract", "err", contractDeploy.Err) + lggr.Errorw("Failed to deploy contract", "chain", chain.String(), "err", contractDeploy.Err) return nil, contractDeploy.Err } _, err := chain.Confirm(contractDeploy.Tx) if err != nil { - lggr.Errorw("Failed to confirm deployment", "err", err) + lggr.Errorw("Failed to confirm deployment", "chain", chain.String(), "Contract", contractDeploy.Tv.String(), "err", err) return nil, err } + lggr.Infow("Deployed contract", "Contract", contractDeploy.Tv.String(), "addr", contractDeploy.Address, "chain", chain.Selector) err = addressBook.Save(chain.Selector, contractDeploy.Address.String(), contractDeploy.Tv) if err != nil { - lggr.Errorw("Failed to save contract address", "err", err) + lggr.Errorw("Failed to save contract address", "Contract", contractDeploy.Tv.String(), "addr", contractDeploy.Address, "chain", chain.String(), "err", err) return nil, err } return &contractDeploy, nil @@ -158,9 +159,25 @@ func IsValidChainSelector(cs uint64) error { if cs == 0 { return fmt.Errorf("chain selector must be set") } - _, err := chain_selectors.ChainIdFromSelector(cs) + _, err := chain_selectors.GetSelectorFamily(cs) if err != nil { - return fmt.Errorf("invalid chain selector: %d - %w", cs, err) + return err } return nil } + +func ChainInfo(cs uint64) (chain_selectors.ChainDetails, error) { + id, err := chain_selectors.GetChainIDFromSelector(cs) + if err != nil { + return chain_selectors.ChainDetails{}, err + } + family, err := chain_selectors.GetSelectorFamily(cs) + if err != nil { + return chain_selectors.ChainDetails{}, err + } + info, err := chain_selectors.GetChainDetailsByChainIDAndFamily(id, family) + if err != nil { + return chain_selectors.ChainDetails{}, err + } + return info, nil +} diff --git a/deployment/keystone/ocr3config_test.go b/deployment/keystone/ocr3config_test.go index 4046787724a..daf869d77e0 100644 --- a/deployment/keystone/ocr3config_test.go +++ b/deployment/keystone/ocr3config_test.go @@ -11,13 +11,14 @@ import ( "github.com/ethereum/go-ethereum/common" chain_selectors "github.com/smartcontractkit/chain-selectors" - "github.com/smartcontractkit/chainlink/deployment" - "github.com/smartcontractkit/chainlink/deployment/common/view" - "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" types2 "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/smartcontractkit/libocr/offchainreporting2plus/types" types3 "github.com/smartcontractkit/libocr/offchainreporting2plus/types" "github.com/test-go/testify/require" + + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/common/view" + "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" ) var wantOCR3Config = `{ @@ -83,7 +84,6 @@ func Test_configureOCR3Request_generateOCR3Config(t *testing.T) { var cfg OracleConfig err := json.Unmarshal([]byte(ocr3Cfg), &cfg) require.NoError(t, err) - r := configureOCR3Request{ cfg: &OracleConfigWithSecrets{OracleConfig: cfg, OCRSecrets: deployment.XXXGenerateTestOCRSecrets()}, nodes: nodes, diff --git a/deployment/multiclient.go b/deployment/multiclient.go index dcda07ebb0b..914c1fbd9e3 100644 --- a/deployment/multiclient.go +++ b/deployment/multiclient.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/pkg/errors" + chainselectors "github.com/smartcontractkit/chain-selectors" "github.com/smartcontractkit/chainlink-common/pkg/logger" ) @@ -46,6 +47,7 @@ type MultiClient struct { Backups []*ethclient.Client RetryConfig RetryConfig lggr logger.Logger + chainName string } func NewMultiClient(lggr logger.Logger, rpcs []RPC, opts ...func(client *MultiClient)) (*MultiClient, error) { @@ -59,6 +61,17 @@ func NewMultiClient(lggr logger.Logger, rpcs []RPC, opts ...func(client *MultiCl if err != nil { return nil, fmt.Errorf("failed to dial ws url '%s': %w", rpc.WSURL, err) } + // fetch chain name if not set + if mc.chainName == "" { + id, err := client.ChainID(context.Background()) + if err == nil { + details, err := chainselectors.GetChainDetailsByChainIDAndFamily(id.String(), chainselectors.FamilyEVM) + if err == nil { + return nil, err + } + mc.chainName = details.ChainName + } + } clients = append(clients, client) } mc.Client = clients[0] @@ -134,11 +147,12 @@ func (mc *MultiClient) WaitMined(ctx context.Context, tx *types.Transaction) (*t func (mc *MultiClient) retryWithBackups(opName string, op func(*ethclient.Client) error) error { var err error - for _, client := range append([]*ethclient.Client{mc.Client}, mc.Backups...) { + for i, client := range append([]*ethclient.Client{mc.Client}, mc.Backups...) { err2 := retry.Do(func() error { + mc.lggr.Debugf("Trying op %s with chain %s client index %d", opName, mc.chainName, i) err = op(client) if err != nil { - mc.lggr.Warnf("retryable error '%s' for op %s with client %v", err.Error(), opName, client) + mc.lggr.Warnf("retryable error '%s' for op %s with chain %s client index %d", err.Error(), opName, mc.chainName, i) return err } return nil @@ -146,7 +160,7 @@ func (mc *MultiClient) retryWithBackups(opName string, op func(*ethclient.Client if err2 == nil { return nil } - mc.lggr.Infof("Client %v failed, trying next client", client) + mc.lggr.Infof("Client at index %d failed, trying next client chain %s", i, mc.chainName) } - return errors.Wrapf(err, "All backup clients %v failed", mc.Backups) + return errors.Wrapf(err, "All backup clients %v failed for chain %s", mc.Backups, mc.chainName) }