chains:
- chain_id: 1
get_logs_range: 500
get_block_batch_amount: 1
store_concurrency: 100
concurrency_threshold: 50000
livefill_threshold: 300
livefill_range: 200
livefill_flush_interval: 10000
confirmations: 200
contracts:
- address: 0xAf41a65F786339e7911F4acDAD6BD49426F2Dc6b
start_block: 18646320
```
## Understanding the Scribe Indexer
The Scribe indexer is composed of three components
1. `Fetcher`: Takes a list of contracts, a block range, and fetches and feeds logs into a channel to be consumed by an indexer.
2. `Indexer`: Takes a list of contracts, a block range, and a config and stores logs, receipts, and txs for all events in that range.
3. `ChainIndexer`: Runs 2+ indexers per chain.
1. 1 indexer for each contract behind the specified livefill threshold (backfill)
2. 1 indexer for every contract within the specified livefill threshold (livefill)
3. 1 indexer for every contract within the specified "unconfirmed" range at the chain tip. (unconfirmed livefill)
### Chain level flow
1. Scribe initializes with config
2. Each chain has a `ChainIndexer` spun up and runs it in a go routine
3. The `ChainIndexer` checks all contracts for their `lastIndexed` block. Contracts without a `lastIndexed` or with a `lastIndexed` block outside the
specified livefill block range are put into individual indexers (backfill). All other contracts are collected into a single indexer (livefill).
4. A contract in an individual indexer (backfill) reaches the livefill threshold, it is passed into a channel where it will be picked up by the go routine running the
indexer for the livefill contracts.
5. While contracts are being livefilled, there is another indexer with all contracts listed on the given chain. This indexer is used to livefill the unconfirmed range at the chain tip. This range is set by the config
and stores data in separate tables than the other indexers. This table has stale rows (old rows) deleted every few hours (set in config).
### Indexer level flow
1. `Indexer` is initialized with config and a list of contracts
2. `Indexer` is started with a block range
3. The indexer creates a `Fetcher` that feeds logs into a channel that is then consumed by the indexer. The fetcher retrieves logs in chunks specified in the config
(`get_logs_range` and `get_logs_batch_amount`).
4. When a new log is retrieved the indexer gets the tx, block header (timestamp), and receipt (and all of its logs) for that log and the stores them in the database. Depending on the concurrency
settings, Scribe will spin up multiple concurrent processes for retrieving this data and storing. It is recommended that concurrency (`concurrency_threshold`) is set to at least a couple hours
from the head to ensure that data is inserted into the database in order (if streaming).
5. The indexer will continue to fetch and store data until it reaches the end of the block range.
### Directory Structure
Scribe
├── api: Contains the Swagger API definition and GQL Client tests.
├── backend: The backend implementation for Scribe
├── client: Client implementation for Scribe (embedded/remote)
├── cmd: The command line interface functions for running Scribe and GraphQL server
├── config: Configuration files for Scribe
├── db: The database schema and functions for interacting with the database
├── graphql: GraphQL implementation for Scribe's recorded data
│ ├── client: The client interface for the GraphQL server
│ ├── contrib: The GraphQL generators for Scribe
│ └── server: The server implementation for GraphQL
│ └── graph: The server's models, resolvers, and schemas
├── grpc: The gRPC client implementation for Scribe
├── internal: Internal packages for Scribe
├── logger: Handles logging for various events in Scribe.
├── metadata: Provides metadata for building .
├── scripts: Scripts for Scribe
├── service: Service holds Scribe indexer code (Fetcher, Indexer, ChainIndexer)
├── testhelper: Assists testing in downstream services.
├── testutil: Test utilities suite for Scribe
└── types: Holds various custom types for Scribe
### Schema
The schema for each table in the database can be found at db/datastore/sql/base
## Regenerating protobuf definitions:
`make generate`