Skip to content

Fix Unknown network for Simplex, LibertyX and Changelly - #244

Merged
j0ntz merged 7 commits into
deployfrom
jon/reports-unknown-network
Nov 10, 2026
Merged

j0ntz merged 7 commits into
deployfrom
jon/reports-unknown-network

Conversation

@j0ntz

@j0ntz j0ntz commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

Asana: task 1220274889691904

Simplex, LibertyX and Changelly volume showed as "Unknown network" in the v2 dashboard because their stored orders had no payout chain id. The processors now set it, and stored chain ids survive a degraded read. A backfill script fills the ids on orders already in Couch.

Changes

  • Overwrite guard (all partners). planTxUpdate in src/util/updateTx.ts carries a stored chain field over when a fresh read leaves it undefined (catalog outage, unmapped code). A defined value, including a null native tokenId, still replaces it. The carry-over is per leg: a read that names a different chain for a leg takes that leg as read, which keeps an old token id off a new chain. queryEngine uses it, so that a degraded run can no longer move volume back to "Unknown network".
  • Changelly. Blockchain codes match in any case, hyperevm is mapped, and the currency catalog fetch retries once before giving up.
  • LibertyX. Payouts are recorded on bitcoin with a null tokenId.
  • Simplex. src/partners/simplexCodes.ts holds a copy of the app's SIMPLEX_ID_MAP (edge-react-gui src/plugins/gui/providers/simplexProvider.ts, source named in the file comment; no runtime link to the GUI repo). Reversed, it maps each crypto_currency code to payout chainPluginId, evmChainId and tokenId. BNB resolves to binancesmartchain. Tokens with no Edge builtin get the chain and leave tokenId unknown. Codes missing from the table (delisted assets) log the usual unmapped warning.

Backfill script

npm run backfillChainIds -- [<appId>_<partnerId>] [--apply]
  • Dry run by default. Nothing is written unless --apply is passed.
  • Scope. Every <appId>_<partnerId> partition whose plugin is simplex, libertyx or changelly (or the one partition named). It selects docs missing depositChainPluginId or payoutChainPluginId and reprocesses each doc's rawTx with the current processor.
  • Fill rule. Only the chain fields a doc is missing are filled. A leg whose stored chain differs from the reprocessed one is left alone, and docs with nothing to fill are never written. A second run reports 0 changes.
  • Output per partition. Docs scanned, docs that would change (or changed) with their complete, priced USD volume, write errors, and the payout codes still unmapped with counts.
  • Changelly. Partitions load the live catalog with that partition's API keys and are skipped with a warning when the keys are absent or the catalog comes back empty.
  • Fiat deposits. Simplex and LibertyX deposits are fiat: depositChainPluginId stays absent and those docs match the selector on every run. Nothing is written for them; they only add scan time.

Cache rebuild after --apply

The v2 dashboard reads the reports_hour/day/month cache. The script prints the oldest changed doc's date and how many months back it is:

  • Within cacheLookbackMonths (default 24): the cache engine's next pass picks the change up.
  • Older: set "cacheLookbackMonths": <N> in config.json for one start.cache pass and restore it, or delete the <partition>:00000000_initialized doc from reports_month for each changed partition. The next pass then recomputes that partition from the start.

Testing

  • npm test has no failures. New tests cover the guard, Changelly case matching and retry, LibertyX, the Simplex reverse map, and missingChainFields.
  • tsc clean.
  • Script run against a local dev CouchDB (not prod) with seeded partitions. Dry run: backfilltest_simplex: scanned 5, would change 2 ($350), with one delisted code (XYZOLD 1) reported unmapped; backfilltest_libertyx: scanned 1, would change 1 ($1,251); the Changelly partition skipped for missing keys; the oldest doc (68 months back) printed both rebuild options. --apply wrote 3 docs (USDT-TRC20 to tron with tokenId, USDT-TON to ton, LibertyX to bitcoin with a null tokenId) and left a wrong-chain doc and a complete doc untouched. A re-run found 0 changes.

The production dry run, --apply, cache rebuild and deploy are Jon's steps.

Test evidence

