apibara/dna

Leverage transactional features to invalidate + update pending data

fracek opened this issue · 2 comments

Is your feature request related to a problem? Please describe.

At the moment, data generated by pending blocks is first invalidated (delete) and then reinserted. This results in a fraction of a second when this data is missing.

Describe the solution you'd like

Invalidation + update should be done in the same db transaction (if the sink is a db).

  • Change the db trait to have a flag in handle_data that signals if the sink implementation should invalidate data before insertion
  • Change connector code to not invalidate data in between pending blocks (or between pending -> accepted), but signal this to the sink.

Describe alternatives you've considered

We could introduce the concept of transaction to the sink (e.g. a begin_txn, commit_txn method) and then have handle_data, handle_invalidate be methods on the transaction object. This is conceptually more correct, but it will introduce more complex types.

This issue has been automatically marked as stale because it has not had activity in the six months. It will be closed in 2 weeks if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant.

fracek commented

Another option is to add a replace_data method to the sink with a default implementation that calls handle_invalidate and handle_data, then specific implementations can override it to use transactions.