Skip to main content

System Models

Bitcoin Crawler includes built-in system models that provide essential blockchain monitoring functionality out of the box. Use them without writing any model code - just subscribe to their events and query their state.


What are System Models?​

System models are pre-built models that handle common blockchain monitoring tasks:

  1. Network Chain Validation Model: Validates blockchain integrity and manages chain state
  2. Mempool Model: Monitors unconfirmed transactions (when enabled)

These models:

  • Work automatically when you start Bitcoin Crawler
  • Generate events you can subscribe to
  • Maintain state you can query
  • Follow same patterns as custom models

System Models Architecture​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ System Models in Framework β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Blockchain Node
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Network Provider β”‚ Fetches blocks and mempool
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Network β”‚ β”‚ Mempool β”‚ β”‚ Your Custom β”‚
β”‚ Model β”‚ β”‚ Model β”‚ β”‚ Models β”‚
β”‚ (built-in) β”‚ β”‚ (built-in) β”‚ β”‚ (your code) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Event Store β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Transport β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Network Chain Validation Model​

Validates blockchain chain integrity and maintains a validated block chain window in memory.

Purpose​

The Network Model:

  • Verifies each block connects to previous block
  • Validates Merkle tree roots (Bitcoin-specific)
  • Detects blockchain reorganizations
  • Maintains sliding window of recent blocks
  • Provides validated block data for queries

What It Tracks​

Chain state:

  • Current number of blocks in memory
  • Latest block height
  • First block height in window
  • Chain validity status

Block data:

  • Recent blocks with full data
  • Block hashes and headers
  • Transaction data

Validation status:

  • Whether chain is valid
  • Whether Merkle trees verified
  • Reorganization history

Events Generated​

Block Added:

  • New block validated and added to chain
  • Contains block height, hash, transactions
  • Emitted after passing all validations

Block Removed:

  • Block removed during reorganization
  • Contains removed block height and hash
  • Part of reorg process

Reorganization Detected:

  • Blockchain fork detected and handled
  • Contains fork point and affected blocks
  • Informational (state already corrected)

Chain Initialized:

  • Network model started
  • Contains initial configuration

Chain Validation Process​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Network Validation Flow β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

New Block Arrives
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Verify block β”‚ Check hash connects to previous
β”‚ links to chain β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Validate Merkle β”‚ Verify Merkle root (if enabled)
β”‚ tree β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Add to chain β”‚ Store in validated chain window
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Emit BlockAdded β”‚ Notify subscribers
β”‚ event β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Reorganization Handling​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Reorganization Detection & Handling β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Detect fork:
Current chain: ... β†’ Block 100 β†’ Block 101 β†’ Block 102
Node's chain: ... β†’ Block 100 β†’ Block 101 β†’ Block 102'
β”‚
β–Ό
Identify fork point: Block 101 (last common)
β”‚
β–Ό
Roll back:
- Emit BlockRemoved for Block 102
- Remove from chain window
β”‚
β–Ό
Replay:
- Fetch Block 102' from node
- Validate new block
- Emit BlockAdded for Block 102'
β”‚
β–Ό
Emit ReorganizationDetected event
- Contains fork point
- Lists affected blocks
β”‚
β–Ό
Chain now matches node's chain

Important: Your model states automatically update during reorg. The reorganization event is informational - for logging or custom business logic only.

Merkle Tree Validation​

For Bitcoin and Bitcoin-like chains:

What it validates:

  • Merkle root in block header matches calculated root
  • Transaction hashes form valid Merkle tree
  • Ensures block data integrity

Why it matters:

  • Detects corrupted block data
  • Ensures data from node is valid
  • Additional verification layer

Configuration:

  • Enabled by default
  • Can be disabled for performance
  • Recommended to keep enabled for production

Performance: Minimal impact on modern servers

Querying Network Model​

Through Transport APIs:

Get network statistics:

  • Current chain size
  • Block height range
  • Validity status
  • Chain window info

Get specific block:

  • Query by height
  • Returns block if in chain window
  • Includes full transaction data

Get multiple blocks:

  • Last N blocks
  • All blocks in window
  • Range queries

Get last block:

  • Most recent validated block
  • Latest height and data

All queries work through HTTP, WebSocket, IPC, or other configured transports.

Using Network Events​

Subscribe to network events in your applications:

Monitor new blocks:

  • React when blocks are added
  • Update UI or trigger processing
  • Log block information

Handle reorganizations:

  • Get notified of reorgs
  • Implement custom logging
  • Alert on unusual activity
  • Note: your state already correct

Track chain status:

  • Monitor chain validity
  • Alert if validation fails
  • Track chain growth

Use in custom models:

  • Your models can subscribe to network events
  • Build logic on top of validated blocks
  • Leverage chain validation

Mempool Model​

Monitors unconfirmed transactions in mempool. Disabled by default - must be enabled in configuration.

Purpose​