e7a283c
Add a chain id backfill script
2026-11-10

1. before unknown network

2. after backfill networks

4. c2 backfill exits after summary
C2 retest: Changelly retry and skip, summary, exit 0 in 1-2 s, no leftover node process, Changelly docs unchanged

Note

Medium Risk
Changes global transaction update merging in the query engine and adds a CouchDB write script; mis-use of --apply could alter stored orders, though guards limit overwrites to missing chain fields only.

Overview
Simplex, LibertyX, and Changelly orders previously lacked payout chain metadata, so v2 dashboard volume landed under "Unknown network". This PR teaches those processors to set payoutChainPluginId / EVM / token fields, prevents degraded partner reads from wiping chains already in Couch, and adds a npm run backfillChainIds path to repair historical docs.

Ingestion guard (all partners). New planTxUpdate / keepKnownChainFields in src/util/updateTx.ts preserves stored chain fields when a fresh read leaves them undefined; queryEngine now uses this instead of blind overwrites.

Partner fixes. Simplex resolves crypto_currency via new simplexCodes.ts (GUI map copy). LibertyX always records native bitcoin payout. Changelly normalizes blockchain case, maps hyperevm, and retries the currency catalog once on failure.

Backfill. backfillChainIds reprocesses rawTx for affected partitions, fills only missing chain fields via missingChainFields, dry-runs by default, and prints cache rebuild guidance after --apply.

Reviewed by Cursor Bugbot for commit e7a283c. Bugbot is set up for automated code reviews on this repo. Configure here.

Pure extraction so the update decision can be unit tested without
loading the query engine, which binds its Couch connection on import.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a15866e. Configure here.

Comment thread src/util/updateTx.ts Resolved
j0ntz added 2 commits November 9, 2026 22:53
A partner read that cannot resolve a chain (a catalog outage, an
unmapped code) returns undefined chain fields. checkUpdateTx counted
defined -> undefined as a change and the update wrote the fresh tx, so
orders in the lookback window lost their stored chains and moved to
"Unknown network". planTxUpdate now carries over any chain field the
fresh read leaves undefined before deciding whether the order changed.
A defined value, including a null tokenId, still replaces the stored
one. This sits on the shared update path, so it covers every partner.
The Changelly catalog sends some blockchain codes in upper case ("BASE"),
so the case-sensitive lookup left those orders without a chain. Lowercase
the code before the lookup and map hyperevm, which Edge supports.
@j0ntz
j0ntz force-pushed the jon/reports-unknown-network branch from a15866e to c07ef0f Compare November 10, 2026 06:54
j0ntz added 4 commits November 9, 2026 23:44
A single failed getCurrenciesFull call stored a whole run of orders
without chain ids. Retry once, treating an empty catalog as a failure,
before degrading to the empty map.
LibertyX only sells bitcoin, but its orders carried no payout chain, so
dashboard v2 counted them under "Unknown network".
Simplex orders carried no payout chain, so dashboard v2 counted all of
them under "Unknown network". Simplex crypto_currency codes are unique
per chain, so a reversed copy of the app's SIMPLEX_ID_MAP resolves each
one to a chain pluginId, EVM chain id and Edge tokenId. BNB resolves to
BNB Smart Chain. Codes missing from the table (delisted assets) log a
warning and keep the order without a payout chain.
Stored Simplex, LibertyX and Changelly orders written before the
processor fixes have no chain ids, so the v2 dashboard keeps their
volume under "Unknown network". backfillChainIds reprocesses each
doc's rawTx with the current partner processor and fills only the
chain fields the doc is missing (missingChainFields). A leg whose
stored chain differs from the reprocessed one is left alone, and docs
with nothing to fill are never written.

Dry run is the default and prints, per partition, the docs scanned,
the docs that would change with their dashboard USD, the currencies
still without a payout chain, and how to rebuild the cache back to the
oldest changed order. --apply writes the changed docs.
@j0ntz
j0ntz force-pushed the jon/reports-unknown-network branch from c07ef0f to e7a283c Compare November 10, 2026 07:45
@j0ntz
j0ntz merged commit e7a283c into deploy Nov 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant