Fix possible duplicate key violation on constraint "hive_notification_cache_pkey" in live sync
There's the following check early in `Blocks._process` function:
```
if cls._head_block_date is None:
cls._head_block_date = cls._current_block_date
```
Then `cls._head_block_date` is passed to indexer classes as `block_date`.
The issue is that after breaking live sync and restarting,
`cls._head_block_date` is not set, which results in it being set to
`cls._current_block_date`, which violates the comment.
This means that the first block to be processed after breaking sync will
have block date set to its block time, which is not correct.
But then, the following block will have its block date set to last imported
block. This is correct, but notice that both blocks were assigned the
same block date, which then resulted in duplicated notification cache
key.
To fix the issue, `cls._head_block_date` needs to be correctly set after
restart. The code already did this in `__init__`, but the method was
never called, because `Blocks` is not used as a class, all methods are
class methods.
This change drops `__init__` entirely and moves its code to `setup`,
which is called by `SyncHiveDb`.
Loading
Please sign in to comment