indexsupply / shovel

An Ethereum to Postgres indexer
https://indexsupply.com/shovel
MIT License
172 stars 22 forks source link

shovel/schema: add latest view query #232

Closed ryandotsmith closed 8 months ago

ryandotsmith commented 8 months ago

Adds 'shovel.latest' view to schema. This is considered a public view that shovel users can query to see where shovel is in the chain.

This view first finds the latest block height of each src/integration pair. It is possible that the src/integration pairs are different even though they get their data from the same source. This is because a task runs exactly 1 integration and tasks are run concurrently.

To account for this, the latest query selects the min(num) across src/integration paris. However, to account for the fact that a particular integration may be "backfilling" we adjust the query so that it only considers src/integration pairs that are within 10 blocks of the most up-to-date src/integration.

Consequently, shovel.latest doesn't always produce a monotonically increasing sequence. As a backfilling integration comes close to the rest of the integrations, the number reported by latest may decrease compared to a prior call. But this will only happen as the backfilling integration approaches the rest of the integrations. Eventually, the query should go back to an increasing sequence.

Callers need to handle a temporarily decreasing sequence.