- π Overview
- β¨ Key Features
- π Directory Structure
- π Data Structure
- β‘οΈ Usage in a Client Interface
- βοΈ Running the Indexer
- π Diagrams
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.
-
π Granular Storage
EachargsBlockNumberis stored in its own file, making lookups and updates lightning-fast π. -
π Instant Lookup via
map.json
map.jsonprovides an O(1) lookup fromargsBlockNumberto its corresponding date directory, simplifying file access. -
π¦ Commit Event Standardization
- If
commitis the only event for a block, it remains standalone. - If other events are added, the
commitdata is replicated in all event entries for the block, ensuring consistent structure.
- If
-
π Update History
history.jsonmaintains a chronological log of updates, so you can process only the latest changes. -
π Aggregated Snapshots
Aggregates are rebuilt at π daily, π monthly, and π yearly levels for streamlined access to analytics.
π 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
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", ... }
}
]- Use
map.jsonto find the directory path forargsBlockNumber:{ "1000000": "2024/12/20" } - Retrieve the file at
data/<network>/2024/12/20/1000000.json.
-
Install Dependencies:
npm install
-
Run Anvil:
anvil
-
Deploy and Indexer HeaderProtocol:
sudo bash ./src/anvil.sh
-
Verify Outputs:
- β
map.json: Lookup table. - β
history.json: Update logs. - β
[blockNumber].json: Event data. - β
Aggregated
index.jsonfiles for analytics.
- β
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
