graphprotocol / graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
https://thegraph.com
Apache License 2.0
2.92k stars 980 forks source link

Do not repeat a rollup after restart in some corner cases #5675

Closed lutter closed 1 month ago

lutter commented 1 month ago

When graph-node is restarted, we need to determine for subgraphs with aggregations when the last rollup was triggered to ensure aggregations get filled without gaps or duplication.

The code used the block_time column in the PoI table for that but that is not correct as the PoI table only records blocks and times for which the subgraph actually has writes. When the subgraph scans through a largish number of blocks without changes, we only update the head pointer but also do rollups as aggregation intervals pass. Because of that, we might perform a rollup without a corresponding entry in the PoI table.

With this change, we actually find the maximum timestamp from all aggregation tables to tell us when the last rollup was triggered as that data reflects when rollups happened accurately.

For safety, this new behavior can be turned off by setting GRAPH_STORE_LAST_ROLLUP_FROM_POI=true to return to the old buggy behavior in case the new behavior causes some other unexpected problems.

Fixes https://github.com/graphprotocol/graph-node/issues/5530