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:
+8
-1
@@ -6,6 +6,7 @@ import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import type { Config } from './config.js';
|
||||
import { openDatabase, type DB } from './db/database.js';
|
||||
import { BlockHeightService, type BlockHeightProvider } from './services/blockHeight.js';
|
||||
import nostrAuth from './plugins/nostr-auth.js';
|
||||
import authRoutes from './routes/auth.js';
|
||||
import placesRoutes from './routes/places.js';
|
||||
@@ -17,6 +18,7 @@ import syncRoutes from './routes/sync.js';
|
||||
export interface AppContext {
|
||||
config: Config;
|
||||
db: DB;
|
||||
blockHeight: BlockHeightProvider;
|
||||
}
|
||||
|
||||
declare module 'fastify' {
|
||||
@@ -29,6 +31,7 @@ export interface BuildAppOptions {
|
||||
config: Config;
|
||||
dbPath?: string; // override for tests (':memory:')
|
||||
logger?: boolean;
|
||||
blockHeight?: BlockHeightProvider; // override for tests — avoids real network calls
|
||||
}
|
||||
|
||||
export async function buildApp(opts: BuildAppOptions): Promise<FastifyInstance> {
|
||||
@@ -37,7 +40,11 @@ export async function buildApp(opts: BuildAppOptions): Promise<FastifyInstance>
|
||||
|
||||
const app = Fastify({ logger: opts.logger ?? true, bodyLimit: 1 * 1024 * 1024 });
|
||||
|
||||
const ctx: AppContext = { config, db };
|
||||
const ctx: AppContext = {
|
||||
config,
|
||||
db,
|
||||
blockHeight: opts.blockHeight ?? new BlockHeightService(config.BLOCK_HEIGHT_API_URL),
|
||||
};
|
||||
app.decorate('ctx', ctx);
|
||||
|
||||
await app.register(cookie);
|
||||
|
||||
Reference in New Issue
Block a user