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
Each argsBlockNumber
is stored in its own file, making lookups and updates lightning-fast ๐.
๐ Instant Lookup via map.json
map.json
provides an O(1) lookup from argsBlockNumber
to its corresponding date directory, simplifying file access.
๐ฆ Commit Event Standardization
commit
is the only event for a block, it remains standalone.commit
data is replicated in all event entries for the block, ensuring consistent structure.๐ Update History
history.json
maintains 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", ... }
}
]
map.json
to find the directory path for argsBlockNumber
:
{ "1000000": "2024/12/20" }
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.index.json
files 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