Currently, daimo-api implements an in-memory indexer. Every time the server starts, it loads history using getLogs() with retry and pagination. This should work fine while we have relatively few users and a short activity history.
Index Supply hosted E2PG (chain events to Postgres)
Ryan proposed following 3 options:
Daimo provisions a database and gives Index Supply tightly scoped user access to the database so that we can insert into a predetermined set of tables.
Daimo provisions a database and we configure logical replication so that Index Supply logically replicates data to Daimo’s database. Logical replication is really neat and would allow you to create your own pg indexes on the replicated tables and additionally you can also add columns to the replicated tables so that your app can do app specific things with the data.
Index Supply provisions a (potentially shared) database in your app’s region and provides a read only connection URL. The indexed data will be available < 100ms after the block is added to the chain. I’ve also seen really great performance from our EL/CL stack such that it receives blocks quicker than most public websites on the web.
Option 2 seems clean, so we're trying that first.
For evaluation, we'll just index testUSDC transfers via the standard erc20 integration.
Set up Shovel to populate all of those logs to PG tables
DC: say we read transfer logs for several tokens—USDC, bridged USDC across Base, Optimism, L1 for example. Would Shovel make 5 tables or 1 table with (chainId, contractAddr) columns? Ryan: 1 table. DC: ideal.
Filtering discussion. TLDR; can’t easily filter to just transfers affecting Daimo accounts. DB will be big. Ryan: RDS is best, DigitalOcean is cheapest & increasingly my choice.
DB discussion.
Conclusion: stick with Render DB for now, move to RDS if necessary.
Maintain invariants: all logs on a given chain caught up to same block.
New block arrives: all logs for that block have to be sent to pipeLogs listeners simultaneously. This ensures that the sync that Daimo apps see remains consistent.
Goal
Fast, scalable access to Daimo account history.
Stopgap
Currently,
daimo-api
implements an in-memory indexer. Every time the server starts, it loads history usinggetLogs()
with retry and pagination. This should work fine while we have relatively few users and a short activity history.Index Supply hosted E2PG (chain events to Postgres)
Ryan proposed following 3 options:
Option 2 seems clean, so we're trying that first.
For evaluation, we'll just index testUSDC transfers via the standard erc20 integration.
Next steps