Skip to content

Tropykus/troubleshooting-rabby

Repository files navigation

Load Monitor

A TypeScript Node.js monitoring tool for RSK (Rootstock) blockchain nodes and Tropykus DeFi protocol markets. Continuously monitors block synchronization, market data consistency, and provider performance across multiple RPC endpoints.

Features

  • βœ… Multi-Provider Monitoring - Tracks 4 providers: Public Node, Alchemy, Tropykus, Rabby
  • βœ… Block Number Sync - Detects when providers are out of sync
  • βœ… Market Data Validation - Compares 10 market metrics across all providers
  • βœ… Inconsistency Detection - Automatically flags when providers disagree
  • βœ… Performance Tracking - Records response times for every request
  • βœ… Database Integration - Stores all data in Supabase for historical analysis
  • βœ… Error Tracking - Captures and logs all provider failures
  • βœ… 24/7 Operation - Runs continuously with graceful shutdown handling

Quick Start

Prerequisites

  • Node.js 18+ installed
  • Supabase account (free tier works)
  • (Optional) Render account for cloud deployment

Local Setup

  1. Clone and install

    git clone <your-repo-url>
    cd node-load-monitor
    npm install
  2. Set up Supabase

    • Create project at https://app.supabase.com
    • Run migration: supabase/migrations/001_initial_schema.sql
    • Disable RLS: DISABLE_RLS.sql
  3. Configure environment

    cp .env.example .env
    # Edit .env with your Supabase credentials
  4. Run locally

    npm run dev  # Development with auto-reload
    npm run build && npm start  # Production build
  5. Verify it works

    • Check console for: [Database] Created monitoring run: ...
    • Check Supabase tables for new rows every 30 seconds

πŸ“– Detailed Setup: See DATABASE_SETUP.md

Deployment to Render

Deploy to Render for 24/7 cloud monitoring:

# 1. Push to GitHub
git add .
git commit -m "Initial commit"
git push origin main

# 2. Follow deployment guide

πŸ“– Full Deployment Guide: See RENDER_DEPLOYMENT.md

Project Structure

β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts          # Main monitoring logic
β”‚   β”œβ”€β”€ database.ts       # Supabase client and helpers
β”‚   β”œβ”€β”€ constants.ts      # RPC endpoints and configuration
β”‚   β”œβ”€β”€ types.ts          # TypeScript type definitions
β”‚   └── abis/             # Smart contract ABIs
β”œβ”€β”€ supabase/
β”‚   └── migrations/       # Database schema
β”œβ”€β”€ dist/                 # Compiled JavaScript (generated)
β”œβ”€β”€ render.yaml           # Render deployment config
β”œβ”€β”€ .env                  # Environment variables (not committed)
└── *.md                  # Documentation

How It Works

Every 30 seconds, the monitor:

  1. Fetches block numbers from all 4 providers via eth_blockNumber
  2. Queries market data (10 metrics) from the first active market
  3. Compares results across providers to detect inconsistencies
  4. Records everything to Supabase database
  5. Logs to console with timestamps and status indicators

Monitored Providers

Provider Type URL
Public Node RSK Public RPC https://public-node.rsk.co/
Alchemy Third-party RPC https://rootstock-mainnet.g.alchemy.com/...
Tropykus Tropykus-operated node https://rsknode-4.tropykus.com/rsk
Rabby Wallet API proxy https://app-api.rabby.io/...

Market Metrics Tracked

For each market (cToken contract):

  • balanceOfUnderlying - User's underlying balance
  • borrowBalanceStored - User's borrow balance
  • getCash - Available liquidity
  • decimals - Token decimals
  • exchangeRateStored - Current exchange rate
  • borrowRatePerBlock - Borrow APY
  • supplyRatePerBlock - Supply APY
  • totalBorrows - Total borrowed
  • totalSupply - Total supplied
  • totalReserves - Protocol reserves

Database Schema

Tables

  • monitoring_runs - Each 30-second cycle
  • block_number_checks - Block number results per provider
  • market_data_checks - Market data results per provider
  • data_inconsistencies - When providers disagree

Example Queries

