Open-source project
OdyseeTeam/chainquery avatar
OdyseeTeam/chainquery

Chainquery copies the LBRY chain into MySQL, and its public /api/sql endpoint takes any query string

Chainquery parses and syncs the LBRY blockchain data into structured SQL

2,202 stars36 forksGoMIT

At a glance

What is it?
Chainquery is a Go daemon that reads LBRY blocks from lbcd or lbrycrd, writes them into MySQL tables, and serves an HTTP API from the same binary. This article covers how it orders blocks, handles reorgs, schedules jobs, and where the API leaves work to the operator.
Who is it for?
Run Chainquery if you operate LBRY infrastructure and want claims, channels, supports and address balances in MySQL tables you can join with plain SQL. Skip it if you need a stable, versioned HTTP API, since the Swagger docs are marked work in progress.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 87 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • OdyseeTeam/chainquery2,202 ★ · -4
Star history
Repository2026-10-082026-11-26
OdyseeTeam/chainquery2.2k2.2k

-4 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

One binary starts both the block daemon and the API server

Chainquery reads the LBRY blockchain into a MySQL database so blocks, transactions, addresses and the claim system (channels, publishes, supports, tips and purchases, tags) can be queried with SQL instead of walking the chain over RPC. It connects to a full node over JSON-RPC. The production node is lbcd, LBRY's Go implementation, and the original lbrycrd also works.

Everything starts from one command, chainquery serve, which launches the API server and the daemon together:

bash
chainquery serve

There are four logical parts inside that one process: the daemon that ingests blocks, the API server, a job scheduler for derived data, and an upgrade manager. Splitting the API into its own process is not something the project describes. The API does use a separate read DSN, apimysqldsn, so queries from callers can be pointed at a different MySQL account or replica than the writer uses. The module is Go, builds against go 1.26 with toolchain go1.26.4, and is licensed MIT. The homepage field points at lbry.tech.

The project lives under the OdyseeTeam organisation, while the module path in go.mod and the badges in the project's introduction still say lbryio. If you import packages or follow links, expect both names.

Block N+1 never starts before block N is committed

The daemon, in daemon/daemon.go and daemon/processing/, asks the node for its current height on each iteration and processes every block above the last height stored in the database. Blocks go strictly in order. A channel handshake between blockQueue and blockProcessedChan, plus a global BlockLock mutex, guarantees that the next block cannot begin until the previous one is committed. Out-of-order processing panics by design, so a bug that breaks ordering stops the daemon instead of writing a corrupted table.

The cost of that rule is that block throughput is bounded by how fast one block can be fully written. Four processing modes set a throttle through daemonmode: beast (0) with no delay, slow-and-steady (1) at 100ms per block, delay (2) with a configurable pause, and daemon (3), which handles one block per daemon iteration. A first sync from genesis wants beast mode. A box that shares a MySQL server with other workloads may want one of the slower modes so the sync does not starve everything else.

The entry points to read first are daemonIteration(), processing.RunBlockProcessing(stopper, height) and processing.ProcessTx(...).

Transactions inside a block run in parallel and retry until their parents exist

Within one block, transactions are not ordered. A worker pool drains a job queue, sized by maxparalleltxprocessing, which defaults to the CPU count. That creates a real problem: a transaction can spend an output created by another transaction in the same block, and the spender may be processed first.

Chainquery answers with a redo queue. A failed transaction is pushed back and retried, up to maxfailures times, with a default of 1000. To reduce the retries, transactions are pre-sorted by dependency depth in optimizeOrderToProcess, so parents tend to run before children. The word tend matters, because the sort does not remove the need for the redo queue.

For operators this has two consequences. The log can show failed transactions in a healthy sync, because a retry is the designed path for in-block dependencies. And if a transaction fails 1000 times, the daemon has a ceiling on how long it will keep trying, so maxfailures is the setting to look at when a block refuses to complete. Nothing in the project text covers what the daemon does after the limit is exhausted, so check daemon/processing/ before running with a lower value.

Reorgs delete up to 100 blocks and reprocess from the divergence point

Before processing a block, the daemon compares the previous-block hash it stored with the hash on the chain. On a mismatch it recursively deletes the diverged blocks, up to a depth of 100, logs the reorg depth, and reprocesses from the height where the chains split.

Two details follow from that description. The delete is recursive, so every table keyed to those blocks (transactions, inputs, outputs) is part of the cleanup, and a deep reorg is a heavy write. And the limit of 100 is explicit: a divergence deeper than that is outside what the automatic path is documented to repair. LBRY reorgs of that size are not mentioned in the project's text, so this is a boundary to know, not a frequent event.

Anyone reading Chainquery data while it syncs should accept that rows can disappear. A client that caches a block hash or a transaction id from /api/sql may see it vanish after a reorg, and nothing in the table schema marks a row as provisional. The upgrade manager and the Mempool Sync job deal with other kinds of change, and neither is a substitute for waiting several confirmations before trusting a result.

