icon-project / centralized-relay

Fault tolerant Relayer.
Apache License 2.0
6 stars 4 forks source link

Implement redundant listener. #308

Closed debendraoli closed 5 days ago

debendraoli commented 3 months ago

This will help to counter missed events.

---
title: Relayer Redundancy
---
flowchart TD
    A[Start] --> B(Starup tasks)
    B --> C(Poller) --> H
    B --> D{Listener}
    D --> | Subscription | E[RPC-1]
    D --> | Subscription | F[RPC-2]
    D --> | Subscription | G[RPC-3]
    E & F --> H[Events]
    G --x H
    G --> | Reconnect | D
    H --> | Process | I(RPCs) <--> | Healthy? | J(Execute Queue)
    D --> | No subs? | C
bcsainju commented 3 months ago

Different Fetching Strategies

Provides multiple strategies to chhose from for any chains (Currently only implemented for evm chains)

Framework Changes

Height Sync

Strategies Implemented:

Fetching Strategies

1. Websocket

flowchart TD
    A[Relayer] -->|Load Configs| C(Start)    
    C -->|Ws| D[Listen to events via websockets]
    C -->|poll| E[sync missing blocks]

2. RPC poll

flowchart TD
    A[Relayer] -->|Load Configs| C(Start)    
    C -->|poll| E[sync blocks every x seconds]

Redundancy Strategies

Redundancy strategies are only applicable for websocket fetching strategy and not for the RPC poll as the poll is costly,slower but deterministic.

1. rpc-verify

flowchart TD
    A[Relayer] -->|Load Configs| C(Start)    
    C -->|Ws| D[Listen to events via websockets]
    C -->|poll| E[sync missing blocks]
    D -->|rpc-verify| X{ws events?}
    X --> |Yes| Y[do nothing]
    X --> |No| Z{verify with rpc if \n events are empty}
    Z --> |yes| M[return]
    Z --> |no| N[process events\nreset ws]
    N --> D

2. WsRedundancy

flowchart TD
    A[Relayer] -->|Load Configs| C(Start)    
    C -->|Ws| D[Listen to events via websockets]
    C -->|Ws| E[Listen to events via websockets]
    C -->|Ws| F[Listen to events via websockets]
    D --> |event| G[internal channel]
    E --> |event| G[internal channel]
    F --> |event| G[internal channel]
    C -->|poll| Z[sync missing blocks]

    G --> H{quorum reached ??}
    H --> |No| I[add to cache \n increment counter]
    H --> |yes| J[Forward to main relayer channel\nreset counter]