-- Provider uptime (last 24h)
SELECT provider,
       COUNT(*) as total,
       SUM(CASE WHEN success THEN 1 ELSE 0 END) as successes,
       ROUND(100.0 * SUM(CASE WHEN success THEN 1 ELSE 0 END) / COUNT(*), 2) as uptime_percent
FROM block_number_checks
WHERE timestamp > NOW() - INTERVAL '24 hours'
GROUP BY provider;

-- Most common errors
SELECT provider, error_message, COUNT(*) as count
FROM market_data_checks
WHERE success = false
GROUP BY provider, error_message
ORDER BY count DESC
LIMIT 10;

πŸ“– More Queries: See DATABASE_SETUP.md

Scripts

Command Description
npm run dev Start with auto-reload (development)
npm run build Compile TypeScript to JavaScript
npm start Run compiled code (production)
npm test Run tests (not yet implemented)

Environment Variables

Variable Required Description
SUPABASE_URL Optional Supabase project URL
SUPABASE_KEY Optional Supabase anon key
NODE_ENV Optional production or development

Note: The monitor works without Supabase, but won't persist data.

Configuration

Change Monitoring Interval

Edit src/index.ts:

setInterval(runMonitoring, 30000);  // Change 30000 to desired milliseconds

Change Monitored Market

Edit src/index.ts:

const testMarket = activeMarkets[0];  // Change index or market address

Add/Remove Providers

Edit src/constants.ts to add new RPC endpoints, then update monitoring functions.

Troubleshooting

Issue Solution
"Database recording disabled" Set SUPABASE_URL and SUPABASE_KEY in .env, run npm install
No data in Supabase Run DISABLE_RLS.sql in Supabase SQL Editor
Build errors Run npm install to ensure all dependencies installed
TypeScript errors Delete dist/, node_modules/, run npm install && npm run build

πŸ“– Detailed Troubleshooting: See TROUBLESHOOTING.md

Documentation

Technology Stack

  • Language: TypeScript 5.9+
  • Runtime: Node.js
  • Blockchain: ethers.js v6 for RSK/Rootstock interactions
  • HTTP: axios for JSON-RPC calls
  • Database: Supabase (PostgreSQL)
  • Deployment: Render (Background Worker)

Development

Run Locally

# Development mode (auto-reloads on changes)
npm run dev

# Production mode
npm run build
npm start

Add New Metrics

  1. Update contract ABIs in src/abis/
  2. Add metric to fetchMarketInfoFromNode() in src/index.ts
  3. Update database schema in supabase/migrations/
  4. Add column to market_data_checks table

Code Quality

  • Strict TypeScript configuration
  • ESModuleInterop enabled
  • Source maps for debugging
  • Type declarations generated

Architecture

Core Flow

Initialize
  β”œβ”€> Fetch active markets from Unitroller
  └─> Filter deprecated markets

Every 30 seconds:
  β”œβ”€> Create monitoring run (database)
  β”œβ”€> Compare block numbers across all providers
  β”‚   β”œβ”€> Record each result
  β”‚   └─> Detect inconsistencies
  β”œβ”€> Test market info across all providers
  β”‚   β”œβ”€> Fetch 10 metrics per provider
  β”‚   β”œβ”€> Record each result
  β”‚   └─> Detect inconsistencies
  └─> Complete monitoring run with statistics

Error Handling

  • Non-blocking database writes (won't crash monitor)
  • Promise.allSettled() for parallel provider checks
  • Graceful degradation if Supabase unavailable
  • SIGINT/SIGTERM handlers for clean shutdown

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make changes and test locally
  4. Commit: git commit -m "Add feature"
  5. Push: git push origin feature-name
  6. Open a Pull Request

License

ISC

Support

Roadmap

  • Add HTTP health check endpoint
  • Implement alerting system (Slack/Discord webhooks)
  • Dashboard for real-time monitoring
  • Support for multiple markets simultaneously
  • Configurable monitoring intervals via env vars
  • Grafana integration for metrics visualization
  • Rate limiting detection and tracking

Acknowledgments

  • Built for Tropykus DeFi protocol monitoring
  • Uses RSK (Rootstock) blockchain infrastructure
  • Powered by Supabase for data persistence
  • Deployed on Render for reliable 24/7 operation

Made with ❀️ for reliable blockchain monitoring

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published