Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restart bug with dynamic contracts #258

Merged
merged 1 commit into from
Oct 10, 2024
Merged

Conversation

JonoPrest
Copy link
Collaborator

Dynamic contract restart resistance has been broken since we removed raw_events being required.

  • Fixes the query that gets dynamic contract registrations on restart
  • Adds test to assert the behaviour of a restart

Comment on lines -425 to -429
SELECT c.contract_address, c.contract_type, c.event_id, c.chain_id, c.block_timestamp
FROM "public"."dynamic_contract_registry" as c
JOIN raw_events e ON c.chain_id = e.chain_id
AND c.event_id = e.event_id
WHERE e.block_number <= ${block_number} AND e.chain_id = ${chainId};`;
Copy link
Collaborator Author

@JonoPrest JonoPrest Oct 10, 2024

Choose a reason for hiding this comment

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

There was a dependency on raw_events table for this start up query and raw_events became opt in from v2. So it's typically empty for most indexers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I got to you so it would lose those dynamic contracts on restart.

Comment on lines +420 to +427
module.exports.readDynamicContractsOnChainIdBeforeEventId = (
sql,
chainId,
block_number,
eventId,
) => sql`
SELECT c.contract_address, c.contract_type, c.event_id, c.chain_id, c.block_timestamp
FROM "public"."dynamic_contract_registry" as c
JOIN raw_events e ON c.chain_id = e.chain_id
AND c.event_id = e.event_id
WHERE e.block_number <= ${block_number} AND e.chain_id = ${chainId};`;
SELECT *
FROM "public"."dynamic_contract_registry"
WHERE event_id < ${eventId} AND chain_id = ${chainId};`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now I construct the eventId of the next block and filter for anything below that ID so you end up with the desired effect

Copy link
Contributor

@JasoonS JasoonS left a comment

Choose a reason for hiding this comment

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

Cool, it makes sense I haven't run it but the SQL query definitely looks much better being simplified like that 👍

@JonoPrest JonoPrest merged commit a13a0fb into main Oct 10, 2024
1 check passed
@JonoPrest JonoPrest deleted the jp/fix-restart-registration branch October 10, 2024 10:34
@JonoPrest
Copy link
Collaborator Author

Cool, it makes sense I haven't run it but the SQL query definitely looks much better being simplified like that 👍

The SQL gets run and validated in the test when it calls makeFromDbState

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.

2 participants