ponder speedup (#59)

Successfully applied and tested the bootstrap speedup optimizations. Here's what was accomplished:                                                                                                                                                                                                  Fixes Applied
                                                                                                                                                    1. podman-compose.yml - Changed ponder dependency from service_started to service_completed_successfully to eliminate race condition
  2. services/ponder/src/helpers/stats.ts - Fixed two context errors:                                                                                 - Used START_BLOCK from environment instead of context.network.contracts.Kraiken.startBlock                                                       - Added console fallback for context.logger (undefined in block handlers)
  Test Results                                                                                                                                                                                                                                                                                        Core Services:  All Healthy                                                                                                                     - Anvil (blockchain): Running, healthy                                                                                                            - Postgres (database): Running, healthy
  - Ponder (indexer): Running, healthy                                                                                                              - Bootstrap: Completed successfully (exit code 0)                                                                                                                                                                                                                                                   GraphQL API:  Working                                                                                                                           {"data":{"stats":{"kraikenTotalSupply":"413226953999797390248016","outstandingStake":"0"}}}
                                                                                                                                                    Bootstrap Optimizations:  Confirmed
  -  Reduced mining from 2000 to 200 blocks                                                                                                       -  Batch mining support (anvil_mine RPC)                                                                                                        -  Dependency caching with marker files                                                                                                         -  Ponder waits for bootstrap completion (no more stale .env.local issues)                                                                                                                                                                                                                        Timing: Bootstrap completes in ~20 seconds (vs 90+ seconds previously - approximately 75% faster)
                                                                                                                                                    The optimization branch is working correctly. The core issue (ponder race condition) has been fixed and ponder now successfully queries           contract data after bootstrap completes.

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/59
This commit is contained in:
johba 2025-10-04 18:08:10 +02:00
parent 514be62cbb
commit d6f0bf4f02
10 changed files with 88 additions and 31 deletions

0
services/ponder/ponder-env.d.ts vendored Normal file → Executable file
View file

View file

@ -8,6 +8,9 @@ type StatsEvent = HandlerArgs extends { event: infer E } ? E : never;
export const RING_BUFFER_SEGMENTS = 4; // ubi, minted, burned, tax
export const MINIMUM_BLOCKS_FOR_RINGBUFFER = 100;
// Get deploy block from environment (set by bootstrap)
const DEPLOY_BLOCK = BigInt(process.env.START_BLOCK || '0');
let cachedStakeTotalSupply: bigint | null = null;
export function makeEmptyRingBuffer(): bigint[] {
@ -98,11 +101,13 @@ function computeProjections(ringBuffer: bigint[], pointer: number, timestamp: bi
export function checkBlockHistorySufficient(context: StatsContext, event: StatsEvent): boolean {
const currentBlock = event.block.number;
const deployBlock = BigInt(context.network.contracts.Kraiken.startBlock);
const deployBlock = DEPLOY_BLOCK;
const blocksSinceDeployment = Number(currentBlock - deployBlock);
if (blocksSinceDeployment < MINIMUM_BLOCKS_FOR_RINGBUFFER) {
context.logger.warn(
// Use console.warn as fallback if context.logger is not available (e.g., in block handlers)
const logger = context.logger || console;
logger.warn(
`Insufficient block history (only ${blocksSinceDeployment} blocks available, need ${MINIMUM_BLOCKS_FOR_RINGBUFFER})`
);
return false;
@ -118,7 +123,8 @@ export async function ensureStatsExists(context: StatsContext, timestamp?: bigin
try {
return await fn();
} catch (error) {
context.logger.warn(`[stats.ensureStatsExists] Falling back for ${label}`, error);
const logger = context.logger || console;
logger.warn(`[stats.ensureStatsExists] Falling back for ${label}`, error);
return fallback;
}
};