Skip to content

A network scanner: CLI and web page (examples/scanner) - #1

Merged
nenkoru merged 3 commits into
nenkoru:mainfrom
4FR4KO-POVELECKO:scanner
Nov 3, 2026
Merged

nenkoru merged 3 commits into
nenkoru:mainfrom
4FR4KO-POVELECKO:scanner

Conversation

@4FR4KO-POVELECKO

Copy link
Copy Markdown
Collaborator

What and why

A read-only scanner for a tern network. A block explorer shows transactions; this shows tern: names and their agents (with daily limits), cards, payments, deals and how they ended, swaps (with a price when one side is money), claims, and mail volume per day. It needs no key and sends nothing.

  • internal/scan: reads the public events of Registry, Bank, SwapCondition, EAS and Inbox, using the ABIs the binary already embeds and net.json. The scan is cached and resumes from the last block. Requests that fail are retried; an RPC that keeps failing is replaced by the next one in rpcs.
  • examples/scanner: the command (names, name NAME, deals, payments, swaps, claims, mail, --json) and serve, one embedded page with no outside resources. Chain data is inserted as text only, under a strict Content-Security-Policy, and the server listens on 127.0.0.1 by default.

No contract changes.

How it was tested

  • go vet ./...
  • go test ./... -timeout 30m (TestScanNetwork on a simulated chain; TestServePage; TestRetry)
  • If a contract changed: n/a
  • Docs updated (examples/scanner/README.md; docs_test.go passes)
  • No keys, identities, operator files or binaries in the diff
  • Commits signed off (git commit -s)

It also ran over all of tern-base-sepolia-1 (about 1.8M blocks, around a minute), including a run where the first RPC was down and it fell back to the next one.

4FR4KO-POVELECKO and others added 3 commits November 3, 2026 01:21
Reads a tern network's public events into one summary: names and agents,
their limits and cards, payments, locks and how they ended, swaps, claims
and the volume of mail. Read-only: no key, no transactions. The scan is
cached and resumes from the last block. TestScanNetwork checks it on a
simulated chain; it also ran over the whole of tern-base-sepolia-1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: 4FR4KO-POVELECKO <15423085+4FR4KO-POVELECKO@users.noreply.github.com>
One page embedded in the binary, nothing loaded from elsewhere: an
overview (counts, recent activity, mail per day), names, deals,
payments, swaps, claims and mail, each filterable, and a page per name.
The server reads new blocks every --every; if the chain can't be read
it keeps serving the cache and the page says why. Chain data goes in
as text only, under a Content-Security-Policy that loads nothing else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: 4FR4KO-POVELECKO <15423085+4FR4KO-POVELECKO@users.noreply.github.com>
A public RPC drops a request now and then (a TLS handshake timeout ended
a first run). Each call is now tried again up to 4 times with a growing
wait; a refused range still comes back at once to be halved. An RPC that
keeps failing is replaced by the next one in net.json (rpcs), going on
from the last block saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: 4FR4KO-POVELECKO <15423085+4FR4KO-POVELECKO@users.noreply.github.com>
nenkoru added a commit that referenced this pull request Nov 3, 2026
Follow-ups to 4FR4KO-POVELECKO's network scanner (PR #1: internal/scan,
examples/scanner), from its review.

- RPC keys stay private. Errors name an RPC by scheme://host only
  (scan.Redact, scan.Origin): a provider's key in the URL's path, query
  or user no longer reaches stderr, state.json or the page.
- serve answers only requests for a loopback name or the --listen host
  (an IP too when listening on every interface), against DNS rebinding.
  Read, write and idle timeouts, a header size limit, and no img-src in
  the CSP.
- Rate limits are not range limits. 429, "rate limit", "compute units",
  "quota" and the like are waited out (longer, more times) and never
  narrow the log window; scan.Dial's transport honours Retry-After, as
  the client's retryRPC does. A refused range narrows to the limit the
  RPC names, else half. "execution reverted" is not asked again. The
  patterns are copied from cmd/ternchain/hostchain.go (internal/ can't
  import a command).
- Bank.PayeeSet is read: a lock opened with no payee (a bounty, a swap's
  answer) shows who it went to instead of "(open)" forever.
- View calls are checked. Bank.locks must match the Locked event (total,
  condition), getAttestation must return the uid asked for, and an itemOf
  error is an error: an RPC that hasn't caught up with the logs stops the
  scan before that range, which is read again next time, rather than a
  claim lost or a lock in the wrong token kept for good.
- --confirmations defaults to 64 (the client's reorg margin).
- Chain text (cards, claim kinds and data, token symbols) is printed
  without control characters or bidi overrides (scan.Printable).
- The cache is saved through its own temp file (os.CreateTemp), and the
  network's name in the cache's file name must be a plain one. Cache
  version 2, so old caches are read again with PayeeSet.
- state.json leaves out the ids and addrs tables. The page looks names up
  with Object.hasOwn ("constructor" is a valid name) and survives a
  malformed #hash.
- README: the above; the scanner is in the root README's table and in the
  documents docs_test checks.

Tests: TestRetry, TestRetryAfter, TestRedact, TestPrintable,
TestUpdateRereadsLaggingViews (a lagging RPC, then PayeeSet),
TestUpdateRateLimitKeepsRange, TestSave, TestServeHostCheck,
TestUpdateErrorRedacted, TestTerminalText; TestScanNetwork adds a bounty
whose payee comes from PayeeSet.

Left for later, from the same review:
- A claim made with a rotated-out controller key, or a revoked agent's
  key, still shows under the name (Addrs keeps old keys).
- An agent's expiry (AgentGranted.expires) isn't tracked, and a re-grant
  with spendPerEpoch 0 keeps the old coin limit.
- internal/scan duplicates the client's log reading (logcache.go's
  shared per-machine cache, hostchain.go's range and rate handling,
  lockKind): move the reader into internal/ and share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: nenkoru <nenkoru@users.noreply.github.com>
@nenkoru
nenkoru merged commit 8aeba19 into nenkoru:main Nov 3, 2026
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.

2 participants