Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log chain ids in addition to chain selectors #1063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/early-readers-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ccip": patch
---

New function on NetworkSelector to get ChainID #added
Align logs and include chainID #changed
15 changes: 8 additions & 7 deletions core/services/ocr2/plugins/liquiditymanager/discoverer/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion core/services/ocr2/plugins/liquiditymanager/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions core/services/ocr2/plugins/liquiditymanager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
Expand Down Expand Up @@ -497,21 +498,22 @@ 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()
if err != nil {
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
}

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading