Public IPs shared by two farms can disappear from GraphQL

Open
#228 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
graphql, typescript
Domain
api, backend, database

Research direction

Start by inspecting the PublicIp entity and the farmUpdated handler, focusing on the address-only lookup and the cleanup at the end of the update. Change the entity key and both operations to include the farm, then verify that shared addresses remain visible for each farm and plan the required resync for the new entity IDs.

Written by the indexing model from the issue text.

Description

What happens

When the same public IP is registered on more than one farm, the indexer can end up
dropping that IP completely — it disappears from GraphQL even though the chain still
has it.

Why

PublicIp is stored one row per IP address, with no farm in the key. In
farmUpdated we look the IP up by address alone:

const savedIP = await ctx.store.get(PublicIp, { where: { ip: ip.ip.toString() }, ... })

So the row belongs to whichever farm claimed the IP first. Any farm that claims it
later finds the row already taken and skips it — no row is created for that farm.
Then, when the first farm eventually gives the IP up, the cleanup step at the end of
farmUpdated deletes the row. Nobody recreates it, so the IP is gone for good even
though it is still assigned to the second farm on chain.

Example (devnet)

125.25.25.2/16 was claimed by farm 2586 (block 10132677), then farm 4291
(block 10142664), then farm 2591 (block 10449919). On chain it currently belongs to
farm 2591. In GraphQL it does not exist at all.

How much it affects us

Small, and only in this one situation — it needs the same IP on two farms, which
shouldn't normally happen.

  • devnet: 48 IPs sit on more than one farm. 7 chain IPs are missing from GraphQL.
  • mainnet: 3 IPs sit on more than one farm (all shared between farms 44 and 3630).
    1 chain IP is missing from GraphQL, and those 3 only ever show under farm 44.
Not a regression

This is long-standing behaviour, not something v2.13.0 introduced. The same code is
in v2.12.3. v2.13.0 actually improved things: before the resync devnet was missing 10
IPs, now it is missing 7, and the 32 IPs that had the wrong gateway are all correct
now. No IP is missing today that wasn't missing before.

Filing this so the remaining case isn't forgotten — it does not need to block anything.

Suggested fix

Key PublicIp by farm + IP instead of IP alone, so two farms can hold the same
address, and scope the lookup and the cleanup in farmUpdated to the farm being
updated. This changes entity IDs, so it needs a resync to take effect.

Dominant language
TypeScript
Stars
2
Forks
3
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from threefoldtech/ledger_graphql

All issues in threefoldtech/ledger_graphql

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.