Add 500km link cap, block-height-based claim expiry, and link count in score

- MAX_LINK_DISTANCE_KM (default 500): flat cap on link length. Real
  Ingress scales this off portal/resonator level (up to ~655km); Regress
  has no leveling system to scale off of, so this is a single ceiling.
- PORTAL_TIMEOUT_BLOCKS (default 2100): claims stamp the current Bitcoin
  block height (claimed_at_block, new migration) and expire back to
  neutral after this many blocks — the game's clock is block height, not
  wall-clock. Current height comes from mempool.space (BlockHeightService,
  60s cache), same trust model as the BTC Map dependency. A background
  sweep actively reverts timed-out claims (tearing down their links, same
  as a normal recapture); claim/link routes also check inline so
  correctness doesn't depend on sweep timing between runs.
- Pre-existing claims (already live in production) get backfilled with
  the real current block height once at startup rather than a guessed
  historical value — dry-run verified against an actual copy of the live
  production database before deploying.
- Score now reports link count per team alongside places/fields/area
  (backend already computed this; only the frontend display was missing).

22 new tests (53 total): pure expiry-logic unit tests plus full
claim/link/sweep integration tests using a network-free fake block-height
provider (BlockHeightProvider interface + FakeBlockHeight test double).
This commit is contained in:
2026-08-05 17:20:35 +00:00
parent 927997543d
commit 4fef930029
16 changed files with 451 additions and 23 deletions
+11
View File
@@ -21,6 +21,17 @@ const envSchema = z.object({
BTCMAP_RADIUS_KM: z.coerce.number().default(45),
// How close (in meters) a player must be to a place to claim it or link from it.
CLAIM_RADIUS_METERS: z.coerce.number().default(40),
// Maximum link length, in kilometers — mirrors Ingress's level-scaled link
// range (up to ~655km at max level) with a single flat cap instead, since
// Regress has no resonator-leveling system to scale it off of.
MAX_LINK_DISTANCE_KM: z.coerce.number().default(500),
// Claims expire after this many Bitcoin blocks and revert to neutral —
// mirrors Ingress's real-world portal decay, but block-height-based
// instead of wall-clock, since that's the native "clock" for this game.
PORTAL_TIMEOUT_BLOCKS: z.coerce.number().default(2100),
BLOCK_HEIGHT_API_URL: z.string().url().default('https://mempool.space/api/blocks/tip/height'),
// How often to sweep for and expire timed-out claims.
EXPIRY_SWEEP_INTERVAL_MS: z.coerce.number().default(5 * 60 * 1000),
});
export type Config = z.infer<typeof envSchema>;