From f24af7895275f9edb5068c130cd42e8de05ef039 Mon Sep 17 00:00:00 2001 From: Amir Y <83904651+amirylm@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:45:43 +0300 Subject: [PATCH] Log chain ids in addition to chain selectors (#1063) ## Motivation ## Solution --- .changeset/early-readers-work.md | 6 ++++++ .../plugins/liquiditymanager/discoverer/evm.go | 15 ++++++++------- .../ocr2/plugins/liquiditymanager/graph/graph.go | 15 ++++++++++++++- .../plugins/liquiditymanager/models/models.go | 5 +++++ .../ocr2/plugins/liquiditymanager/plugin.go | 13 +++++++------ .../plugins/liquiditymanager/plugin_validate.go | 4 ++-- 6 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 .changeset/early-readers-work.md diff --git a/.changeset/early-readers-work.md b/.changeset/early-readers-work.md new file mode 100644 index 0000000000..6da59d5883 --- /dev/null +++ b/.changeset/early-readers-work.md @@ -0,0 +1,6 @@ +--- +"ccip": patch +--- + +New function on NetworkSelector to get ChainID #added +Align logs and include chainID #changed diff --git a/core/services/ocr2/plugins/liquiditymanager/discoverer/evm.go b/core/services/ocr2/plugins/liquiditymanager/discoverer/evm.go index 8b2a48bb9e..4cc3377705 100644 --- a/core/services/ocr2/plugins/liquiditymanager/discoverer/evm.go +++ b/core/services/ocr2/plugins/liquiditymanager/discoverer/evm.go @@ -47,11 +47,12 @@ func (e *evmDiscoverer) Discover(ctx context.Context) (graph.Graph, error) { NetworkSelector: e.masterSelector, LiquidityManager: e.masterLiquidityManager, }, func(ctx context.Context, v graph.Vertex) (graph.Data, []graph.Vertex, error) { + lggr := e.lggr.With("selector", v.NetworkSelector, "chainID", v.NetworkSelector.ChainID(), "addr", v.LiquidityManager) d, n, err := e.getVertexData(ctx, v) if err != nil { - e.lggr.Warnw("failed to get vertex data", "selector", v.NetworkSelector, "addr", v.LiquidityManager, "error", err) + lggr.Warnw("failed to get vertex data", "error", err) } else { - e.lggr.Debugw("Got vertex data", "selector", v.NetworkSelector, "addr", v.LiquidityManager, "data", d) + lggr.Debugw("Got vertex data", "data", d) } return d, n, err }) @@ -165,13 +166,13 @@ func (e *evmDiscoverer) getVertexData(ctx context.Context, v graph.Vertex) (grap func (e *evmDiscoverer) updateLiquidity(ctx context.Context, selector models.NetworkSelector, g graph.Graph, liquidityGetter evmLiquidityGetter) error { lmAddress, err := g.GetLiquidityManagerAddress(selector) if err != nil { - return fmt.Errorf("get rebalancer address: %w", err) + return fmt.Errorf("get rebalancer address(%d, %s): %w", selector, lmAddress, err) } liquidity, err := liquidityGetter(ctx, selector, common.Address(lmAddress)) if err != nil { - return fmt.Errorf("get liquidity: %w", err) + return fmt.Errorf("get liquidity (%d, %s): %w", selector, lmAddress, err) } - e.lggr.Debugw("Updating liquidity", "liquidity", liquidity, "selector", selector, "lmAddress", lmAddress) + e.lggr.Debugw("Updating liquidity", "liquidity", liquidity, "selector", selector, "chainID", selector.ChainID(), "lmAddress", lmAddress) _ = g.SetLiquidity(selector, liquidity) // TODO: handle non-existing network return nil } @@ -190,11 +191,11 @@ func (e *evmDiscoverer) getDep(selector models.NetworkSelector) (*evmDep, bool) func (e *evmDiscoverer) defaultLiquidityGetter(ctx context.Context, selector models.NetworkSelector, lmAddress common.Address) (*big.Int, error) { dep, ok := e.getDep(selector) if !ok { - return nil, fmt.Errorf("no client for master chain %+v", selector) + return nil, fmt.Errorf("no client for master chain %d", selector) } rebal, err := liquiditymanager.NewLiquidityManager(lmAddress, dep.ethClient) if err != nil { - return nil, fmt.Errorf("new liquiditymanager: %w", err) + return nil, fmt.Errorf("new liquiditymanager (%d, %s): %w", selector, lmAddress, err) } return rebal.GetLiquidity(&bind.CallOpts{ Context: ctx, diff --git a/core/services/ocr2/plugins/liquiditymanager/graph/graph.go b/core/services/ocr2/plugins/liquiditymanager/graph/graph.go index 6d15afa566..625c8ac81e 100644 --- a/core/services/ocr2/plugins/liquiditymanager/graph/graph.go +++ b/core/services/ocr2/plugins/liquiditymanager/graph/graph.go @@ -136,7 +136,20 @@ func (g *liquidityGraph) String() string { g.lock.RLock() defer g.lock.RUnlock() - return fmt.Sprintf("Graph{networksGraph: %+v, networkBalance: %+v}", g.adj, g.data) + type network struct { + Selector models.NetworkSelector + ChainID uint64 + } + adj := make([]network, 0, len(g.adj)) + for n := range g.adj { + adj = append(adj, network{Selector: n, ChainID: n.ChainID()}) + } + data := make(map[network]Data, len(g.data)) + for n, d := range g.data { + data[network{Selector: n, ChainID: n.ChainID()}] = d + } + + return fmt.Sprintf("Graph{graph: %+v, data: %+v}", adj, data) } func (g *liquidityGraph) Reset() { diff --git a/core/services/ocr2/plugins/liquiditymanager/models/models.go b/core/services/ocr2/plugins/liquiditymanager/models/models.go index 4c116de964..e9880590fe 100644 --- a/core/services/ocr2/plugins/liquiditymanager/models/models.go +++ b/core/services/ocr2/plugins/liquiditymanager/models/models.go @@ -52,6 +52,11 @@ func (n NetworkSelector) Type() NetworkType { return NetworkTypeUnknown } +func (n NetworkSelector) ChainID() uint64 { + chainID, _ := chainsel.ChainIdFromSelector(uint64(n)) + return chainID +} + type NetworkType string // ProposedTransfer is a transfer that is proposed by the rebalancing algorithm. diff --git a/core/services/ocr2/plugins/liquiditymanager/plugin.go b/core/services/ocr2/plugins/liquiditymanager/plugin.go index 9b89bc7c7e..23a6f21136 100644 --- a/core/services/ocr2/plugins/liquiditymanager/plugin.go +++ b/core/services/ocr2/plugins/liquiditymanager/plugin.go @@ -439,7 +439,8 @@ func (p *Plugin) Close() error { var errs []error for _, networkID := range p.liquidityGraph.GetNetworks() { - p.lggr.Infow("closing liquidityManager network", "network", networkID) + lggr := p.lggr.With("network", networkID, "chainID", networkID.ChainID()) + lggr.Infow("closing liquidityManager network") liquidityManagerAddress, err := p.liquidityGraph.GetLiquidityManagerAddress(networkID) if err != nil { @@ -458,7 +459,7 @@ func (p *Plugin) Close() error { continue } - p.lggr.Infow("finished closing liquidityManager network", "network", networkID, "liquidityManager", liquidityManagerAddress.String()) + lggr.Infow("finished closing liquidityManager network", "liquidityManager", liquidityManagerAddress.String()) } return multierr.Combine(errs...) @@ -497,7 +498,7 @@ func (p *Plugin) syncGraph(ctx context.Context) error { } func (p *Plugin) loadPendingTransfers(ctx context.Context, lggr logger.Logger) ([]models.PendingTransfer, error) { - p.lggr.Infow("loading pending transfers") + lggr.Infow("loading pending transfers") pendingTransfers := make([]models.PendingTransfer, 0) edges, err := p.liquidityGraph.GetEdges() @@ -505,13 +506,14 @@ func (p *Plugin) loadPendingTransfers(ctx context.Context, lggr logger.Logger) ( return nil, fmt.Errorf("get edges: %w", err) } for _, edge := range edges { + logger := lggr.With("sourceNetwork", edge.Source, "sourceChainID", edge.Source.ChainID(), "destNetwork", edge.Dest, "destChainID", edge.Dest.ChainID()) bridge, err := p.bridgeFactory.NewBridge(edge.Source, edge.Dest) if err != nil { return nil, fmt.Errorf("init bridge: %w", err) } if bridge == nil { - lggr.Warnw("no bridge found for network pair", "sourceNetwork", edge.Source, "destNetwork", edge.Dest) + logger.Warn("no bridge found for network pair") continue } @@ -529,11 +531,10 @@ func (p *Plugin) loadPendingTransfers(ctx context.Context, lggr logger.Logger) ( return nil, fmt.Errorf("get pending transfers: %w", err) } - lggr.Infow("loaded pending transfers for network", "network", edge.Source, "pendingTransfers", netPendingTransfers) + logger.Infow("loaded pending transfers for network", "pendingTransfers", netPendingTransfers) pendingTransfers = append(pendingTransfers, netPendingTransfers...) } - // todo: why do we add this here? it's not used anywhere return pendingTransfers, nil } diff --git a/core/services/ocr2/plugins/liquiditymanager/plugin_validate.go b/core/services/ocr2/plugins/liquiditymanager/plugin_validate.go index 1774772066..491b885065 100644 --- a/core/services/ocr2/plugins/liquiditymanager/plugin_validate.go +++ b/core/services/ocr2/plugins/liquiditymanager/plugin_validate.go @@ -93,11 +93,11 @@ func validateItems[T any](keyFn func(T) string, items []T, validateFns ...func(T for _, item := range items { k := keyFn(item) if existing[k] { - return fmt.Errorf("duplicated item") + return fmt.Errorf("duplicated item (%s)", k) } for _, validateFn := range validateFns { if err := validateFn(item); err != nil { - return fmt.Errorf("invalid item: %w", err) + return fmt.Errorf("invalid item (%s): %w", k, err) } } existing[k] = true