Anyone can call /api/sql, and the guard is a timeout, not authentication

The API server binds to apihostport, default 0.0.0.0:6300, so by default it listens on every interface. Its routes split into open and keyed. Open endpoints are /api/ (returns Hello World!), /api/sql, /api/addresssummary, /api/status (table names and sizes) and /api/validate. Keyed endpoints are /api/process (a block or range of blocks), /api/sync/name, /api/sync/addresses and /api/sync/txvalues. Those four are rejected unless the supplied Key appears in the apikeys config, and an empty apikeys list, the default, disables them entirely.

/api/sql is the unusual one. It is described as public read-only SQL: it runs the query parameter against MySQL, injects MAX_EXECUTION_TIME, and caps the run at maxsqlapitimeout. That bounds how long a single statement runs. It does not say how many statements can run at once, and the project does not describe rate limiting. If the endpoint faces the internet, put a proxy with limits in front of it and give apimysqldsn an account that has SELECT privileges only.

/metrics serves Prometheus data under basic auth, guarded by promuser and prompass when those are set. Leaving them unset leaves the route unprotected, so set both before exposing the port.

Eight scheduled jobs fill in what the raw chain does not contain

Periodic jobs in daemon/jobs/, registered in initJobs(), compute data that is not part of the raw blockchain or that is cheaper to precompute. Claimtrie Sync runs every 15 minutes and pulls claim status and effective amount from lbrycrd's ClaimTrie. Mempool Sync runs every second for unconfirmed transactions. Certificate Sync and Chain Sync both run every 5 seconds, for channel data and chain-derived data. A code note says Chain Sync must finish in under 2.5 minutes.

Four more run every 24 hours: Validate Chain for integrity, Address Balance Sync, Transaction Value Sync, and Claim Count in Channel. The job_status table records each job's last run, which is the first place to look when a balance or a channel's claim count looks stale.

Any job can also be run once from the command line with chainquery run followed by the job name, which is how you repair a single derived table without restarting the daemon. The Claimtrie Sync entry is the one that pushes against the node choice: it reads from lbrycrd's ClaimTrie, while the introduction names lbcd as the node used in production. The project text does not explain how the claim data reaches the job on lbcd, so check which node your deployment talks to before relying on claim status columns.

The schema is generated, and the notification settings are only partly shown

The data model is the basic chain types, block, transaction, input, output and address, plus the LBRY tables: claim, support, purchase, tag, claim_tag, claim_in_list and abnormal_claim. Two bookkeeping tables, job_status and application_status, sit beside them. Models under model/ are generated by SQLBoiler, configured by sqlboiler.toml, and the reference schema is db/chainquery_schema.sql. The upgrade manager in daemon/upgrademanager/ runs data and schema upgrade scripts on startup, using application_status to track app, data and API versions.

A practical result is that hand-editing a model file does not hold: regenerate it from the schema. Another is that startup is not read-only. Upgrading the binary can rewrite data before the API answers.

Notifications are a fixed set. Sockety, set through socketyurl and socketytoken, sends a new_block message for each processed block. Subscribers in config are webhook URLs for payment and new_claim events. Slack uses slackbottoken, slackchannel and slackloglevel. Further Slack options and the rest of the CLI documentation are not covered here.

The Swagger documentation is labelled work in progress at lbryio.github.io/chainquery, with the spec in swagger/apiserver/api/swagger.yaml. Releases show v2.6.0 on 12 June 2026, after v2.5.4 and v2.5.3 on 26 October 2020. The last push was on 31 August 2026, and the repository is not archived.

Editorial conclusion

Run Chainquery if you operate LBRY infrastructure and want claims, channels, supports and address balances in MySQL tables you can join with plain SQL. Skip it if you need a stable, versioned HTTP API, since the Swagger docs are marked work in progress. Before exposing it, decide what you put behind /api/sql and /metrics, and confirm whether your node is lbcd or lbrycrd, because the daemon talks to either one over JSON-RPC.

Frequently asked questions

What does Chainquery do?

Chainquery reads LBRY blocks from a full node and writes them into MySQL, including claims, channels, supports and tags. It also serves an HTTP API with a public read-only SQL endpoint.

Does Chainquery work with lbcd or lbrycrd?

It connects over JSON-RPC to either node. lbcd, LBRY's Go implementation, is the one named for production, and the original lbrycrd is also supported.

How do I run Chainquery?

Run the single binary with chainquery serve, which starts the API server and the block daemon together. Individual jobs can be run once with chainquery run followed by the job name.

Official sources

  1. License: MIT
  2. OdyseeTeam/chainquery on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/odyseeteam-chainquery.svg)](https://hysenlabs.com/projects/odyseeteam-chainquery)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/odyseeteam-chainquery.svg)](https://hysenlabs.com/projects/odyseeteam-chainquery)

Was this useful?