Skip to content

headerprotocol/indexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ HeaderProtocol: Event Indexer Service


πŸ“š Table of Contents


Overview

The HeaderProtocol Event Indexer listens to blockchain events for requested block headers, responses, commits, and refunds. It efficiently organizes this data, enabling πŸ”Ž fast lookups and πŸ›  incremental updates, even when new events arrive long after the initial request.


Key Features

  1. πŸ—ƒ Granular Storage
    Each argsBlockNumber is stored in its own file, making lookups and updates lightning-fast πŸš€.

  2. πŸ“ Instant Lookup via map.json
    map.json provides an O(1) lookup from argsBlockNumber to its corresponding date directory, simplifying file access.

  3. πŸ“¦ Commit Event Standardization

    • If commit is the only event for a block, it remains standalone.
    • If other events are added, the commit data is replicated in all event entries for the block, ensuring consistent structure.
  4. πŸ“œ Update History
    history.json maintains a chronological log of updates, so you can process only the latest changes.

  5. πŸ“Š Aggregated Snapshots
    Aggregates are rebuilt at πŸ“… daily, πŸ—“ monthly, and πŸ“† yearly levels for streamlined access to analytics.


Directory Structure

πŸ“‚ data/<network>/
β”œβ”€β”€ πŸ—‚ map.json           # πŸ—Ί Maps argsBlockNumber β†’ "YYYY/MM/DD"
β”œβ”€β”€ πŸ—‚ history.json       # πŸ“œ Chronological record of updates
β”œβ”€β”€ πŸ“‚ YYYY/              # πŸ“† Yearly directory
β”‚   β”œβ”€β”€ πŸ“‚ MM/            # πŸ—“ Monthly directory
β”‚   β”‚   β”œβ”€β”€ πŸ“‚ DD/        # πŸ“… Daily directory
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ—‚ [blockNumber].json  # πŸ—ƒ Events for blockNumber
β”‚   β”‚   β”‚   └── πŸ—‚ index.json         # πŸ“Š Daily aggregated data
β”‚   β”‚   └── πŸ—‚ index.json             # πŸ“Š Monthly aggregated data
β”‚   └── πŸ—‚ index.json                 # πŸ“Š Yearly aggregated data

Data Structure

Example [blockNumber].json:

[
  {
    "chainId": "31337",
    "blockNumber": "20",
    "headerIndex": "9",
    "createdAt": "2024-12-20T19:28:42.156Z",
    "updatedAt": "2024-12-20T19:28:42.157Z",
    "request": { "rewardAmount": "0", ... },
    "responses": [ { "responder": "0xf39Fd6...", ... } ],
    "commit": { "blockNumber": "27", ... }
  }
]

Usage in a Client Interface

Quick Lookup πŸš€

  1. Use map.json to find the directory path for argsBlockNumber:
    { "1000000": "2024/12/20" }
  2. Retrieve the file at data/<network>/2024/12/20/1000000.json.

βš™οΈ Running the Indexer

  1. Install Dependencies:

    npm install
  2. Run Anvil:

    anvil
  3. Deploy and Indexer HeaderProtocol:

    sudo bash ./src/anvil.sh
  4. Verify Outputs:

    • βœ… map.json: Lookup table.
    • βœ… history.json: Update logs.
    • βœ… [blockNumber].json: Event data.
    • βœ… Aggregated index.json files for analytics.

Diagrams

Sequence Diagram: How the Indexer Works

sequenceDiagram
    participant Client
    participant Indexer
    participant Blockchain
    participant Storage

    Client->>Indexer: Request indexing for block headers
    Indexer->>Blockchain: Listen for events (request, response, commit)
    Blockchain-->>Indexer: Emit events
    Indexer->>Storage: Write `argsBlockNumber.json`
    Indexer->>Storage: Update `map.json` and `history.json`
    Storage-->>Client: Return updated JSON files
Loading

About

🧒 headerprotocol blockchain indexer.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •