Skip to content

Fix indexer stopping fetching nested dynamic contract registrations on restart when a preRegistration is used - #411

Merged
DZakh merged 6 commits into
mainfrom
dz/fix-pre-registration-restart
Jan 10, 2025
Merged

Fix indexer stopping fetching nested dynamic contract registrations on restart when a preRegistration is used#411
DZakh merged 6 commits into
mainfrom
dz/fix-pre-registration-restart

Conversation

@DZakh

@DZakh DZakh commented Jan 9, 2025

Copy link
Copy Markdown
Member

Bug reproduction:

  1. Have an indexer with a preRegistering dynamic contract
  2. The preRegistering one should register a contract which registers another contract
  3. If we stop the indexer and start it again, the nested registered contract won't be indexing

Terminology:

  • dc - dynamic contract

The issue was caused by incorrect dc recovering logic when we have an event with preRegistration.
Without preRegistration we recover all dcs registered before or equal to the start block, while with preRegistration event this logic is changed to get all events with preRegistration and extract them from the db. Even though it sounds broken, but this worked in 95% of the usecases, besides when we got new dc registrations after preRegistration. It caused two bugs:

  1. If a dc contract is registered after preRegistration and NONE of its events have preRegistration enabled, it won't be loaded from db on the restart recovery
  2. If a dc contract is registered after preRegistration and SOME of its events have preRegistration enabled, in some cases it will be loaded from db even after the restart start block

To solve the problem:

  1. I've added the is_pre_registered flag to the dc entity in the db, so it's possible to correctly get all preRegistered dcs from db correctly for both 1 and 2 cases mentioned above.
  2. Fixed overwriting the dc in db when it's already registered. Wasn't really an issue before, besides wasted resources, but now it caused overwriting the is_pre_registered flag

Unrelated issue I solved:
If a single event registers multiple dcs with the same addresses, the duplicate wasn't detected correctly.

@DZakh DZakh changed the title Fix indexer stopping indexing nested dynamic registrations on restart when a preRegistration is used Fix indexer stopping fetching nested dynamic contract registrations on restart when a preRegistration is used Jan 9, 2025
@DZakh
DZakh requested a review from JasoonS January 9, 2025 14:55

@JasoonS JasoonS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

@DZakh
DZakh enabled auto-merge (squash) January 10, 2025 11:19
@DZakh
DZakh merged commit 391c94f into main Jan 10, 2025
@DZakh
DZakh deleted the dz/fix-pre-registration-restart branch January 10, 2025 11:28
@DenhamPreen

Copy link
Copy Markdown
Contributor

Great find and fix @DZakh 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants