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

Dynamic Contract Pre Registration #252

Merged
merged 12 commits into from
Oct 11, 2024
Merged

Conversation

JonoPrest
Copy link
Collaborator

@JonoPrest JonoPrest commented Oct 4, 2024

Implements Dynamic Contract Preregistration

  • Adds separate start up process for only fetching events from contractRegister functions configured for pre registration
  • Adds indexer restart resistance
  • Implemented ONLY for HyperSync indexers currently (should not be much work to implement for fuel and RPC)
  • Adds a TUI representation for pre registration

Before this gets merged for a release, we need to validate how the change affects the hosted service UI since events sync state table has been updated

Base automatically changed from release-concurrent-partitions to main October 7, 2024 08:58
@JonoPrest JonoPrest marked this pull request as ready for review October 8, 2024 14:06
@JonoPrest JonoPrest requested a review from JasoonS October 8, 2024 14:06
@JonoPrest
Copy link
Collaborator Author

It doesn't break anything on the hosted service. Will need to adapt the UI a bit to represent the pre registration step.

}

@genType
type eventConfig<'eventFilter> = {
wildcard?: bool,
eventFilters?: SingleOrMultiple.t<'eventFilter>,
preRegister?: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
preRegister?: bool,
shouldPreRegisterDynamicContracts?: bool,

(and everywhere else)

I think it is good to have consistent naming on this. I assume you want it to be less verbose in the config and more verbose in the code. Maybe then we just use preregister everywhere instead of the longer variable. I don't think it is unclear to just be preRegister

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO I prefer the verbose naming since it's quite an esoteric feature.

The shortened version I just used for the user API since I don't think they should have such a verbose flag. In the same way, we use isWildcard for our internal config everywhere but for the user API it's simply wildcard

I would be open to renaming the the user facing config flag but would prefer to keep the verbose name everywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, maybe middle ground - preRegisterDynamicContracts everywhere?

I don't really agree that the variable will be confusing, especially since the variable comes from the user's handlers and will be in our box, etc., but I think we can make it more descriptive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JasoonS for the user API we have Contract.Event.contractRegister so maybe even preRegisterContracts I was thinking?

Still prefer verbose naming with "should" or "is" prefix in internal code to imply boolean type.

@@ -316,7 +317,12 @@ module Make = (
)

//Instantiate each time to add new registered contract addresses
let recieptsSelection = getRecieptsSelection(~contractAddressMapping, ~shouldApplyWildcards)
let recieptsSelection = if isPreRegisteringDynamicContracts {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, is there no way to catch this at codegen time? I guess the user will get notified as soon as it starts. So, fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm - it is temprorary too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No since the config is set with the js API

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, I think the only real thing is to change the variable to pre-register everywhere, even internally. The code seems really good. I didn't notice any bugs or anything.

It is quite a bit to follow though, so I don't fully trust myself to have caught bugs - but I think we can start testing it in the wild.

@@ -810,7 +965,6 @@ let injectedTaskReducer = (
//On the first time we enter the reorg threshold, copy all entities to entity history
//And set the isInReorgThreshold isInReorgThreshold state to true
dispatchAction(SetIsInReorgThreshold(true))
//TODO: persist the isInReorgThreshold state to the db in a transaction with copy
Copy link
Contributor

Choose a reason for hiding this comment

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

Just removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's implemented 👍🏼

codegenerator/cli/templates/static/codegen/src/Config.res Outdated Show resolved Hide resolved
@@ -130,7 +134,7 @@ let make = (~chainData: chainData) => {
loaded={latestProcessedBlock - firstEventBlockNumber}
buffered={latestFetchedBlockNumber - firstEventBlockNumber}
outOf={toBlock - firstEventBlockNumber}
loadingColor=Secondary
loadingColor={isPreRegisteringDynamicContracts ? Primary : Secondary}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

@@ -41,6 +41,22 @@ type chainConfig = {
chainWorker: module(ChainWorker.S),
}

let shouldPreRegisterDynamicContracts = (chainConfig: chainConfig) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function name is fine, but then change the variable to just preRegister (as the user sees it)

@JonoPrest JonoPrest merged commit 2ef29c7 into main Oct 11, 2024
1 check passed
@JonoPrest JonoPrest deleted the jp/contract-preregistration branch October 11, 2024 11:44
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