Skip to content

fix: stop Satoshi historical scan log OOM - #604

Merged
macterra merged 2 commits into
mainfrom
fix/satoshi-raw-scan-segv
Jun 4, 2026
Merged

fix: stop Satoshi historical scan log OOM#604
macterra merged 2 commits into
mainfrom
fix/satoshi-raw-scan-segv

Conversation

@macterra

@macterra macterra commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the remaining BTC mainnet historical catch-up OOM after PR #595 by removing per-transaction stdout logging from the scan hot path and avoiding repeated primary RPC failures for blocks known to be below the primary node's prune height.

Root Cause

The raw-block parser itself stays small, but the mediator still logged every transaction while scanning historical blocks. During catch-up, stdout could not flush Docker log lines as quickly as the mediator produced them, so V8 retained a huge backlog of log strings until the process hit the heap limit and exited with code 139.

The JSON DB showed the scan had advanced beyond the last flushed tx log line, confirming the process was still scanning while stdout buffering lagged behind.

Changes

  • Remove per-transaction console.log(height, index, txid) from fetchBlock().
  • Keep block-level progress logs.
  • Record the primary node prune height learned at startup.
  • When a fallback RPC is configured and the requested raw block is at or below the primary prune height, fetch raw block hex directly from fallback instead of failing primary first.

Validation

  • npm run build in services/mediators/satoshi
  • npx eslint services/mediators/satoshi/src/satoshi-mediator.ts services/mediators/satoshi/src/config.ts
  • git diff --check
  • Rebuilt and restarted btc-mainnet-mediator locally.
  • Live catch-up continued past the previous crash area:
    • DB height advanced from 940211 to 941163+
    • container remained running with OOMKilled=false
    • memory stayed in the normal hundreds of MiB instead of climbing toward the ~2 GB V8 heap limit
    • logs are now block-level progress only, without per-tx spam

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses BTC mainnet historical catch-up OOMs in the Satoshi mediator by removing per-transaction logging from the block scan hot path and improving pruned-node behavior by short-circuiting to a configured fallback RPC for blocks known to be pruned on the primary node.

Changes:

  • Remove per-transaction console.log(height, index, txid) during historical scans to prevent stdout buffering from causing V8 heap growth.
  • Capture the primary node prune height at startup.
  • When a fallback RPC is configured and a block is at/below the primary prune height, fetch the raw block hex directly from fallback (avoiding repeated expected primary failures).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/mediators/satoshi/src/satoshi-mediator.ts
Comment thread services/mediators/satoshi/src/satoshi-mediator.ts Outdated
@macterra
macterra merged commit 0bd713b into main Jun 4, 2026
28 checks passed
@macterra
macterra deleted the fix/satoshi-raw-scan-segv branch June 4, 2026 13:29
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