Skip to content

Conversation

Seth-Schmidt
Copy link
Contributor

Fixes https://github.com/PowerLoom/product/issues/240

Checklist

  • My branch is up-to-date with upstream/main branch.
  • Everything works and tested for major version of Python/NodeJS/Go and above.
  • I ran pre-commit checks against my changes.
  • I've written tests against my changes and all the current present tests are passing.

Current behaviour

The application currently uses direct Ethereum client connections via ethclient.Client with custom retry logic implemented through the MustQuery function. Each contract call is wrapped in exponential backoff retry logic, and there's no centralized error handling or alerting system for RPC failures. The configuration only supports a single RPC URL via PROST_RPC_URL environment variable, limiting redundancy and fault tolerance.

New expected behaviour

The application now uses the go-rpc-helper library which provides:

  • Multiple RPC node support with automatic failover
  • Separate archive node configuration for historical queries
  • Built-in retry logic with exponential backoff
  • Webhook-based alerting system for RPC failures
  • Centralized RPC configuration and management
  • Better error handling and logging
  • Support for both regular and archive RPC nodes

Change logs

Added

  • Integration with github.com/powerloom/go-rpc-helper v1.0.1 library
  • Support for multiple RPC nodes via RPC_NODES environment variable (JSON array format)
  • Support for archive RPC nodes via ARCHIVE_RPC_NODES environment variable
  • Configurable retry parameters: RPC_MAX_RETRIES, RPC_RETRY_DELAY_MS, RPC_MAX_RETRY_DELAY_S, RPC_REQUEST_TIMEOUT_S
  • Webhook alerting configuration using existing SLACK_REPORTING_URL for RPC failures
  • ToRPCConfig() method in Settings struct to convert configuration to RPC helper format
  • getEnvInt() utility function for parsing integer environment variables
  • Enhanced debug logging for RPC connectivity and contract verification
  • Backward compatibility with existing PROST_RPC_URL environment variable

Changed

  • Replaced direct ethclient.Client usage with RPCHelper from go-rpc-helper library
  • Updated ConfigureClient() to initialize RPC helper instead of direct client connection
  • Modified LoadContractStateVariables() to use direct contract calls with better error handling
  • Updated block fetching in detector to use RPCHelper.BlockNumber() and RPCHelper.HeaderByNumber()
  • Modified event processing to use RPCHelper.FilterLogs() with built-in retry logic
  • Updated window manager to use RPC helper for block number queries
  • Enhanced contract state loading with extensive debugging and error reporting
  • Updated API service to use direct contract calls instead of MustQuery wrapper

Fixed

  • Improved error handling for contract calls with proper context propagation
  • Better RPC connection failure detection and reporting
  • Enhanced contract deployment verification with code existence checks
  • Fixed potential timeout issues by using RPC helper's built-in timeout handling

Removed

  • MustQuery function and its custom retry logic (replaced by RPC helper's built-in retry)
  • Direct HTTP client configuration with TLS settings (handled by RPC helper)
  • Manual exponential backoff implementation in event processing
  • MustQuery constant from constants.go (no longer needed)
  • Redundant retry logic in various contract interaction functions

Deployment Instructions

Environment Variable Updates Required:

  1. Replace single RPC URL with array format:

    • Old: PROST_RPC_URL=https://rpc.example.com
    • New: RPC_NODES=["https://rpc1.example.com", "https://rpc2.example.com"]
  2. Optional: Configure archive nodes:

    • Add: ARCHIVE_RPC_NODES=["https://archive1.example.com", "https://archive2.example.com"]
  3. Optional: Configure RPC retry parameters:

    • RPC_MAX_RETRIES=3 (default: 3)
    • RPC_RETRY_DELAY_MS=500 (default: 500)
    • RPC_MAX_RETRY_DELAY_S=30 (default: 30)
    • RPC_REQUEST_TIMEOUT_S=30 (default: 30)
  4. Webhook alerting (optional):

    • Ensure SLACK_REPORTING_URL is configured for RPC failure alerts

…nt variables for improved flexibility and backward compatibility
…events, and window manager for consistency and improved error handling
…introduce getEnvInt utility for improved environment variable handling
…g method for improved clarity and maintainability
…variable loading with direct calls to contract methods for improved error handling
…ions in processor and api for improved error handling and clarity
@Seth-Schmidt Seth-Schmidt self-assigned this Jul 7, 2025
@Seth-Schmidt Seth-Schmidt requested review from anomit and xadahiya July 7, 2025 23:04
Copy link
Member

@anomit anomit left a comment

Choose a reason for hiding this comment

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

Deployed and operational on devnet sequencer against the master branch of rpc helper

@anomit anomit merged commit 08eac81 into main Jul 31, 2025
1 check passed
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