The Mempool Model:

  • Tracks pending transactions before confirmation
  • Monitors transaction additions and removals
  • Handles multiple mempool sources
  • Provides real-time mempool state
  • Generates events for mempool changes

What It Tracks​

Mempool state:

  • Total transaction IDs tracked
  • Number of fully loaded transactions
  • Synchronization status
  • Performance metrics

Transaction data:

  • Transaction IDs in mempool
  • Full transaction details (when loaded)
  • Fee rates and sizes
  • Input/output data

Load status:

  • Which transactions are fully loaded
  • Which are ID-only (below fee threshold)
  • Load timestamps

Events Generated​

Transaction Added:

  • New transaction appeared in mempool
  • Contains transaction ID
  • Initial detection event

Transaction Loaded:

  • Transaction details fully fetched
  • Contains complete transaction data
  • Follows Added event

Transaction Removed:

  • Transaction left mempool
  • Reason: confirmed in block or dropped
  • Contains confirmation height (if confirmed)

Transaction Updated:

  • Transaction status changed
  • Example: RBF replacement
  • Contains updated data

Mempool Initialized:

  • Mempool monitoring started
  • Contains initial configuration

Mempool Monitoring Flow​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Mempool Monitoring Process β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Poll mempool (every ~10 seconds)
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Fetch mempool β”‚ Get list of transaction IDs
β”‚ transaction IDs β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Compare with β”‚ Find new transactions
β”‚ known txids β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Emit Transaction β”‚ For each new transaction
β”‚ Added event β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Load details β”‚ Fetch transaction data
β”‚ (if fee >= min) β”‚ (filtered by fee rate)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Emit Transaction β”‚ After details loaded
β”‚ Loaded event β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Track until β”‚ Monitor for confirmation
β”‚ confirmed/droppedβ”‚ or removal from mempool
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Configuration​

Enable mempool monitoring:

  • Disabled by default
  • Enable in configuration
  • Works only through RPC providers

Settings:

  • Sync strategy threshold
  • Minimum fee rate filter
  • Multiple provider URLs (optional)

See Mempool Monitoring documentation for detailed configuration.

Querying Mempool Model​

Through Transport APIs:

Get mempool statistics:

  • Total transactions tracked
  • Loaded transaction count
  • Synchronization status
  • Performance metrics

Get all transactions:

  • Filter by load status
  • Stream large datasets
  • Batch processing

Get transaction IDs:

  • With or without load info
  • Stream for large mempools

Check specific transaction:

  • Verify if in mempool
  • Get load status
  • Retrieve details

Using Mempool Events​

Subscribe to mempool events in your applications:

Track pending payments:

  • Detect incoming transactions
  • Show pending status in UI
  • Monitor until confirmed

Analyze fee market:

  • Track fee distributions
  • Calculate fee estimates
  • Monitor market changes

Build transaction tools:

  • Identify stuck transactions
  • Track replacements (RBF)
  • Monitor confirmation times

Use in custom models:

  • Subscribe to mempool events
  • Filter by your criteria
  • Maintain pending state
  • Update when confirmed

Performance Considerations​

Request volume:

  • Significantly higher than block processing
  • Multiple providers multiply requests
  • Monitor rate limits carefully

Memory usage:

  • Tracks many transactions in memory
  • Consider for large mempools
  • Filter with minimum fee rate

Event frequency:

  • High event rate during busy periods
  • Can be thousands of events per minute
  • Filter aggressively in your code

See Mempool Monitoring documentation for optimization strategies.

Using System Models​

In Your Applications​

Subscribe to events:

  • Network events for block monitoring
  • Mempool events for pending transactions
  • React to state changes

Query state:

  • Get current chain status
  • Check mempool statistics
  • Retrieve specific blocks or transactions

Build on top:

  • Use system events as triggers
  • Combine with your custom logic
  • Leverage validated data

In Custom Models​

Your custom models can use system model events:

React to network events:

  • Process blocks after validation
  • Handle reorganizations
  • Use validated chain data

React to mempool events:

  • Track pending transactions
  • Filter by your criteria
  • Maintain pending balances

Combine with custom logic:

  • Add business rules
  • Filter and transform
  • Store relevant data only

This gives complete control over how system data affects your business logic.

Best Practices​

Network Model​

Always available: Works automatically, no configuration needed

Subscribe to reorg events: For logging and monitoring

Don't store block data: Query from network model instead

Monitor chain validity: Alert if isValid becomes false

Mempool Model​

Enable only if needed: Increases costs and complexity

Filter aggressively: Don't process every transaction

Set appropriate fee threshold: Ignore very low-fee transactions

Monitor request volume: Much higher than block processing

Separate pending state: Keep mempool data separate from confirmed

Architecture Context​

System models integrate with all framework components:

Network Providers fetch data β†’ System Models process System Models generate events β†’ Event Store persists Transport exposes β†’ Clients query and subscribe Custom Models can use β†’ System Model events as triggers

System models provide foundation - you build business logic on top.